diff --git a/adapters/sdk.go b/adapters/sdk.go index ff1ccefb..35333024 100644 --- a/adapters/sdk.go +++ b/adapters/sdk.go @@ -158,7 +158,7 @@ func (b *SDKAdapter) GetLatestBlock( Height: flowBlock.Header.Height, Timestamp: flowBlock.Header.Timestamp, }, - BlockPayload: sdk.BlockPayload{}, + BlockPayload: convertBlockPayload(flowBlock.Payload), } return &block, sdk.BlockStatusSealed, nil } @@ -183,7 +183,7 @@ func (b *SDKAdapter) GetBlockByHeight( Height: flowBlock.Header.Height, Timestamp: flowBlock.Header.Timestamp, }, - BlockPayload: sdk.BlockPayload{}, + BlockPayload: convertBlockPayload(flowBlock.Payload), } return &block, sdk.BlockStatusSealed, nil } @@ -208,11 +208,41 @@ func (b *SDKAdapter) GetBlockByID( Height: flowBlock.Header.Height, Timestamp: flowBlock.Header.Timestamp, }, - BlockPayload: sdk.BlockPayload{}, + BlockPayload: convertBlockPayload(flowBlock.Payload), } return &block, sdk.BlockStatusSealed, nil } +func convertBlockPayload(payload *flowgo.Payload) sdk.BlockPayload { + var seals []*sdk.BlockSeal + sealCount := len(payload.Seals) + if sealCount > 0 { + seals = make([]*sdk.BlockSeal, 0, sealCount) + for _, seal := range payload.Seals { + seals = append(seals, &sdk.BlockSeal{ + BlockID: sdk.Identifier(seal.BlockID), + ExecutionReceiptID: sdk.Identifier(seal.ResultID), + }) + } + } + + var collectionGuarantees []*sdk.CollectionGuarantee + guaranteesCount := len(payload.Guarantees) + if guaranteesCount > 0 { + collectionGuarantees = make([]*sdk.CollectionGuarantee, 0, guaranteesCount) + for _, guarantee := range payload.Guarantees { + collectionGuarantees = append(collectionGuarantees, &sdk.CollectionGuarantee{ + CollectionID: sdk.Identifier(guarantee.CollectionID), + }) + } + } + + return sdk.BlockPayload{ + Seals: seals, + CollectionGuarantees: collectionGuarantees, + } +} + // GetCollectionByID gets a collection by ID. func (b *SDKAdapter) GetCollectionByID( _ context.Context, diff --git a/adapters/sdk_test.go b/adapters/sdk_test.go index 8d63399e..66c2675c 100644 --- a/adapters/sdk_test.go +++ b/adapters/sdk_test.go @@ -185,6 +185,19 @@ func TestSDK(t *testing.T) { Header: &flowgo.Header{ Height: 42, }, + Payload: &flowgo.Payload{ + Guarantees: []*flowgo.CollectionGuarantee{ + { + CollectionID: flowgo.MustHexStringToIdentifier("db94e7ef4c9e758f27f96777c61b5cca10528e9db5e7dfd3b44ffceb26b284c0"), + }, + }, + Seals: []*flowgo.Seal{ + { + BlockID: flowgo.MustHexStringToIdentifier("890581b4ee0666d2a90b7e9212aaa37535f7bcec76f571c3402bc4bc58ee2918"), + ResultID: flowgo.MustHexStringToIdentifier("a7990b0bab754a68844de3698bb2d2c7966acb9ef65fd5a3a5be53a93a764edf"), + }, + }, + }, } block := flowgosdk.Block{ @@ -192,6 +205,19 @@ func TestSDK(t *testing.T) { ID: flowgosdk.Identifier{0x8c, 0x3c, 0xf9, 0x36, 0xbf, 0x2d, 0x3, 0x8d, 0x21, 0x71, 0xb4, 0x80, 0x1f, 0xba, 0x30, 0x36, 0x3c, 0xd5, 0x76, 0xc3, 0x21, 0xb4, 0x3d, 0xbd, 0xa2, 0x69, 0xa1, 0xe2, 0x7c, 0x6f, 0x58, 0x28}, Height: 42, }, + BlockPayload: flowgosdk.BlockPayload{ + CollectionGuarantees: []*flowgosdk.CollectionGuarantee{ + { + CollectionID: flowgosdk.HexToID("db94e7ef4c9e758f27f96777c61b5cca10528e9db5e7dfd3b44ffceb26b284c0"), + }, + }, + Seals: []*flowgosdk.BlockSeal{ + { + BlockID: flowgosdk.HexToID("890581b4ee0666d2a90b7e9212aaa37535f7bcec76f571c3402bc4bc58ee2918"), + ExecutionReceiptID: flowgosdk.HexToID("a7990b0bab754a68844de3698bb2d2c7966acb9ef65fd5a3a5be53a93a764edf"), + }, + }, + }, } //success @@ -224,6 +250,19 @@ func TestSDK(t *testing.T) { Header: &flowgo.Header{ Height: 42, }, + Payload: &flowgo.Payload{ + Guarantees: []*flowgo.CollectionGuarantee{ + { + CollectionID: flowgo.MustHexStringToIdentifier("db94e7ef4c9e758f27f96777c61b5cca10528e9db5e7dfd3b44ffceb26b284c0"), + }, + }, + Seals: []*flowgo.Seal{ + { + BlockID: flowgo.MustHexStringToIdentifier("890581b4ee0666d2a90b7e9212aaa37535f7bcec76f571c3402bc4bc58ee2918"), + ResultID: flowgo.MustHexStringToIdentifier("a7990b0bab754a68844de3698bb2d2c7966acb9ef65fd5a3a5be53a93a764edf"), + }, + }, + }, } block := flowgosdk.Block{ @@ -231,6 +270,19 @@ func TestSDK(t *testing.T) { ID: flowgosdk.Identifier{0x8c, 0x3c, 0xf9, 0x36, 0xbf, 0x2d, 0x3, 0x8d, 0x21, 0x71, 0xb4, 0x80, 0x1f, 0xba, 0x30, 0x36, 0x3c, 0xd5, 0x76, 0xc3, 0x21, 0xb4, 0x3d, 0xbd, 0xa2, 0x69, 0xa1, 0xe2, 0x7c, 0x6f, 0x58, 0x28}, Height: 42, }, + BlockPayload: flowgosdk.BlockPayload{ + CollectionGuarantees: []*flowgosdk.CollectionGuarantee{ + { + CollectionID: flowgosdk.HexToID("db94e7ef4c9e758f27f96777c61b5cca10528e9db5e7dfd3b44ffceb26b284c0"), + }, + }, + Seals: []*flowgosdk.BlockSeal{ + { + BlockID: flowgosdk.HexToID("890581b4ee0666d2a90b7e9212aaa37535f7bcec76f571c3402bc4bc58ee2918"), + ExecutionReceiptID: flowgosdk.HexToID("a7990b0bab754a68844de3698bb2d2c7966acb9ef65fd5a3a5be53a93a764edf"), + }, + }, + }, } //success @@ -264,6 +316,19 @@ func TestSDK(t *testing.T) { Header: &flowgo.Header{ Height: 42, }, + Payload: &flowgo.Payload{ + Guarantees: []*flowgo.CollectionGuarantee{ + { + CollectionID: flowgo.MustHexStringToIdentifier("db94e7ef4c9e758f27f96777c61b5cca10528e9db5e7dfd3b44ffceb26b284c0"), + }, + }, + Seals: []*flowgo.Seal{ + { + BlockID: flowgo.MustHexStringToIdentifier("890581b4ee0666d2a90b7e9212aaa37535f7bcec76f571c3402bc4bc58ee2918"), + ResultID: flowgo.MustHexStringToIdentifier("a7990b0bab754a68844de3698bb2d2c7966acb9ef65fd5a3a5be53a93a764edf"), + }, + }, + }, } block := flowgosdk.Block{ @@ -271,6 +336,19 @@ func TestSDK(t *testing.T) { ID: flowgosdk.Identifier{0x8c, 0x3c, 0xf9, 0x36, 0xbf, 0x2d, 0x3, 0x8d, 0x21, 0x71, 0xb4, 0x80, 0x1f, 0xba, 0x30, 0x36, 0x3c, 0xd5, 0x76, 0xc3, 0x21, 0xb4, 0x3d, 0xbd, 0xa2, 0x69, 0xa1, 0xe2, 0x7c, 0x6f, 0x58, 0x28}, Height: 42, }, + BlockPayload: flowgosdk.BlockPayload{ + CollectionGuarantees: []*flowgosdk.CollectionGuarantee{ + { + CollectionID: flowgosdk.HexToID("db94e7ef4c9e758f27f96777c61b5cca10528e9db5e7dfd3b44ffceb26b284c0"), + }, + }, + Seals: []*flowgosdk.BlockSeal{ + { + BlockID: flowgosdk.HexToID("890581b4ee0666d2a90b7e9212aaa37535f7bcec76f571c3402bc4bc58ee2918"), + ExecutionReceiptID: flowgosdk.HexToID("a7990b0bab754a68844de3698bb2d2c7966acb9ef65fd5a3a5be53a93a764edf"), + }, + }, + }, } //success