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,3 @@
BEGIN;
ALTER TABLE tokenbalance RENAME TO tokenaccount;
COMMIT:
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BEGIN;
ALTER TABLE tokenaccount RENAME TO tokenbalance;
COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE tokenbalance RENAME TO tokenaccount;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE tokenaccount RENAME TO tokenbalance;
110 changes: 110 additions & 0 deletions docs/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4128,6 +4128,7 @@ paths:
description: ""
/namespaces/{ns}/tokens/{type}/pools:
get:
deprecated: true
description: 'TODO: Description'
operationId: getTokenPoolsByType
parameters:
Expand Down Expand Up @@ -4281,6 +4282,7 @@ paths:
default:
description: ""
post:
deprecated: true
description: 'TODO: Description'
operationId: postTokenPoolByType
parameters:
Expand Down Expand Up @@ -4404,6 +4406,7 @@ paths:
description: ""
/namespaces/{ns}/tokens/{type}/pools/{name}:
get:
deprecated: true
description: 'TODO: Description'
operationId: getTokenPoolByName
parameters:
Expand Down Expand Up @@ -4473,6 +4476,7 @@ paths:
description: ""
/namespaces/{ns}/tokens/{type}/pools/{name}/accounts:
get:
deprecated: true
description: 'TODO: Description'
operationId: getTokenAccountsByPool
parameters:
Expand Down Expand Up @@ -4597,6 +4601,7 @@ paths:
description: ""
/namespaces/{ns}/tokens/{type}/pools/{name}/burn:
post:
deprecated: true
description: 'TODO: Description'
operationId: postTokenBurnByType
parameters:
Expand Down Expand Up @@ -4817,6 +4822,7 @@ paths:
description: ""
/namespaces/{ns}/tokens/{type}/pools/{name}/mint:
post:
deprecated: true
description: 'TODO: Description'
operationId: postTokenMintByType
parameters:
Expand Down Expand Up @@ -5037,6 +5043,7 @@ paths:
description: ""
/namespaces/{ns}/tokens/{type}/pools/{name}/transfers:
get:
deprecated: true
description: 'TODO: Description'
operationId: getTokenTransfersByPool
parameters:
Expand Down Expand Up @@ -5201,6 +5208,7 @@ paths:
default:
description: ""
post:
deprecated: true
description: 'TODO: Description'
operationId: postTokenTransferByType
parameters:
Expand Down Expand Up @@ -5424,6 +5432,108 @@ paths:
description: 'TODO: Description'
operationId: getTokenAccounts
parameters:
- description: 'TODO: Description'
in: path
name: ns
required: true
schema:
example: default
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
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: balance
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: connector
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
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
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: tokenindex
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: updated
schema:
type: string
- description: Sort field. For multi-field sort use comma separated values (or
multiple query values) with '-' prefix for descending
in: query
name: sort
schema:
type: string
- description: Ascending sort order (overrides all fields in a multi-field sort)
in: query
name: ascending
schema:
type: string
- description: Descending sort order (overrides all fields in a multi-field
sort)
in: query
name: descending
schema:
type: string
- description: 'The number of records to skip (max: 1,000). Unsuitable for bulk
operations'
in: query
name: skip
schema:
type: string
- description: 'The maximum number of records to return (max: 1,000)'
in: query
name: limit
schema:
example: "25"
type: string
- description: Return a total count as well as items (adds extra database processing)
in: query
name: count
schema:
type: string
responses:
"200":
content:
application/json:
schema:
items:
properties:
key:
type: string
type: object
type: array
description: Success
default:
description: ""
/namespaces/{ns}/tokens/balances:
get:
description: 'TODO: Description'
operationId: getTokenBalances
parameters:
- description: 'TODO: Description'
in: path
name: ns
Expand Down
2 changes: 1 addition & 1 deletion internal/apiserver/route_get_token_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var getTokenAccounts = &oapispec.Route{
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
},
QueryParams: nil,
FilterFactory: database.TokenAccountQueryFactory,
FilterFactory: database.TokenBalanceQueryFactory,
Description: i18n.MsgTBD,
JSONInputValue: nil,
JSONOutputValue: func() interface{} { return []*fftypes.TokenAccount{} },
Expand Down
7 changes: 4 additions & 3 deletions internal/apiserver/route_get_token_accounts_by_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ var getTokenAccountsByPool = &oapispec.Route{
{Name: "name", Description: i18n.MsgTBD},
},
QueryParams: nil,
FilterFactory: database.TokenAccountQueryFactory,
FilterFactory: database.TokenBalanceQueryFactory,
Description: i18n.MsgTBD,
JSONInputValue: nil,
JSONOutputValue: func() interface{} { return []*fftypes.TokenAccount{} },
JSONOutputValue: func() interface{} { return []*fftypes.TokenBalance{} },
JSONOutputCodes: []int{http.StatusOK},
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
return filterResult(r.Or.Assets().GetTokenAccountsByPool(r.Ctx, r.PP["ns"], r.PP["type"], r.PP["name"], r.Filter))
return filterResult(r.Or.Assets().GetTokenBalancesByPool(r.Ctx, r.PP["ns"], r.PP["type"], r.PP["name"], r.Filter))
},
Deprecated: true,
}
4 changes: 2 additions & 2 deletions internal/apiserver/route_get_token_accounts_by_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func TestGetTokenAccountsByPool(t *testing.T) {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mam.On("GetTokenAccountsByPool", mock.Anything, "ns1", "tok1", "pool1", mock.Anything).
Return([]*fftypes.TokenAccount{}, nil, nil)
mam.On("GetTokenBalancesByPool", mock.Anything, "ns1", "tok1", "pool1", mock.Anything).
Return([]*fftypes.TokenBalance{}, nil, nil)
r.ServeHTTP(res, req)

assert.Equal(t, 200, res.Result().StatusCode)
Expand Down
45 changes: 45 additions & 0 deletions internal/apiserver/route_get_token_balances.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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/database"
"github.com/hyperledger/firefly/pkg/fftypes"
)

