Skip to content

Commit

Permalink
Set protocolId in all transaction receipts
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Whitehead <matthew.whitehead@kaleido.io>
  • Loading branch information
matthew1001 committed Dec 20, 2022
1 parent da7273f commit 048d853
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/ethereum/get_receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package ethereum
import (
"context"
"encoding/json"
"fmt"

"github.com/hyperledger/firefly-common/pkg/fftypes"
"github.com/hyperledger/firefly-common/pkg/i18n"
Expand Down Expand Up @@ -82,6 +83,13 @@ func (c *ethConnector) getTransactionInfo(ctx context.Context, hash ethtypes.Hex
return txInfo, err
}

func ProtocolIDForReceipt(blockNumber, transactionIndex *fftypes.FFBigInt) string {
if blockNumber != nil && transactionIndex != nil {
return fmt.Sprintf("%.12d/%.6d", blockNumber.Int(), transactionIndex.Int())
}
return ""
}

func (c *ethConnector) TransactionReceipt(ctx context.Context, req *ffcapi.TransactionReceiptRequest) (*ffcapi.TransactionReceiptResponse, ffcapi.ErrorReason, error) {

// Get the receipt in the back-end JSON/RPC format
Expand Down Expand Up @@ -114,6 +122,7 @@ func (c *ethConnector) TransactionReceipt(ctx context.Context, req *ffcapi.Trans
TransactionIndex: fftypes.NewFFBigInt(txIndex),
BlockHash: ethReceipt.BlockHash.String(),
Success: isSuccess,
ProtocolID: ProtocolIDForReceipt((*fftypes.FFBigInt)(ethReceipt.BlockNumber), fftypes.NewFFBigInt(txIndex)),
ExtraInfo: fftypes.JSONAnyPtrBytes(fullReceipt),
}, "", nil

Expand Down
6 changes: 6 additions & 0 deletions internal/ethereum/get_receipt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"
"testing"

"github.com/hyperledger/firefly-common/pkg/fftypes"
"github.com/hyperledger/firefly-signer/pkg/rpcbackend"
"github.com/hyperledger/firefly-transaction-manager/pkg/ffcapi"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -134,3 +135,8 @@ func TestGetReceiptError(t *testing.T) {
assert.Nil(t, res)

}

func TestProtocolIDForReceipt(t *testing.T) {
assert.Equal(t, "000000012345/000042", ProtocolIDForReceipt(fftypes.NewFFBigInt(12345), fftypes.NewFFBigInt(42)))
assert.Equal(t, "", ProtocolIDForReceipt(nil, nil))
}

0 comments on commit 048d853

Please sign in to comment.