【问题标题】:How can i move token from node to account in Corda如何在 Corda 中将令牌从节点移动到帐户
【发布时间】:2020-05-21 02:53:03
【问题描述】:

我使用 Corda 令牌 sdk 和 Corda 帐户。 (Corda_version = 4.1,tokens_version = 1.0 和 accounts_version = 1.0-rc04)

我只是构建了简单的场景:
流_1。 PartyA-node创建账户“lisa”

start CreateAccount name: "lisa"

流_2。 PartA-node给自己发Token

Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);
MyEvolvableToken myEvolvableToken = new MyEvolvableToken(...);
TransactionState<MyEvolvableToken> transactionState = new TransactionState<>(myEvolvableToken, notary);
subFlow(new CreateEvolvableTokens(myEvolvableToken));
・
・
・
//issue token to self
FungibleToken fungibleToken = new FungibleToken(amount, partya,TransactionUtilitiesKt.getAttachmentIdForGenericParam(tokenPointer))
return subFlow(new IssueTokens(ImmutableList.of(fungibleToken)));

流_3。 PartA-node将Token移动到“lisa”

//Get Token from db
MyEvolvableToken token = stateAndRef.getState().getData();
TokenPointer tokenPointer = token.toPointer(token.getClass());
//Get Account from db
stateAndRefAccount = subFlow(new AccountInfoByName("lisa")).get(0);
AccountInfo lisaAccount = stateAndRefAccount.getState().getData();
//fresh account publicKey
PublicKey key = getServiceHub().getKeyManagementService().freshKey(lisaAccount.getIdentifier().getId()); 
AnonymousParty lisaParty = new AnonyMousParty(key);
//specify amount token to transfer
Amount<TokenPointer> amount = new Amount(10,tokenPointer);
PartyAndAmount partyAndAmount = new PartyAndAmount(lisaParty,amount);
return subFlow(new MoveFungibleTokens(partyAndAmount));

但是,当我启动 Flow_3 时出现错误。
AnonymousParty 不起作用 ??
如何将代币从节点转移到账户?

java.lang.IllegalArgumentException: Called flow with anonymous party that node doesn't know about.Make sure that RequestConfidentialIdentity flow is called before.
.
.
at com.r3.corda.lib.tokens.workflows.flows.rpc.MoveFungibleTokens.call(MoveTokens.kt:22)
・
・

【问题讨论】:

  • 很奇怪,我在流程中执行完全相同的步骤,它对我有用。我建议您添加断点并调试您的流程,确保您没有在其中一行获得空值。
  • 在旁注中,您使用new Amount(10, tokenPointer); 创建了一个金额,我不知道您的代币类型中有多少个小数点,但如果它是 100,那么您正在使用该代码创建 @987654326 @ 你的令牌不是10。我推荐使用AmountUtilitiesKt.amount(10, tokenPointer);这实际上将创建一个数量为10的令牌。
  • 这也是错字吗? new AnonyMousParty(key);(而不是AnonymousParty(key)?)
  • @AdelRustum 我将 Corda_version 4.1 更改为 4.3,然后它就可以工作了。

标签: token corda


【解决方案1】:

请参考我们关于账户+令牌集成的最新示例:https://github.com/corda/samples-java/tree/master/Accounts/worldcupticketbooking

要回答您关于如何从节点到账户发行令牌的问题,您可以直接向账户的匿名方发行令牌

例如:

//mention the current holder which is now going to be the dealer account 
NonFungibleToken nonFungibleToken = new NonFungibleToken(issuedTokenType, dealerAccount, new UniqueIdentifier(),TransactionUtilitiesKt.getAttachmentIdForGenericParam(tokenPointer)); 

//call built in flow to issue non fungible tokens 
SignedTransaction stx =  subFlow(new IssueTokens(Arrays.asList(nonFungibleToken)));

dealerAccount 是 AnonymousParty。

【讨论】:

    猜你喜欢
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    • 2020-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多