var getTokenBalances = &oapispec.Route{
Name: "getTokenBalances",
Path: "namespaces/{ns}/tokens/balances",
Method: http.MethodGet,
PathParams: []*oapispec.PathParam{
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
},
QueryParams: nil,
FilterFactory: database.TokenBalanceQueryFactory,
Description: i18n.MsgTBD,
JSONInputValue: nil,
JSONOutputValue: func() interface{} { return []*fftypes.TokenBalance{} },
JSONOutputCodes: []int{http.StatusOK},
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
return filterResult(r.Or.Assets().GetTokenBalances(r.Ctx, r.PP["ns"], r.Filter))
},
}
42 changes: 42 additions & 0 deletions internal/apiserver/route_get_token_balances_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 TestGetTokenBalances(t *testing.T) {
o, r := newTestAPIServer()
mam := &assetmocks.Manager{}
o.On("Assets").Return(mam)
req := httptest.NewRequest("GET", "/api/v1/namespaces/ns1/tokens/balances", nil)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mam.On("GetTokenBalances", mock.Anything, "ns1", mock.Anything).
Return([]*fftypes.TokenBalance{}, nil, nil)
r.ServeHTTP(res, req)

assert.Equal(t, 200, res.Result().StatusCode)
}
1 change: 1 addition & 0 deletions internal/apiserver/route_get_token_pool_by_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ var getTokenPoolByName = &oapispec.Route{
output, err = r.Or.Assets().GetTokenPool(r.Ctx, r.PP["ns"], r.PP["type"], r.PP["name"])
return output, err
},
Deprecated: true,
}
1 change: 1 addition & 0 deletions internal/apiserver/route_get_token_pools_by_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ var getTokenPoolsByType = &oapispec.Route{
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
return filterResult(r.Or.Assets().GetTokenPoolsByType(r.Ctx, r.PP["ns"], r.PP["type"], r.Filter))
},
Deprecated: true,
}
1 change: 1 addition & 0 deletions internal/apiserver/route_get_token_transfers_by_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ var getTokenTransfersByPool = &oapispec.Route{
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
return filterResult(r.Or.Assets().GetTokenTransfersByPool(r.Ctx, r.PP["ns"], r.PP["type"], r.PP["name"], r.Filter))
},
Deprecated: true,
}
1 change: 1 addition & 0 deletions internal/apiserver/route_post_token_burn_by_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ var postTokenBurnByType = &oapispec.Route{
r.SuccessStatus = syncRetcode(waitConfirm)
return r.Or.Assets().BurnTokensByType(r.Ctx, r.PP["ns"], r.PP["type"], r.PP["name"], r.Input.(*fftypes.TokenTransferInput), waitConfirm)
},
Deprecated: true,
}
1 change: 1 addition & 0 deletions internal/apiserver/route_post_token_mint_by_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ var postTokenMintByType = &oapispec.Route{
r.SuccessStatus = syncRetcode(waitConfirm)
return r.Or.Assets().MintTokensByType(r.Ctx, r.PP["ns"], r.PP["type"], r.PP["name"], r.Input.(*fftypes.TokenTransferInput), waitConfirm)
},
Deprecated: true,
}
1 change: 1 addition & 0 deletions internal/apiserver/route_post_token_pool_by_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ var postTokenPoolByType = &oapispec.Route{
r.SuccessStatus = syncRetcode(waitConfirm)
return r.Or.Assets().CreateTokenPoolByType(r.Ctx, r.PP["ns"], r.PP["type"], r.Input.(*fftypes.TokenPool), waitConfirm)
},
Deprecated: true,
}
1 change: 1 addition & 0 deletions internal/apiserver/route_post_token_transfer_by_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ var postTokenTransferByType = &oapispec.Route{
r.SuccessStatus = syncRetcode(waitConfirm)
return r.Or.Assets().TransferTokensByType(r.Ctx, r.PP["ns"], r.PP["type"], r.PP["name"], r.Input.(*fftypes.TokenTransferInput), waitConfirm)
},
Deprecated: true,
}
1 change: 1 addition & 0 deletions internal/apiserver/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ var routes = []*oapispec.Route{
getTokenPoolsByType,
getTokenPoolByNameOrID,
getTokenPoolByName,
getTokenBalances,
getTokenAccounts,
getTokenAccountsByPool,
getTokenTransfers,
Expand Down
Loading