如何在Amount类中表示负数?

By simon at 2018-02-27 • 0人收藏 • 77人看过

负数不允许在Amount类中根据 文档: 当一个ContractState类有一个Amount字段可以变为负数(对于 例如一个balance可以多付)什么是最好的代表方式 负数?

3 个回复 | 最后更新于 2018-02-27
2018-02-27   #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块。

2018-02-27   #2

Corda中不能有负数,因为您无法支付负面费用 在账户中余额或持有负的余额。但是你可以发出一个义务(iou),你可以看看r3 Corda 在这里示例:https://github.com/roger3cev/obliga重刑,cordapp

2018-02-27   #3

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块。

登录后方可回帖

Loading...