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
124 changes: 124 additions & 0 deletions docs/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5859,6 +5859,69 @@ paths:
description: Success
default:
description: ""
/namespaces/{ns}/tokens/pools/{nameOrID}:
get:
description: 'TODO: Description'
operationId: getTokenPoolByNameOrID
parameters:
- description: 'TODO: Description'
in: path
name: ns
required: true
schema:
example: default
type: string
- description: 'TODO: Description'
in: path
name: nameOrID
required: true
schema:
type: string
- description: Server-side request timeout (millseconds, or set a custom suffix
like 10s)
in: header
name: Request-Timeout
schema:
default: 120s
type: string
responses:
"200":
content:
application/json:
schema:
properties:
config:
additionalProperties: {}
type: object
connector:
type: string
created: {}
id: {}
key:
type: string
message: {}
name:
type: string
namespace:
type: string
protocolId:
type: string
standard:
type: string
symbol:
type: string
tx:
properties:
id: {}
type:
type: string
type: object
type:
type: string
type: object
description: Success
default:
description: ""
/namespaces/{ns}/tokens/transfers:
get:
description: 'TODO: Description'
Expand Down Expand Up @@ -6005,6 +6068,67 @@ paths:
description: Success
default:
description: ""
/namespaces/{ns}/tokens/transfers/{transferID}:
get:
description: 'TODO: Description'
operationId: getTokenTransferByID
parameters:
- description: 'TODO: Description'
in: path
name: ns
required: true
schema:
example: default
type: string
- description: 'TODO: Description'
in: path
name: transferID
required: true
schema:
type: string
- description: Server-side request timeout (millseconds, or set a custom suffix
like 10s)
in: header
name: Request-Timeout
schema:
default: 120s
type: string
responses:
"200":
content:
application/json:
schema:
properties:
amount: {}
connector:
type: string
created: {}
from:
type: string
key:
type: string
localId: {}
messageHash: {}
poolProtocolId:
type: string
protocolId:
type: string
to:
type: string
tokenIndex:
type: string
tx:
properties:
id: {}
type:
type: string
type: object
type:
type: string
type: object
description: Success
default:
description: ""
/namespaces/{ns}/transactions:
get:
description: 'TODO: Description'
Expand Down
46 changes: 46 additions & 0 deletions internal/apiserver/route_get_token_pool_by_name_or_id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright © 2021 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package apiserver

import (
"net/http"

"github.com/hyperledger/firefly/internal/config"
"github.com/hyperledger/firefly/internal/i18n"
"github.com/hyperledger/firefly/internal/oapispec"
"github.com/hyperledger/firefly/pkg/fftypes"
)

var getTokenPoolByNameOrID = &oapispec.Route{
Name: "getTokenPoolByNameOrID",
Path: "namespaces/{ns}/tokens/pools/{nameOrID}",
Method: http.MethodGet,
PathParams: []*oapispec.PathParam{
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
{Name: "nameOrID", Description: i18n.MsgTBD},
},
QueryParams: nil,
FilterFactory: nil,
Description: i18n.MsgTBD,
JSONInputValue: nil,
JSONOutputValue: func() interface{} { return &fftypes.TokenPool{} },
JSONOutputCodes: []int{http.StatusOK},
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
output, err = r.Or.Assets().GetTokenPoolByNameOrID(r.Ctx, r.PP["ns"], r.PP["nameOrID"])
return output, err
},
}
42 changes: 42 additions & 0 deletions internal/apiserver/route_get_token_pool_by_name_or_id_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright © 2021 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package apiserver

import (
"net/http/httptest"
"testing"

"github.com/hyperledger/firefly/mocks/assetmocks"
"github.com/hyperledger/firefly/pkg/fftypes"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestGetTokenPoolByNameOrID(t *testing.T) {
o, r := newTestAPIServer()
mam := &assetmocks.Manager{}
o.On("Assets").Return(mam)
req := httptest.NewRequest("GET", "/api/v1/namespaces/ns1/tokens/pools/abc", nil)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mam.On("GetTokenPoolByNameOrID", mock.Anything, "ns1", "abc").
Return(&fftypes.TokenPool{}, nil)
r.ServeHTTP(res, req)

assert.Equal(t, 200, res.Result().StatusCode)
}
46 changes: 46 additions & 0 deletions internal/apiserver/route_get_token_transfers_by_id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright © 2021 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package apiserver

import (
"net/http"

"github.com/hyperledger/firefly/internal/config"
"github.com/hyperledger/firefly/internal/i18n"
"github.com/hyperledger/firefly/internal/oapispec"
"github.com/hyperledger/firefly/pkg/fftypes"
)

var getTokenTransferByID = &oapispec.Route{
Name: "getTokenTransferByID",
Path: "namespaces/{ns}/tokens/transfers/{transferID}",
Method: http.MethodGet,
PathParams: []*oapispec.PathParam{
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
{Name: "transferID", Description: i18n.MsgTBD},
},
QueryParams: nil,
FilterFactory: nil,
Description: i18n.MsgTBD,
JSONInputValue: nil,
JSONOutputValue: func() interface{} { return &fftypes.TokenTransfer{} },
JSONOutputCodes: []int{http.StatusOK},
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
output, err = r.Or.Assets().GetTokenTransferByID(r.Ctx, r.PP["ns"], r.PP["transferID"])
return output, err
},
}
42 changes: 42 additions & 0 deletions internal/apiserver/route_get_token_transfers_by_id_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright © 2021 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package apiserver

