29 lines
1.3 KiB
JavaScript
29 lines
1.3 KiB
JavaScript
const Action = require('./Action.js')
|
||
|
||
const DAD = module.exports = function ActionTransfer (prop) {
|
||
this._class = 'ActionTransfer'
|
||
this.setProp(prop) // 没有定义 ActionTransfer.prototype._model,因此继承了上级Action.prototype._model,因此通过this.setProp,继承了上级Action定义的实例自有数据。另一个方案是,调用 Action.call(this, prop)
|
||
this.type = 'ActionTransfer'
|
||
}
|
||
DAD.__proto__ = Action
|
||
const MOM = DAD.prototype
|
||
MOM.__proto__ = Action.prototype
|
||
|
||
DAD.validate = async function (action) {
|
||
// if (sender && sender.type !== 'multisig' && action.toAddress != action.actorAddress && sender.balance >= action.amount + action.fee){
|
||
let sender = await wo.Store.getBalance(action.actorAddress)
|
||
return action.actorAddress && action.toAddress && action.toAddress != action.actorAddress && action.amount && action.amount > 0 && sender >= action.amount + action.fee && action.fee >= wo.Config.MIN_FEE_ActionTransfer
|
||
}
|
||
|
||
DAD.execute = async function (action) {
|
||
let sender = await wo.Store.getBalance(action.actorAddress)
|
||
if (sender >= action.amount + action.fee) {
|
||
await wo.Store.decrease(action.actorAddress, action.amount + action.fee)
|
||
await wo.Store.increase(action.toAddress, action.amount)
|
||
return true
|
||
}
|
||
return null
|
||
}
|
||
|
||
DAD.api = {}
|