首页 > 解决方案 > 为什么要使用 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://github.com/corda/corda-training-solutions/blob/master/kotlin-source/src/main/kotlin/net/corda/training/state/IOUState.kt

此外,任务是将其定义为磅,但我不知道该怎么做。

我在以下位置找到了英镑的参考:

https://docs.corda.net/api/kotlin/corda/net.corda.finance/kotlin.-int/index.html

我只是不明白我将如何定义该功能。

有人对我有任何指示或建议吗?这段代码编译并且测试通过了,但我想知道为什么......谢谢!

标签: unit-testingkotlincorda

解决方案


令牌只是表明这是一个数量。

所以在这里使用时:

val paid: Amount<Currency> = Amount(0, amount.token)

您将使用用于金额参数的任何代币,例如 POUNDS、DOLLARS 等,并将支付的金额设置为相同的代币类型。

看看它是如何在 Corda 中的 currency.kt 中完成的


推荐阅读