Repository: hyperledger/firefly
Pull request #1225 (2023-03-20 13:45:04)

Use the channel and signer to query transaction details from fabconnect
Closes https://github.com/hyperledger/firefly/issues/1206

Screenshot of a fabric operation with these changes:

![image](https://user-images.githubusercontent.com/6599269/226379073-5d5cb1eb-6b1c-457f-9eb1-0b185d7c26e1.png)



Patch:
diff --git a/internal/blockchain/fabric/fabric.go b/internal/blockchain/fabric/fabric.go
index 9ec154946..d0719f74e 100644
--- a/internal/blockchain/fabric/fabric.go
+++ b/internal/blockchain/fabric/fabric.go
@@ -914,9 +914,18 @@ func (f *Fabric) GetAndConvertDeprecatedContractConfig(ctx context.Context) (loc
 }
 
 func (f *Fabric) GetTransactionStatus(ctx context.Context, operation *core.Operation) (interface{}, error) {
-	txnID := (&core.PreparedOperation{ID: operation.ID, Namespace: operation.Namespace}).NamespacedIDString()
+	txHash := operation.Output.GetString("transactionHash")
 
-	transactionRequestPath := fmt.Sprintf("/transactions/%s", txnID)
+	defaultChannel := f.fabconnectConf.GetString(FabconnectConfigDefaultChannel)
+	if defaultChannel == "" {
+		return nil, i18n.NewError(ctx, coremsgs.MsgDefaultChannelNotConfigured)
+	}
+	defaultSigner := f.fabconnectConf.GetString(FabconnectConfigSigner)
+	if defaultSigner == "" {
+		return nil, i18n.NewError(ctx, coremsgs.MsgNodeMissingBlockchainKey)
+	}
+
+	transactionRequestPath := fmt.Sprintf("/transactions/%s", txHash)
 	client := f.client
 	var resErr fabError
 	var statusResponse fftypes.JSONObject
@@ -924,6 +933,8 @@ func (f *Fabric) GetTransactionStatus(ctx context.Context, operation *core.Opera
 		SetContext(ctx).
 		SetError(&resErr).
 		SetResult(&statusResponse).
+		SetQueryParam("fly-channel", defaultChannel).
+		SetQueryParam("fly-signer", defaultSigner).
 		Get(transactionRequestPath)
 	if err != nil || !res.IsSuccess() {
 		if res.StatusCode() == 404 {
diff --git a/internal/coremsgs/en_error_messages.go b/internal/coremsgs/en_error_messages.go
index 92c7aa368..ee69081a8 100644
--- a/internal/coremsgs/en_error_messages.go
+++ b/internal/coremsgs/en_error_messages.go
@@ -278,4 +278,5 @@ var (
 	MsgMissingNamespace                   = ffe("FF10437", "Missing namespace in request", 400)
 	MsgDeprecatedResetWithAutoReload      = ffe("FF10438", "The deprecated reset API cannot be used when dynamic config reload is enabled", 409)
 	MsgConfigArrayVsRawConfigMismatch     = ffe("FF10439", "Error processing configuration - mismatch between raw and processed array lengths")
+	MsgDefaultChannelNotConfigured        = ffe("FF10440", "No default channel configured for this namespace", 400)
 )


Test patch:
diff --git a/internal/blockchain/fabric/fabric_test.go b/internal/blockchain/fabric/fabric_test.go
index 783fdc344..6d47e076a 100644
--- a/internal/blockchain/fabric/fabric_test.go
+++ b/internal/blockchain/fabric/fabric_test.go
@@ -2731,13 +2731,18 @@ func TestGetTransactionStatus(t *testing.T) {
 	defer cancel()
 	httpmock.ActivateNonDefault(e.client.GetClient())
 	defer httpmock.DeactivateAndReset()
+	resetConf(e)
+
+	utFabconnectConf.Set(FabconnectConfigSigner, "signer001")
+	utFabconnectConf.Set(FabconnectConfigDefaultChannel, "firefly")
 
+	output := make(map[string]interface{}, 0)
+	output["transactionHash"] = "7cd2549e310898ceb5f8d15112e74e0395c2f7ccd434293cd29cdb6bc358e85a"
 	op := &core.Operation{
-		Namespace: "ns1",
-		ID:        fftypes.MustParseUUID("9ffc50ff-6bfe-4502-adc7-93aea54cc059"),
+		Output: output,
 	}
 
-	httpmock.RegisterResponder("GET", `http://localhost:12345/transactions/ns1:9ffc50ff-6bfe-4502-adc7-93aea54cc059`,
+	httpmock.RegisterResponder("GET", `http://localhost:12345/transactions/7cd2549e310898ceb5f8d15112e74e0395c2f7ccd434293cd29cdb6bc358e85a?fly-channel=firefly&fly-signer=signer001`,
 		func(req *http.Request) (*http.Response, error) {
 			return httpmock.NewJsonResponderOrPanic(200, make(map[string]interface{}))(req)
 		})
@@ -2752,13 +2757,18 @@ func TestGetTransactionStatusNoResult(t *testing.T) {
 	defer cancel()
 	httpmock.ActivateNonDefault(e.client.GetClient())
 	defer httpmock.DeactivateAndReset()
+	resetConf(e)
 
+	utFabconnectConf.Set(FabconnectConfigSigner, "signer001")
+	utFabconnectConf.Set(FabconnectConfigDefaultChannel, "firefly")
+
+	output := make(map[string]interface{}, 0)
+	output["transactionHash"] = "7cd2549e310898ceb5f8d15112e74e0395c2f7ccd434293cd29cdb6bc358e85a"
 	op := &core.Operation{
-		Namespace: "ns1",
-		ID:        fftypes.MustParseUUID("9ffc50ff-6bfe-4502-adc7-93aea54cc059"),
+		Output: output,
 	}
 
-	httpmock.RegisterResponder("GET", `http://localhost:12345/transactions/ns1:9ffc50ff-6bfe-4502-adc7-93aea54cc059`,
+	httpmock.RegisterResponder("GET", `http://localhost:12345/transactions/7cd2549e310898ceb5f8d15112e74e0395c2f7ccd434293cd29cdb6bc358e85a?fly-channel=firefly&fly-signer=signer001`,
 		func(req *http.Request) (*http.Response, error) {
 			return httpmock.NewJsonResponderOrPanic(404, make(map[string]interface{}))(req)
 		})
@@ -2773,6 +2783,10 @@ func TestGetTransactionStatusBadResult(t *testing.T) {
 	defer cancel()
 	httpmock.ActivateNonDefault(e.client.GetClient())
 	defer httpmock.DeactivateAndReset()
+	resetConf(e)
+
+	utFabconnectConf.Set(FabconnectConfigSigner, "signer001")
+	utFabconnectConf.Set(FabconnectConfigDefaultChannel, "firefly")
 
 	op := &core.Operation{
 		Namespace: "ns1",