From 3aac00ccad6031b94cddadfa74e36d75cf97d788 Mon Sep 17 00:00:00 2001 From: Andrew Richardson Date: Mon, 22 Nov 2021 14:18:56 -0500 Subject: [PATCH 1/2] Add token URI Signed-off-by: Andrew Richardson --- .../000047_add_token_uri_fields.down.sql | 9 + .../000047_add_token_uri_fields.up.sql | 9 + .../000047_add_token_uri_fields.down.sql | 7 + .../sqlite/000047_add_token_uri_fields.up.sql | 7 + docs/swagger/swagger.yaml | 526 +++--------------- internal/apiserver/route_post_token_burn.go | 2 +- .../route_post_token_burn_by_type.go | 2 +- internal/apiserver/route_post_token_mint.go | 2 +- .../route_post_token_mint_by_type.go | 2 +- .../apiserver/route_post_token_transfer.go | 2 +- .../route_post_token_transfer_by_type.go | 2 +- .../database/sqlcommon/tokenbalance_sql.go | 4 + .../sqlcommon/tokenbalance_sql_test.go | 5 +- .../database/sqlcommon/tokentransfer_sql.go | 4 + .../sqlcommon/tokentransfer_sql_test.go | 1 + internal/events/tokens_transferred_test.go | 6 + internal/tokens/fftokens/fftokens.go | 2 + pkg/database/plugin.go | 2 + pkg/fftypes/tokenbalance.go | 1 + pkg/fftypes/tokentransfer.go | 1 + 20 files changed, 151 insertions(+), 445 deletions(-) create mode 100644 db/migrations/postgres/000047_add_token_uri_fields.down.sql create mode 100644 db/migrations/postgres/000047_add_token_uri_fields.up.sql create mode 100644 db/migrations/sqlite/000047_add_token_uri_fields.down.sql create mode 100644 db/migrations/sqlite/000047_add_token_uri_fields.up.sql diff --git a/db/migrations/postgres/000047_add_token_uri_fields.down.sql b/db/migrations/postgres/000047_add_token_uri_fields.down.sql new file mode 100644 index 0000000000..a8d230ccb9 --- /dev/null +++ b/db/migrations/postgres/000047_add_token_uri_fields.down.sql @@ -0,0 +1,9 @@ +BEGIN; +DROP INDEX tokenbalance_pool; +DROP INDEX tokenbalance_uri; + +ALTER TABLE tokenbalance DROP COLUMN uri; +ALTER TABLE tokentransfer DROP COLUMN uri; + +CREATE UNIQUE INDEX tokenbalance_pool ON tokenbalance(key,pool_id,token_index); +COMMIT; diff --git a/db/migrations/postgres/000047_add_token_uri_fields.up.sql b/db/migrations/postgres/000047_add_token_uri_fields.up.sql new file mode 100644 index 0000000000..eced698bdf --- /dev/null +++ b/db/migrations/postgres/000047_add_token_uri_fields.up.sql @@ -0,0 +1,9 @@ +BEGIN; +DROP INDEX tokenbalance_pool; + +ALTER TABLE tokenbalance ADD COLUMN uri VARCHAR(1024); +ALTER TABLE tokentransfer ADD COLUMN uri VARCHAR(1024); + +CREATE UNIQUE INDEX tokenbalance_pool ON tokenbalance(namespace,key,pool_id,token_index); +CREATE UNIQUE INDEX tokenbalance_uri ON tokenbalance(namespace,key,pool_id,uri); +COMMIT; diff --git a/db/migrations/sqlite/000047_add_token_uri_fields.down.sql b/db/migrations/sqlite/000047_add_token_uri_fields.down.sql new file mode 100644 index 0000000000..45aea4d407 --- /dev/null +++ b/db/migrations/sqlite/000047_add_token_uri_fields.down.sql @@ -0,0 +1,7 @@ +DROP INDEX tokenbalance_pool; +DROP INDEX tokenbalance_uri; + +ALTER TABLE tokenbalance DROP COLUMN uri; +ALTER TABLE tokentransfer DROP COLUMN uri; + +CREATE UNIQUE INDEX tokenbalance_pool ON tokenbalance(key,pool_id,token_index); diff --git a/db/migrations/sqlite/000047_add_token_uri_fields.up.sql b/db/migrations/sqlite/000047_add_token_uri_fields.up.sql new file mode 100644 index 0000000000..d8a55d5106 --- /dev/null +++ b/db/migrations/sqlite/000047_add_token_uri_fields.up.sql @@ -0,0 +1,7 @@ +DROP INDEX tokenbalance_pool; + +ALTER TABLE tokenbalance ADD COLUMN uri VARCHAR(1024); +ALTER TABLE tokentransfer ADD COLUMN uri VARCHAR(1024); + +CREATE UNIQUE INDEX tokenbalance_pool ON tokenbalance(namespace,key,pool_id,token_index); +CREATE UNIQUE INDEX tokenbalance_uri ON tokenbalance(namespace,key,pool_id,uri); diff --git a/docs/swagger/swagger.yaml b/docs/swagger/swagger.yaml index 88f30cd8ed..b974c35734 100644 --- a/docs/swagger/swagger.yaml +++ b/docs/swagger/swagger.yaml @@ -4561,6 +4561,11 @@ paths: name: updated schema: type: string + - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' + in: query + name: uri + schema: + type: string - description: Sort field. For multi-field sort use comma separated values (or multiple query values) with '-' prefix for descending in: query @@ -4613,6 +4618,8 @@ paths: tokenIndex: type: string updated: {} + uri: + type: string type: object type: array description: Success @@ -4669,82 +4676,11 @@ paths: key: type: string localId: {} - message: - properties: - batch: {} - confirmed: {} - data: - items: - properties: - hash: {} - id: {} - type: object - type: array - group: - properties: - ledger: {} - members: - items: - properties: - identity: - type: string - node: - type: string - type: object - type: array - name: - type: string - type: object - hash: {} - header: - properties: - author: - type: string - cid: {} - created: {} - datahash: {} - group: {} - id: {} - key: - type: string - namespace: - type: string - tag: - type: string - topics: - items: - type: string - type: array - txtype: - type: string - type: - enum: - - definition - - broadcast - - private - - groupinit - - transfer_broadcast - - transfer_private - type: string - type: object - pins: - items: - type: string - type: array - state: - enum: - - staged - - ready - - pending - - confirmed - - rejected - type: string - type: object + message: {} messageHash: {} namespace: type: string - pool: - type: string + pool: {} protocolId: type: string to: @@ -4763,6 +4699,8 @@ paths: - burn - transfer type: string + uri: + type: string type: object responses: "200": @@ -4798,6 +4736,8 @@ paths: type: object type: type: string + uri: + type: string type: object description: Success "202": @@ -4833,6 +4773,8 @@ paths: type: object type: type: string + uri: + type: string type: object description: Success default: @@ -4888,82 +4830,11 @@ paths: key: type: string localId: {} - message: - properties: - batch: {} - confirmed: {} - data: - items: - properties: - hash: {} - id: {} - type: object - type: array - group: - properties: - ledger: {} - members: - items: - properties: - identity: - type: string - node: - type: string - type: object - type: array - name: - type: string - type: object - hash: {} - header: - properties: - author: - type: string - cid: {} - created: {} - datahash: {} - group: {} - id: {} - key: - type: string - namespace: - type: string - tag: - type: string - topics: - items: - type: string - type: array - txtype: - type: string - type: - enum: - - definition - - broadcast - - private - - groupinit - - transfer_broadcast - - transfer_private - type: string - type: object - pins: - items: - type: string - type: array - state: - enum: - - staged - - ready - - pending - - confirmed - - rejected - type: string - type: object + message: {} messageHash: {} namespace: type: string - pool: - type: string + pool: {} protocolId: type: string to: @@ -4982,6 +4853,8 @@ paths: - burn - transfer type: string + uri: + type: string type: object responses: "200": @@ -5017,6 +4890,8 @@ paths: type: object type: type: string + uri: + type: string type: object description: Success "202": @@ -5052,6 +4927,8 @@ paths: type: object type: type: string + uri: + type: string type: object description: Success default: @@ -5153,6 +5030,11 @@ paths: name: tokenindex schema: type: string + - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' + in: query + name: uri + schema: + type: string - description: Sort field. For multi-field sort use comma separated values (or multiple query values) with '-' prefix for descending in: query @@ -5222,6 +5104,8 @@ paths: type: object type: type: string + uri: + type: string type: object type: array description: Success @@ -5277,82 +5161,11 @@ paths: key: type: string localId: {} - message: - properties: - batch: {} - confirmed: {} - data: - items: - properties: - hash: {} - id: {} - type: object - type: array - group: - properties: - ledger: {} - members: - items: - properties: - identity: - type: string - node: - type: string - type: object - type: array - name: - type: string - type: object - hash: {} - header: - properties: - author: - type: string - cid: {} - created: {} - datahash: {} - group: {} - id: {} - key: - type: string - namespace: - type: string - tag: - type: string - topics: - items: - type: string - type: array - txtype: - type: string - type: - enum: - - definition - - broadcast - - private - - groupinit - - transfer_broadcast - - transfer_private - type: string - type: object - pins: - items: - type: string - type: array - state: - enum: - - staged - - ready - - pending - - confirmed - - rejected - type: string - type: object + message: {} messageHash: {} namespace: type: string - pool: - type: string + pool: {} protocolId: type: string to: @@ -5371,6 +5184,8 @@ paths: - burn - transfer type: string + uri: + type: string type: object responses: "200": @@ -5406,6 +5221,8 @@ paths: type: object type: type: string + uri: + type: string type: object description: Success "202": @@ -5441,6 +5258,8 @@ paths: type: object type: type: string + uri: + type: string type: object description: Success default: @@ -5499,6 +5318,11 @@ paths: name: updated schema: type: string + - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' + in: query + name: uri + schema: + type: string - description: Sort field. For multi-field sort use comma separated values (or multiple query values) with '-' prefix for descending in: query @@ -5607,6 +5431,11 @@ paths: name: updated schema: type: string + - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' + in: query + name: uri + schema: + type: string - description: Sort field. For multi-field sort use comma separated values (or multiple query values) with '-' prefix for descending in: query @@ -5708,6 +5537,11 @@ paths: name: updated schema: type: string + - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' + in: query + name: uri + schema: + type: string - description: Sort field. For multi-field sort use comma separated values (or multiple query values) with '-' prefix for descending in: query @@ -5760,6 +5594,8 @@ paths: tokenIndex: type: string updated: {} + uri: + type: string type: object type: array description: Success @@ -5803,82 +5639,11 @@ paths: key: type: string localId: {} - message: - properties: - batch: {} - confirmed: {} - data: - items: - properties: - hash: {} - id: {} - type: object - type: array - group: - properties: - ledger: {} - members: - items: - properties: - identity: - type: string - node: - type: string - type: object - type: array - name: - type: string - type: object - hash: {} - header: - properties: - author: - type: string - cid: {} - created: {} - datahash: {} - group: {} - id: {} - key: - type: string - namespace: - type: string - tag: - type: string - topics: - items: - type: string - type: array - txtype: - type: string - type: - enum: - - definition - - broadcast - - private - - groupinit - - transfer_broadcast - - transfer_private - type: string - type: object - pins: - items: - type: string - type: array - state: - enum: - - staged - - ready - - pending - - confirmed - - rejected - type: string - type: object + message: {} messageHash: {} namespace: type: string - pool: - type: string + pool: {} protocolId: type: string to: @@ -5897,6 +5662,8 @@ paths: - burn - transfer type: string + uri: + type: string type: object responses: "200": @@ -5932,6 +5699,8 @@ paths: type: object type: type: string + uri: + type: string type: object description: Success "202": @@ -5967,6 +5736,8 @@ paths: type: object type: type: string + uri: + type: string type: object description: Success default: @@ -6042,82 +5813,11 @@ paths: key: type: string localId: {} - message: - properties: - batch: {} - confirmed: {} - data: - items: - properties: - hash: {} - id: {} - type: object - type: array - group: - properties: - ledger: {} - members: - items: - properties: - identity: - type: string - node: - type: string - type: object - type: array - name: - type: string - type: object - hash: {} - header: - properties: - author: - type: string - cid: {} - created: {} - datahash: {} - group: {} - id: {} - key: - type: string - namespace: - type: string - tag: - type: string - topics: - items: - type: string - type: array - txtype: - type: string - type: - enum: - - definition - - broadcast - - private - - groupinit - - transfer_broadcast - - transfer_private - type: string - type: object - pins: - items: - type: string - type: array - state: - enum: - - staged - - ready - - pending - - confirmed - - rejected - type: string - type: object + message: {} messageHash: {} namespace: type: string - pool: - type: string + pool: {} protocolId: type: string to: @@ -6136,6 +5836,8 @@ paths: - burn - transfer type: string + uri: + type: string type: object responses: "200": @@ -6171,6 +5873,8 @@ paths: type: object type: type: string + uri: + type: string type: object description: Success "202": @@ -6206,6 +5910,8 @@ paths: type: object type: type: string + uri: + type: string type: object description: Success default: @@ -6641,6 +6347,11 @@ paths: name: tokenindex schema: type: string + - description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^' + in: query + name: uri + schema: + type: string - description: Sort field. For multi-field sort use comma separated values (or multiple query values) with '-' prefix for descending in: query @@ -6710,6 +6421,8 @@ paths: type: object type: type: string + uri: + type: string type: object type: array description: Success @@ -6752,82 +6465,11 @@ paths: key: type: string localId: {} - message: - properties: - batch: {} - confirmed: {} - data: - items: - properties: - hash: {} - id: {} - type: object - type: array - group: - properties: - ledger: {} - members: - items: - properties: - identity: - type: string - node: - type: string - type: object - type: array - name: - type: string - type: object - hash: {} - header: - properties: - author: - type: string - cid: {} - created: {} - datahash: {} - group: {} - id: {} - key: - type: string - namespace: - type: string - tag: - type: string - topics: - items: - type: string - type: array - txtype: - type: string - type: - enum: - - definition - - broadcast - - private - - groupinit - - transfer_broadcast - - transfer_private - type: string - type: object - pins: - items: - type: string - type: array - state: - enum: - - staged - - ready - - pending - - confirmed - - rejected - type: string - type: object + message: {} messageHash: {} namespace: type: string - pool: - type: string + pool: {} protocolId: type: string to: @@ -6846,6 +6488,8 @@ paths: - burn - transfer type: string + uri: + type: string type: object responses: "200": @@ -6881,6 +6525,8 @@ paths: type: object type: type: string + uri: + type: string type: object description: Success "202": @@ -6916,6 +6562,8 @@ paths: type: object type: type: string + uri: + type: string type: object description: Success default: @@ -6979,6 +6627,8 @@ paths: type: object type: type: string + uri: + type: string type: object description: Success default: diff --git a/internal/apiserver/route_post_token_burn.go b/internal/apiserver/route_post_token_burn.go index 074a0d743e..36f8a7b48a 100644 --- a/internal/apiserver/route_post_token_burn.go +++ b/internal/apiserver/route_post_token_burn.go @@ -39,7 +39,7 @@ var postTokenBurn = &oapispec.Route{ FilterFactory: nil, Description: i18n.MsgTBD, JSONInputValue: func() interface{} { return &fftypes.TokenTransferInput{} }, - JSONInputMask: []string{"Type", "LocalID", "PoolProtocolID", "To", "ProtocolID", "MessageHash", "TX", "Created"}, + JSONInputMask: []string{"Type", "LocalID", "URI", "To", "ProtocolID", "MessageHash", "TX", "Created"}, JSONOutputValue: func() interface{} { return &fftypes.TokenTransfer{} }, JSONOutputCodes: []int{http.StatusAccepted, http.StatusOK}, JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) { diff --git a/internal/apiserver/route_post_token_burn_by_type.go b/internal/apiserver/route_post_token_burn_by_type.go index f1d0ba9177..e257fe73ed 100644 --- a/internal/apiserver/route_post_token_burn_by_type.go +++ b/internal/apiserver/route_post_token_burn_by_type.go @@ -41,7 +41,7 @@ var postTokenBurnByType = &oapispec.Route{ FilterFactory: nil, Description: i18n.MsgTBD, JSONInputValue: func() interface{} { return &fftypes.TokenTransferInput{} }, - JSONInputMask: []string{"Type", "LocalID", "PoolProtocolID", "To", "ProtocolID", "MessageHash", "Connector", "TX", "Created"}, + JSONInputMask: []string{"Type", "LocalID", "URI", "To", "ProtocolID", "MessageHash", "Connector", "TX", "Created"}, JSONOutputValue: func() interface{} { return &fftypes.TokenTransfer{} }, JSONOutputCodes: []int{http.StatusAccepted, http.StatusOK}, JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) { diff --git a/internal/apiserver/route_post_token_mint.go b/internal/apiserver/route_post_token_mint.go index 4d8802c5d7..5807c386d4 100644 --- a/internal/apiserver/route_post_token_mint.go +++ b/internal/apiserver/route_post_token_mint.go @@ -39,7 +39,7 @@ var postTokenMint = &oapispec.Route{ FilterFactory: nil, Description: i18n.MsgTBD, JSONInputValue: func() interface{} { return &fftypes.TokenTransferInput{} }, - JSONInputMask: []string{"Type", "LocalID", "PoolProtocolID", "TokenIndex", "From", "ProtocolID", "MessageHash", "TX", "Created"}, + JSONInputMask: []string{"Type", "LocalID", "TokenIndex", "URI", "From", "ProtocolID", "MessageHash", "TX", "Created"}, JSONOutputValue: func() interface{} { return &fftypes.TokenTransfer{} }, JSONOutputCodes: []int{http.StatusAccepted, http.StatusOK}, JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) { diff --git a/internal/apiserver/route_post_token_mint_by_type.go b/internal/apiserver/route_post_token_mint_by_type.go index 1e87b71216..23bbd88fb0 100644 --- a/internal/apiserver/route_post_token_mint_by_type.go +++ b/internal/apiserver/route_post_token_mint_by_type.go @@ -41,7 +41,7 @@ var postTokenMintByType = &oapispec.Route{ FilterFactory: nil, Description: i18n.MsgTBD, JSONInputValue: func() interface{} { return &fftypes.TokenTransferInput{} }, - JSONInputMask: []string{"Type", "LocalID", "PoolProtocolID", "TokenIndex", "From", "ProtocolID", "MessageHash", "Connector", "TX", "Created"}, + JSONInputMask: []string{"Type", "LocalID", "TokenIndex", "URI", "From", "ProtocolID", "MessageHash", "Connector", "TX", "Created"}, JSONOutputValue: func() interface{} { return &fftypes.TokenTransfer{} }, JSONOutputCodes: []int{http.StatusAccepted, http.StatusOK}, JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) { diff --git a/internal/apiserver/route_post_token_transfer.go b/internal/apiserver/route_post_token_transfer.go index 1fe71e50ac..464385c51c 100644 --- a/internal/apiserver/route_post_token_transfer.go +++ b/internal/apiserver/route_post_token_transfer.go @@ -39,7 +39,7 @@ var postTokenTransfer = &oapispec.Route{ FilterFactory: nil, Description: i18n.MsgTBD, JSONInputValue: func() interface{} { return &fftypes.TokenTransferInput{} }, - JSONInputMask: []string{"Type", "LocalID", "PoolProtocolID", "ProtocolID", "MessageHash", "Namespace", "TX", "Created"}, + JSONInputMask: []string{"Type", "LocalID", "URI", "ProtocolID", "MessageHash", "Namespace", "TX", "Created"}, JSONOutputValue: func() interface{} { return &fftypes.TokenTransfer{} }, JSONOutputCodes: []int{http.StatusAccepted, http.StatusOK}, JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) { diff --git a/internal/apiserver/route_post_token_transfer_by_type.go b/internal/apiserver/route_post_token_transfer_by_type.go index e37439cc8b..01c28eeb15 100644 --- a/internal/apiserver/route_post_token_transfer_by_type.go +++ b/internal/apiserver/route_post_token_transfer_by_type.go @@ -41,7 +41,7 @@ var postTokenTransferByType = &oapispec.Route{ FilterFactory: nil, Description: i18n.MsgTBD, JSONInputValue: func() interface{} { return &fftypes.TokenTransferInput{} }, - JSONInputMask: []string{"Type", "LocalID", "PoolProtocolID", "ProtocolID", "MessageHash", "Connector", "Namespace", "TX", "Created"}, + JSONInputMask: []string{"Type", "LocalID", "URI", "ProtocolID", "MessageHash", "Connector", "Namespace", "TX", "Created"}, JSONOutputValue: func() interface{} { return &fftypes.TokenTransfer{} }, JSONOutputCodes: []int{http.StatusAccepted, http.StatusOK}, JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) { diff --git a/internal/database/sqlcommon/tokenbalance_sql.go b/internal/database/sqlcommon/tokenbalance_sql.go index 15d131321c..62c38287d1 100644 --- a/internal/database/sqlcommon/tokenbalance_sql.go +++ b/internal/database/sqlcommon/tokenbalance_sql.go @@ -31,6 +31,7 @@ var ( tokenBalanceColumns = []string{ "pool_id", "token_index", + "uri", "connector", "namespace", "key", @@ -64,6 +65,7 @@ func (s *SQLCommon) addTokenBalance(ctx context.Context, tx *txWrapper, transfer if account != nil { if _, err = s.updateTx(ctx, tx, sq.Update("tokenbalance"). + Set("uri", transfer.URI). Set("balance", balance). Set("updated", fftypes.Now()). Where(sq.And{ @@ -82,6 +84,7 @@ func (s *SQLCommon) addTokenBalance(ctx context.Context, tx *txWrapper, transfer Values( transfer.Pool, transfer.TokenIndex, + transfer.URI, transfer.Connector, transfer.Namespace, key, @@ -123,6 +126,7 @@ func (s *SQLCommon) tokenBalanceResult(ctx context.Context, row *sql.Rows) (*fft err := row.Scan( &account.Pool, &account.TokenIndex, + &account.URI, &account.Connector, &account.Namespace, &account.Key, diff --git a/internal/database/sqlcommon/tokenbalance_sql_test.go b/internal/database/sqlcommon/tokenbalance_sql_test.go index 7c56f315ac..aa8acae2b5 100644 --- a/internal/database/sqlcommon/tokenbalance_sql_test.go +++ b/internal/database/sqlcommon/tokenbalance_sql_test.go @@ -35,9 +35,11 @@ func TestTokenBalanceE2EWithDB(t *testing.T) { ctx := context.Background() // Create a new token account + uri := "firefly://token/1" transfer := &fftypes.TokenTransfer{ Pool: fftypes.NewUUID(), TokenIndex: "1", + URI: uri, Connector: "erc1155", Namespace: "ns1", To: "0x0", @@ -46,6 +48,7 @@ func TestTokenBalanceE2EWithDB(t *testing.T) { balance := &fftypes.TokenBalance{ Pool: transfer.Pool, TokenIndex: "1", + URI: uri, Connector: "erc1155", Namespace: "ns1", Key: "0x0", @@ -171,7 +174,7 @@ func TestUpdateTokenBalancesFailInsert2(t *testing.T) { func TestUpdateTokenBalancesFailUpdate(t *testing.T) { s, mock := newMockProvider().init() mock.ExpectBegin() - mock.ExpectQuery("SELECT .*").WillReturnRows(sqlmock.NewRows(tokenBalanceColumns).AddRow(fftypes.NewUUID().String(), "1", "", "", "0x0", "0", 0)) + mock.ExpectQuery("SELECT .*").WillReturnRows(sqlmock.NewRows(tokenBalanceColumns).AddRow(fftypes.NewUUID().String(), "1", "", "", "", "0x0", "0", 0)) mock.ExpectExec("UPDATE .*").WillReturnError(fmt.Errorf("pop")) mock.ExpectRollback() err := s.UpdateTokenBalances(context.Background(), &fftypes.TokenTransfer{To: "0x0"}) diff --git a/internal/database/sqlcommon/tokentransfer_sql.go b/internal/database/sqlcommon/tokentransfer_sql.go index 1a8d52c3d5..6f2724f63a 100644 --- a/internal/database/sqlcommon/tokentransfer_sql.go +++ b/internal/database/sqlcommon/tokentransfer_sql.go @@ -33,6 +33,7 @@ var ( "local_id", "pool_id", "token_index", + "uri", "connector", "namespace", "key", @@ -85,6 +86,7 @@ func (s *SQLCommon) UpsertTokenTransfer(ctx context.Context, transfer *fftypes.T Set("local_id", transfer.LocalID). Set("pool_id", transfer.Pool). Set("token_index", transfer.TokenIndex). + Set("uri", transfer.URI). Set("connector", transfer.Connector). Set("namespace", transfer.Namespace). Set("key", transfer.Key). @@ -112,6 +114,7 @@ func (s *SQLCommon) UpsertTokenTransfer(ctx context.Context, transfer *fftypes.T transfer.LocalID, transfer.Pool, transfer.TokenIndex, + transfer.URI, transfer.Connector, transfer.Namespace, transfer.Key, @@ -143,6 +146,7 @@ func (s *SQLCommon) tokenTransferResult(ctx context.Context, row *sql.Rows) (*ff &transfer.LocalID, &transfer.Pool, &transfer.TokenIndex, + &transfer.URI, &transfer.Connector, &transfer.Namespace, &transfer.Key, diff --git a/internal/database/sqlcommon/tokentransfer_sql_test.go b/internal/database/sqlcommon/tokentransfer_sql_test.go index 54fb3ea4af..ca1f4716ab 100644 --- a/internal/database/sqlcommon/tokentransfer_sql_test.go +++ b/internal/database/sqlcommon/tokentransfer_sql_test.go @@ -40,6 +40,7 @@ func TestTokenTransferE2EWithDB(t *testing.T) { Type: fftypes.TokenTransferTypeTransfer, Pool: fftypes.NewUUID(), TokenIndex: "1", + URI: "firefly://token/1", Connector: "erc1155", Namespace: "ns1", From: "0x01", diff --git a/internal/events/tokens_transferred_test.go b/internal/events/tokens_transferred_test.go index 2c366eddde..5cdeda6dad 100644 --- a/internal/events/tokens_transferred_test.go +++ b/internal/events/tokens_transferred_test.go @@ -35,9 +35,11 @@ func TestTokensTransferredSucceedWithRetries(t *testing.T) { mdi := em.database.(*databasemocks.Plugin) mti := &tokenmocks.Plugin{} + uri := "firefly://token/1" transfer := &fftypes.TokenTransfer{ Type: fftypes.TokenTransferTypeTransfer, TokenIndex: "0", + URI: uri, Connector: "erc1155", Key: "0x12345", From: "0x1", @@ -187,9 +189,11 @@ func TestTokensTransferredWithMessageReceived(t *testing.T) { mdi := em.database.(*databasemocks.Plugin) mti := &tokenmocks.Plugin{} + uri := "firefly://token/1" transfer := &fftypes.TokenTransfer{ Type: fftypes.TokenTransferTypeTransfer, TokenIndex: "0", + URI: uri, Connector: "erc1155", Key: "0x12345", From: "0x1", @@ -230,9 +234,11 @@ func TestTokensTransferredWithMessageSend(t *testing.T) { mdi := em.database.(*databasemocks.Plugin) mti := &tokenmocks.Plugin{} + uri := "firefly://token/1" transfer := &fftypes.TokenTransfer{ Type: fftypes.TokenTransferTypeTransfer, TokenIndex: "0", + URI: uri, Connector: "erc1155", Key: "0x12345", From: "0x1", diff --git a/internal/tokens/fftokens/fftokens.go b/internal/tokens/fftokens/fftokens.go index dc863bedc0..da0192fdf0 100644 --- a/internal/tokens/fftokens/fftokens.go +++ b/internal/tokens/fftokens/fftokens.go @@ -209,6 +209,7 @@ func (ft *FFTokens) handleTokenPoolCreate(ctx context.Context, data fftypes.JSON func (ft *FFTokens) handleTokenTransfer(ctx context.Context, t fftypes.TokenTransferType, data fftypes.JSONObject) (err error) { tokenIndex := data.GetString("tokenIndex") + uri := data.GetString("uri") poolProtocolID := data.GetString("poolId") operatorAddress := data.GetString("operator") fromAddress := data.GetString("from") @@ -249,6 +250,7 @@ func (ft *FFTokens) handleTokenTransfer(ctx context.Context, t fftypes.TokenTran transfer := &fftypes.TokenTransfer{ Type: t, TokenIndex: tokenIndex, + URI: uri, Connector: ft.configuredName, From: fromAddress, To: toAddress, diff --git a/pkg/database/plugin.go b/pkg/database/plugin.go index 324e37556c..a22f32c298 100644 --- a/pkg/database/plugin.go +++ b/pkg/database/plugin.go @@ -792,6 +792,7 @@ var TokenPoolQueryFactory = &queryFields{ var TokenBalanceQueryFactory = &queryFields{ "pool": &UUIDField{}, "tokenindex": &StringField{}, + "uri": &StringField{}, "connector": &StringField{}, "namespace": &StringField{}, "key": &StringField{}, @@ -804,6 +805,7 @@ var TokenTransferQueryFactory = &queryFields{ "localid": &StringField{}, "pool": &UUIDField{}, "tokenindex": &StringField{}, + "uri": &StringField{}, "connector": &StringField{}, "namespace": &StringField{}, "key": &StringField{}, diff --git a/pkg/fftypes/tokenbalance.go b/pkg/fftypes/tokenbalance.go index d3f997c230..d82e6dc64c 100644 --- a/pkg/fftypes/tokenbalance.go +++ b/pkg/fftypes/tokenbalance.go @@ -19,6 +19,7 @@ package fftypes type TokenBalance struct { Pool *UUID `json:"pool,omitempty"` TokenIndex string `json:"tokenIndex,omitempty"` + URI string `json:"uri,omitempty"` Connector string `json:"connector,omitempty"` Namespace string `json:"namespace,omitempty"` Key string `json:"key,omitempty"` diff --git a/pkg/fftypes/tokentransfer.go b/pkg/fftypes/tokentransfer.go index 13a5e89bf0..1686d39ee9 100644 --- a/pkg/fftypes/tokentransfer.go +++ b/pkg/fftypes/tokentransfer.go @@ -29,6 +29,7 @@ type TokenTransfer struct { LocalID *UUID `json:"localId,omitempty"` Pool *UUID `json:"pool,omitempty"` TokenIndex string `json:"tokenIndex,omitempty"` + URI string `json:"uri,omitempty"` Connector string `json:"connector,omitempty"` Namespace string `json:"namespace,omitempty"` Key string `json:"key,omitempty"` From 04a349a17fd5ba6407821eac88f8dc70506ed2e5 Mon Sep 17 00:00:00 2001 From: Andrew Richardson Date: Tue, 23 Nov 2021 15:47:34 -0500 Subject: [PATCH 2/2] Update firefly-tokens-erc1155 version Signed-off-by: Andrew Richardson --- manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index db4e0ce87f..e74e14fe17 100644 --- a/manifest.json +++ b/manifest.json @@ -16,7 +16,7 @@ }, "tokens-erc1155": { "image": "ghcr.io/hyperledger/firefly-tokens-erc1155", - "tag": "v0.10.0", - "sha": "a43ae3aaf50fe830a24ad18030134b2f8e0d77411e01deb999956bb82ffcf838" + "tag": "v0.10.0-20211123-8", + "sha": "ee9e8b0d9112dfae70dbb35a18de8da9863632cbd56f275c3048f0d257e4a6b7" } }