Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BEGIN;
ALTER TABLE tokenaccount DROP COLUMN namespace;
ALTER TABLE tokentransfer DROP COLUMN namespace;
COMMIT;
13 changes: 13 additions & 0 deletions db/migrations/postgres/000037_add_token_namespace_fields.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
BEGIN;
ALTER TABLE tokenaccount ADD COLUMN namespace VARCHAR(64);
ALTER TABLE tokentransfer ADD COLUMN namespace VARCHAR(64);

UPDATE tokenaccount SET namespace = pool.namespace
FROM (SELECT protocol_id, namespace FROM tokenpool) AS pool
WHERE tokenaccount.pool_protocol_id = pool.protocol_id;

UPDATE tokentransfer SET namespace = pool.namespace
FROM (SELECT protocol_id, namespace FROM tokenpool) AS pool
WHERE tokentransfer.pool_protocol_id = pool.protocol_id;

COMMIT;
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
DELETE FROM tokenaccount;
ALTER TABLE tokenaccount ADD COLUMN connector VARCHAR(64);
ALTER TABLE tokentransfer ADD COLUMN connector VARCHAR(64);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE tokenaccount DROP COLUMN namespace;
ALTER TABLE tokentransfer DROP COLUMN namespace;
10 changes: 10 additions & 0 deletions db/migrations/sqlite/000037_add_token_namespace_fields.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ALTER TABLE tokenaccount ADD COLUMN namespace VARCHAR(64);
ALTER TABLE tokentransfer ADD COLUMN namespace VARCHAR(64);

UPDATE tokenaccount SET namespace = pool.namespace
FROM (SELECT protocol_id, namespace FROM tokenpool) AS pool
WHERE tokenaccount.pool_protocol_id = pool.protocol_id;

