根据文档https://docs.corda.net/api/kotlin/corda/net.corda.core.contracts/-amount/
,Amount
类不允许使用负数
如果ContractState
类的Amount
字段可以为负值(例如可以多付的余额),那么表示负数的最佳方式是什么?
答案 0 :(得分:2)
您在Corda中无法获得负数,因为您无法支付负余额或将负余额存入帐户。
但是你可以发布义务(iou),你可以在这里查看r3 Corda样本:https://github.com/roger3cev/obligation-cordapp
答案 1 :(得分:1)
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
可用于对负转移进行建模。或者,您只需复制排除此Amount
块的init
类。