import (
"net/http/httptest"
"testing"

"github.com/hyperledger/firefly/mocks/assetmocks"
"github.com/hyperledger/firefly/pkg/fftypes"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestGetTokenTransferByID(t *testing.T) {
o, r := newTestAPIServer()
mam := &assetmocks.Manager{}
o.On("Assets").Return(mam)
req := httptest.NewRequest("GET", "/api/v1/namespaces/ns1/tokens/transfers/id1", nil)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mam.On("GetTokenTransferByID", mock.Anything, "ns1", "id1").
Return(&fftypes.TokenTransfer{}, nil)
r.ServeHTTP(res, req)

assert.Equal(t, 200, res.Result().StatusCode)
}
2 changes: 2 additions & 0 deletions internal/apiserver/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ var routes = []*oapispec.Route{
postTokenPool,
getTokenPools,
getTokenPoolsByType,
getTokenPoolByNameOrID,
getTokenPoolByName,
getTokenAccounts,
getTokenAccountsByPool,
getTokenTransfers,
getTokenTransfersByPool,
getTokenTransferByID,
postTokenMint,
postTokenBurn,
postTokenTransfer,
Expand Down
2 changes: 2 additions & 0 deletions internal/assets/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ type Manager interface {
GetTokenPools(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.TokenPool, *database.FilterResult, error)
GetTokenPoolsByType(ctx context.Context, ns, connector string, filter database.AndFilter) ([]*fftypes.TokenPool, *database.FilterResult, error)
GetTokenPool(ctx context.Context, ns, connector, poolName string) (*fftypes.TokenPool, error)
GetTokenPoolByNameOrID(ctx context.Context, ns string, poolNameOrID string) (*fftypes.TokenPool, error)
ValidateTokenPoolTx(ctx context.Context, pool *fftypes.TokenPool, protocolTxID string) error
GetTokenAccounts(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.TokenAccount, *database.FilterResult, error)
GetTokenAccountsByPool(ctx context.Context, ns, connector, poolName string, filter database.AndFilter) ([]*fftypes.TokenAccount, *database.FilterResult, error)
GetTokenTransfers(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error)
GetTokenTransferByID(ctx context.Context, ns, id string) (*fftypes.TokenTransfer, error)
GetTokenTransfersByPool(ctx context.Context, ns, connector, poolName string, filter database.AndFilter) ([]*fftypes.TokenTransfer, *database.FilterResult, error)
NewTransfer(ns, connector, poolName string, transfer *fftypes.TokenTransferInput) sysmessaging.MessageSender
MintTokens(ctx context.Context, ns, connector, poolName string, transfer *fftypes.TokenTransferInput, waitConfirm bool) (*fftypes.TokenTransfer, error)
Expand Down
24 changes: 24 additions & 0 deletions internal/assets/token_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,30 @@ func (am *assetManager) GetTokenPool(ctx context.Context, ns, connector, poolNam
return pool, nil
}

func (am *assetManager) GetTokenPoolByNameOrID(ctx context.Context, ns, poolNameOrID string) (*fftypes.TokenPool, error) {
if err := fftypes.ValidateFFNameField(ctx, ns, "namespace"); err != nil {
return nil, err
}

var pool *fftypes.TokenPool

poolID, err := fftypes.ParseUUID(ctx, poolNameOrID)
if err != nil {
if err := fftypes.ValidateFFNameField(ctx, poolNameOrID, "name"); err != nil {
return nil, err
}
if pool, err = am.database.GetTokenPool(ctx, ns, poolNameOrID); err != nil {
return nil, err
}
} else if pool, err = am.database.GetTokenPoolByID(ctx, poolID); err != nil {
return nil, err
}
if pool == nil {
return nil, i18n.NewError(ctx, i18n.Msg404NotFound)
}
return pool, nil
}

func (am *assetManager) ValidateTokenPoolTx(ctx context.Context, pool *fftypes.TokenPool, protocolTxID string) error {
// TODO: validate that the given token pool was created with the given protocolTxId
return nil
Expand Down
Loading