UPDATE tokentransfer SET namespace = pool.namespace
FROM (SELECT protocol_id, namespace FROM tokenpool) AS pool
WHERE tokentransfer.pool_protocol_id = pool.protocol_id;
48 changes: 48 additions & 0 deletions docs/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4661,6 +4661,11 @@ paths:
name: key
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: namespace
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: poolprotocolid
Expand Down Expand Up @@ -4722,6 +4727,8 @@ paths:
type: string
key:
type: string
namespace:
type: string
poolProtocolId:
type: string
tokenIndex:
Expand Down Expand Up @@ -4870,6 +4877,8 @@ paths:
type: boolean
type: object
messageHash: {}
namespace:
type: string
poolProtocolId:
type: string
protocolId:
Expand Down Expand Up @@ -4907,6 +4916,8 @@ paths:
type: string
localId: {}
messageHash: {}
namespace:
type: string
poolProtocolId:
type: string
protocolId:
Expand Down Expand Up @@ -4940,6 +4951,8 @@ paths:
type: string
localId: {}
messageHash: {}
namespace:
type: string
poolProtocolId:
type: string
protocolId:
Expand Down Expand Up @@ -5098,6 +5111,8 @@ paths:
type: boolean
type: object
messageHash: {}
namespace:
type: string
poolProtocolId:
type: string
protocolId:
Expand Down Expand Up @@ -5135,6 +5150,8 @@ paths:
type: string
localId: {}
messageHash: {}
namespace:
type: string
poolProtocolId:
type: string
protocolId:
Expand Down Expand Up @@ -5168,6 +5185,8 @@ paths:
type: string
localId: {}
messageHash: {}
namespace:
type: string
poolProtocolId:
type: string
protocolId:
Expand Down Expand Up @@ -5254,6 +5273,11 @@ paths:
name: messagehash
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: namespace
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: poolprotocolid
Expand Down Expand Up @@ -5325,6 +5349,8 @@ paths:
type: string
localId: {}
messageHash: {}
namespace:
type: string
poolProtocolId:
type: string
protocolId:
Expand Down Expand Up @@ -5483,6 +5509,8 @@ paths:
type: boolean
type: object
messageHash: {}
namespace:
type: string
poolProtocolId:
type: string
protocolId:
Expand Down Expand Up @@ -5520,6 +5548,8 @@ paths:
type: string
localId: {}
messageHash: {}
namespace:
type: string
poolProtocolId:
type: string
protocolId:
Expand Down Expand Up @@ -5553,6 +5583,8 @@ paths:
type: string
localId: {}
messageHash: {}
namespace:
type: string
poolProtocolId:
type: string
protocolId:
Expand Down Expand Up @@ -5607,6 +5639,11 @@ paths:
name: key
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: namespace
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: poolprotocolid
Expand Down Expand Up @@ -5668,6 +5705,8 @@ paths:
type: string
key:
type: string
namespace:
type: string
poolProtocolId:
type: string
tokenIndex:
Expand Down Expand Up @@ -5976,6 +6015,11 @@ paths:
name: messagehash
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: namespace
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: poolprotocolid
Expand Down Expand Up @@ -6047,6 +6091,8 @@ paths:
type: string
localId: {}
messageHash: {}
namespace:
type: string
poolProtocolId:
type: string
protocolId:
Expand Down Expand Up @@ -6109,6 +6155,8 @@ paths:
type: string
localId: {}
messageHash: {}
namespace:
type: string
poolProtocolId:
type: string
protocolId:
Expand Down
2 changes: 1 addition & 1 deletion internal/apiserver/route_post_token_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var postTokenTransfer = &oapispec.Route{
FilterFactory: nil,
Description: i18n.MsgTBD,
JSONInputValue: func() interface{} { return &fftypes.TokenTransferInput{} },
JSONInputMask: []string{"Type", "LocalID", "PoolProtocolID", "ProtocolID", "MessageHash", "Connector", "TX", "Created"},
JSONInputMask: []string{"Type", "LocalID", "PoolProtocolID", "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) {
Expand Down
2 changes: 1 addition & 1 deletion internal/assets/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (am *assetManager) scopeNS(ns string, filter database.AndFilter) database.A
}

func (am *assetManager) GetTokenAccounts(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.TokenAccount, *database.FilterResult, error) {
return am.database.GetTokenAccounts(ctx, filter)
return am.database.GetTokenAccounts(ctx, am.scopeNS(ns, filter))
}

func (am *assetManager) GetTokenAccountsByPool(ctx context.Context, ns, connector, poolName string, filter database.AndFilter) ([]*fftypes.TokenAccount, *database.FilterResult, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/assets/token_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func addTokenTransferInputs(op *fftypes.Operation, transfer *fftypes.TokenTransf
}

func (am *assetManager) GetTokenTransfers(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error) {
return am.database.GetTokenTransfers(ctx, filter)
return am.database.GetTokenTransfers(ctx, am.scopeNS(ns, filter))
}

func (am *assetManager) GetTokenTransferByID(ctx context.Context, ns, id string) (*fftypes.TokenTransfer, error) {
Expand Down
3 changes: 3 additions & 0 deletions internal/database/sqlcommon/tokenaccount_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
"pool_protocol_id",
"token_index",
"connector",
"namespace",
"key",
"balance",
"updated",
Expand Down Expand Up @@ -94,6 +95,7 @@ func (s *SQLCommon) AddTokenAccountBalance(ctx context.Context, account *fftypes
account.PoolProtocolID,
account.TokenIndex,
account.Connector,
account.Namespace,
account.Key,
account.Amount,
fftypes.Now(),
Expand All @@ -113,6 +115,7 @@ func (s *SQLCommon) tokenAccountResult(ctx context.Context, row *sql.Rows) (*fft
&account.PoolProtocolID,
&account.TokenIndex,
&account.Connector,
&account.Namespace,
&account.Key,
&account.Balance,
&account.Updated,
Expand Down
5 changes: 4 additions & 1 deletion internal/database/sqlcommon/tokenaccount_sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ func TestTokenAccountE2EWithDB(t *testing.T) {
PoolProtocolID: "F1",
TokenIndex: "1",
Connector: "erc1155",
Namespace: "ns1",
Key: "0x0",
}
operation.Amount.Int().SetInt64(10)
account := &fftypes.TokenAccount{
PoolProtocolID: "F1",
TokenIndex: "1",
Connector: "erc1155",
Namespace: "ns1",
Key: "0x0",
}
account.Balance.Int().SetInt64(10)
Expand Down Expand Up @@ -167,14 +169,15 @@ func TestAddTokenAccountBalanceInsertSuccess(t *testing.T) {
PoolProtocolID: "F1",
TokenIndex: "1",
Connector: "erc1155",
Namespace: "ns1",
Key: "0x0",
}
operation.Amount.Int().SetInt64(10)

db.ExpectBegin()
db.ExpectQuery("SELECT .*").WillReturnRows(sqlmock.NewRows([]string{"id"}))
db.ExpectExec("INSERT .*").
WithArgs("F1", "1", "erc1155", "0x0", sqlmock.AnyArg(), sqlmock.AnyArg()).
WithArgs("F1", "1", "erc1155", "ns1", "0x0", sqlmock.AnyArg(), sqlmock.AnyArg()).
WillReturnResult(sqlmock.NewResult(1, 1))
db.ExpectCommit()
err := s.AddTokenAccountBalance(context.Background(), operation)
Expand Down
4 changes: 4 additions & 0 deletions internal/database/sqlcommon/tokentransfer_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
"pool_protocol_id",
"token_index",
"connector",
"namespace",
"key",
"from_key",
"to_key",
Expand Down Expand Up @@ -83,6 +84,7 @@ func (s *SQLCommon) UpsertTokenTransfer(ctx context.Context, transfer *fftypes.T
Set("pool_protocol_id", transfer.PoolProtocolID).
Set("token_index", transfer.TokenIndex).
Set("connector", transfer.Connector).
Set("namespace", transfer.Namespace).
Set("key", transfer.Key).
Set("from_key", transfer.From).
Set("to_key", transfer.To).
Expand All @@ -108,6 +110,7 @@ func (s *SQLCommon) UpsertTokenTransfer(ctx context.Context, transfer *fftypes.T
transfer.PoolProtocolID,
transfer.TokenIndex,
transfer.Connector,
transfer.Namespace,
transfer.Key,
transfer.From,
transfer.To,
Expand Down Expand Up @@ -137,6 +140,7 @@ func (s *SQLCommon) tokenTransferResult(ctx context.Context, row *sql.Rows) (*ff
&transfer.PoolProtocolID,
&transfer.TokenIndex,
&transfer.Connector,
&transfer.Namespace,
&transfer.Key,
&transfer.From,
&transfer.To,
Expand Down
1 change: 1 addition & 0 deletions internal/database/sqlcommon/tokentransfer_sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestTokenTransferE2EWithDB(t *testing.T) {
PoolProtocolID: "F1",
TokenIndex: "1",
Connector: "erc1155",
Namespace: "ns1",
From: "0x01",
To: "0x02",
ProtocolID: "12345",
Expand Down
2 changes: 2 additions & 0 deletions internal/events/tokens_transferred.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (em *eventManager) TokensTransferred(tk tokens.Plugin, transfer *fftypes.To
log.L(ctx).Warnf("Token transfer received for unknown pool '%s' - ignoring: %s", transfer.PoolProtocolID, protocolTxID)
return nil
}
transfer.Namespace = pool.Namespace

if transfer.TX.ID != nil {
if valid, err := em.persistTokenTransaction(ctx, pool.Namespace, transfer, protocolTxID, additionalInfo); err != nil || !valid {
Expand All @@ -120,6 +121,7 @@ func (em *eventManager) TokensTransferred(tk tokens.Plugin, transfer *fftypes.To
PoolProtocolID: transfer.PoolProtocolID,
TokenIndex: transfer.TokenIndex,
Connector: transfer.Connector,
Namespace: transfer.Namespace,
}

if transfer.Type != fftypes.TokenTransferTypeMint {
Expand Down
Loading