From fa9980b45a0c38625bdea9f50fec34aaa30f036a Mon Sep 17 00:00:00 2001 From: Luk Lu Date: Sat, 29 Feb 2020 15:09:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=8A=20executeMe=20=E9=87=8C=E5=AF=B9=20wo?= =?UTF-8?q?.Store=20=E7=9A=84=E5=BC=95=E7=94=A8=E9=83=BD=E6=94=B9=E5=9B=9E?= =?UTF-8?q?=E4=BB=8E=E5=89=8D=E7=9A=84=20wo.Account?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Action.js | 7 +++++++ ActionTransfer.js | 13 ++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) 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 }