Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove Track and IsTxFinal #681

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 0 additions & 2 deletions integration/fabric/atsa/chaincode/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ package chaincode
import (
"github.com/hyperledger-labs/fabric-smart-client/integration/fabric/atsa/chaincode/views"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/common"
"github.com/hyperledger-labs/fabric-smart-client/pkg/api"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
)

type ViewClient interface {
CallView(fid string, in []byte) (interface{}, error)
IsTxFinal(txid string, opts ...api.ServiceOption) error
}

type Client struct {
Expand Down
10 changes: 6 additions & 4 deletions integration/fabric/atsa/fsc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import (
"github.com/hyperledger-labs/fabric-smart-client/integration/fabric/atsa/fsc/states"
"github.com/hyperledger-labs/fabric-smart-client/integration/fabric/atsa/fsc/views"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/common"
"github.com/hyperledger-labs/fabric-smart-client/pkg/api"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
)

type ViewClient interface {
CallView(fid string, in []byte) (interface{}, error)
IsTxFinal(txid string, opts ...api.ServiceOption) error
}

type Client struct {
Expand Down Expand Up @@ -80,6 +78,10 @@ func (c *Client) Transfer(assetID string, agreementID string, recipient view.Ide
return nil
}

func (c *Client) IsTxFinal(id string, opts ...api.ServiceOption) error {
return c.c.IsTxFinal(id, opts...)
func (c *Client) IsTxFinal(id string) error {
_, err := c.c.CallView("finality", common.JSONMarshall(views.Finality{TxID: id}))
if err != nil {
return err
}
return nil
}
12 changes: 8 additions & 4 deletions integration/fabric/atsa/fsc/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ func Topology(sdk api2.SDK, commType fsc.P2PCommunicationType, replicationOpts *
RegisterResponder(&views.ApproverView{}, &views.IssueView{}).
RegisterResponder(&views.ApproverView{}, &views.AgreeToSellView{}).
RegisterResponder(&views.ApproverView{}, &views.AgreeToBuyView{}).
RegisterResponder(&views.ApproverView{}, &views.TransferView{})
RegisterResponder(&views.ApproverView{}, &views.TransferView{}).
RegisterViewFactory("finality", &views.FinalityViewFactory{})

// Issuer
fscTopology.AddNodeByName("issuer").
AddOptions(fabric.WithOrganization("Org3")).
AddOptions(replicationOpts.For("issuer")...).
RegisterViewFactory("issue", &views.IssueViewFactory{})
RegisterViewFactory("issue", &views.IssueViewFactory{}).
RegisterViewFactory("finality", &views.FinalityViewFactory{})

// Alice
fscTopology.AddNodeByName("alice").
Expand All @@ -53,7 +55,8 @@ func Topology(sdk api2.SDK, commType fsc.P2PCommunicationType, replicationOpts *
RegisterViewFactory("agreeToSell", &views.AgreeToSellViewFactory{}).
RegisterViewFactory("agreeToBuy", &views.AgreeToBuyViewFactory{}).
RegisterResponder(&views.AcceptAssetView{}, &views.IssueView{}).
RegisterResponder(&views.TransferResponderView{}, &views.TransferView{})
RegisterResponder(&views.TransferResponderView{}, &views.TransferView{}).
RegisterViewFactory("finality", &views.FinalityViewFactory{})

// Bob
fscTopology.AddNodeByName("bob").
Expand All @@ -63,7 +66,8 @@ func Topology(sdk api2.SDK, commType fsc.P2PCommunicationType, replicationOpts *
RegisterViewFactory("agreeToSell", &views.AgreeToSellViewFactory{}).
RegisterViewFactory("agreeToBuy", &views.AgreeToBuyViewFactory{}).
RegisterResponder(&views.AcceptAssetView{}, &views.IssueView{}).
RegisterResponder(&views.TransferResponderView{}, &views.TransferView{})
RegisterResponder(&views.TransferResponderView{}, &views.TransferView{}).
RegisterViewFactory("finality", &views.FinalityViewFactory{})

// Add Fabric SDK to FSC Nodes
fscTopology.AddSDK(sdk)
Expand Down
41 changes: 41 additions & 0 deletions integration/fabric/atsa/fsc/views/finality.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright IBM Corp All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package views

import (
"encoding/json"

"github.com/hyperledger-labs/fabric-smart-client/platform/fabric"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/assert"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
)

type Finality struct {
TxID string
Network string
Channel string
}

type FinalityView struct {
*Finality
}

func (a *FinalityView) Call(context view.Context) (interface{}, error) {
_, ch, err := fabric.GetChannel(context, a.Network, a.Channel)
assert.NoError(err, "failed getting channel [%s:%s]", a.Network, a.Channel)
err = ch.Finality().IsFinal(context.Context(), a.TxID)
return nil, err
}

type FinalityViewFactory struct{}

func (c *FinalityViewFactory) NewView(in []byte) (view.View, error) {
f := &FinalityView{Finality: &Finality{}}
err := json.Unmarshal(in, f.Finality)
assert.NoError(err, "failed unmarshalling input")
return f, nil
}
2 changes: 0 additions & 2 deletions integration/fabric/events/chaincode/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ package chaincode
import (
"github.com/hyperledger-labs/fabric-smart-client/integration/fabric/events/chaincode/views"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/common"
"github.com/hyperledger-labs/fabric-smart-client/pkg/api"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
)

type ViewClient interface {
CallView(fid string, in []byte) (interface{}, error)
IsTxFinal(txid string, opts ...api.ServiceOption) error
}

type Client struct {
Expand Down
3 changes: 2 additions & 1 deletion integration/fabric/iou/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func UpdateIOUWithBorrower(ii *integration.Infrastructure, borrower, iouStateID
)
Expect(err).NotTo(HaveOccurred())
txID := common.JSONUnmarshalString(txIDBoxed)
Expect(ii.Client("lender").IsTxFinal(txID)).NotTo(HaveOccurred())
_, err = ii.Client("lender").CallView("finality", common.JSONMarshall(views.Finality{TxID: txID}))
Expect(err).NotTo(HaveOccurred())
}

func InitApprover(ii *integration.Infrastructure, approver string) {
Expand Down
12 changes: 8 additions & 4 deletions integration/fabric/iou/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func Topology(sdk api2.SDK, commType fsc.P2PCommunicationType, replicationOpts *
AddOptions(replicationOpts.For("approver1")...).
RegisterResponder(&views.ApproverView{}, &views.CreateIOUView{}).
RegisterResponder(&views.ApproverView{}, &views.UpdateIOUView{}).
RegisterViewFactory("init", &views.ApproverInitViewFactory{})
RegisterViewFactory("init", &views.ApproverInitViewFactory{}).
RegisterViewFactory("finality", &views.FinalityViewFactory{})

// Add another approver as well
fscTopology.AddNodeByName("approver2").
Expand All @@ -53,23 +54,26 @@ func Topology(sdk api2.SDK, commType fsc.P2PCommunicationType, replicationOpts *
AddOptions(replicationOpts.For("approver2")...).
RegisterResponder(&views.ApproverView{}, &views.CreateIOUView{}).
RegisterResponder(&views.ApproverView{}, &views.UpdateIOUView{}).
RegisterViewFactory("init", &views.ApproverInitViewFactory{})
RegisterViewFactory("init", &views.ApproverInitViewFactory{}).
RegisterViewFactory("finality", &views.FinalityViewFactory{})

// Add the borrower's FSC node
fscTopology.AddNodeByName("borrower").
AddOptions(fabric.WithOrganization("Org2")).
AddOptions(replicationOpts.For("borrower")...).
RegisterViewFactory("create", &views.CreateIOUViewFactory{}).
RegisterViewFactory("update", &views.UpdateIOUViewFactory{}).
RegisterViewFactory("query", &views.QueryViewFactory{})
RegisterViewFactory("query", &views.QueryViewFactory{}).
RegisterViewFactory("finality", &views.FinalityViewFactory{})

// Add the lender's FSC node
fscTopology.AddNodeByName("lender").
AddOptions(fabric.WithOrganization("Org3")).
AddOptions(replicationOpts.For("lender")...).
RegisterResponder(&views.CreateIOUResponderView{}, &views.CreateIOUView{}).
RegisterResponder(&views.UpdateIOUResponderView{}, &views.UpdateIOUView{}).
RegisterViewFactory("query", &views.QueryViewFactory{})
RegisterViewFactory("query", &views.QueryViewFactory{}).
RegisterViewFactory("finality", &views.FinalityViewFactory{})

// Monitoring
monitoringTopology := monitoring.NewTopology()
Expand Down
41 changes: 41 additions & 0 deletions integration/fabric/iou/views/finality.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright IBM Corp All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package views

import (
"encoding/json"

"github.com/hyperledger-labs/fabric-smart-client/platform/fabric"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/assert"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
)

type Finality struct {
TxID string
Network string
Channel string
}

type FinalityView struct {
*Finality
}

func (a *FinalityView) Call(context view.Context) (interface{}, error) {
_, ch, err := fabric.GetChannel(context, a.Network, a.Channel)
assert.NoError(err, "failed getting channel [%s:%s]", a.Network, a.Channel)
err = ch.Finality().IsFinal(context.Context(), a.TxID)
return nil, err
}

type FinalityViewFactory struct{}

func (c *FinalityViewFactory) NewView(in []byte) (view.View, error) {
f := &FinalityView{Finality: &Finality{}}
err := json.Unmarshal(in, f.Finality)
assert.NoError(err, "failed unmarshalling input")
return f, nil
}
2 changes: 0 additions & 2 deletions integration/nwo/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package api
import (
"context"

"github.com/hyperledger-labs/fabric-smart-client/pkg/api"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/client/view"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/client/web"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/grpc"
Expand Down Expand Up @@ -88,7 +87,6 @@ type Builder interface {
type ViewClient interface {
CallViewWithContext(ctx context.Context, fid string, in []byte) (interface{}, error)
CallView(fid string, in []byte) (interface{}, error)
IsTxFinal(txid string, opts ...api.ServiceOption) error
}

type GRPCClient interface {
Expand Down
5 changes: 0 additions & 5 deletions integration/nwo/fsc/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/commands"
"github.com/hyperledger-labs/fabric-smart-client/pkg/api"
"github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)
Expand All @@ -38,7 +37,3 @@ func (f *fscCLIViewClient) CallViewWithContext(_ context.Context, fid string, in

return string(sess.Out.Contents()), nil
}

func (f *fscCLIViewClient) IsTxFinal(txid string, opts ...api.ServiceOption) error {
panic("not implemented yet")
}
49 changes: 0 additions & 49 deletions pkg/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,6 @@ SPDX-License-Identifier: Apache-2.0

package api

import "time"

type ServiceOptions struct {
Network string
Channel string
Timeout time.Duration
}

func CompileServiceOptions(opts ...ServiceOption) (*ServiceOptions, error) {
txOptions := &ServiceOptions{}
for _, opt := range opts {
if err := opt(txOptions); err != nil {
return nil, err
}
}
return txOptions, nil
}

type ServiceOption func(*ServiceOptions) error

func WithNetwork(network string) ServiceOption {
return func(o *ServiceOptions) error {
o.Network = network
return nil
}
}

func WithChannel(channel string) ServiceOption {
return func(o *ServiceOptions) error {
o.Channel = channel
return nil
}
}

func WithTimeout(timeout time.Duration) ServiceOption {
return func(o *ServiceOptions) error {
o.Timeout = timeout
return nil
}
}

type ViewClient interface {
// CallView takes in input a view factory identifier, fid, and an input, in, and invokes the
// factory f bound to fid on input in. The view returned by the factory is invoked on
Expand All @@ -59,12 +18,4 @@ type ViewClient interface {
// a freshly created context whose identifier, cid, is immediately returned.
// This call is non-blocking.
Initiate(fid string, in []byte) (string, error)

// Track takes in input a context identifier, cid, and returns the latest
// status of the context as set by the views using it.
Track(cid string) string

// IsTxFinal takes in input a transaction id and return nil if the transaction has been committed,
// an error otherwise.
IsTxFinal(txid string, opts ...ServiceOption) error
}
24 changes: 0 additions & 24 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"runtime/debug"

"github.com/hyperledger-labs/fabric-smart-client/pkg/api"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric"
view2 "github.com/hyperledger-labs/fabric-smart-client/platform/view"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/core/config"
tracing2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/sdk/tracing"
Expand Down Expand Up @@ -195,25 +194,6 @@ func (n *node) ResolveIdentities(endpoints ...string) ([]view.Identity, error) {
return ids, nil
}

func (n *node) IsTxFinal(txID string, opts ...api.ServiceOption) error {
options, err := api.CompileServiceOptions(opts...)
if err != nil {
return errors.Wrapf(err, "failed to compile service options")
}
c := context.Background()
if options.Timeout != 0 {
var cancel context.CancelFunc
c, cancel = context.WithTimeout(c, options.Timeout)
defer cancel()
}
// TODO: network might refer to orion
_, ch, err := fabric.GetChannel(n.registry, options.Network, options.Channel)
if err != nil {
return err
}
return ch.Finality().IsFinal(c, txID)
}

func (n *node) getTracer() trace.Tracer {
if n.tracer == nil {
n.tracer = tracing2.Get(n.registry).Tracer("node_view_client", tracing.WithMetricsOpts(tracing.MetricsOpts{
Expand Down Expand Up @@ -290,7 +270,3 @@ func (n *node) Context(contextID string) (view.Context, error) {
func (n *node) Initiate(fid string, in []byte) (string, error) {
panic("implement me")
}

func (n *node) Track(cid string) string {
panic("implement me")
}
6 changes: 0 additions & 6 deletions platform/view/sdk/dig/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package sdk
import (
"context"
"errors"
"reflect"

"github.com/go-kit/log"
"github.com/hyperledger-labs/fabric-smart-client/pkg/node"
Expand Down Expand Up @@ -164,11 +163,6 @@ func (p *SDK) Install() error {
if err := p.C.Invoke(func(resolverService *endpoint.ResolverService) error { return resolverService.LoadResolvers() }); err != nil {
return err
}
if err := p.C.Invoke(func(server finality.Server, manager *finality.Manager) {
server.RegisterProcessor(reflect.TypeOf(&protos.Command_IsTxFinal{}), manager.IsTxFinal)
}); err != nil {
return err
}
logger.Debugf("Services installed:\n%s", digutils.Visualize(p.C))
return nil
}
Expand Down
Loading
Loading