diff --git a/Action.js b/Action.js index 1f5063c..375a8d3 100644 --- a/Action.js +++ b/Action.js @@ -170,6 +170,13 @@ DAD.api.getActionList = async function (option) { return await DAD.getAll(option) } +DAD.api.getMyActionList = async function ({myAddress, config}={}) { + let list = {} + list.fromMe = await DAD.getAll({Action:{actorAddress:myAddress}, config:config}) + list.toMe = await DAD.getAll({Action:{toAddress: myAddress}, config:config}) + return list +} + DAD.api.prepare = async function (option) { if (typeof option === 'string') { try { diff --git a/ActionTransfer.js b/ActionTransfer.js index c03f4b3..090ea1d 100644 --- a/ActionTransfer.js +++ b/ActionTransfer.js @@ -18,17 +18,20 @@ MOM.validateMe = function () { } MOM.executableMe = async function() { - let balance = await wo.Store.getBalance(this.actorAddress) + let balance = await wo.Account.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) + let sender= await wo.Account.getOne({Account: { address: this.actorAddress }}) + if (sender && sender.type !== 'multisig' && this.toAddress != this.actorAddress && sender.balance >= this.amount + this.fee){ + await sender.setMe({Account:{ balance: sender.balance-this.amount-this.fee }, cond:{ address:sender.address}}) + let getter= await wo.Account.getOne({Account: { address: this.toAddress }}) || await wo.Account.addOne({Account: { address: this.toAddress }}) + await getter.setMe({Account:{ balance: getter.balance+this.amount }, cond:{ address:getter.address}}) + mylog.info('Excecuted action='+JSON.stringify(this)) return this } + // mylog.info('balance('+sender.address+')='+sender.balance+' is less than '+this.amount+', 无法转账') return null }