tic-traction/ling/ActTransfer.js

29 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const Action = require('./Action.js')
const DAD = module.exports = function ActTransfer (prop) {
this._class = 'ActTransfer'
this.setProp(prop) // 没有定义 ActTransfer.prototype._model因此继承了上级Action.prototype._model因此通过this.setProp继承了上级Action定义的实例自有数据。另一个方案是调用 Action.call(this, prop)
this.type = 'ActTransfer'
}
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_ActTransfer
}
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 = {}