我正在遵循以下Corda教程:https://docs.corda.net/tutorial-test-dsl.html。
请问有人能解释一下
请问有人能解释一下
val inState = getPaper()
这行代码吗?在这个页面之前没有出现过。val inState = getPaper()
这行代码吗?在这个页面之前没有出现过。这只是一个测试方法,用于返回新的商业票据状态。
目前,在Hello, World!教程(https://docs.corda.net/hello-world-introduction.html和https://docs.corda.net/tut-two-party-introduction.html)之外,其他教程不应该按照顺序跟进,以创建完整的CorDapp。它们只是展示各种功能的示例。
此外,查看这里定义的各种样本CorDapps也可能会有所帮助:https://www.corda.net/samples/。
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));
}
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)
}