如何使用TokenSDK中的addIssueTokens Utility方法
How to use addIssueTokens Utility method in TokenSDK
我想使用 addIssueTokens 将令牌添加到 TransactionBuilder。
我的代码
@InitiatingFlow
@StartableByRPC
class Issue(val otherParty: Party) : FlowLogic<SignedTransaction>() {
override val progressTracker = ProgressTracker()
@Suspendable
override fun call() : SignedTransaction{
val jpyToken = createFungibleToken("JPY", 1000, otherParty)
val gbToken = createFungibleToken("GB", 1000, otherParty)
val notary = serviceHub.networkMapCache.notaryIdentities.single()
val txBuilder = TransactionBuilder(notary)
//may be add other output input
//....
//add token to txBuilder
addIssueTokens(txBuilder, listOf(jpyToken,gbToken))
txBuilder.verify(serviceHub)
// Sign the transaction
val ptx = serviceHub.signInitialTransaction(txBuilder, ourIdentity.owningKey)
// Instantiate a network session with the shareholder
val holderSession = initiateFlow(otherParty)
val sessions = listOf(holderSession)
// Ask the shareholder to sign the transaction
val stx = subFlow(CollectSignaturesFlow(ptx, listOf(holderSession)))
return subFlow<SignedTransaction>(FinalityFlow(stx, sessions))
}
fun createFungibleToken(symbol:String,amout:Long,target : AbstractParty) : FungibleToken{
val tokenType = TokenType(symbol, 0)
val issuedTokenType = IssuedTokenType(ourIdentity, tokenType)
val amount = Amount<IssuedTokenType>(amout, issuedTokenType)
return FungibleToken(amount, target)
}
}
@InitiatedBy(Issue::class)
class IssueResponder(val otherPartySession: FlowSession) : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
val signTransactionFlow = object : SignTransactionFlow(otherPartySession) {
override fun checkTransaction(stx: SignedTransaction) = requireThat {
}
}
val txId = subFlow(signTransactionFlow).id
return subFlow(ReceiveFinalityFlow(otherPartySession, expectedTxId = txId))
}
}
shell: 开始流程
>>start com.template.flows.Issue otherParty: "O=PartyB,L=New York,C=US"
Starting
Collecting signatures from counterparties.
Starting
Broadcasting transaction to participants
Done
Flow completed with result: SignedTransaction(id=547B812BA5574168DA8085C87AADFCAFA2A098CF62F375C21D450C0FE2402547)
好像Flow完成了。但是我查了partyB的数据库,vault_states table .
里面没有数据
为什么?
ps.i 知道如何使用 com.r3.corda.lib.tokens.workflows.flows.rpc.IssueTokens flow
在发行代币时,holder
不是必需的签名者;尝试从发起者和响应者流中删除 CollectSignaturesFlow
和 SignTransactionFlow
调用;只保留 FinalityFlow
和 ReceiveFinalityFlow
.
您可以看到here所需的签名者是:
- 发行
issuer
。
-
holder
就搬家了。
- 赎回
issuer
和holder
。
而且合同还说 here 可能还有其他签名者;所以我不能 100% 确定这就是问题的原因。
尝试删除签名流程并重新 运行 您的测试;让我知道它是否有效。
另一件事,检查启动节点的日志(日志位于节点文件夹结构内的 logs
文件夹内);有什么错误吗?
我想使用 addIssueTokens 将令牌添加到 TransactionBuilder。 我的代码
@InitiatingFlow
@StartableByRPC
class Issue(val otherParty: Party) : FlowLogic<SignedTransaction>() {
override val progressTracker = ProgressTracker()
@Suspendable
override fun call() : SignedTransaction{
val jpyToken = createFungibleToken("JPY", 1000, otherParty)
val gbToken = createFungibleToken("GB", 1000, otherParty)
val notary = serviceHub.networkMapCache.notaryIdentities.single()
val txBuilder = TransactionBuilder(notary)
//may be add other output input
//....
//add token to txBuilder
addIssueTokens(txBuilder, listOf(jpyToken,gbToken))
txBuilder.verify(serviceHub)
// Sign the transaction
val ptx = serviceHub.signInitialTransaction(txBuilder, ourIdentity.owningKey)
// Instantiate a network session with the shareholder
val holderSession = initiateFlow(otherParty)
val sessions = listOf(holderSession)
// Ask the shareholder to sign the transaction
val stx = subFlow(CollectSignaturesFlow(ptx, listOf(holderSession)))
return subFlow<SignedTransaction>(FinalityFlow(stx, sessions))
}
fun createFungibleToken(symbol:String,amout:Long,target : AbstractParty) : FungibleToken{
val tokenType = TokenType(symbol, 0)
val issuedTokenType = IssuedTokenType(ourIdentity, tokenType)
val amount = Amount<IssuedTokenType>(amout, issuedTokenType)
return FungibleToken(amount, target)
}
}
@InitiatedBy(Issue::class)
class IssueResponder(val otherPartySession: FlowSession) : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
val signTransactionFlow = object : SignTransactionFlow(otherPartySession) {
override fun checkTransaction(stx: SignedTransaction) = requireThat {
}
}
val txId = subFlow(signTransactionFlow).id
return subFlow(ReceiveFinalityFlow(otherPartySession, expectedTxId = txId))
}
}
shell: 开始流程
>>start com.template.flows.Issue otherParty: "O=PartyB,L=New York,C=US"
Starting
Collecting signatures from counterparties.
Starting
Broadcasting transaction to participants
Done
Flow completed with result: SignedTransaction(id=547B812BA5574168DA8085C87AADFCAFA2A098CF62F375C21D450C0FE2402547)
好像Flow完成了。但是我查了partyB的数据库,vault_states table .
里面没有数据为什么?
ps.i 知道如何使用 com.r3.corda.lib.tokens.workflows.flows.rpc.IssueTokens flow
在发行代币时,holder
不是必需的签名者;尝试从发起者和响应者流中删除 CollectSignaturesFlow
和 SignTransactionFlow
调用;只保留 FinalityFlow
和 ReceiveFinalityFlow
.
您可以看到here所需的签名者是:
- 发行
issuer
。 -
holder
就搬家了。 - 赎回
issuer
和holder
。
而且合同还说 here 可能还有其他签名者;所以我不能 100% 确定这就是问题的原因。
尝试删除签名流程并重新 运行 您的测试;让我知道它是否有效。
另一件事,检查启动节点的日志(日志位于节点文件夹结构内的 logs
文件夹内);有什么错误吗?