Skip to content
827 changes: 787 additions & 40 deletions docs/swagger/swagger.yaml

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions internal/apiserver/route_post_token_burn.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,23 @@ import (

var postTokenBurn = &oapispec.Route{
Name: "postTokenBurn",
Path: "namespaces/{ns}/tokens/{type}/pools/{name}/burn",
Path: "namespaces/{ns}/tokens/burn",
Method: http.MethodPost,
PathParams: []*oapispec.PathParam{
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
{Name: "type", Description: i18n.MsgTBD},
{Name: "name", Description: i18n.MsgTBD},
},
QueryParams: []*oapispec.QueryParam{
{Name: "confirm", Description: i18n.MsgConfirmQueryParam, IsBool: true},
},
FilterFactory: nil,
Description: i18n.MsgTBD,
JSONInputValue: func() interface{} { return &fftypes.TokenTransferInput{} },
JSONInputMask: []string{"Type", "LocalID", "PoolProtocolID", "To", "ProtocolID", "MessageHash", "Connector", "TX", "Created"},
JSONInputMask: []string{"Type", "LocalID", "PoolProtocolID", "To", "ProtocolID", "MessageHash", "TX", "Created"},
JSONOutputValue: func() interface{} { return &fftypes.TokenTransfer{} },
JSONOutputCodes: []int{http.StatusAccepted, http.StatusOK},
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
waitConfirm := strings.EqualFold(r.QP["confirm"], "true")
r.SuccessStatus = syncRetcode(waitConfirm)
return r.Or.Assets().BurnTokens(r.Ctx, r.PP["ns"], r.PP["type"], r.PP["name"], r.Input.(*fftypes.TokenTransferInput), waitConfirm)
return r.Or.Assets().BurnTokens(r.Ctx, r.PP["ns"], r.Input.(*fftypes.TokenTransferInput), waitConfirm)
},
}
52 changes: 52 additions & 0 deletions internal/apiserver/route_post_token_burn_by_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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"
"strings"

