Skip to content

Commit

Permalink
Add namespace to token connector API calls
Browse files Browse the repository at this point in the history
Signed-off-by: Nicko Guyer <[email protected]>
  • Loading branch information
nguyer committed Nov 1, 2023
1 parent 9655d6f commit 91a18fc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
3 changes: 3 additions & 0 deletions internal/assets/token_approval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions internal/assets/token_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down
24 changes: 24 additions & 0 deletions internal/tokens/fftokens/fftokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
Expand All @@ -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"`
Expand All @@ -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"`
Expand All @@ -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"`
Expand All @@ -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"`
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 91a18fc

Please sign in to comment.