如何获取特定节点参与者的"PartyAndCertificate"?
How to get "PartyAndCertificate" of a specific node participant?
在我的流程中,我想调用预定义的子流程
fun generateSpend(services: ServiceHub,
tx: TransactionBuilder,
amount: Amount<Currency>,
ourIdentity: PartyAndCertificate,
to: AbstractParty,
onlyFromParties: Set<AbstractParty> = emptySet()): Pair<TransactionBuilder, List<PublicKey>> {
return generateSpend(services, tx, listOf(PartyAndAmount(to, amount)), ourIdentity, onlyFromParties)
}
我的问题是如何在我的流程中获得特定节点参与者的 "PartyAndCertificate",其中 ourIdentity 需要?
有几种方法:
可以使用FlowLogic.ourIdentityAndCert
方法获取自己节点的PartyAndCertificate
您可以使用以下方法获取网络上所有节点的PartyAndCertificate
:
serviceHub.networkMapCache.allNodes.flatMap { it.legalIdentitiesAndCerts }
您可以使用以下方法获取网络上特定节点的 PartyAndCertificate
s:
serviceHub.networkMapCache.getNodeByLegalName(CordaX500Name("ANodeOrg", "", "GB"))
?.legalIdentitiesAndCerts
?: throw FlowException("Party not found on network.")
请注意,从 Corda 3.1 开始,网络上的每个节点只有一个合法身份(即 legalIdentitiesAndCerts
列表将只包含每个节点的一项)。
在我的流程中,我想调用预定义的子流程
fun generateSpend(services: ServiceHub,
tx: TransactionBuilder,
amount: Amount<Currency>,
ourIdentity: PartyAndCertificate,
to: AbstractParty,
onlyFromParties: Set<AbstractParty> = emptySet()): Pair<TransactionBuilder, List<PublicKey>> {
return generateSpend(services, tx, listOf(PartyAndAmount(to, amount)), ourIdentity, onlyFromParties)
}
我的问题是如何在我的流程中获得特定节点参与者的 "PartyAndCertificate",其中 ourIdentity 需要?
有几种方法:
可以使用
FlowLogic.ourIdentityAndCert
方法获取自己节点的PartyAndCertificate
您可以使用以下方法获取网络上所有节点的
PartyAndCertificate
:serviceHub.networkMapCache.allNodes.flatMap { it.legalIdentitiesAndCerts }
您可以使用以下方法获取网络上特定节点的
PartyAndCertificate
s:serviceHub.networkMapCache.getNodeByLegalName(CordaX500Name("ANodeOrg", "", "GB")) ?.legalIdentitiesAndCerts ?: throw FlowException("Party not found on network.")
请注意,从 Corda 3.1 开始,网络上的每个节点只有一个合法身份(即 legalIdentitiesAndCerts
列表将只包含每个节点的一项)。