tic-traction/ActionTransfer.js
luk.lu a289a4b2ad 1. 把 validateMe 分解成 静态数据检查(给客户端调用)validateMe 和 动态可执行性检查(给链节点调用)executableMe.
2. 在 Action.api.prepare() 里,生成可运行的对象 typedAction 存入 ActionPool,而不是仅仅存数据 option.Action进去。
3. 删除 Action.getJson(),把 DAD.verifyXxx(action) 都改为 MOM.verifyXxx().
4. 添加了 ActionRegisterChain.js 作为 应用链注册事务。
2019-04-13 13:37:38 +08:00

36 lines
1.4 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 ActionTransfer (prop) {
this._class = this.constructor.name
this.setProp(prop) // 没有定义 ActionTransfer.prototype._model因此继承了上级Action.prototype._model因此通过this.setProp继承了上级Action定义的实例自有数据。另一个方案是调用 Action.call(this, prop)
this.type = this.constructor.name
}
DAD.__proto__ = Action
const MOM = DAD.prototype
MOM.__proto__ = Action.prototype
MOM.validateMe = function () {
// if (sender && sender.type !== 'multisig' && action.toAddress != action.actorAddress && sender.balance >= action.amount + action.fee){
return this.actorAddress && this.toAddress && this.toAddress != this.actorAddress
&& this.amount && this.amount > 0 && (this.fee >= wo.Config.MIN_FEE_ActionTransfer || 0)
}
MOM.executableMe = async function() {
let balance = await wo.Store.getBalance(this.actorAddress)
return balance >= this.amount + this.fee
}
MOM.executeMe = async function () {
let balance = await wo.Store.getBalance(this.actorAddress)
if (balance >= this.amount + this.fee) {
await wo.Store.decrease(this.actorAddress, this.amount + this.fee)
await wo.Store.increase(this.toAddress, this.amount)
return this
}
return null
}
/** ****************** Public of class ********************/
DAD.api = {}