Amount class 中如何表示负数?
How can negative numbers be represented in the Amount class?
根据文档,Amount
class 中不允许使用负数:https://docs.corda.net/api/kotlin/corda/net.corda.core.contracts/-amount/
当 ContractState
class 有一个可以为负数的 Amount
字段(例如可以多付的余额)时,表示负数的最佳方式是什么?
您不能在 Corda 中拥有负数额,因为您不能支付负余额或将负余额存入帐户。
但是您可以发布义务 (iou),您可以在此处查看 r3 Corda 示例:https://github.com/roger3cev/obligation-cordapp
Amount
旨在不允许负数。以下 init
块阻止这样做:
init {
// Amount represents a static balance of physical assets as managed by the distributed ledger and is not allowed
// to become negative a rule further maintained by the Contract verify method.
// N.B. If concepts such as an account overdraft are required this should be modelled separately via Obligations,
// or similar second order smart contract concepts.
require(quantity >= 0) { "Negative amounts are not allowed: $quantity" }
}
AmountTransfer
可用于对负迁移建模。或者,您可以简单地制作排除此 init
块的 Amount
class 的副本。
根据文档,Amount
class 中不允许使用负数:https://docs.corda.net/api/kotlin/corda/net.corda.core.contracts/-amount/
当 ContractState
class 有一个可以为负数的 Amount
字段(例如可以多付的余额)时,表示负数的最佳方式是什么?
您不能在 Corda 中拥有负数额,因为您不能支付负余额或将负余额存入帐户。
但是您可以发布义务 (iou),您可以在此处查看 r3 Corda 示例:https://github.com/roger3cev/obligation-cordapp
Amount
旨在不允许负数。以下 init
块阻止这样做:
init {
// Amount represents a static balance of physical assets as managed by the distributed ledger and is not allowed
// to become negative a rule further maintained by the Contract verify method.
// N.B. If concepts such as an account overdraft are required this should be modelled separately via Obligations,
// or similar second order smart contract concepts.
require(quantity >= 0) { "Negative amounts are not allowed: $quantity" }
}
AmountTransfer
可用于对负迁移建模。或者,您可以简单地制作排除此 init
块的 Amount
class 的副本。