From 91a18fcbc642b6421b70aed53d463cfbaec128ad Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Wed, 1 Nov 2023 09:21:59 -0400 Subject: [PATCH] Add namespace to token connector API calls Signed-off-by: Nicko Guyer --- go.sum | 1 + internal/assets/token_approval.go | 3 +++ internal/assets/token_transfer.go | 9 +++++++++ internal/tokens/fftokens/fftokens.go | 24 ++++++++++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/go.sum b/go.sum index c5c653a63..789faf2b3 100644 --- a/go.sum +++ b/go.sum @@ -457,6 +457,7 @@ github.com/go-latex/latex v0.0.0-20210118124228-b3d85cf34e07/go.mod h1:CO1AlKB2C github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= +github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= diff --git a/internal/assets/token_approval.go b/internal/assets/token_approval.go index 406af13e6..ecec79a2e 100644 --- a/internal/assets/token_approval.go +++ b/internal/assets/token_approval.go @@ -63,6 +63,9 @@ func (am *assetManager) NewApproval(approval *core.TokenApprovalInput) syncasync approval: approval, idempotentSubmit: approval.IdempotencyKey != "", } + if approval.Namespace == "" { + approval.Namespace = am.namespace + } sender.setDefaults() return sender } diff --git a/internal/assets/token_transfer.go b/internal/assets/token_transfer.go index 0d26c1c06..11b947b7b 100644 --- a/internal/assets/token_transfer.go +++ b/internal/assets/token_transfer.go @@ -120,6 +120,9 @@ func (am *assetManager) validateTransfer(ctx context.Context, transfer *core.Tok func (am *assetManager) MintTokens(ctx context.Context, transfer *core.TokenTransferInput, waitConfirm bool) (out *core.TokenTransfer, err error) { transfer.Type = core.TokenTransferTypeMint + if transfer.Namespace == "" { + transfer.Namespace = am.namespace + } sender := am.NewTransfer(transfer) if am.metrics.IsMetricsEnabled() { @@ -135,6 +138,9 @@ func (am *assetManager) MintTokens(ctx context.Context, transfer *core.TokenTran func (am *assetManager) BurnTokens(ctx context.Context, transfer *core.TokenTransferInput, waitConfirm bool) (out *core.TokenTransfer, err error) { transfer.Type = core.TokenTransferTypeBurn + if transfer.Namespace == "" { + transfer.Namespace = am.namespace + } sender := am.NewTransfer(transfer) if am.metrics.IsMetricsEnabled() { @@ -150,6 +156,9 @@ func (am *assetManager) BurnTokens(ctx context.Context, transfer *core.TokenTran func (am *assetManager) TransferTokens(ctx context.Context, transfer *core.TokenTransferInput, waitConfirm bool) (out *core.TokenTransfer, err error) { transfer.Type = core.TokenTransferTypeTransfer + if transfer.Namespace == "" { + transfer.Namespace = am.namespace + } sender := am.NewTransfer(transfer) if am.metrics.IsMetricsEnabled() { diff --git a/internal/tokens/fftokens/fftokens.go b/internal/tokens/fftokens/fftokens.go index 55e74091f..0a789a2ab 100644 --- a/internal/tokens/fftokens/fftokens.go +++ b/internal/tokens/fftokens/fftokens.go @@ -163,6 +163,7 @@ type tokenData struct { } type createPool struct { + Namespace string `json:"namespace"` Type core.TokenType `json:"type"` RequestID string `json:"requestId"` Signer string `json:"signer"` @@ -173,12 +174,14 @@ type createPool struct { } type activatePool struct { + Namespace string `json:"namespace"` PoolData string `json:"poolData"` PoolLocator string `json:"poolLocator"` Config fftypes.JSONObject `json:"config"` } type deactivatePool struct { + Namespace string `json:"namespace"` PoolData string `json:"poolData"` PoolLocator string `json:"poolLocator"` Config fftypes.JSONObject `json:"config"` @@ -195,6 +198,7 @@ type checkInterface struct { } type mintTokens struct { + Namespace string `json:"namespace"` PoolLocator string `json:"poolLocator"` TokenIndex string `json:"tokenIndex,omitempty"` To string `json:"to"` @@ -208,6 +212,7 @@ type mintTokens struct { } type burnTokens struct { + Namespace string `json:"namespace"` PoolLocator string `json:"poolLocator"` TokenIndex string `json:"tokenIndex,omitempty"` From string `json:"from"` @@ -221,6 +226,7 @@ type burnTokens struct { type transferTokens struct { PoolLocator string `json:"poolLocator"` + Namespace string `json:"namespace"` TokenIndex string `json:"tokenIndex,omitempty"` From string `json:"from"` To string `json:"to"` @@ -233,6 +239,7 @@ type transferTokens struct { } type tokenApproval struct { + Namespace string `json:"namespace"` Signer string `json:"signer"` Operator string `json:"operator"` Approved bool `json:"approved"` @@ -318,6 +325,16 @@ func (ft *FFTokens) StartNamespace(ctx context.Context, namespace string) (err e if err != nil { return err } + startCmd := core.WSStart{ + WSActionBase: core.WSActionBase{ + Type: core.WSClientActionStart, + }, + Namespace: namespace, + } + b, _ := json.Marshal(startCmd) + if err := ft.wsconn[namespace].Send(ctx, b); err != nil { + return err + } go ft.eventLoop(namespace) @@ -716,6 +733,7 @@ func (ft *FFTokens) CreateTokenPool(ctx context.Context, nsOpID string, pool *co var errRes tokenError res, err := ft.client.R().SetContext(ctx). SetBody(&createPool{ + Namespace: pool.Namespace, Type: pool.Type, RequestID: nsOpID, Signer: pool.Key, @@ -746,6 +764,7 @@ func (ft *FFTokens) ActivateTokenPool(ctx context.Context, pool *core.TokenPool) var errRes tokenError res, err := ft.client.R().SetContext(ctx). SetBody(&activatePool{ + Namespace: pool.Namespace, PoolData: packPoolData(pool.Namespace, pool.ID), PoolLocator: pool.Locator, Config: pool.Config, @@ -778,6 +797,7 @@ func (ft *FFTokens) DeactivateTokenPool(ctx context.Context, pool *core.TokenPoo var errRes tokenError res, err := ft.client.R().SetContext(ctx). SetBody(&deactivatePool{ + Namespace: pool.Namespace, PoolData: pool.PluginData, PoolLocator: pool.Locator, Config: pool.Config, @@ -855,6 +875,7 @@ func (ft *FFTokens) MintTokens(ctx context.Context, nsOpID string, poolLocator s var errRes tokenError res, err := ft.client.R().SetContext(ctx). SetBody(&mintTokens{ + Namespace: mint.Namespace, PoolLocator: poolLocator, TokenIndex: mint.TokenIndex, To: mint.To, @@ -890,6 +911,7 @@ func (ft *FFTokens) BurnTokens(ctx context.Context, nsOpID string, poolLocator s var errRes tokenError res, err := ft.client.R().SetContext(ctx). SetBody(&burnTokens{ + Namespace: burn.Namespace, PoolLocator: poolLocator, TokenIndex: burn.TokenIndex, From: burn.From, @@ -924,6 +946,7 @@ func (ft *FFTokens) TransferTokens(ctx context.Context, nsOpID string, poolLocat var errRes tokenError res, err := ft.client.R().SetContext(ctx). SetBody(&transferTokens{ + Namespace: transfer.Namespace, PoolLocator: poolLocator, TokenIndex: transfer.TokenIndex, From: transfer.From, @@ -959,6 +982,7 @@ func (ft *FFTokens) TokensApproval(ctx context.Context, nsOpID string, poolLocat var errRes tokenError res, err := ft.client.R().SetContext(ctx). SetBody(&tokenApproval{ + Namespace: approval.Namespace, PoolLocator: poolLocator, Signer: approval.Key, Operator: approval.Operator,