Skip to content

Commit 91a18fc

Browse files
committed
Add namespace to token connector API calls
Signed-off-by: Nicko Guyer <[email protected]>
1 parent 9655d6f commit 91a18fc

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ github.com/go-latex/latex v0.0.0-20210118124228-b3d85cf34e07/go.mod h1:CO1AlKB2C
457457
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
458458
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
459459
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
460+
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
460461
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
461462
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
462463
github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=

internal/assets/token_approval.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ func (am *assetManager) NewApproval(approval *core.TokenApprovalInput) syncasync
6363
approval: approval,
6464
idempotentSubmit: approval.IdempotencyKey != "",
6565
}
66+
if approval.Namespace == "" {
67+
approval.Namespace = am.namespace
68+
}
6669
sender.setDefaults()
6770
return sender
6871
}

internal/assets/token_transfer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ func (am *assetManager) validateTransfer(ctx context.Context, transfer *core.Tok
120120

121121
func (am *assetManager) MintTokens(ctx context.Context, transfer *core.TokenTransferInput, waitConfirm bool) (out *core.TokenTransfer, err error) {
122122
transfer.Type = core.TokenTransferTypeMint
123+
if transfer.Namespace == "" {
124+
transfer.Namespace = am.namespace
125+
}
123126

124127
sender := am.NewTransfer(transfer)
125128
if am.metrics.IsMetricsEnabled() {
@@ -135,6 +138,9 @@ func (am *assetManager) MintTokens(ctx context.Context, transfer *core.TokenTran
135138

136139
func (am *assetManager) BurnTokens(ctx context.Context, transfer *core.TokenTransferInput, waitConfirm bool) (out *core.TokenTransfer, err error) {
137140
transfer.Type = core.TokenTransferTypeBurn
141+
if transfer.Namespace == "" {
142+
transfer.Namespace = am.namespace
143+
}
138144

139145
sender := am.NewTransfer(transfer)
140146
if am.metrics.IsMetricsEnabled() {
@@ -150,6 +156,9 @@ func (am *assetManager) BurnTokens(ctx context.Context, transfer *core.TokenTran
150156

151157
func (am *assetManager) TransferTokens(ctx context.Context, transfer *core.TokenTransferInput, waitConfirm bool) (out *core.TokenTransfer, err error) {
152158
transfer.Type = core.TokenTransferTypeTransfer
159+
if transfer.Namespace == "" {
160+
transfer.Namespace = am.namespace
161+
}
153162

154163
sender := am.NewTransfer(transfer)
155164
if am.metrics.IsMetricsEnabled() {

internal/tokens/fftokens/fftokens.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ type tokenData struct {
163163
}
164164

165165
type createPool struct {
166+
Namespace string `json:"namespace"`
166167
Type core.TokenType `json:"type"`
167168
RequestID string `json:"requestId"`
168169
Signer string `json:"signer"`
@@ -173,12 +174,14 @@ type createPool struct {
173174
}
174175

175176
type activatePool struct {
177+
Namespace string `json:"namespace"`
176178
PoolData string `json:"poolData"`
177179
PoolLocator string `json:"poolLocator"`
178180
Config fftypes.JSONObject `json:"config"`
179181
}
180182

181183
type deactivatePool struct {
184+
Namespace string `json:"namespace"`
182185
PoolData string `json:"poolData"`
183186
PoolLocator string `json:"poolLocator"`
184187
Config fftypes.JSONObject `json:"config"`
@@ -195,6 +198,7 @@ type checkInterface struct {
195198
}
196199

197200
type mintTokens struct {
201+
Namespace string `json:"namespace"`
198202
PoolLocator string `json:"poolLocator"`
199203
TokenIndex string `json:"tokenIndex,omitempty"`
200204
To string `json:"to"`
@@ -208,6 +212,7 @@ type mintTokens struct {
208212
}
209213

210214
type burnTokens struct {
215+
Namespace string `json:"namespace"`
211216
PoolLocator string `json:"poolLocator"`
212217
TokenIndex string `json:"tokenIndex,omitempty"`
213218
From string `json:"from"`
@@ -221,6 +226,7 @@ type burnTokens struct {
221226

222227
type transferTokens struct {
223228
PoolLocator string `json:"poolLocator"`
229+
Namespace string `json:"namespace"`
224230
TokenIndex string `json:"tokenIndex,omitempty"`
225231
From string `json:"from"`
226232
To string `json:"to"`
@@ -233,6 +239,7 @@ type transferTokens struct {
233239
}
234240

235241
type tokenApproval struct {
242+
Namespace string `json:"namespace"`
236243
Signer string `json:"signer"`
237244
Operator string `json:"operator"`
238245
Approved bool `json:"approved"`
@@ -318,6 +325,16 @@ func (ft *FFTokens) StartNamespace(ctx context.Context, namespace string) (err e
318325
if err != nil {
319326
return err
320327
}
328+
startCmd := core.WSStart{
329+
WSActionBase: core.WSActionBase{
330+
Type: core.WSClientActionStart,
331+
},
332+
Namespace: namespace,
333+
}
334+
b, _ := json.Marshal(startCmd)
335+
if err := ft.wsconn[namespace].Send(ctx, b); err != nil {
336+
return err
337+
}
321338

322339
go ft.eventLoop(namespace)
323340

@@ -716,6 +733,7 @@ func (ft *FFTokens) CreateTokenPool(ctx context.Context, nsOpID string, pool *co
716733
var errRes tokenError
717734
res, err := ft.client.R().SetContext(ctx).
718735
SetBody(&createPool{
736+
Namespace: pool.Namespace,
719737
Type: pool.Type,
720738
RequestID: nsOpID,
721739
Signer: pool.Key,
@@ -746,6 +764,7 @@ func (ft *FFTokens) ActivateTokenPool(ctx context.Context, pool *core.TokenPool)
746764
var errRes tokenError
747765
res, err := ft.client.R().SetContext(ctx).
748766
SetBody(&activatePool{
767+
Namespace: pool.Namespace,
749768
PoolData: packPoolData(pool.Namespace, pool.ID),
750769
PoolLocator: pool.Locator,
751770
Config: pool.Config,
@@ -778,6 +797,7 @@ func (ft *FFTokens) DeactivateTokenPool(ctx context.Context, pool *core.TokenPoo
778797
var errRes tokenError
779798
res, err := ft.client.R().SetContext(ctx).
780799
SetBody(&deactivatePool{
800+
Namespace: pool.Namespace,
781801
PoolData: pool.PluginData,
782802
PoolLocator: pool.Locator,
783803
Config: pool.Config,
@@ -855,6 +875,7 @@ func (ft *FFTokens) MintTokens(ctx context.Context, nsOpID string, poolLocator s
855875
var errRes tokenError
856876
res, err := ft.client.R().SetContext(ctx).
857877
SetBody(&mintTokens{
878+
Namespace: mint.Namespace,
858879
PoolLocator: poolLocator,
859880
TokenIndex: mint.TokenIndex,
860881
To: mint.To,
@@ -890,6 +911,7 @@ func (ft *FFTokens) BurnTokens(ctx context.Context, nsOpID string, poolLocator s
890911
var errRes tokenError
891912
res, err := ft.client.R().SetContext(ctx).
892913
SetBody(&burnTokens{
914+
Namespace: burn.Namespace,
893915
PoolLocator: poolLocator,
894916
TokenIndex: burn.TokenIndex,
895917
From: burn.From,
@@ -924,6 +946,7 @@ func (ft *FFTokens) TransferTokens(ctx context.Context, nsOpID string, poolLocat
924946
var errRes tokenError
925947
res, err := ft.client.R().SetContext(ctx).
926948
SetBody(&transferTokens{
949+
Namespace: transfer.Namespace,
927950
PoolLocator: poolLocator,
928951
TokenIndex: transfer.TokenIndex,
929952
From: transfer.From,
@@ -959,6 +982,7 @@ func (ft *FFTokens) TokensApproval(ctx context.Context, nsOpID string, poolLocat
959982
var errRes tokenError
960983
res, err := ft.client.R().SetContext(ctx).
961984
SetBody(&tokenApproval{
985+
Namespace: approval.Namespace,
962986
PoolLocator: poolLocator,
963987
Signer: approval.Key,
964988
Operator: approval.Operator,

0 commit comments

Comments
 (0)