-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add route to get all pools held by a token account
Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
- Loading branch information
Showing
12 changed files
with
351 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/database" | ||
"github.com/hyperledger/firefly/pkg/fftypes" | ||
) | ||
|
||
var getTokenAccountPools = &oapispec.Route{ | ||
Name: "getTokenAccountPools", | ||
Path: "namespaces/{ns}/tokens/accounts/{key}", | ||
Method: http.MethodGet, | ||
PathParams: []*oapispec.PathParam{ | ||
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD}, | ||
{Name: "key", Description: i18n.MsgTBD}, | ||
}, | ||
QueryParams: nil, | ||
FilterFactory: database.TokenBalanceQueryFactory, | ||
Description: i18n.MsgTBD, | ||
JSONInputValue: nil, | ||
JSONOutputValue: func() interface{} { return []*fftypes.TokenAccountPool{} }, | ||
JSONOutputCodes: []int{http.StatusOK}, | ||
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) { | ||
return filterResult(r.Or.Assets().GetTokenAccountPools(r.Ctx, r.PP["ns"], r.PP["key"], r.Filter)) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 TestGetTokenAccountPools(t *testing.T) { | ||
o, r := newTestAPIServer() | ||
mam := &assetmocks.Manager{} | ||
o.On("Assets").Return(mam) | ||
req := httptest.NewRequest("GET", "/api/v1/namespaces/ns1/tokens/accounts/0x1", nil) | ||
req.Header.Set("Content-Type", "application/json; charset=utf-8") | ||
res := httptest.NewRecorder() | ||
|
||
mam.On("GetTokenAccountPools", mock.Anything, "ns1", "0x1", mock.Anything). | ||
Return([]*fftypes.TokenAccountPool{}, nil, nil) | ||
r.ServeHTTP(res, req) | ||
|
||
assert.Equal(t, 200, res.Result().StatusCode) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.