我正在关注以下Corda教程:https://docs.corda.net/tutorial-test-dsl.html。
有人可以解释一下val inState = getPaper()
行吗?它没有出现在此页面之前。
答案 0 :(得分:0)
这只是一种返回新商业票据状态的测试方法。
目前,除了Hello,World!教程(https://docs.corda.net/hello-world-introduction.html和https://docs.corda.net/tut-two-party-introduction.html),教程不应该相互依赖,以创建一个完整的CorDapp。它们只是各种功能如何运作的例子。
查看此处定义的各种示例CorDapp可能也会有所帮助:https://www.corda.net/samples/。
答案 1 :(得分:0)
执行此操作的一种简单方法如下
private companion object {
val testIssuance = bigCorp.ref(111)
val testPounds: Cash.State = 1999.POUNDS.CASH issuedBy testIssuance
}
fun getPaper(): CommercialPaperState {
return CommercialPaperState(testIssuance, testIssuance.party, testPounds.amount , Instant.now()+10.days)
}
或者以下是另一种更复杂的处理方法,而无需使用随Corda 4一起提供的Finance CorDapp提供的现金。
import net.corda.finance.`issued by`
private companion object {
val bigCorp = TestIdentity((CordaX500Name("BigCorp", "New York", "GB")))
val testIssuance = bigCorp.ref((("JoinKey").toByte()))
val testAmount = Amount<Currency>(1000,Currency.getInstance(Locale.GERMANY))
}
fun getPaper(): CommercialPaperState {
return CommercialPaperState(testIssuance, testIssuance.party, testAmount `issued by` testIssuance, Instant.now()+10.days)
}
答案 2 :(得分:0)
我发现了
override fun getPaper(): ICommercialPaperState = JavaCommercialPaper.State(
megaCorp.ref(123),
megaCorp.party,
1000.DOLLARS `issued by` megaCorp.ref(123),
TEST_TX_TIME + 7.days
)
有用(来自CommercialPaperTests.kt)
我将其翻译为:
private OwnableState getPaper() {
PartyAndReference partyAndReference = new PartyAndReference((AbstractParty) this.megaCorp.getParty(), OpaqueBytes.of((byte) 0));
Amount<Issued<Currency>> issuedAmount = Amount.fromDecimal(new BigDecimal(1000), new Issued<Currency> (partyAndReference, Currency.getInstance(Locale.US)));
return (OwnableState) new CommercialPaper.State(this.megaCorp.ref((byte) 123), this.megaCorp.getParty(), issuedAmount, Instant.now().plus(7, ChronoUnit.DAYS));
}