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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ $(eval $(call makemock, pkg/dataexchange, Callbacks, dataexcha
$(eval $(call makemock, pkg/tokens, Plugin, tokenmocks))
$(eval $(call makemock, pkg/tokens, Callbacks, tokenmocks))
$(eval $(call makemock, pkg/wsclient, WSClient, wsmocks))
$(eval $(call makemock, internal/txcommon, Helper, txcommonmocks))
$(eval $(call makemock, internal/identity, Manager, identitymanagermocks))
$(eval $(call makemock, internal/batchpin, Submitter, batchpinmocks))
$(eval $(call makemock, internal/sysmessaging, SystemEvents, sysmessagingmocks))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ALTER TABLE transactions ADD COLUMN signer VARCHAR(1024);
ALTER TABLE transactions ADD COLUMN hash CHAR(64);
ALTER TABLE transactions ADD COLUMN protocol_id VARCHAR(256);
ALTER TABLE transactions ADD COLUMN info BYTEA;
ALTER TABLE transactions ADD COLUMN status VARCHAR(64);

CREATE INDEX transactions_protocol_id ON transactions(protocol_id);
CREATE INDEX transactions_ref ON transactions(ref);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ALTER TABLE transactions DROP COLUMN signer;
ALTER TABLE transactions DROP COLUMN hash;
ALTER TABLE transactions DROP COLUMN protocol_id;
ALTER TABLE transactions DROP COLUMN info;
ALTER TABLE transactions DROP COLUMN status;

ALTER TABLE transactions ADD COLUMN blockchain_ids VARCHAR(1024);
CREATE INDEX transactions_blockchain_ids ON transactions(blockchain_ids);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ALTER TABLE transactions ADD COLUMN signer VARCHAR(1024);
ALTER TABLE transactions ADD COLUMN hash CHAR(64);
ALTER TABLE transactions ADD COLUMN protocol_id VARCHAR(256);
ALTER TABLE transactions ADD COLUMN info BYTEA;
ALTER TABLE transactions ADD COLUMN status VARCHAR(64);

CREATE INDEX transactions_protocol_id ON transactions(protocol_id);
CREATE INDEX transactions_ref ON transactions(ref);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ALTER TABLE transactions DROP COLUMN signer;
ALTER TABLE transactions DROP COLUMN hash;
ALTER TABLE transactions DROP COLUMN protocol_id;
ALTER TABLE transactions DROP COLUMN info;
ALTER TABLE transactions DROP COLUMN status;

ALTER TABLE transactions ADD COLUMN blockchain_ids VARCHAR(1024);
CREATE INDEX transactions_blockchain_ids ON transactions(blockchain_ids);
94 changes: 78 additions & 16 deletions docs/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4231,6 +4231,7 @@ paths:
type: integer
type:
enum:
- transaction_submitted
- message_confirmed
- message_rejected
- namespace_confirmed
Expand Down Expand Up @@ -4291,6 +4292,7 @@ paths:
type: integer
type:
enum:
- transaction_submitted
- message_confirmed
- message_rejected
- namespace_confirmed
Expand Down Expand Up @@ -4962,6 +4964,7 @@ paths:
type: integer
type:
enum:
- transaction_submitted
- message_confirmed
- message_rejected
- namespace_confirmed
Expand Down Expand Up @@ -5086,8 +5089,6 @@ paths:
id: {}
namespace:
type: string
status:
type: string
type:
enum:
- none
Expand Down Expand Up @@ -6878,6 +6879,16 @@ paths:
name: symbol
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: tx.id
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: tx.type
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: type
Expand Down Expand Up @@ -9048,6 +9059,16 @@ paths:
name: symbol
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: tx.id
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: tx.type
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: type
Expand Down Expand Up @@ -9861,11 +9882,6 @@ paths:
name: namespace
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: status
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: type
Expand Down Expand Up @@ -9919,8 +9935,6 @@ paths:
id: {}
namespace:
type: string
status:
type: string
type:
enum:
- none
Expand Down Expand Up @@ -9978,11 +9992,6 @@ paths:
name: namespace
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: status
schema:
type: string
- description: 'Data filter field. Prefixes supported: > >= < <= @ ^ ! !@ !^'
in: query
name: type
Expand Down Expand Up @@ -10036,8 +10045,6 @@ paths:
id: {}
namespace:
type: string
status:
type: string
type:
enum:
- none
Expand Down Expand Up @@ -10181,6 +10188,61 @@ paths:
description: Success
default:
description: ""
/namespaces/{ns}/transactions/{txnid}/status:
get:
description: 'TODO: Description'
operationId: getTxnStatus
parameters:
- description: 'TODO: Description'
in: path
name: ns
required: true
schema:
example: default
type: string
- description: 'TODO: Description'
in: path
name: txnid
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:
details:
items:
properties:
error:
type: string
id: {}
info:
additionalProperties: {}
type: object
status:
type: string
subtype:
type: string
timestamp: {}
type:
type: string
type: object
type: array
status:
type: string
type: object
description: Success
default:
description: ""
/network/nodes:
get:
description: 'TODO: Description'
Expand Down
45 changes: 45 additions & 0 deletions internal/apiserver/route_get_txn_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright © 2022 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 getTxnStatus = &oapispec.Route{
Name: "getTxnStatus",
Path: "namespaces/{ns}/transactions/{txnid}/status",
Method: http.MethodGet,
PathParams: []*oapispec.PathParam{
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
{Name: "txnid", Description: i18n.MsgTBD},
},
QueryParams: nil,
FilterFactory: nil,
Description: i18n.MsgTBD,
JSONInputValue: nil,
JSONOutputValue: func() interface{} { return &fftypes.TransactionStatus{} },
JSONOutputCodes: []int{http.StatusOK},
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
return getOr(r.Ctx).GetTransactionStatus(r.Ctx, r.PP["ns"], r.PP["txnid"])
},
}
39 changes: 39 additions & 0 deletions internal/apiserver/route_get_txn_status_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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/pkg/fftypes"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestGetTxnStatus(t *testing.T) {
o, r := newTestAPIServer()
req := httptest.NewRequest("GET", "/api/v1/namespaces/mynamespace/transactions/abcd12345/status", nil)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

o.On("GetTransactionStatus", mock.Anything, "mynamespace", "abcd12345").
Return(&fftypes.TransactionStatus{}, nil, nil)
r.ServeHTTP(res, req)

assert.Equal(t, 200, res.Result().StatusCode)
}
1 change: 1 addition & 0 deletions internal/apiserver/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var routes = []*oapispec.Route{
getTxnByID,
getTxnOps,
getTxnBlockchainEvents,
getTxnStatus,
getTxns,

getChartHistogram,
Expand Down
3 changes: 3 additions & 0 deletions internal/assets/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/hyperledger/firefly/internal/retry"
"github.com/hyperledger/firefly/internal/syncasync"
"github.com/hyperledger/firefly/internal/sysmessaging"
"github.com/hyperledger/firefly/internal/txcommon"
"github.com/hyperledger/firefly/pkg/database"
"github.com/hyperledger/firefly/pkg/fftypes"
"github.com/hyperledger/firefly/pkg/tokens"
Expand Down Expand Up @@ -70,6 +71,7 @@ type Manager interface {
type assetManager struct {
ctx context.Context
database database.Plugin
txHelper txcommon.Helper
identity identity.Manager
data data.Manager
syncasync syncasync.Bridge
Expand All @@ -86,6 +88,7 @@ func NewAssetManager(ctx context.Context, di database.Plugin, im identity.Manage
am := &assetManager{
ctx: ctx,
database: di,
txHelper: txcommon.NewTransactionHelper(di),
identity: im,
data: dm,
syncasync: sa,
Expand Down
5 changes: 4 additions & 1 deletion internal/assets/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/hyperledger/firefly/mocks/privatemessagingmocks"
"github.com/hyperledger/firefly/mocks/syncasyncmocks"
"github.com/hyperledger/firefly/mocks/tokenmocks"
"github.com/hyperledger/firefly/mocks/txcommonmocks"
"github.com/hyperledger/firefly/pkg/database"
"github.com/hyperledger/firefly/pkg/fftypes"
"github.com/hyperledger/firefly/pkg/tokens"
Expand All @@ -51,7 +52,9 @@ func newTestAssets(t *testing.T) (*assetManager, func()) {
rag.ReturnArguments = mock.Arguments{a[1].(func(context.Context) error)(a[0].(context.Context))}
}
assert.NoError(t, err)
return a.(*assetManager), cancel
am := a.(*assetManager)
am.txHelper = &txcommonmocks.Helper{}
return am, cancel
}

func TestInitFail(t *testing.T) {
Expand Down
41 changes: 18 additions & 23 deletions internal/assets/token_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,26 @@ func (am *assetManager) createTokenPoolInternal(ctx context.Context, pool *fftyp
})
}

tx := &fftypes.Transaction{
ID: fftypes.NewUUID(),
Namespace: pool.Namespace,
Type: fftypes.TransactionTypeTokenPool,
Created: fftypes.Now(),
Status: fftypes.OpStatusPending,
}
pool.TX.ID = tx.ID
pool.TX.Type = tx.Type

op := fftypes.NewTXOperation(
plugin,
pool.Namespace,
tx.ID,
"",
fftypes.OpTypeTokenCreatePool,
fftypes.OpStatusPending)
txcommon.AddTokenPoolCreateInputs(op, pool)

var op *fftypes.Operation
err = am.database.RunAsGroup(ctx, func(ctx context.Context) (err error) {
err = am.database.UpsertTransaction(ctx, tx)
if err == nil {
err = am.database.InsertOperation(ctx, op)
txid, err := am.txHelper.SubmitNewTransaction(ctx, pool.Namespace, fftypes.TransactionTypeTokenPool)
if err != nil {
return err
}
return err

pool.TX.ID = txid
pool.TX.Type = fftypes.TransactionTypeTokenPool

op = fftypes.NewTXOperation(
plugin,
pool.Namespace,
txid,
"",
fftypes.OpTypeTokenCreatePool,
fftypes.OpStatusPending)
txcommon.AddTokenPoolCreateInputs(op, pool)

return am.database.InsertOperation(ctx, op)
})
if err != nil {
return nil, err
Expand Down
Loading