From 647d2dbfeb317e64bae1e0e6df0a56e3a0c9161e Mon Sep 17 00:00:00 2001 From: Angelo De Caro Date: Tue, 11 Jul 2023 14:32:10 +0200 Subject: [PATCH] Two TMS on the same fabric network (#476) Signed-off-by: Angelo De Caro Signed-off-by: Alexandros Filios --- .github/workflows/tests.yml | 1 + Makefile | 1 + cmd/tokengen/samples/topology/fungible.go | 12 +- fungible.mk | 4 + integration/nwo/token/options.go | 7 +- integration/token/dvp/topology.go | 4 +- .../token/fungible/dloghsm/topology.go | 22 +-- .../token/fungible/mixed/mixed_suite_test.go | 29 +++ .../token/fungible/mixed/mixed_test.go | 44 +++++ integration/token/fungible/mixed/topology.go | 178 ++++++++++++++++++ integration/token/fungible/support.go | 108 +++++++++-- integration/token/fungible/tests.go | 71 ++++++- .../token/fungible/topology/topology.go | 26 +-- integration/token/fungible/views/accept.go | 3 +- integration/token/fungible/views/auditor.go | 32 +++- integration/token/fungible/views/balance.go | 4 +- integration/token/fungible/views/history.go | 7 +- integration/token/fungible/views/info.go | 8 +- integration/token/fungible/views/issue.go | 15 +- integration/token/fungible/views/list.go | 4 +- integration/token/fungible/views/redeem.go | 6 +- integration/token/fungible/views/transfer.go | 12 +- integration/token/fungible/views/utils.go | 16 ++ integration/token/interop/support.go | 7 +- integration/token/interop/topology.go | 38 ++-- integration/token/nft/topology.go | 6 +- samples/fungible/topology/fabric.go | 12 +- samples/fungible/topology/orion.go | 12 +- samples/nft/topology/fabric.go | 4 +- samples/nft/topology/orion.go | 4 +- token/services/ttx/transaction.go | 4 + 31 files changed, 572 insertions(+), 129 deletions(-) create mode 100644 integration/token/fungible/mixed/mixed_suite_test.go create mode 100644 integration/token/fungible/mixed/mixed_test.go create mode 100644 integration/token/fungible/mixed/topology.go diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7591a49a2..3761a8b6d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -86,6 +86,7 @@ jobs: tests: [ dlog-fabric-t1, dlog-fabric-t2, + fabtoken-dlog-fabric, dloghsm-fabric-t1, dloghsm-fabric-t2, fabtoken-fabric, diff --git a/Makefile b/Makefile index 4567ba192..51ca1c4ce 100644 --- a/Makefile +++ b/Makefile @@ -107,6 +107,7 @@ clean: rm -rf ./integration/token/fungible/fabtoken/cmd/ rm -rf ./integration/token/fungible/odlog/cmd/ rm -rf ./integration/token/fungible/ofabtoken/cmd/ + rm -rf ./integration/token/fungible/mixed/cmd/ rm -rf ./integration/token/nft/dlog/cmd/ rm -rf ./integration/token/nft/fabtoken/cmd/ rm -rf ./integration/token/nft/odlog/cmd/ diff --git a/cmd/tokengen/samples/topology/fungible.go b/cmd/tokengen/samples/topology/fungible.go index 3aa1e64a9..20907de35 100644 --- a/cmd/tokengen/samples/topology/fungible.go +++ b/cmd/tokengen/samples/topology/fungible.go @@ -57,8 +57,8 @@ func Topology(tokenSDKDriver string) []api.Topology { alice := fscTopology.AddNodeByName("alice").AddOptions( fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "alice.id1"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("alice.id1"), ) alice.RegisterResponder(&views.AcceptCashView{}, &views.IssueCashView{}) alice.RegisterResponder(&views.AcceptCashView{}, &views.TransferView{}) @@ -71,8 +71,8 @@ func Topology(tokenSDKDriver string) []api.Topology { bob := fscTopology.AddNodeByName("bob").AddOptions( fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "bob.id1"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("bob.id1"), ) bob.RegisterResponder(&views.AcceptCashView{}, &views.IssueCashView{}) bob.RegisterResponder(&views.AcceptCashView{}, &views.TransferView{}) @@ -86,8 +86,8 @@ func Topology(tokenSDKDriver string) []api.Topology { charlie := fscTopology.AddNodeByName("charlie").AddOptions( fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "charlie.id1"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("charlie.id1"), ) charlie.RegisterResponder(&views.AcceptCashView{}, &views.IssueCashView{}) charlie.RegisterResponder(&views.AcceptCashView{}, &views.TransferView{}) diff --git a/fungible.mk b/fungible.mk index e872362a6..cdbf4b62f 100644 --- a/fungible.mk +++ b/fungible.mk @@ -10,6 +10,10 @@ integration-tests-dlog-fabric-t1: integration-tests-dlog-fabric-t2: cd ./integration/token/fungible/dlog; export FAB_BINS=$(FAB_BINS); ginkgo $(GINKGO_TEST_OPTS) --focus "Fungible with Auditor = Issuer" . +.PHONY: integration-tests-fabtoken-dlog-fabric +integration-tests-mixed: + cd ./integration/token/fungible/mixed; export FAB_BINS=$(FAB_BINS); ginkgo $(GINKGO_TEST_OPTS) . + .PHONY: integration-tests-dloghsm-fabric integration-tests-dloghsm-fabric: install-softhsm @echo "Setup SoftHSM" diff --git a/integration/nwo/token/options.go b/integration/nwo/token/options.go index 2bbec04b9..468e60710 100644 --- a/integration/nwo/token/options.go +++ b/integration/nwo/token/options.go @@ -8,7 +8,6 @@ package token import ( fsc "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/node" - "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/topology" ) @@ -45,11 +44,11 @@ func WithDefaultIssuerIdentityWithHSM() fsc.Option { return WithIssuerIdentityWithHSM("_default_") } -func WithDefaultOwnerIdentity(driver string) fsc.Option { - return WithOwnerIdentity(driver, "_default_") +func WithDefaultOwnerIdentity() fsc.Option { + return WithOwnerIdentity("_default_") } -func WithOwnerIdentity(driver string, label string) fsc.Option { +func WithOwnerIdentity(label string) fsc.Option { return func(o *fsc.Options) error { to := topology.ToOptions(o) to.SetOwners(append(to.Owners(), label)) diff --git a/integration/token/dvp/topology.go b/integration/token/dvp/topology.go index 34dd9d7d9..9a1d7f2f7 100644 --- a/integration/token/dvp/topology.go +++ b/integration/token/dvp/topology.go @@ -70,7 +70,7 @@ func Topology(tokenSDKDriver string) []api.Topology { seller := fscTopology.AddNodeByName("seller").AddOptions( fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), - token.WithDefaultOwnerIdentity(tokenSDKDriver), + token.WithDefaultOwnerIdentity(), ) seller.RegisterResponder(&house.AcceptHouseView{}, &house.IssueHouseView{}) seller.RegisterViewFactory("sell", &views2.SellHouseViewFactory{}) @@ -80,7 +80,7 @@ func Topology(tokenSDKDriver string) []api.Topology { buyer := fscTopology.AddNodeByName("buyer").AddOptions( fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), - token.WithDefaultOwnerIdentity(tokenSDKDriver), + token.WithDefaultOwnerIdentity(), ) buyer.RegisterResponder(&cash.AcceptCashView{}, &cash.IssueCashView{}) buyer.RegisterResponder(&views2.BuyHouseView{}, &views2.SellHouseView{}) diff --git a/integration/token/fungible/dloghsm/topology.go b/integration/token/fungible/dloghsm/topology.go index b4a84bacb..0b75cffe1 100644 --- a/integration/token/fungible/dloghsm/topology.go +++ b/integration/token/fungible/dloghsm/topology.go @@ -50,8 +50,8 @@ func Topology(backend string, tokenSDKDriver string, auditorAsIssuer bool) []api orion.WithRole("issuer"), token.WithDefaultIssuerIdentityWithHSM(), token.WithIssuerIdentityWithHSM("issuer.id1"), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "issuer.owner"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("issuer.owner"), ) issuer.RegisterViewFactory("issue", &views.IssueCashViewFactory{}) issuer.RegisterViewFactory("transfer", &views.TransferViewFactory{}) @@ -109,7 +109,7 @@ func Topology(backend string, tokenSDKDriver string, auditorAsIssuer bool) []api fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), orion.WithRole("alice"), - token.WithOwnerIdentity(tokenSDKDriver, "alice.id1"), + token.WithOwnerIdentity("alice.id1"), ) alice.RegisterResponder(&views.AcceptCashView{}, &views.IssueCashView{}) alice.RegisterResponder(&views.AcceptCashView{}, &views.TransferView{}) @@ -137,8 +137,8 @@ func Topology(backend string, tokenSDKDriver string, auditorAsIssuer bool) []api fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), orion.WithRole("bob"), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "bob.id1"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("bob.id1"), ) bob.RegisterResponder(&views.AcceptCashView{}, &views.IssueCashView{}) bob.RegisterResponder(&views.AcceptCashView{}, &views.TransferView{}) @@ -168,8 +168,8 @@ func Topology(backend string, tokenSDKDriver string, auditorAsIssuer bool) []api fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), orion.WithRole("charlie"), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "charlie.id1"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("charlie.id1"), ) charlie.RegisterResponder(&views.AcceptCashView{}, &views.IssueCashView{}) charlie.RegisterResponder(&views.AcceptCashView{}, &views.TransferView{}) @@ -195,10 +195,10 @@ func Topology(backend string, tokenSDKDriver string, auditorAsIssuer bool) []api fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), orion.WithRole("manager"), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "manager.id1"), - token.WithOwnerIdentity(tokenSDKDriver, "manager.id2"), - token.WithOwnerIdentity(tokenSDKDriver, "manager.id3"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("manager.id1"), + token.WithOwnerIdentity("manager.id2"), + token.WithOwnerIdentity("manager.id3"), ) manager.RegisterResponder(&views.AcceptCashView{}, &views.IssueCashView{}) manager.RegisterResponder(&views.AcceptCashView{}, &views.TransferView{}) diff --git a/integration/token/fungible/mixed/mixed_suite_test.go b/integration/token/fungible/mixed/mixed_suite_test.go new file mode 100644 index 000000000..a4dd6313f --- /dev/null +++ b/integration/token/fungible/mixed/mixed_suite_test.go @@ -0,0 +1,29 @@ +/* +Copyright IBM Corp All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package mixed + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "github.com/hyperledger-labs/fabric-token-sdk/integration" +) + +func TestEndToEnd(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode.") + } + + RegisterFailHandler(Fail) + RunSpecs(t, "EndToEnd Fungible (DLOG) Suite") +} + +func StartPortDlog() int { + return integration.ZKATDLogFungible.StartPortForNode() +} diff --git a/integration/token/fungible/mixed/mixed_test.go b/integration/token/fungible/mixed/mixed_test.go new file mode 100644 index 000000000..8f9d00a23 --- /dev/null +++ b/integration/token/fungible/mixed/mixed_test.go @@ -0,0 +1,44 @@ +/* +Copyright IBM Corp All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package mixed + +import ( + "github.com/hyperledger-labs/fabric-smart-client/integration" + "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token" + "github.com/hyperledger-labs/fabric-token-sdk/integration/token/fungible" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +var _ = Describe("EndToEnd", func() { + var ( + network *integration.Infrastructure + ) + + AfterEach(func() { + network.Stop() + }) + + Describe("Fungible with Auditor ne Issuer", func() { + BeforeEach(func() { + var err error + network, err = integration.New(StartPortDlog(), "", Topology()...) + Expect(err).NotTo(HaveOccurred()) + network.DeleteOnStop = false + network.DeleteOnStart = true + network.RegisterPlatformFactory(token.NewPlatformFactory()) + network.Generate() + network.Start() + }) + + It("succeeded", func() { + fungible.TestMixed(network) + }) + + }) + +}) diff --git a/integration/token/fungible/mixed/topology.go b/integration/token/fungible/mixed/topology.go new file mode 100644 index 000000000..66d65bec2 --- /dev/null +++ b/integration/token/fungible/mixed/topology.go @@ -0,0 +1,178 @@ +/* +Copyright IBM Corp. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package mixed + +import ( + "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/api" + "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric" + "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc" + "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/node" + fabric3 "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/sdk" + "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token" + fabric2 "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/fabric" + "github.com/hyperledger-labs/fabric-token-sdk/integration/token/fungible/views" + sdk "github.com/hyperledger-labs/fabric-token-sdk/token/sdk" +) + +const ( + DLogDriver = "dlog" + FabtokenDriver = "fabtoken" + DLogNamespace = "dlog-token-chaincode" + FabTokenNamespace = "fabtoken-token-chaincode" +) + +func Topology() []api.Topology { + fabricTopology := fabric.NewDefaultTopology() + fabricTopology.EnableIdemix() + fabricTopology.AddOrganizationsByName("Org1", "Org2", "Org3") + fabricTopology.SetNamespaceApproverOrgsOR("Org1", "Org2") + backendNetwork := fabricTopology + backendChannel := fabricTopology.Channels[0].Name + + // FSC + fscTopology := fsc.NewTopology() + fscTopology.SetLogging("debug", "") + + issuer := fscTopology.NewTemplate("issuer") + issuer.RegisterViewFactory("issue", &views.IssueCashViewFactory{}) + issuer.RegisterViewFactory("transfer", &views.TransferViewFactory{}) + issuer.RegisterViewFactory("transferWithSelector", &views.TransferWithSelectorViewFactory{}) + issuer.RegisterViewFactory("redeem", &views.RedeemViewFactory{}) + issuer.RegisterViewFactory("balance", &views.BalanceViewFactory{}) + issuer.RegisterViewFactory("historyIssuedToken", &views.ListIssuedTokensViewFactory{}) + issuer.RegisterViewFactory("issuedTokenQuery", &views.ListIssuedTokensViewFactory{}) + issuer.RegisterViewFactory("GetEnrollmentID", &views.GetEnrollmentIDViewFactory{}) + issuer.RegisterViewFactory("acceptedTransactionHistory", &views.ListAcceptedTransactionsViewFactory{}) + issuer.RegisterViewFactory("transactionInfo", &views.TransactionInfoViewFactory{}) + issuer.RegisterViewFactory("CheckPublicParamsMatch", &views.CheckPublicParamsMatchViewFactory{}) + issuer.RegisterViewFactory("CheckTTXDB", &views.CheckTTXDBViewFactory{}) + issuer.RegisterViewFactory("RegisterIssuerWallet", &views.RegisterIssuerWalletViewFactory{}) + issuer.RegisterViewFactory("PruneInvalidUnspentTokens", &views.PruneInvalidUnspentTokensViewFactory{}) + issuer.RegisterViewFactory("WhoDeletedToken", &views.WhoDeletedTokenViewFactory{}) + issuer.RegisterViewFactory("GetPublicParams", &views.GetPublicParamsViewFactory{}) + + issuer1 := fscTopology.AddNodeFromTemplate("issuer1", issuer).AddOptions( + fabric.WithOrganization("Org1"), + fabric.WithAnonymousIdentity(), + token.WithDefaultIssuerIdentity(), + ) + issuer2 := fscTopology.AddNodeFromTemplate("issuer2", issuer).AddOptions( + fabric.WithOrganization("Org2"), + fabric.WithAnonymousIdentity(), + token.WithDefaultIssuerIdentity(), + ) + + auditor := fscTopology.NewTemplate("auditor") + auditor.RegisterViewFactory("registerAuditor", &views.RegisterAuditorViewFactory{}) + auditor.RegisterViewFactory("historyAuditing", &views.ListAuditedTransactionsViewFactory{}) + auditor.RegisterViewFactory("holding", &views.CurrentHoldingViewFactory{}) + auditor.RegisterViewFactory("spending", &views.CurrentSpendingViewFactory{}) + auditor.RegisterViewFactory("balance", &views.BalanceViewFactory{}) + auditor.RegisterViewFactory("CheckPublicParamsMatch", &views.CheckPublicParamsMatchViewFactory{}) + auditor.RegisterViewFactory("SetTransactionAuditStatus", &views.SetTransactionAuditStatusViewFactory{}) + auditor.RegisterViewFactory("CheckTTXDB", &views.CheckTTXDBViewFactory{}) + auditor.RegisterViewFactory("PruneInvalidUnspentTokens", &views.PruneInvalidUnspentTokensViewFactory{}) + auditor.RegisterViewFactory("WhoDeletedToken", &views.WhoDeletedTokenViewFactory{}) + auditor.RegisterViewFactory("ListVaultUnspentTokens", &views.ListVaultUnspentTokensViewFactory{}) + auditor.RegisterViewFactory("CheckIfExistsInVault", &views.CheckIfExistsInVaultViewFactory{}) + auditor.RegisterViewFactory("GetAuditorWalletIdentity", &views.GetAuditorWalletIdentityViewFactory{}) + auditor.RegisterViewFactory("RevokeUser", &views.RevokeUserViewFactory{}) + + auditor1 := fscTopology.AddNodeFromTemplate("auditor1", auditor).AddOptions( + fabric.WithOrganization("Org1"), + fabric.WithAnonymousIdentity(), + token.WithAuditorIdentity(), + ) + auditor2 := fscTopology.AddNodeFromTemplate("auditor2", auditor).AddOptions( + fabric.WithOrganization("Org2"), + fabric.WithAnonymousIdentity(), + token.WithAuditorIdentity(), + ) + + alice := fscTopology.AddNodeByName("alice").AddOptions( + fabric.WithOrganization("Org1"), + fabric.WithAnonymousIdentity(), + token.WithOwnerIdentity("alice"), + ) + alice.RegisterResponder(&views.AcceptCashView{}, &views.IssueCashView{}) + alice.RegisterResponder(&views.AcceptCashView{}, &views.TransferView{}) + alice.RegisterResponder(&views.AcceptCashView{}, &views.TransferWithSelectorView{}) + alice.RegisterResponder(&views.AcceptPreparedCashView{}, &views.PrepareTransferView{}) + alice.RegisterViewFactory("transfer", &views.TransferViewFactory{}) + alice.RegisterViewFactory("transferWithSelector", &views.TransferWithSelectorViewFactory{}) + alice.RegisterViewFactory("redeem", &views.RedeemViewFactory{}) + alice.RegisterViewFactory("swap", &views.SwapInitiatorViewFactory{}) + alice.RegisterViewFactory("history", &views.ListUnspentTokensViewFactory{}) + alice.RegisterViewFactory("balance", &views.BalanceViewFactory{}) + alice.RegisterViewFactory("GetEnrollmentID", &views.GetEnrollmentIDViewFactory{}) + alice.RegisterViewFactory("acceptedTransactionHistory", &views.ListAcceptedTransactionsViewFactory{}) + alice.RegisterViewFactory("transactionInfo", &views.TransactionInfoViewFactory{}) + alice.RegisterViewFactory("prepareTransfer", &views.PrepareTransferViewFactory{}) + alice.RegisterViewFactory("broadcastPreparedTransfer", &views.BroadcastPreparedTransferViewFactory{}) + alice.RegisterViewFactory("CheckPublicParamsMatch", &views.CheckPublicParamsMatchViewFactory{}) + alice.RegisterViewFactory("CheckTTXDB", &views.CheckTTXDBViewFactory{}) + alice.RegisterViewFactory("SetTransactionOwnerStatus", &views.SetTransactionOwnerStatusViewFactory{}) + alice.RegisterViewFactory("PruneInvalidUnspentTokens", &views.PruneInvalidUnspentTokensViewFactory{}) + alice.RegisterViewFactory("WhoDeletedToken", &views.WhoDeletedTokenViewFactory{}) + alice.RegisterViewFactory("ListVaultUnspentTokens", &views.ListVaultUnspentTokensViewFactory{}) + + bob := fscTopology.AddNodeByName("bob").AddOptions( + fabric.WithOrganization("Org2"), + fabric.WithAnonymousIdentity(), + token.WithOwnerIdentity("bob"), + ) + bob.RegisterResponder(&views.AcceptCashView{}, &views.IssueCashView{}) + bob.RegisterResponder(&views.AcceptCashView{}, &views.TransferView{}) + bob.RegisterResponder(&views.AcceptCashView{}, &views.TransferWithSelectorView{}) + bob.RegisterResponder(&views.AcceptPreparedCashView{}, &views.PrepareTransferView{}) + bob.RegisterResponder(&views.SwapResponderView{}, &views.SwapInitiatorView{}) + bob.RegisterViewFactory("transfer", &views.TransferViewFactory{}) + bob.RegisterViewFactory("transferWithSelector", &views.TransferWithSelectorViewFactory{}) + bob.RegisterViewFactory("redeem", &views.RedeemViewFactory{}) + bob.RegisterViewFactory("swap", &views.SwapInitiatorViewFactory{}) + bob.RegisterViewFactory("history", &views.ListUnspentTokensViewFactory{}) + bob.RegisterViewFactory("balance", &views.BalanceViewFactory{}) + bob.RegisterViewFactory("GetEnrollmentID", &views.GetEnrollmentIDViewFactory{}) + bob.RegisterViewFactory("acceptedTransactionHistory", &views.ListAcceptedTransactionsViewFactory{}) + bob.RegisterViewFactory("transactionInfo", &views.TransactionInfoViewFactory{}) + bob.RegisterViewFactory("CheckPublicParamsMatch", &views.CheckPublicParamsMatchViewFactory{}) + bob.RegisterViewFactory("prepareTransfer", &views.PrepareTransferViewFactory{}) + bob.RegisterViewFactory("TokenSelectorUnlock", &views.TokenSelectorUnlockViewFactory{}) + bob.RegisterViewFactory("FinalityWithTimeout", &views.FinalityWithTimeoutViewFactory{}) + bob.RegisterViewFactory("CheckTTXDB", &views.CheckTTXDBViewFactory{}) + bob.RegisterViewFactory("SetTransactionOwnerStatus", &views.SetTransactionOwnerStatusViewFactory{}) + bob.RegisterViewFactory("PruneInvalidUnspentTokens", &views.PruneInvalidUnspentTokensViewFactory{}) + bob.RegisterViewFactory("WhoDeletedToken", &views.WhoDeletedTokenViewFactory{}) + bob.RegisterViewFactory("ListVaultUnspentTokens", &views.ListVaultUnspentTokensViewFactory{}) + bob.RegisterViewFactory("GetRevocationHandle", &views.GetRevocationHandleViewFactory{}) + + // Token topology + tokenTopology := token.NewTopology() + + // we have two TMS, one with the dlog driver and one with the fabtoken driver + dlogTms := tokenTopology.AddTMS([]*node.Node{issuer1, auditor1, alice, bob}, backendNetwork, backendChannel, DLogDriver) + dlogTms.SetNamespace(DLogNamespace) + // max token value is 100^2 - 1 = 9999 + dlogTms.SetTokenGenPublicParams("100", "2") + fabric2.SetOrgs(dlogTms, "Org1") + + fabTokenTms := tokenTopology.AddTMS([]*node.Node{issuer2, auditor2, alice, bob}, backendNetwork, backendChannel, FabtokenDriver) + fabTokenTms.SetNamespace(FabTokenNamespace) + fabTokenTms.SetTokenGenPublicParams("9998") + fabric2.SetOrgs(fabTokenTms, "Org2") + + tokenTopology.SetSDK(fscTopology, &sdk.SDK{}) + dlogTms.AddAuditor(auditor1) + fabTokenTms.AddAuditor(auditor2) + + // FSC topology + fscTopology.SetBootstrapNode(fscTopology.AddNodeByName("lib-p2p-bootstrap-node")) + // Add Fabric SDK to FSC Nodes + fscTopology.AddSDK(&fabric3.SDK{}) + + return []api.Topology{backendNetwork, tokenTopology, fscTopology} +} diff --git a/integration/token/fungible/support.go b/integration/token/fungible/support.go index 158ba3182..1aa7dab60 100644 --- a/integration/token/fungible/support.go +++ b/integration/token/fungible/support.go @@ -13,15 +13,16 @@ import ( "strings" "time" - "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/hash" - "github.com/hyperledger-labs/fabric-smart-client/integration" "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/common" "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric" + topology2 "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/topology" "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/orion" + "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/hash" platform "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token" "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/topology" "github.com/hyperledger-labs/fabric-token-sdk/integration/token/fungible/views" + token2 "github.com/hyperledger-labs/fabric-token-sdk/token" "github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx" "github.com/hyperledger-labs/fabric-token-sdk/token/services/ttxdb" "github.com/hyperledger-labs/fabric-token-sdk/token/services/ttxdb/driver" @@ -30,19 +31,47 @@ import ( ) func RegisterAuditor(network *integration.Infrastructure, id string, onAuditorRestart OnAuditorRestartFunc) { - _, err := network.Client(id).CallView("registerAuditor", nil) + RegisterAuditorForTMSID(network, id, nil, onAuditorRestart) +} + +func RegisterAuditorForTMSID(network *integration.Infrastructure, id string, tmsId *token2.TMSID, onAuditorRestart OnAuditorRestartFunc) { + _, err := network.Client(id).CallView("registerAuditor", common.JSONMarshall(&views.RegisterAuditor{ + TMSID: tmsId, + })) Expect(err).NotTo(HaveOccurred()) if onAuditorRestart != nil { onAuditorRestart(network, id) } } +func getTmsId(network *integration.Infrastructure, namespace string) *token2.TMSID { + fabricTopology := getFabricTopology(network) + return &token2.TMSID{ + Network: fabricTopology.Name(), + Channel: fabricTopology.Channels[0].Name, + Namespace: namespace, + } +} + +func getFabricTopology(network *integration.Infrastructure) *topology2.Topology { + for _, t := range network.Topologies { + if t.Type() == "fabric" { + return t.(*topology2.Topology) + } + } + panic("no fabric topology found") +} + func RegisterCertifier(network *integration.Infrastructure, id string) { _, err := network.Client(id).CallView("registerCertifier", nil) Expect(err).NotTo(HaveOccurred()) } func IssueCash(network *integration.Infrastructure, wallet string, typ string, amount uint64, receiver string, auditor string, anonymous bool, IssuerId string, expectedErrorMsgs ...string) string { + return IssueCashForTMSID(network, wallet, typ, amount, receiver, auditor, anonymous, IssuerId, nil, expectedErrorMsgs...) +} + +func IssueCashForTMSID(network *integration.Infrastructure, wallet string, typ string, amount uint64, receiver string, auditor string, anonymous bool, IssuerId string, tmsId *token2.TMSID, expectedErrorMsgs ...string) string { if auditor == "issuer" || auditor == "newIssuer" { // the issuer is the auditor, choose default identity auditor = "" @@ -55,6 +84,7 @@ func IssueCash(network *integration.Infrastructure, wallet string, typ string, a Quantity: amount, Recipient: network.Identity(receiver), RecipientEID: receiver, + TMSID: tmsId, })) if len(expectedErrorMsgs) == 0 { @@ -137,10 +167,20 @@ func CheckBalanceAndHolding(network *integration.Infrastructure, id string, wall CheckHolding(network, id, wallet, typ, int64(expected), auditorId) } +func CheckBalanceAndHoldingForTMSID(network *integration.Infrastructure, id string, wallet string, typ string, expected uint64, auditorId string, tmsID *token2.TMSID) { + CheckBalanceForTMSID(network, id, wallet, typ, expected, tmsID) + CheckHoldingForTMSID(network, id, wallet, typ, int64(expected), auditorId, tmsID) +} + func CheckBalance(network *integration.Infrastructure, id string, wallet string, typ string, expected uint64) { + CheckBalanceForTMSID(network, id, wallet, typ, expected, nil) +} + +func CheckBalanceForTMSID(network *integration.Infrastructure, id string, wallet string, typ string, expected uint64, tmsID *token2.TMSID) { res, err := network.Client(id).CallView("balance", common.JSONMarshall(&views.BalanceQuery{ Wallet: wallet, Type: typ, + TMSID: tmsID, })) Expect(err).NotTo(HaveOccurred()) b := &views.Balance{} @@ -153,8 +193,13 @@ func CheckBalance(network *integration.Infrastructure, id string, wallet string, } func CheckHolding(network *integration.Infrastructure, id string, wallet string, typ string, expected int64, auditorId string) { + CheckHoldingForTMSID(network, id, wallet, typ, expected, auditorId, nil) +} + +func CheckHoldingForTMSID(network *integration.Infrastructure, id string, wallet string, typ string, expected int64, auditorId string, tmsID *token2.TMSID) { eIDBoxed, err := network.Client(id).CallView("GetEnrollmentID", common.JSONMarshall(&views.GetEnrollmentID{ Wallet: wallet, + TMSID: tmsID, })) Expect(err).NotTo(HaveOccurred()) eID := common.JSONUnmarshalString(eIDBoxed) @@ -169,16 +214,22 @@ func CheckHolding(network *integration.Infrastructure, id string, wallet string, } func CheckSpending(network *integration.Infrastructure, id string, wallet string, tokenType string, auditor string, expected uint64) { + CheckSpendingForTMSID(network, id, wallet, tokenType, auditor, expected, nil) +} + +func CheckSpendingForTMSID(network *integration.Infrastructure, id string, wallet string, tokenType string, auditor string, expected uint64, tmsId *token2.TMSID) { // check spending // first get the enrollment id eIDBoxed, err := network.Client(id).CallView("GetEnrollmentID", common.JSONMarshall(&views.GetEnrollmentID{ Wallet: wallet, + TMSID: tmsId, })) Expect(err).NotTo(HaveOccurred()) eID := common.JSONUnmarshalString(eIDBoxed) spendingBoxed, err := network.Client(auditor).CallView("spending", common.JSONMarshall(&views.CurrentSpending{ EnrollmentID: eID, TokenType: tokenType, + TMSID: tmsId, })) Expect(err).NotTo(HaveOccurred()) spending, err := strconv.ParseUint(common.JSONUnmarshalString(spendingBoxed), 10, 64) @@ -186,10 +237,15 @@ func CheckSpending(network *integration.Infrastructure, id string, wallet string Expect(spending).To(Equal(expected)) } -func ListIssuerHistory(network *integration.Infrastructure, wallet string, typ string) *token.IssuedTokens { - res, err := network.Client("issuer").CallView("historyIssuedToken", common.JSONMarshall(&views.ListIssuedTokens{ +func ListIssuerHistory(network *integration.Infrastructure, wallet, typ, issuer string) *token.IssuedTokens { + return ListIssuerHistoryForTMSID(network, wallet, typ, issuer, nil) +} + +func ListIssuerHistoryForTMSID(network *integration.Infrastructure, wallet, typ, issuer string, tmsId *token2.TMSID) *token.IssuedTokens { + res, err := network.Client(issuer).CallView("historyIssuedToken", common.JSONMarshall(&views.ListIssuedTokens{ Wallet: wallet, TokenType: typ, + TMSID: tmsId, })) Expect(err).NotTo(HaveOccurred()) @@ -199,9 +255,14 @@ func ListIssuerHistory(network *integration.Infrastructure, wallet string, typ s } func ListUnspentTokens(network *integration.Infrastructure, id string, wallet string, typ string) *token.UnspentTokens { + return ListUnspentTokensForTMSID(network, id, wallet, typ, nil) +} + +func ListUnspentTokensForTMSID(network *integration.Infrastructure, id string, wallet string, typ string, tmsId *token2.TMSID) *token.UnspentTokens { res, err := network.Client(id).CallView("history", common.JSONMarshall(&views.ListUnspentTokens{ Wallet: wallet, TokenType: typ, + TMSID: tmsId, })) Expect(err).NotTo(HaveOccurred()) @@ -211,6 +272,10 @@ func ListUnspentTokens(network *integration.Infrastructure, id string, wallet st } func TransferCash(network *integration.Infrastructure, id string, wallet string, typ string, amount uint64, receiver string, auditor string, expectedErrorMsgs ...string) string { + return TransferCashForTMSID(network, id, wallet, typ, amount, receiver, auditor, nil, expectedErrorMsgs...) +} + +func TransferCashForTMSID(network *integration.Infrastructure, id string, wallet string, typ string, amount uint64, receiver string, auditor string, tmsId *token2.TMSID, expectedErrorMsgs ...string) string { txidBoxed, err := network.Client(id).CallView("transfer", common.JSONMarshall(&views.Transfer{ Auditor: auditor, Wallet: wallet, @@ -218,18 +283,19 @@ func TransferCash(network *integration.Infrastructure, id string, wallet string, Amount: amount, Recipient: network.Identity(receiver), RecipientEID: receiver, + TMSID: tmsId, })) if len(expectedErrorMsgs) == 0 { txID := common.JSONUnmarshalString(txidBoxed) Expect(err).NotTo(HaveOccurred()) Expect(network.Client(receiver).IsTxFinal(txID)).NotTo(HaveOccurred()) - Expect(network.Client("auditor").IsTxFinal(txID)).NotTo(HaveOccurred()) + Expect(network.Client(auditor).IsTxFinal(txID)).NotTo(HaveOccurred()) signers := []string{auditor} if !strings.HasPrefix(receiver, id) { signers = append(signers, strings.Split(receiver, ".")[0]) } - txInfo := GetTransactionInfo(network, id, txID) + txInfo := GetTransactionInfoForTMSID(network, id, txID, tmsId) for _, identity := range signers { sigma, ok := txInfo.EndorsementAcks[network.Identity(identity).UniqueID()] Expect(ok).To(BeTrue(), "identity %s not found in txInfo.EndorsementAcks", identity) @@ -381,8 +447,13 @@ func FinalityWithTimeout(network *integration.Infrastructure, id string, tx []by } func GetTransactionInfo(network *integration.Infrastructure, id string, txnId string) *ttx.TransactionInfo { + return GetTransactionInfoForTMSID(network, id, txnId, nil) +} + +func GetTransactionInfoForTMSID(network *integration.Infrastructure, id string, txnId string, tmsId *token2.TMSID) *ttx.TransactionInfo { boxed, err := network.Client(id).CallView("transactionInfo", common.JSONMarshall(&views.TransactionInfo{ TransactionID: txnId, + TMSID: tmsId, })) Expect(err).NotTo(HaveOccurred()) info := &ttx.TransactionInfo{} @@ -404,7 +475,7 @@ func TransferCashByIDs(network *integration.Infrastructure, id string, wallet st if len(expectedErrorMsgs) == 0 { Expect(err).NotTo(HaveOccurred()) Expect(network.Client(receiver).IsTxFinal(common.JSONUnmarshalString(txIDBoxed))).NotTo(HaveOccurred()) - Expect(network.Client("auditor").IsTxFinal(common.JSONUnmarshalString(txIDBoxed))).NotTo(HaveOccurred()) + Expect(network.Client(auditor).IsTxFinal(common.JSONUnmarshalString(txIDBoxed))).NotTo(HaveOccurred()) return common.JSONUnmarshalString(txIDBoxed) } else { Expect(err).To(HaveOccurred()) @@ -428,7 +499,7 @@ func TransferCashWithSelector(network *integration.Infrastructure, id string, wa if len(expectedErrorMsgs) == 0 { Expect(err).NotTo(HaveOccurred()) Expect(network.Client(receiver).IsTxFinal(common.JSONUnmarshalString(txid))).NotTo(HaveOccurred()) - Expect(network.Client("auditor").IsTxFinal(common.JSONUnmarshalString(txid))).NotTo(HaveOccurred()) + Expect(network.Client(auditor).IsTxFinal(common.JSONUnmarshalString(txid))).NotTo(HaveOccurred()) } else { Expect(err).To(HaveOccurred()) for _, msg := range expectedErrorMsgs { @@ -439,14 +510,19 @@ func TransferCashWithSelector(network *integration.Infrastructure, id string, wa } func RedeemCash(network *integration.Infrastructure, id string, wallet string, typ string, amount uint64, auditor string) { + RedeemCashForTMSID(network, id, wallet, typ, amount, auditor, nil) +} + +func RedeemCashForTMSID(network *integration.Infrastructure, id string, wallet string, typ string, amount uint64, auditor string, tmsId *token2.TMSID) { txid, err := network.Client(id).CallView("redeem", common.JSONMarshall(&views.Redeem{ Auditor: auditor, Wallet: wallet, Type: typ, Amount: amount, + TMSID: tmsId, })) Expect(err).NotTo(HaveOccurred()) - Expect(network.Client("auditor").IsTxFinal(common.JSONUnmarshalString(txid))).NotTo(HaveOccurred()) + Expect(network.Client(auditor).IsTxFinal(common.JSONUnmarshalString(txid))).NotTo(HaveOccurred()) } func RedeemCashByIDs(network *integration.Infrastructure, id string, wallet string, ids []*token.ID, amount uint64, auditor string) { @@ -458,7 +534,7 @@ func RedeemCashByIDs(network *integration.Infrastructure, id string, wallet stri Amount: amount, })) Expect(err).NotTo(HaveOccurred()) - Expect(network.Client("auditor").IsTxFinal(common.JSONUnmarshalString(txid))).NotTo(HaveOccurred()) + Expect(network.Client(auditor).IsTxFinal(common.JSONUnmarshalString(txid))).NotTo(HaveOccurred()) } func SwapCash(network *integration.Infrastructure, id string, wallet string, typeLeft string, amountLeft uint64, typRight string, amountRight uint64, receiver string, auditor string) { @@ -473,12 +549,18 @@ func SwapCash(network *integration.Infrastructure, id string, wallet string, typ })) Expect(err).NotTo(HaveOccurred()) Expect(network.Client(receiver).IsTxFinal(common.JSONUnmarshalString(txid))).NotTo(HaveOccurred()) - Expect(network.Client("auditor").IsTxFinal(common.JSONUnmarshalString(txid))).NotTo(HaveOccurred()) + Expect(network.Client(auditor).IsTxFinal(common.JSONUnmarshalString(txid))).NotTo(HaveOccurred()) } func CheckPublicParams(network *integration.Infrastructure, ids ...string) { + CheckPublicParamsForTMSID(network, nil, ids...) +} + +func CheckPublicParamsForTMSID(network *integration.Infrastructure, tmsId *token2.TMSID, ids ...string) { for _, id := range ids { - _, err := network.Client(id).CallView("CheckPublicParamsMatch", common.JSONMarshall(&views.CheckPublicParamsMatch{})) + _, err := network.Client(id).CallView("CheckPublicParamsMatch", common.JSONMarshall(&views.CheckPublicParamsMatch{ + TMSID: tmsId, + })) Expect(err).NotTo(HaveOccurred(), "failed to check public params at [%s]", id) } } diff --git a/integration/token/fungible/tests.go b/integration/token/fungible/tests.go index 8f6bc06f4..82d13d2d6 100644 --- a/integration/token/fungible/tests.go +++ b/integration/token/fungible/tests.go @@ -24,6 +24,11 @@ import ( . "github.com/onsi/gomega" ) +const ( + DLogNamespace = "dlog-token-chaincode" + FabTokenNamespace = "fabtoken-token-chaincode" +) + var AuditedTransactions = []*ttxdb.TransactionRecord{ { TxID: "", @@ -298,12 +303,12 @@ func TestAll(network *integration.Infrastructure, auditor string, onAuditorResta CheckAcceptedTransactions(network, "alice", "", AliceAcceptedTransactions[:2], &t0, &t3, nil) CheckAcceptedTransactions(network, "alice", "", AliceAcceptedTransactions[1:2], &t2, &t3, nil) - h := ListIssuerHistory(network, "", "USD") + h := ListIssuerHistory(network, "", "USD", "issuer") Expect(h.Count() > 0).To(BeTrue()) Expect(h.Sum(64).ToBigInt().Cmp(big.NewInt(120))).To(BeEquivalentTo(0)) Expect(h.ByType("USD").Count()).To(BeEquivalentTo(h.Count())) - h = ListIssuerHistory(network, "", "EUR") + h = ListIssuerHistory(network, "", "EUR", "issuer") Expect(h.Count()).To(BeEquivalentTo(0)) // Register a new issuer wallet and issue with that wallet @@ -332,12 +337,12 @@ func TestAll(network *integration.Infrastructure, auditor string, onAuditorResta CheckAcceptedTransactions(network, "bob", "", BobAcceptedTransactions[:3], nil, nil, nil) CheckAcceptedTransactions(network, "bob", "", BobAcceptedTransactions[:3], &t4, &t7, nil) - h = ListIssuerHistory(network, "", "USD") + h = ListIssuerHistory(network, "", "USD", "issuer") Expect(h.Count() > 0).To(BeTrue()) Expect(h.Sum(64).ToBigInt().Cmp(big.NewInt(120))).To(BeEquivalentTo(0)) Expect(h.ByType("USD").Count()).To(BeEquivalentTo(h.Count())) - h = ListIssuerHistory(network, "newIssuerWallet", "EUR") + h = ListIssuerHistory(network, "newIssuerWallet", "EUR", "issuer") Expect(h.Count() > 0).To(BeTrue()) Expect(h.Sum(64).ToBigInt().Cmp(big.NewInt(30))).To(BeEquivalentTo(0)) Expect(h.ByType("EUR").Count()).To(BeEquivalentTo(h.Count())) @@ -424,12 +429,12 @@ func TestAll(network *integration.Infrastructure, auditor string, onAuditorResta IssueCash(network, "newIssuerWallet", "EUR", 150, "issuer", auditor, true, "issuer") IssueCash(network, "issuer.id1", "EUR", 10, "issuer.owner", auditor, true, "issuer") - h = ListIssuerHistory(network, "", "USD") + h = ListIssuerHistory(network, "", "USD", "issuer") Expect(h.Count() > 0).To(BeTrue()) Expect(h.Sum(64).ToBigInt().Cmp(big.NewInt(241))).To(BeEquivalentTo(0)) Expect(h.ByType("USD").Count()).To(BeEquivalentTo(h.Count())) - h = ListIssuerHistory(network, "newIssuerWallet", "EUR") + h = ListIssuerHistory(network, "newIssuerWallet", "EUR", "issuer") Expect(h.Count() > 0).To(BeTrue()) Expect(h.Sum(64).ToBigInt().Cmp(big.NewInt(180))).To(BeEquivalentTo(0)) Expect(h.ByType("EUR").Count()).To(BeEquivalentTo(h.Count())) @@ -800,3 +805,57 @@ func TestRevokeIdentity(network *integration.Infrastructure, auditor string, rev CheckBalanceAndHolding(network, "bob", "", "USD", 0, auditor) CheckBalanceAndHolding(network, "bob", "bob.id1", "USD", 90, auditor) } + +func TestMixed(network *integration.Infrastructure) { + dlogId := getTmsId(network, DLogNamespace) + fabTokenId := getTmsId(network, FabTokenNamespace) + RegisterAuditorForTMSID(network, "auditor1", dlogId, nil) + RegisterAuditorForTMSID(network, "auditor2", fabTokenId, nil) + + // give some time to the nodes to get the public parameters + time.Sleep(10 * time.Second) + + CheckPublicParamsForTMSID(network, dlogId, "issuer1", "auditor1", "alice", "bob") + CheckPublicParamsForTMSID(network, fabTokenId, "issuer2", "auditor2", "alice", "bob") + + IssueCashForTMSID(network, "", "USD", 110, "alice", "auditor1", true, "issuer1", dlogId) + IssueCashForTMSID(network, "", "USD", 115, "alice", "auditor2", true, "issuer2", fabTokenId) + + TransferCashForTMSID(network, "alice", "", "USD", 20, "bob", "auditor1", dlogId) + TransferCashForTMSID(network, "alice", "", "USD", 30, "bob", "auditor2", fabTokenId) + + RedeemCashForTMSID(network, "bob", "", "USD", 11, "auditor1", dlogId) + CheckSpendingForTMSID(network, "bob", "", "USD", "auditor1", 11, dlogId) + + CheckBalanceAndHoldingForTMSID(network, "alice", "", "USD", 90, "auditor1", dlogId) + CheckBalanceAndHoldingForTMSID(network, "alice", "", "USD", 85, "auditor2", fabTokenId) + CheckBalanceAndHoldingForTMSID(network, "bob", "", "USD", 9, "auditor1", dlogId) + CheckBalanceAndHoldingForTMSID(network, "bob", "", "USD", 30, "auditor2", fabTokenId) + + h := ListIssuerHistoryForTMSID(network, "", "USD", "issuer1", dlogId) + Expect(h.Count() > 0).To(BeTrue()) + Expect(h.Sum(64).ToBigInt().Cmp(big.NewInt(110))).To(BeEquivalentTo(0)) + Expect(h.ByType("USD").Count()).To(BeEquivalentTo(h.Count())) + + // Error cases + + // Try to approve dlog with auditor2 + TransferCashForTMSID(network, "alice", "", "USD", 20, "bob", "auditor2", dlogId, "") + // Try to issue on dlog with issuer2 + IssueCashForTMSID(network, "", "USD", 110, "alice", "auditor1", true, "issuer2", dlogId, "") + // Try to spend on dlog coins from fabtoken + TransferCashForTMSID(network, "alice", "", "USD", 120, "bob", "auditor2", fabTokenId, "") + // Try to issue more coins than the max + IssueCashForTMSID(network, "", "MAX", 9999, "bob", "auditor1", true, "issuer1", dlogId) + IssueCashForTMSID(network, "", "MAX", 9999, "bob", "auditor2", true, "issuer2", fabTokenId, "q is larger than max token value [9998]") + + // Shut down one auditor and try to issue cash for both chaincodes + Restart(network, true, "auditor2") + IssueCashForTMSID(network, "", "USD", 10, "alice", "auditor1", true, "issuer1", dlogId) + IssueCashForTMSID(network, "", "USD", 20, "alice", "auditor2", true, "issuer2", fabTokenId, "") + RegisterAuditor(network, "auditor2", nil) + IssueCashForTMSID(network, "", "USD", 30, "alice", "auditor2", true, "issuer2", fabTokenId) + + CheckBalanceAndHoldingForTMSID(network, "alice", "", "USD", 100, "auditor1", dlogId) + CheckBalanceAndHoldingForTMSID(network, "alice", "", "USD", 115, "auditor2", fabTokenId) +} diff --git a/integration/token/fungible/topology/topology.go b/integration/token/fungible/topology/topology.go index 6cc4e85eb..a08ba6305 100644 --- a/integration/token/fungible/topology/topology.go +++ b/integration/token/fungible/topology/topology.go @@ -50,8 +50,8 @@ func Topology(backend string, tokenSDKDriver string, auditorAsIssuer bool) []api orion.WithRole("issuer"), token.WithDefaultIssuerIdentity(), token.WithIssuerIdentity("issuer.id1"), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "issuer.owner"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("issuer.owner"), ) issuer.RegisterViewFactory("issue", &views.IssueCashViewFactory{}) issuer.RegisterViewFactory("transfer", &views.TransferViewFactory{}) @@ -76,8 +76,8 @@ func Topology(backend string, tokenSDKDriver string, auditorAsIssuer bool) []api orion.WithRole("issuer"), token.WithDefaultIssuerIdentity(), token.WithIssuerIdentity("newIssuer.id1"), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "newIssuer.owner"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("newIssuer.owner"), ) newIssuer.RegisterViewFactory("issue", &views.IssueCashViewFactory{}) newIssuer.RegisterViewFactory("GetPublicParams", &views.GetPublicParamsViewFactory{}) @@ -152,7 +152,7 @@ func Topology(backend string, tokenSDKDriver string, auditorAsIssuer bool) []api fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), orion.WithRole("alice"), - token.WithOwnerIdentity(tokenSDKDriver, "alice.id1"), + token.WithOwnerIdentity("alice.id1"), ) alice.RegisterResponder(&views.AcceptCashView{}, &views.IssueCashView{}) alice.RegisterResponder(&views.AcceptCashView{}, &views.TransferView{}) @@ -180,8 +180,8 @@ func Topology(backend string, tokenSDKDriver string, auditorAsIssuer bool) []api fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), orion.WithRole("bob"), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "bob.id1"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("bob.id1"), ) bob.RegisterResponder(&views.AcceptCashView{}, &views.IssueCashView{}) bob.RegisterResponder(&views.AcceptCashView{}, &views.TransferView{}) @@ -212,8 +212,8 @@ func Topology(backend string, tokenSDKDriver string, auditorAsIssuer bool) []api fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), orion.WithRole("charlie"), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "charlie.id1"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("charlie.id1"), ) charlie.RegisterResponder(&views.AcceptCashView{}, &views.IssueCashView{}) charlie.RegisterResponder(&views.AcceptCashView{}, &views.TransferView{}) @@ -239,10 +239,10 @@ func Topology(backend string, tokenSDKDriver string, auditorAsIssuer bool) []api fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), orion.WithRole("manager"), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "manager.id1"), - token.WithOwnerIdentity(tokenSDKDriver, "manager.id2"), - token.WithOwnerIdentity(tokenSDKDriver, "manager.id3"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("manager.id1"), + token.WithOwnerIdentity("manager.id2"), + token.WithOwnerIdentity("manager.id3"), ) manager.RegisterResponder(&views.AcceptCashView{}, &views.IssueCashView{}) manager.RegisterResponder(&views.AcceptCashView{}, &views.TransferView{}) diff --git a/integration/token/fungible/views/accept.go b/integration/token/fungible/views/accept.go index 9ff370282..288038ac8 100644 --- a/integration/token/fungible/views/accept.go +++ b/integration/token/fungible/views/accept.go @@ -9,6 +9,7 @@ package views import ( "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/assert" "github.com/hyperledger-labs/fabric-smart-client/platform/view/view" + "github.com/hyperledger-labs/fabric-token-sdk/token" "github.com/hyperledger-labs/fabric-token-sdk/token/services/network" "github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx" token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token" @@ -44,7 +45,7 @@ func (a *AcceptCashView) Call(context view.Context) (interface{}, error) { if output.Type == "MAX" { continue } - unspentTokens, err := ttx.MyWallet(context).ListUnspentTokens(ttx.WithType(output.Type)) + unspentTokens, err := ttx.MyWallet(context, token.WithTMSID(tx.TMSID())).ListUnspentTokens(ttx.WithType(output.Type)) assert.NoError(err, "failed retrieving the unspent tokens for type [%s]", output.Type) upperBound, err := token2.UInt64ToQuantity(3000, precision) assert.NoError(err, "failed to convert to quantity") diff --git a/integration/token/fungible/views/auditor.go b/integration/token/fungible/views/auditor.go index ebd8e252d..5719defe4 100644 --- a/integration/token/fungible/views/auditor.go +++ b/integration/token/fungible/views/auditor.go @@ -22,16 +22,18 @@ import ( "github.com/pkg/errors" ) -type AuditView struct{} +type AuditView struct { + *token.TMSID +} func (a *AuditView) Call(context view.Context) (interface{}, error) { logger.Debugf("AuditView: [%s]", context.ID()) - tx, err := ttx.ReceiveTransaction(context, ttx.WithNoTransactionVerification()) + tx, err := ttx.ReceiveTransaction(context, append(TxOpts(a.TMSID), ttx.WithNoTransactionVerification())...) assert.NoError(err, "failed receiving transaction") logger.Debugf("AuditView: [%s]", tx.ID()) - w := ttx.MyAuditorWallet(context) + w := ttx.MyAuditorWallet(context, ServiceOpts(a.TMSID)...) assert.NotNil(w, "failed getting default auditor wallet") // Validate @@ -183,18 +185,29 @@ func (a *AuditView) Call(context view.Context) (interface{}, error) { return res, err } -type RegisterAuditorView struct{} +type RegisterAuditor struct { + *token.TMSID +} + +type RegisterAuditorView struct { + *RegisterAuditor +} func (r *RegisterAuditorView) Call(context view.Context) (interface{}, error) { return context.RunView(ttx.NewRegisterAuditorView( - &AuditView{}, + &AuditView{r.TMSID}, + ServiceOpts(r.TMSID)..., )) } type RegisterAuditorViewFactory struct{} func (p *RegisterAuditorViewFactory) NewView(in []byte) (view.View, error) { - f := &RegisterAuditorView{} + f := &RegisterAuditorView{RegisterAuditor: &RegisterAuditor{}} + if in != nil { + err := json.Unmarshal(in, f.RegisterAuditor) + assert.NoError(err, "failed unmarshalling input") + } return f, nil } @@ -241,8 +254,9 @@ func (p *CurrentHoldingViewFactory) NewView(in []byte) (view.View, error) { } type CurrentSpending struct { - EnrollmentID string `json:"enrollment_id"` - TokenType string `json:"token_type"` + EnrollmentID string `json:"enrollment_id"` + TokenType string `json:"token_type"` + TMSID *token.TMSID `json:"tmsid"` } // CurrentSpendingView is used to retrieve the current spending of token type of the passed enrollment id @@ -251,7 +265,7 @@ type CurrentSpendingView struct { } func (r *CurrentSpendingView) Call(context view.Context) (interface{}, error) { - w := ttx.MyAuditorWallet(context) + w := ttx.MyAuditorWallet(context, ServiceOpts(r.TMSID)...) assert.NotNil(w, "failed getting default auditor wallet") auditor := ttx.NewAuditor(context, w) diff --git a/integration/token/fungible/views/balance.go b/integration/token/fungible/views/balance.go index 700319baf..1b08223e0 100644 --- a/integration/token/fungible/views/balance.go +++ b/integration/token/fungible/views/balance.go @@ -16,7 +16,7 @@ import ( ) type BalanceQuery struct { - TMSID token.TMSID + TMSID *token.TMSID Wallet string Type string } @@ -31,7 +31,7 @@ type BalanceView struct { } func (b *BalanceView) Call(context view.Context) (interface{}, error) { - tms := token.GetManagementService(context, token.WithTMSID(b.TMSID)) + tms := token.GetManagementService(context, ServiceOpts(b.TMSID)...) wallet := tms.WalletManager().OwnerWallet(b.Wallet) if wallet == nil { return nil, fmt.Errorf("wallet %s not found", b.Wallet) diff --git a/integration/token/fungible/views/history.go b/integration/token/fungible/views/history.go index d0f084b10..f961c53a7 100644 --- a/integration/token/fungible/views/history.go +++ b/integration/token/fungible/views/history.go @@ -25,6 +25,8 @@ type ListIssuedTokens struct { Wallet string // TokenType is the token type to select TokenType string + // The TMS to pick in case of multiple TMSIDs + TMSID *token.TMSID } type ListIssuedTokensView struct { @@ -33,7 +35,7 @@ type ListIssuedTokensView struct { func (p *ListIssuedTokensView) Call(context view.Context) (interface{}, error) { // Tokens issued by identities in this wallet will be listed - wallet := ttx.GetIssuerWallet(context, p.Wallet) + wallet := ttx.GetIssuerWallet(context, p.Wallet, ServiceOpts(p.TMSID)...) assert.NotNil(wallet, "wallet [%s] not found", p.Wallet) // Return the list of issued tokens by type @@ -148,6 +150,7 @@ func (l *ListAcceptedTransactionsViewFactory) NewView(in []byte) (view.View, err // TransactionInfo contains the input information to search for transaction info type TransactionInfo struct { TransactionID string + TMSID *token.TMSID } type TransactionInfoView struct { @@ -155,7 +158,7 @@ type TransactionInfoView struct { } func (t *TransactionInfoView) Call(context view.Context) (interface{}, error) { - owner := ttx.NewOwner(context, token.GetManagementService(context)) + owner := ttx.NewOwner(context, token.GetManagementService(context, ServiceOpts(t.TMSID)...)) info, err := owner.TransactionInfo(t.TransactionID) assert.NoError(err, "failed getting transaction info") diff --git a/integration/token/fungible/views/info.go b/integration/token/fungible/views/info.go index d2b9b1e0e..97c5d8796 100644 --- a/integration/token/fungible/views/info.go +++ b/integration/token/fungible/views/info.go @@ -19,7 +19,7 @@ import ( type GetEnrollmentID struct { Wallet string - TMSID token.TMSID + TMSID *token.TMSID } // GetEnrollmentIDView is a view that returns the enrollment ID of a wallet. @@ -28,7 +28,7 @@ type GetEnrollmentIDView struct { } func (r *GetEnrollmentIDView) Call(context view.Context) (interface{}, error) { - tms := token.GetManagementService(context, token.WithTMSID(r.TMSID)) + tms := token.GetManagementService(context, ServiceOpts(r.TMSID)...) assert.NotNil(tms, "tms not found [%s]", r.TMSID) w := tms.WalletManager().OwnerWallet(r.Wallet) assert.NotNil(w, "wallet not found [%s]", r.Wallet) @@ -46,7 +46,7 @@ func (p *GetEnrollmentIDViewFactory) NewView(in []byte) (view.View, error) { } type CheckPublicParamsMatch struct { - TMSID token.TMSID + TMSID *token.TMSID } type CheckPublicParamsMatchView struct { @@ -54,7 +54,7 @@ type CheckPublicParamsMatchView struct { } func (p *CheckPublicParamsMatchView) Call(context view.Context) (interface{}, error) { - tms := token.GetManagementService(context, token.WithTMSID(p.TMSID)) + tms := token.GetManagementService(context, ServiceOpts(p.TMSID)...) assert.NotNil(tms, "failed to get TMS") assert.NoError(tms.PublicParametersManager().Validate(), "failed to validate local public parameters") diff --git a/integration/token/fungible/views/issue.go b/integration/token/fungible/views/issue.go index 295dfac11..505abfc7e 100644 --- a/integration/token/fungible/views/issue.go +++ b/integration/token/fungible/views/issue.go @@ -22,6 +22,7 @@ import ( // IssueCash contains the input information to issue a token type IssueCash struct { + TMSID *token.TMSID // Anonymous set to true if the transaction is anonymous, false otherwise Anonymous bool // Auditor is the name of the auditor identity @@ -47,11 +48,11 @@ func (p *IssueCashView) Call(context view.Context) (interface{}, error) { // to ask for the identity to use to assign ownership of the freshly created token. // Notice that, this step would not be required if the issuer knew already which // identity the recipient wants to use. - recipient, err := ttx.RequestRecipientIdentity(context, p.Recipient) + recipient, err := ttx.RequestRecipientIdentity(context, p.Recipient, ServiceOpts(p.TMSID)...) assert.NoError(err, "failed getting recipient identity") // match recipient EID - eID, err := token.GetManagementService(context).WalletManager().GetEnrollmentID(recipient) + eID, err := token.GetManagementService(context, ServiceOpts(p.TMSID)...).WalletManager().GetEnrollmentID(recipient) assert.NoError(err, "failed to get enrollment id for recipient [%s]", recipient) assert.True(strings.HasPrefix(eID, p.RecipientEID), "recipient EID [%s] does not match the expected one [%s]", eID, p.RecipientEID) @@ -59,11 +60,11 @@ func (p *IssueCashView) Call(context view.Context) (interface{}, error) { // In this example, if the token type is USD, the issuer checks that no more than 230 units of USD // have been issued already including the current request. // No check is performed for other types. - wallet := ttx.GetIssuerWallet(context, p.IssuerWallet) + wallet := ttx.GetIssuerWallet(context, p.IssuerWallet, ServiceOpts(p.TMSID)...) assert.NotNil(wallet, "issuer wallet [%s] not found", p.IssuerWallet) if p.TokenType == "USD" { // Retrieve the list of issued tokens using a specific wallet for a given token type. - precision := token.GetManagementService(context).PublicParametersManager().PublicParameters().Precision() + precision := token.GetManagementService(context, ServiceOpts(p.TMSID)...).PublicParametersManager().PublicParameters().Precision() history, err := wallet.ListIssuedTokens(ttx.WithType(p.TokenType)) assert.NoError(err, "failed getting history for token type [%s]", p.TokenType) @@ -86,13 +87,13 @@ func (p *IssueCashView) Call(context view.Context) (interface{}, error) { } else { auditorID = view2.GetIdentityProvider(context).Identity(p.Auditor) } - auditorOpt := ttx.WithAuditor(auditorID) + opts := append(TxOpts(p.TMSID), ttx.WithAuditor(auditorID)) if p.Anonymous { // The issuer creates an anonymous transaction (this means that the resulting Fabric transaction will be signed using idemix, for example), - tx, err = ttx.NewAnonymousTransaction(context, auditorOpt) + tx, err = ttx.NewAnonymousTransaction(context, opts...) } else { // The issuer creates a nominal transaction using the default identity - tx, err = ttx.NewTransaction(context, nil, auditorOpt) + tx, err = ttx.NewTransaction(context, nil, opts...) } assert.NoError(err, "failed creating issue transaction") tx.SetApplicationMetadata("github.com/hyperledger-labs/fabric-token-sdk/integration/token/fungible/issue", []byte("issue")) diff --git a/integration/token/fungible/views/list.go b/integration/token/fungible/views/list.go index 085d24330..f332afa8d 100644 --- a/integration/token/fungible/views/list.go +++ b/integration/token/fungible/views/list.go @@ -22,6 +22,8 @@ type ListUnspentTokens struct { Wallet string // TokenType is the token type to select TokenType string + // The TMS to pick in case of multiple TMSIDs + TMSID *token.TMSID } type ListUnspentTokensView struct { @@ -30,7 +32,7 @@ type ListUnspentTokensView struct { func (p *ListUnspentTokensView) Call(context view.Context) (interface{}, error) { // Tokens owner by identities in this wallet will be listed - wallet := ttx.GetWallet(context, p.Wallet) + wallet := ttx.GetWallet(context, p.Wallet, ServiceOpts(p.TMSID)...) assert.NotNil(wallet, "wallet [%s] not found", p.Wallet) // Return the list of unspent tokens by type diff --git a/integration/token/fungible/views/redeem.go b/integration/token/fungible/views/redeem.go index 309246cc1..a2e09b101 100644 --- a/integration/token/fungible/views/redeem.go +++ b/integration/token/fungible/views/redeem.go @@ -30,6 +30,8 @@ type Redeem struct { Type string // Amount to redeem Amount uint64 + // The TMS to pick in case of multiple TMSIDs + TMSID *token2.TMSID } type RedeemView struct { @@ -42,12 +44,12 @@ func (t *RedeemView) Call(context view.Context) (interface{}, error) { // and specify the auditor that must be contacted to approve the operation. tx, err := ttx.NewAnonymousTransaction( context, - ttx.WithAuditor(view2.GetIdentityProvider(context).Identity(t.Auditor)), + append(TxOpts(t.TMSID), ttx.WithAuditor(view2.GetIdentityProvider(context).Identity(t.Auditor)))..., ) assert.NoError(err, "failed creating transaction") // The sender will select tokens owned by this wallet - senderWallet := ttx.GetWallet(context, t.Wallet) + senderWallet := ttx.GetWallet(context, t.Wallet, ServiceOpts(t.TMSID)...) assert.NotNil(senderWallet, "sender wallet [%s] not found", t.Wallet) // The senders adds a new redeem operation to the transaction following the instruction received. diff --git a/integration/token/fungible/views/transfer.go b/integration/token/fungible/views/transfer.go index dad043424..951cbadf8 100644 --- a/integration/token/fungible/views/transfer.go +++ b/integration/token/fungible/views/transfer.go @@ -53,6 +53,8 @@ type Transfer struct { FailToRelease bool // For additional transfer actions TransferAction []TransferAction + // The TMS to pick in case of multiple TMSIDs + TMSID *token2.TMSID } type TransferView struct { @@ -64,14 +66,14 @@ func (t *TransferView) Call(context view.Context) (interface{}, error) { // to ask for the identity to use to assign ownership of the freshly created token. // Notice that, this step would not be required if the sender knew already which // identity the recipient wants to use. - recipient, err := ttx.RequestRecipientIdentity(context, t.Recipient) + recipient, err := ttx.RequestRecipientIdentity(context, t.Recipient, ServiceOpts(t.TMSID)...) assert.NoError(err, "failed getting recipient") - wm := token2.GetManagementService(context).WalletManager() + wm := token2.GetManagementService(context, ServiceOpts(t.TMSID)...).WalletManager() // if there are more recipients, ask for their recipient identity var additionalRecipients []view.Identity for _, action := range t.TransferAction { - actionRecipient, err := ttx.RequestRecipientIdentity(context, action.Recipient) + actionRecipient, err := ttx.RequestRecipientIdentity(context, action.Recipient, ServiceOpts(t.TMSID)...) assert.NoError(err, "failed getting recipient") eID, err := wm.GetEnrollmentID(recipient) assert.NoError(err, "failed to get enrollment id for recipient [%s]", recipient) @@ -89,12 +91,12 @@ func (t *TransferView) Call(context view.Context) (interface{}, error) { // and specify the auditor that must be contacted to approve the operation. tx, err := ttx.NewAnonymousTransaction( context, - ttx.WithAuditor(view2.GetIdentityProvider(context).Identity(t.Auditor)), + append(TxOpts(t.TMSID), ttx.WithAuditor(view2.GetIdentityProvider(context).Identity(t.Auditor)))..., ) assert.NoError(err, "failed creating transaction") // The sender will select tokens owned by this wallet - senderWallet := ttx.GetWallet(context, t.Wallet) + senderWallet := ttx.GetWallet(context, t.Wallet, ServiceOpts(t.TMSID)...) assert.NotNil(senderWallet, "sender wallet [%s] not found", t.Wallet) // The sender adds a new transfer operation to the transaction following the instruction received. diff --git a/integration/token/fungible/views/utils.go b/integration/token/fungible/views/utils.go index aa8f70ccd..ba222a7d0 100644 --- a/integration/token/fungible/views/utils.go +++ b/integration/token/fungible/views/utils.go @@ -37,3 +37,19 @@ func AssertTokensInVault(vault *network.Vault, tx *ttx.Transaction, outputs *tok } } + +func ServiceOpts(tmsId *token.TMSID) []token.ServiceOption { + var serviceOpts []token.ServiceOption + if tmsId != nil { + serviceOpts = append(serviceOpts, token.WithTMSID(*tmsId)) + } + return serviceOpts +} + +func TxOpts(tmsId *token.TMSID) []ttx.TxOption { + var txOpts []ttx.TxOption + if tmsId != nil { + txOpts = append(txOpts, ttx.WithTMSID(*tmsId)) + } + return txOpts +} diff --git a/integration/token/interop/support.go b/integration/token/interop/support.go index 815155f14..d01306f0d 100644 --- a/integration/token/interop/support.go +++ b/integration/token/interop/support.go @@ -108,16 +108,17 @@ func CheckBalance(network *integration.Infrastructure, id string, wallet string, func CheckHolding(network *integration.Infrastructure, id string, wallet string, typ string, expected int64, opts ...token.ServiceOption) { opt, err := token.CompileServiceOptions(opts...) Expect(err).NotTo(HaveOccurred(), "failed to compile options [%v]", opts) + tmsId := opt.TMSID() eIDBoxed, err := network.Client(id).CallView("GetEnrollmentID", common.JSONMarshall(&views.GetEnrollmentID{ Wallet: wallet, - TMSID: opt.TMSID(), + TMSID: &tmsId, })) Expect(err).NotTo(HaveOccurred()) eID := common.JSONUnmarshalString(eIDBoxed) holdingBoxed, err := network.Client("auditor").CallView("holding", common.JSONMarshall(&views.CurrentHolding{ EnrollmentID: eID, TokenType: typ, - TMSID: opt.TMSID(), + TMSID: tmsId, })) Expect(err).NotTo(HaveOccurred()) holding, err := strconv.Atoi(common.JSONUnmarshalString(holdingBoxed)) @@ -166,7 +167,7 @@ func CheckBalanceWithLockedAndHolding(network *integration.Infrastructure, id st func CheckPublicParams(network *integration.Infrastructure, tmsID token.TMSID, ids ...string) { for _, id := range ids { _, err := network.Client(id).CallView("CheckPublicParamsMatch", common.JSONMarshall(&views.CheckPublicParamsMatch{ - TMSID: tmsID, + TMSID: &tmsID, })) Expect(err).NotTo(HaveOccurred()) } diff --git a/integration/token/interop/topology.go b/integration/token/interop/topology.go index cc695acbe..4abdd8225 100644 --- a/integration/token/interop/topology.go +++ b/integration/token/interop/topology.go @@ -36,7 +36,7 @@ func HTLCSingleFabricNetworkTopology(tokenSDKDriver string) []api.Topology { fabric.WithOrganization("Org1"), fabric.WithAnonymousIdentity(), token.WithIssuerIdentity("issuer.id1"), - token.WithOwnerIdentity(tokenSDKDriver, "issuer.owner"), + token.WithOwnerIdentity("issuer.owner"), ) issuer.RegisterViewFactory("issue", &views2.IssueCashViewFactory{}) issuer.RegisterViewFactory("history", &views.ListIssuedTokensViewFactory{}) @@ -60,7 +60,7 @@ func HTLCSingleFabricNetworkTopology(tokenSDKDriver string) []api.Topology { alice := fscTopology.AddNodeByName("alice").AddOptions( fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), - token.WithOwnerIdentity(tokenSDKDriver, "alice.id1"), + token.WithOwnerIdentity("alice.id1"), ) alice.RegisterResponder(&views2.AcceptCashView{}, &views2.IssueCashView{}) alice.RegisterViewFactory("htlc.lock", &htlc.LockViewFactory{}) @@ -76,7 +76,7 @@ func HTLCSingleFabricNetworkTopology(tokenSDKDriver string) []api.Topology { bob := fscTopology.AddNodeByName("bob").AddOptions( fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), - token.WithOwnerIdentity(tokenSDKDriver, "bob.id1"), + token.WithOwnerIdentity("bob.id1"), ) bob.RegisterResponder(&views2.AcceptCashView{}, &views2.IssueCashView{}) bob.RegisterResponder(&htlc.LockAcceptView{}, &htlc.LockView{}) @@ -117,7 +117,7 @@ func HTLCSingleOrionNetworkTopology(tokenSDKDriver string) []api.Topology { fabric.WithAnonymousIdentity(), orion.WithRole("issuer"), token.WithIssuerIdentity("issuer.id1"), - token.WithOwnerIdentity(tokenSDKDriver, "issuer.owner"), + token.WithOwnerIdentity("issuer.owner"), ) issuer.RegisterViewFactory("issue", &views2.IssueCashViewFactory{}) issuer.RegisterViewFactory("history", &views.ListIssuedTokensViewFactory{}) @@ -143,7 +143,7 @@ func HTLCSingleOrionNetworkTopology(tokenSDKDriver string) []api.Topology { fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), orion.WithRole("alice"), - token.WithOwnerIdentity(tokenSDKDriver, "alice.id1"), + token.WithOwnerIdentity("alice.id1"), ) alice.RegisterResponder(&views2.AcceptCashView{}, &views2.IssueCashView{}) alice.RegisterViewFactory("htlc.lock", &htlc.LockViewFactory{}) @@ -160,7 +160,7 @@ func HTLCSingleOrionNetworkTopology(tokenSDKDriver string) []api.Topology { fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), orion.WithRole("bob"), - token.WithOwnerIdentity(tokenSDKDriver, "bob.id1"), + token.WithOwnerIdentity("bob.id1"), ) bob.RegisterResponder(&views2.AcceptCashView{}, &views2.IssueCashView{}) bob.RegisterResponder(&htlc.LockAcceptView{}, &htlc.LockView{}) @@ -212,7 +212,7 @@ func HTLCTwoFabricNetworksTopology(tokenSDKDriver string) []api.Topology { fabric.WithNetworkOrganization("beta", "Org3"), fabric.WithAnonymousIdentity(), token.WithIssuerIdentity("issuer.id1"), - token.WithOwnerIdentity(tokenSDKDriver, "issuer.owner"), + token.WithOwnerIdentity("issuer.owner"), ) issuer.RegisterViewFactory("issue", &views2.IssueCashViewFactory{}) issuer.RegisterViewFactory("history", &views.ListIssuedTokensViewFactory{}) @@ -238,7 +238,7 @@ func HTLCTwoFabricNetworksTopology(tokenSDKDriver string) []api.Topology { fabric.WithNetworkOrganization("alpha", "Org2"), fabric.WithNetworkOrganization("beta", "Org4"), fabric.WithAnonymousIdentity(), - token.WithOwnerIdentity(tokenSDKDriver, "alice.id1"), + token.WithOwnerIdentity("alice.id1"), ) alice.RegisterResponder(&views2.AcceptCashView{}, &views2.IssueCashView{}) alice.RegisterViewFactory("htlc.lock", &htlc.LockViewFactory{}) @@ -259,7 +259,7 @@ func HTLCTwoFabricNetworksTopology(tokenSDKDriver string) []api.Topology { fabric.WithNetworkOrganization("alpha", "Org2"), fabric.WithNetworkOrganization("beta", "Org4"), fabric.WithAnonymousIdentity(), - token.WithOwnerIdentity(tokenSDKDriver, "bob.id1"), + token.WithOwnerIdentity("bob.id1"), ) bob.RegisterResponder(&views2.AcceptCashView{}, &views2.IssueCashView{}) bob.RegisterResponder(&views2.AcceptCashView{}, &views2.IssueCashView{}) @@ -314,7 +314,7 @@ func HTLCNoCrossClaimTopology(tokenSDKDriver string) []api.Topology { fabric.WithNetworkOrganization("beta", "Org3"), fabric.WithAnonymousIdentity(), token.WithIssuerIdentity("issuer.id1"), - token.WithOwnerIdentity(tokenSDKDriver, "issuer.owner"), + token.WithOwnerIdentity("issuer.owner"), ) issuer.RegisterViewFactory("issue", &views2.IssueCashViewFactory{}) issuer.RegisterViewFactory("history", &views.ListIssuedTokensViewFactory{}) @@ -339,8 +339,8 @@ func HTLCNoCrossClaimTopology(tokenSDKDriver string) []api.Topology { alice := fscTopology.AddNodeByName("alice").AddOptions( fabric.WithNetworkOrganization("alpha", "Org2"), fabric.WithAnonymousIdentity(), - token.WithOwnerIdentity(tokenSDKDriver, "alice.id1"), - token.WithOwnerIdentity(tokenSDKDriver, "alice.id2"), + token.WithOwnerIdentity("alice.id1"), + token.WithOwnerIdentity("alice.id2"), ) alice.RegisterResponder(&views2.AcceptCashView{}, &views2.IssueCashView{}) alice.RegisterViewFactory("htlc.lock", &htlc.LockViewFactory{}) @@ -359,8 +359,8 @@ func HTLCNoCrossClaimTopology(tokenSDKDriver string) []api.Topology { bob := fscTopology.AddNodeByName("bob").AddOptions( fabric.WithNetworkOrganization("beta", "Org4"), fabric.WithAnonymousIdentity(), - token.WithOwnerIdentity(tokenSDKDriver, "bob.id1"), - token.WithOwnerIdentity(tokenSDKDriver, "bob.id2"), + token.WithOwnerIdentity("bob.id1"), + token.WithOwnerIdentity("bob.id2"), ) bob.RegisterResponder(&views2.AcceptCashView{}, &views2.IssueCashView{}) bob.RegisterViewFactory("htlc.lock", &htlc.LockViewFactory{}) @@ -415,7 +415,7 @@ func HTLCNoCrossClaimWithOrionTopology(tokenSDKDriver string) []api.Topology { fabric.WithAnonymousIdentity(), orion.WithRole("issuer"), token.WithIssuerIdentity("issuer.id1"), - token.WithOwnerIdentity(tokenSDKDriver, "issuer.owner"), + token.WithOwnerIdentity("issuer.owner"), ) issuer.RegisterViewFactory("issue", &views2.IssueCashViewFactory{}) issuer.RegisterViewFactory("history", &views.ListIssuedTokensViewFactory{}) @@ -441,8 +441,8 @@ func HTLCNoCrossClaimWithOrionTopology(tokenSDKDriver string) []api.Topology { alice := fscTopology.AddNodeByName("alice").AddOptions( fabric.WithNetworkOrganization("alpha", "Org2"), fabric.WithAnonymousIdentity(), - token.WithOwnerIdentity(tokenSDKDriver, "alice.id1"), - token.WithOwnerIdentity(tokenSDKDriver, "alice.id2"), + token.WithOwnerIdentity("alice.id1"), + token.WithOwnerIdentity("alice.id2"), ) alice.RegisterResponder(&views2.AcceptCashView{}, &views2.IssueCashView{}) alice.RegisterViewFactory("htlc.lock", &htlc.LockViewFactory{}) @@ -460,8 +460,8 @@ func HTLCNoCrossClaimWithOrionTopology(tokenSDKDriver string) []api.Topology { bob := fscTopology.AddNodeByName("bob").AddOptions( orion.WithRole("bob"), - token.WithOwnerIdentity(tokenSDKDriver, "bob.id1"), - token.WithOwnerIdentity(tokenSDKDriver, "bob.id2"), + token.WithOwnerIdentity("bob.id1"), + token.WithOwnerIdentity("bob.id2"), ) bob.RegisterResponder(&views2.AcceptCashView{}, &views2.IssueCashView{}) bob.RegisterViewFactory("htlc.lock", &htlc.LockViewFactory{}) diff --git a/integration/token/nft/topology.go b/integration/token/nft/topology.go index 92ba8c693..0bfbad85c 100644 --- a/integration/token/nft/topology.go +++ b/integration/token/nft/topology.go @@ -61,7 +61,7 @@ func Topology(backend, tokenSDKDriver string) []api.Topology { fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), orion.WithRole("alice"), - token.WithOwnerIdentity(tokenSDKDriver, "alice.id1"), + token.WithOwnerIdentity("alice.id1"), ) alice.RegisterResponder(&views.AcceptIssuedHouseView{}, &views.IssueHouseView{}) alice.RegisterResponder(&views.AcceptTransferHouseView{}, &views.TransferHouseView{}) @@ -72,8 +72,8 @@ func Topology(backend, tokenSDKDriver string) []api.Topology { fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), orion.WithRole("bob"), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "bob.id1"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("bob.id1"), ) bob.RegisterResponder(&views.AcceptIssuedHouseView{}, &views.IssueHouseView{}) bob.RegisterResponder(&views.AcceptTransferHouseView{}, &views.TransferHouseView{}) diff --git a/samples/fungible/topology/fabric.go b/samples/fungible/topology/fabric.go index fa0fbc49a..773983f1d 100644 --- a/samples/fungible/topology/fabric.go +++ b/samples/fungible/topology/fabric.go @@ -56,8 +56,8 @@ func Fabric(tokenSDKDriver string) []api.Topology { alice := fscTopology.AddNodeByName("alice").AddOptions( fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "alice.id1"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("alice.id1"), ) alice.RegisterResponder(&views2.AcceptCashView{}, &views2.IssueCashView{}) alice.RegisterResponder(&views2.AcceptCashView{}, &views2.TransferView{}) @@ -70,8 +70,8 @@ func Fabric(tokenSDKDriver string) []api.Topology { bob := fscTopology.AddNodeByName("bob").AddOptions( fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "bob.id1"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("bob.id1"), ) bob.RegisterResponder(&views2.AcceptCashView{}, &views2.IssueCashView{}) bob.RegisterResponder(&views2.AcceptCashView{}, &views2.TransferView{}) @@ -85,8 +85,8 @@ func Fabric(tokenSDKDriver string) []api.Topology { charlie := fscTopology.AddNodeByName("charlie").AddOptions( fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "charlie.id1"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("charlie.id1"), ) charlie.RegisterResponder(&views2.AcceptCashView{}, &views2.IssueCashView{}) charlie.RegisterResponder(&views2.AcceptCashView{}, &views2.TransferView{}) diff --git a/samples/fungible/topology/orion.go b/samples/fungible/topology/orion.go index 1f05eaaf2..8d646cf1b 100644 --- a/samples/fungible/topology/orion.go +++ b/samples/fungible/topology/orion.go @@ -45,8 +45,8 @@ func Orion(tokenSDKDriver string) []api.Topology { // alice alice := fscTopology.AddNodeByName("alice").AddOptions( orion.WithRole("alice"), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "alice.id1"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("alice.id1"), ) alice.RegisterResponder(&views2.AcceptCashView{}, &views2.IssueCashView{}) alice.RegisterResponder(&views2.AcceptCashView{}, &views2.TransferView{}) @@ -58,8 +58,8 @@ func Orion(tokenSDKDriver string) []api.Topology { // bob bob := fscTopology.AddNodeByName("bob").AddOptions( orion.WithRole("bob"), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "bob.id1"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("bob.id1"), ) bob.RegisterResponder(&views2.AcceptCashView{}, &views2.IssueCashView{}) bob.RegisterResponder(&views2.AcceptCashView{}, &views2.TransferView{}) @@ -72,8 +72,8 @@ func Orion(tokenSDKDriver string) []api.Topology { // charlie charlie := fscTopology.AddNodeByName("charlie").AddOptions( orion.WithRole("charlie"), - token.WithDefaultOwnerIdentity(tokenSDKDriver), - token.WithOwnerIdentity(tokenSDKDriver, "charlie.id1"), + token.WithDefaultOwnerIdentity(), + token.WithOwnerIdentity("charlie.id1"), ) charlie.RegisterResponder(&views2.AcceptCashView{}, &views2.IssueCashView{}) charlie.RegisterResponder(&views2.AcceptCashView{}, &views2.TransferView{}) diff --git a/samples/nft/topology/fabric.go b/samples/nft/topology/fabric.go index 0a973c2ee..f72aa758c 100644 --- a/samples/nft/topology/fabric.go +++ b/samples/nft/topology/fabric.go @@ -45,7 +45,7 @@ func Fabric(tokenSDKDriver string) []api.Topology { alice := fscTopology.AddNodeByName("alice").AddOptions( fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), - token.WithDefaultOwnerIdentity(tokenSDKDriver), + token.WithDefaultOwnerIdentity(), ) alice.RegisterResponder(&views.AcceptIssuedHouseView{}, &views.IssueHouseView{}) alice.RegisterResponder(&views.AcceptTransferHouseView{}, &views.TransferHouseView{}) @@ -55,7 +55,7 @@ func Fabric(tokenSDKDriver string) []api.Topology { bob := fscTopology.AddNodeByName("bob").AddOptions( fabric.WithOrganization("Org2"), fabric.WithAnonymousIdentity(), - token.WithDefaultOwnerIdentity(tokenSDKDriver), + token.WithDefaultOwnerIdentity(), ) bob.RegisterResponder(&views.AcceptIssuedHouseView{}, &views.IssueHouseView{}) bob.RegisterResponder(&views.AcceptTransferHouseView{}, &views.TransferHouseView{}) diff --git a/samples/nft/topology/orion.go b/samples/nft/topology/orion.go index 4007f3dc9..2a1116aa5 100644 --- a/samples/nft/topology/orion.go +++ b/samples/nft/topology/orion.go @@ -38,7 +38,7 @@ func Orion(tokenSDKDriver string) []api.Topology { alice := fscTopology.AddNodeByName("alice").AddOptions( orion.WithRole("alice"), - token.WithDefaultOwnerIdentity(tokenSDKDriver), + token.WithDefaultOwnerIdentity(), ) alice.RegisterResponder(&views.AcceptIssuedHouseView{}, &views.IssueHouseView{}) alice.RegisterResponder(&views.AcceptTransferHouseView{}, &views.TransferHouseView{}) @@ -47,7 +47,7 @@ func Orion(tokenSDKDriver string) []api.Topology { bob := fscTopology.AddNodeByName("bob").AddOptions( orion.WithRole("bob"), - token.WithDefaultOwnerIdentity(tokenSDKDriver), + token.WithDefaultOwnerIdentity(), ) bob.RegisterResponder(&views.AcceptIssuedHouseView{}, &views.IssueHouseView{}) bob.RegisterResponder(&views.AcceptTransferHouseView{}, &views.TransferHouseView{}) diff --git a/token/services/ttx/transaction.go b/token/services/ttx/transaction.go index 25c0ba853..25e994a95 100644 --- a/token/services/ttx/transaction.go +++ b/token/services/ttx/transaction.go @@ -270,6 +270,10 @@ func (t *Transaction) SetApplicationMetadata(k string, v []byte) { t.TokenRequest.SetApplicationMetadata(k, v) } +func (t *Transaction) TMSID() token.TMSID { + return t.TokenRequest.TokenService.ID() +} + func (t *Transaction) storeTransient() error { if logger.IsEnabledFor(zapcore.DebugLevel) { logger.Debugf("Storing transient for [%s]", t.ID())