unit-testing - 为什么要使用 amount.token 来初始化 Paid 变量?
问题描述
我正在学习 Corda R3 培训课程并且正在取得进展,但是当被要求创建一个初始化为 0 的付费变量时,答案是:
package net.corda.training.state
import net.corda.core.contracts.Amount
import net.corda.core.contracts.ContractState
import net.corda.core.identity.Party
import java.util.*
/**
* This is where you'll add the definition of your state object. Look at the unit tests in [IOUStateTests] for
* instructions on how to complete the [IOUState] class.
*
* Remove the "val data: String = "data" property before starting the [IOUState] tasks.
*/
data class IOUState(val amount: Amount<Currency>,
val lender: Party,
val borrower: Party,
val paid: Amount<Currency> = Amount(0, amount.token) ):
ContractState {
override val participants: List<Party> get() = listOf()
}
现在我明白我们需要将值转换为 Amount 类型,但是为什么要使用 amount.token 呢?我从以下解决方案:
此外,任务是将其定义为磅,但我不知道该怎么做。
我在以下位置找到了英镑的参考:
https://docs.corda.net/api/kotlin/corda/net.corda.finance/kotlin.-int/index.html
我只是不明白我将如何定义该功能。
有人对我有任何指示或建议吗?这段代码编译并且测试通过了,但我想知道为什么......谢谢!
解决方案
令牌只是表明这是一个数量。
所以在这里使用时:
val paid: Amount<Currency> = Amount(0, amount.token)
您将使用用于金额参数的任何代币,例如 POUNDS、DOLLARS 等,并将支付的金额设置为相同的代币类型。
看看它是如何在 Corda 中的 currency.kt 中完成的
推荐阅读
- wordpress - 仅为登录用户显示帖子 - Wordpress
- java - 如何打印说明用户输入索引太大的错误消息?
- c++ - 如何返回包含 for 循环的素因子算法的结果?
- python - 将值作为公式而不是数据读取的问题
- c# - 使用 WPF 应用程序中的 UWP MediaCapture
- docker - 两个 docker 容器之间的连接
- java - 在空对象引用上颤振 java.io.File android.app.Activity.getExternalFilesDir(java.lang.String)'
- java - 在 Maven 上运行时出现 java.lang.NoClassDefFoundError
- linux - Linux 上的所有 tmpfs 实例是否共享同一个内存池?
- c# - 根据条件键从 ConcurrentDictionary 中删除多个项目