Repository: hyperledger/firefly (go)

Issue:
New Event Types should be enriched
The following event types have been added to `event.go` and should be enriched:

```go
// EventTypePoolOpFailed occurs when a token pool creation initiated by this node has failed (based on feedback from connector)
EventTypePoolOpFailed = ffEnum("eventtype", "token_pool_op_failed")
// EventTypeBlockchainInvokeOpSucceeded occurs when a blockchain "invoke" request has succeeded
EventTypeBlockchainInvokeOpSucceeded = ffEnum("eventtype", "blockchain_invoke_op_succeeded")
// EventTypeBlockchainInvokeOpFailed occurs when a blockchain "invoke" request has failed
EventTypeBlockchainInvokeOpFailed = ffEnum("eventtype", "blockchain_invoke_op_failed")
```

Pull request description:
add additional event enrichment
 - TokenPoolOpFailed
 - BlockchainInvokeOpSucceeded
 - BlockchainInvokeOpFailed

closes #736 

Patch:
diff --git a/internal/txcommon/event_enrich.go b/internal/txcommon/event_enrich.go
index 4171dc924..c76a0912b 100644
--- a/internal/txcommon/event_enrich.go
+++ b/internal/txcommon/event_enrich.go
@@ -82,18 +82,24 @@ func (t *transactionHelper) EnrichEvent(ctx context.Context, event *fftypes.Even
 			return nil, err
 		}
 		e.TokenPool = tokenPool
-	case fftypes.EventTypeApprovalConfirmed, fftypes.EventTypeApprovalOpFailed:
+	case fftypes.EventTypeApprovalConfirmed:
 		approval, err := t.database.GetTokenApprovalByID(ctx, event.Reference)
 		if err != nil {
 			return nil, err
 		}
 		e.TokenApproval = approval
-	case fftypes.EventTypeTransferConfirmed, fftypes.EventTypeTransferOpFailed:
+	case fftypes.EventTypeTransferConfirmed:
 		transfer, err := t.database.GetTokenTransferByID(ctx, event.Reference)
 		if err != nil {
 			return nil, err
 		}
 		e.TokenTransfer = transfer
+	case fftypes.EventTypeApprovalOpFailed, fftypes.EventTypeTransferOpFailed, fftypes.EventTypeBlockchainInvokeOpFailed, fftypes.EventTypePoolOpFailed, fftypes.EventTypeBlockchainInvokeOpSucceeded:
+		operation, err := t.database.GetOperationByID(ctx, event.Reference)
+		if err != nil {
+			return nil, err
+		}
+		e.Operation = operation
 	}
 	return e, nil
 }
diff --git a/pkg/fftypes/event.go b/pkg/fftypes/event.go
index f4d3aebe5..8101e600a 100644
--- a/pkg/fftypes/event.go
+++ b/pkg/fftypes/event.go
@@ -86,6 +86,7 @@ type EnrichedEvent struct {
 	TokenPool         *TokenPool       `ffstruct:"EnrichedEvent" json:"tokenPool,omitempty"`
 	TokenTransfer     *TokenTransfer   `ffstruct:"EnrichedEvent" json:"tokenTransfer,omitempty"`
 	Transaction       *Transaction     `ffstruct:"EnrichedEvent" json:"transaction,omitempty"`
+	Operation         *Operation       `ffstruct:"EnrichedEvent" json:"operation,omitempty"`
 }
 
 // EventDelivery adds the referred object to an event, as well as details of the subscription that caused the event to


Test patch:
diff --git a/internal/txcommon/event_enrich_test.go b/internal/txcommon/event_enrich_test.go
index f1b25bfab..0266d5301 100644
--- a/internal/txcommon/event_enrich_test.go
+++ b/internal/txcommon/event_enrich_test.go
@@ -534,8 +534,8 @@ func TestEnrichTokenApprovalFailed(t *testing.T) {
 	ev1 := fftypes.NewUUID()
 
 	// Setup enrichment
-	mdi.On("GetTokenApprovalByID", mock.Anything, ref1).Return(&fftypes.TokenApproval{
-		LocalID: ref1,
+	mdi.On("GetOperationByID", mock.Anything, ref1).Return(&fftypes.Operation{
+		ID: ref1,
 	}, nil)
 
 	event := &fftypes.Event{
@@ -546,7 +546,7 @@ func TestEnrichTokenApprovalFailed(t *testing.T) {
 
 	enriched, err := txHelper.EnrichEvent(ctx, event)
 	assert.NoError(t, err)
-	assert.Equal(t, ref1, enriched.TokenApproval.LocalID)
+	assert.Equal(t, ref1, enriched.Operation.ID)
 }
 
 func TestEnrichTokenApprovalConfirmedFail(t *testing.T) {
@@ -609,8 +609,8 @@ func TestEnrichTokenTransferFailed(t *testing.T) {
 	ev1 := fftypes.NewUUID()
 
 	// Setup enrichment
-	mdi.On("GetTokenTransferByID", mock.Anything, ref1).Return(&fftypes.TokenTransfer{
-		LocalID: ref1,
+	mdi.On("GetOperationByID", mock.Anything, ref1).Return(&fftypes.Operation{
+		ID: ref1,
 	}, nil)
 
 	event := &fftypes.Event{
@@ -621,7 +621,7 @@ func TestEnrichTokenTransferFailed(t *testing.T) {
 
 	enriched, err := txHelper.EnrichEvent(ctx, event)
 	assert.NoError(t, err)
-	assert.Equal(t, ref1, enriched.TokenTransfer.LocalID)
+	assert.Equal(t, ref1, enriched.Operation.ID)
 }
 
 func TestEnrichTokenTransferConfirmedFail(t *testing.T) {
@@ -646,3 +646,26 @@ func TestEnrichTokenTransferConfirmedFail(t *testing.T) {
 	_, err := txHelper.EnrichEvent(ctx, event)
 	assert.EqualError(t, err, "pop")
 }
+
+func TestEnrichOperationFail(t *testing.T) {
+	mdi := &databasemocks.Plugin{}
+	mdm := &datamocks.Manager{}
+	txHelper := NewTransactionHelper(mdi, mdm)
+	ctx := context.Background()
+
+	// Setup the IDs
+	ref1 := fftypes.NewUUID()
+	ev1 := fftypes.NewUUID()
+
+	// Setup enrichment
+	mdi.On("GetOperationByID", mock.Anything, ref1).Return(nil, fmt.Errorf("pop"))
+
+	event := &fftypes.Event{
+		ID:        ev1,
+		Type:      fftypes.EventTypeApprovalOpFailed,
+		Reference: ref1,
+	}
+
+	_, err := txHelper.EnrichEvent(ctx, event)
+	assert.EqualError(t, err, "pop")
+}