"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 postTokenBurnByType = &oapispec.Route{
Name: "postTokenBurnByType",
Path: "namespaces/{ns}/tokens/{type}/pools/{name}/burn",
Method: http.MethodPost,
PathParams: []*oapispec.PathParam{
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
{Name: "type", Description: i18n.MsgTBD},
{Name: "name", Description: i18n.MsgTBD},
},
QueryParams: []*oapispec.QueryParam{
{Name: "confirm", Description: i18n.MsgConfirmQueryParam, IsBool: true},
},
FilterFactory: nil,
Description: i18n.MsgTBD,
JSONInputValue: func() interface{} { return &fftypes.TokenTransferInput{} },
JSONInputMask: []string{"Type", "LocalID", "PoolProtocolID", "To", "ProtocolID", "MessageHash", "Connector", "TX", "Created"},
JSONOutputValue: func() interface{} { return &fftypes.TokenTransfer{} },
JSONOutputCodes: []int{http.StatusAccepted, http.StatusOK},
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
waitConfirm := strings.EqualFold(r.QP["confirm"], "true")
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)
},
}
47 changes: 47 additions & 0 deletions internal/apiserver/route_post_token_burn_by_type_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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 (
"bytes"
"encoding/json"
"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 TestPostTokenBurnByType(t *testing.T) {
o, r := newTestAPIServer()
mam := &assetmocks.Manager{}
o.On("Assets").Return(mam)
input := fftypes.TokenTransferInput{}
var buf bytes.Buffer
json.NewEncoder(&buf).Encode(&input)
req := httptest.NewRequest("POST", "/api/v1/namespaces/ns1/tokens/tok1/pools/pool1/burn", &buf)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mam.On("BurnTokensByType", mock.Anything, "ns1", "tok1", "pool1", mock.AnythingOfType("*fftypes.TokenTransferInput"), false).
Return(&fftypes.TokenTransfer{}, nil)
r.ServeHTTP(res, req)

assert.Equal(t, 202, res.Result().StatusCode)
}
4 changes: 2 additions & 2 deletions internal/apiserver/route_post_token_burn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ func TestPostTokenBurn(t *testing.T) {
input := fftypes.TokenTransferInput{}
var buf bytes.Buffer
json.NewEncoder(&buf).Encode(&input)
req := httptest.NewRequest("POST", "/api/v1/namespaces/ns1/tokens/tok1/pools/pool1/burn", &buf)
req := httptest.NewRequest("POST", "/api/v1/namespaces/ns1/tokens/burn", &buf)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mam.On("BurnTokens", mock.Anything, "ns1", "tok1", "pool1", mock.AnythingOfType("*fftypes.TokenTransferInput"), false).
mam.On("BurnTokens", mock.Anything, "ns1", mock.AnythingOfType("*fftypes.TokenTransferInput"), false).
Return(&fftypes.TokenTransfer{}, nil)
r.ServeHTTP(res, req)

Expand Down
8 changes: 3 additions & 5 deletions internal/apiserver/route_post_token_mint.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,23 @@ import (

var postTokenMint = &oapispec.Route{
Name: "postTokenMint",
Path: "namespaces/{ns}/tokens/{type}/pools/{name}/mint",
Path: "namespaces/{ns}/tokens/mint",
Method: http.MethodPost,
PathParams: []*oapispec.PathParam{
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
{Name: "type", Description: i18n.MsgTBD},
{Name: "name", Description: i18n.MsgTBD},
},
QueryParams: []*oapispec.QueryParam{
{Name: "confirm", Description: i18n.MsgConfirmQueryParam, IsBool: true},
},
FilterFactory: nil,
Description: i18n.MsgTBD,
JSONInputValue: func() interface{} { return &fftypes.TokenTransferInput{} },
JSONInputMask: []string{"Type", "LocalID", "PoolProtocolID", "TokenIndex", "From", "ProtocolID", "MessageHash", "Connector", "TX", "Created"},
JSONInputMask: []string{"Type", "LocalID", "PoolProtocolID", "TokenIndex", "From", "ProtocolID", "MessageHash", "TX", "Created"},
JSONOutputValue: func() interface{} { return &fftypes.TokenTransfer{} },
JSONOutputCodes: []int{http.StatusAccepted, http.StatusOK},
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
waitConfirm := strings.EqualFold(r.QP["confirm"], "true")
r.SuccessStatus = syncRetcode(waitConfirm)
return r.Or.Assets().MintTokens(r.Ctx, r.PP["ns"], r.PP["type"], r.PP["name"], r.Input.(*fftypes.TokenTransferInput), waitConfirm)
return r.Or.Assets().MintTokens(r.Ctx, r.PP["ns"], r.Input.(*fftypes.TokenTransferInput), waitConfirm)
},
}
52 changes: 52 additions & 0 deletions internal/apiserver/route_post_token_mint_by_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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"
"strings"

"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 postTokenMintByType = &oapispec.Route{
Name: "postTokenMintByType",
Path: "namespaces/{ns}/tokens/{type}/pools/{name}/mint",
Method: http.MethodPost,
PathParams: []*oapispec.PathParam{
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
{Name: "type", Description: i18n.MsgTBD},
{Name: "name", Description: i18n.MsgTBD},
},
QueryParams: []*oapispec.QueryParam{
{Name: "confirm", Description: i18n.MsgConfirmQueryParam, IsBool: true},
},
FilterFactory: nil,
Description: i18n.MsgTBD,
JSONInputValue: func() interface{} { return &fftypes.TokenTransferInput{} },
JSONInputMask: []string{"Type", "LocalID", "PoolProtocolID", "TokenIndex", "From", "ProtocolID", "MessageHash", "Connector", "TX", "Created"},
JSONOutputValue: func() interface{} { return &fftypes.TokenTransfer{} },
JSONOutputCodes: []int{http.StatusAccepted, http.StatusOK},
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
waitConfirm := strings.EqualFold(r.QP["confirm"], "true")
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)
},
}
47 changes: 47 additions & 0 deletions internal/apiserver/route_post_token_mint_by_type_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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 (
"bytes"
"encoding/json"
"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 TestPostTokenMintByType(t *testing.T) {
o, r := newTestAPIServer()
mam := &assetmocks.Manager{}
o.On("Assets").Return(mam)
input := fftypes.TokenTransferInput{}
var buf bytes.Buffer
json.NewEncoder(&buf).Encode(&input)
req := httptest.NewRequest("POST", "/api/v1/namespaces/ns1/tokens/tok1/pools/pool1/mint", &buf)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mam.On("MintTokensByType", mock.Anything, "ns1", "tok1", "pool1", mock.AnythingOfType("*fftypes.TokenTransferInput"), false).
Return(&fftypes.TokenTransfer{}, nil)
r.ServeHTTP(res, req)

assert.Equal(t, 202, res.Result().StatusCode)
}
4 changes: 2 additions & 2 deletions internal/apiserver/route_post_token_mint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ func TestPostTokenMint(t *testing.T) {
input := fftypes.TokenTransferInput{}
var buf bytes.Buffer
json.NewEncoder(&buf).Encode(&input)
req := httptest.NewRequest("POST", "/api/v1/namespaces/ns1/tokens/tok1/pools/pool1/mint", &buf)
req := httptest.NewRequest("POST", "/api/v1/namespaces/ns1/tokens/mint", &buf)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mam.On("MintTokens", mock.Anything, "ns1", "tok1", "pool1", mock.AnythingOfType("*fftypes.TokenTransferInput"), false).
mam.On("MintTokens", mock.Anything, "ns1", mock.AnythingOfType("*fftypes.TokenTransferInput"), false).
Return(&fftypes.TokenTransfer{}, nil)
r.ServeHTTP(res, req)

Expand Down
7 changes: 3 additions & 4 deletions internal/apiserver/route_post_token_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,23 @@ import (

var postTokenPool = &oapispec.Route{
Name: "postTokenPool",
Path: "namespaces/{ns}/tokens/{type}/pools",
Path: "namespaces/{ns}/tokens/pools",
Method: http.MethodPost,
PathParams: []*oapispec.PathParam{
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
{Name: "type", Description: i18n.MsgTBD},
},
QueryParams: []*oapispec.QueryParam{
{Name: "confirm", Description: i18n.MsgConfirmQueryParam, IsBool: true},
},
FilterFactory: nil,
Description: i18n.MsgTBD,
JSONInputValue: func() interface{} { return &fftypes.TokenPool{} },
JSONInputMask: []string{"ID", "Namespace", "Standard", "ProtocolID", "TX", "Connector", "Message", "Created"},
JSONInputMask: []string{"ID", "Namespace", "Standard", "ProtocolID", "TX", "Message", "Created"},
JSONOutputValue: func() interface{} { return &fftypes.TokenPool{} },
JSONOutputCodes: []int{http.StatusAccepted, http.StatusOK},
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
waitConfirm := strings.EqualFold(r.QP["confirm"], "true")
r.SuccessStatus = syncRetcode(waitConfirm)
return r.Or.Assets().CreateTokenPool(r.Ctx, r.PP["ns"], r.PP["type"], r.Input.(*fftypes.TokenPool), waitConfirm)
return r.Or.Assets().CreateTokenPool(r.Ctx, r.PP["ns"], r.Input.(*fftypes.TokenPool), waitConfirm)
},
}
51 changes: 51 additions & 0 deletions internal/apiserver/route_post_token_pool_by_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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"
"strings"

"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 postTokenPoolByType = &oapispec.Route{
Name: "postTokenPoolByType",
Path: "namespaces/{ns}/tokens/{type}/pools",
Method: http.MethodPost,
PathParams: []*oapispec.PathParam{
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
{Name: "type", Description: i18n.MsgTBD},
},
QueryParams: []*oapispec.QueryParam{
{Name: "confirm", Description: i18n.MsgConfirmQueryParam, IsBool: true},
},
FilterFactory: nil,
Description: i18n.MsgTBD,
JSONInputValue: func() interface{} { return &fftypes.TokenPool{} },
JSONInputMask: []string{"ID", "Namespace", "Standard", "ProtocolID", "TX", "Connector", "Message", "Created"},
JSONOutputValue: func() interface{} { return &fftypes.TokenPool{} },
JSONOutputCodes: []int{http.StatusAccepted, http.StatusOK},
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
waitConfirm := strings.EqualFold(r.QP["confirm"], "true")
r.SuccessStatus = syncRetcode(waitConfirm)
return r.Or.Assets().CreateTokenPoolByType(r.Ctx, r.PP["ns"], r.PP["type"], r.Input.(*fftypes.TokenPool), waitConfirm)
},
}
Loading