2. 在 Action.api.prepare() 里,生成可运行的对象 typedAction 存入 ActionPool,而不是仅仅存数据 option.Action进去。 3. 删除 Action.getJson(),把 DAD.verifyXxx(action) 都改为 MOM.verifyXxx(). 4. 添加了 ActionRegisterChain.js 作为 应用链注册事务。
40 lines
1.5 KiB
JavaScript
40 lines
1.5 KiB
JavaScript
const Action = require('./Action.js')
|
||
|
||
/** ****************** Public of instance ********************/
|
||
|
||
const DAD = module.exports = function ActionStore (prop) {
|
||
this._class = this.constructor.name
|
||
this.setProp(prop) // 没有定义 DAD.prototype._model,因此继承了上级Action.prototype._model,因此通过this.setProp,继承了上级Action定义的实例自有数据。另一个方案是,调用 Action.call(this, prop)
|
||
this.type = this.constructor.name
|
||
}
|
||
DAD.__proto__ = Action
|
||
// DAD._table=DAD.name // 注释掉,从而继承父类Action的数据库表格名
|
||
const MOM = DAD.prototype
|
||
MOM.__proto__ = Action.prototype
|
||
|
||
/** ****************** Shared by instances ********************/
|
||
|
||
MOM.validateMe = function () {
|
||
// check size, account balance >= fee, fee>wo.Config.MIN_FEE_ActionStore
|
||
return (this.fee >= wo.Config.MIN_FEE_ActionStore || 0)
|
||
}
|
||
|
||
MOM.executableMe = async function (){
|
||
let balance = await wo.Store.getBalance(this.actorAddress)
|
||
return balance >= this.fee &&
|
||
true // todo: 检查服务器上的存储容量是否还够用?
|
||
}
|
||
|
||
MOM.executeMe = async function () {
|
||
let actor = await wo.Account.getOne({ Account: { address: this.actorAddress } })
|
||
if (actor && actor.balance >= this.fee) {
|
||
await actor.setMe({ Account: { balance: actor.balance - this.fee }, cond: { address: actor.address } }) // todo 20190409: change to use wo.Store
|
||
return this
|
||
}
|
||
return null
|
||
}
|
||
|
||
/** ****************** Public of class ********************/
|
||
|
||
DAD.api = {}
|