From 9099da4ab93191b5dd8fb1f0ea86770ddb057ddb Mon Sep 17 00:00:00 2001 From: Luk Lu Date: Fri, 28 Feb 2020 12:24:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=B8=AAcommit=E4=B8=8D=E5=A4=9F?= =?UTF-8?q?=E5=AF=B9=EF=BC=8CactorAddress=20=E6=98=AF=E5=9C=A8=20packMe=20?= =?UTF-8?q?=E4=B8=AD=E8=A2=AB=E8=B5=8B=E5=80=BC=E7=9A=84=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E6=8F=90=E5=89=8D=E6=A3=80=E6=B5=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Action.js | 6 +++--- ActionTransfer.js | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Action.js b/Action.js index f78ff69..9abdb08 100644 --- a/Action.js +++ b/Action.js @@ -82,7 +82,7 @@ DAD.verifyHash = function (actionData) { return typedAction.verifyHash() } -MOM.validateMe = function() { // Applicable on chain server. 子类应当覆盖本方法,静态的检查事务内容的格式和语义,是否符合该子类事务的特性要求。To validate an action's content format. +MOM.validateMe = function() { // Applicable on both client and chain server. 子类应当覆盖本方法,静态的检查事务内容的格式。不能检查 balance 等需要全链数据库的东西,因为本方法也要用在前端检查。 // to implement in subclasses: 检查子类事务内容的格式 let typedAction = new wo[this.type](this) return typedAction.validateMe() @@ -124,11 +124,11 @@ DAD._initTypeDict = function(typedActionDict) { } DAD.build = async function (action, keypair) { // Applicable on client. 客户端调用 Action.build,即可新建、并打包成一个完整的子事务,不需要亲自调用 constructor, packMe 等方法。 - if (action && action.type && keypair && keypair.seckey && keypair.pubkey) { + if (action && action.type && keypair && keypair.seckey && keypair.pubkey && ticCrypto.seckey2pubkey(keypair.seckey)===keypair.pubkey) { let typedAction = new wo[action.type](action) typedAction.actorPubkey = keypair.pubkey if (typedAction.validateMe()) { - await typedAction.packMe(keypair) + await typedAction.packMe(keypair) // 在 packMe 里,会把 actorPubkey 转存为 actorAddress。 return typedAction } } diff --git a/ActionTransfer.js b/ActionTransfer.js index 1b32121..c03f4b3 100644 --- a/ActionTransfer.js +++ b/ActionTransfer.js @@ -13,10 +13,8 @@ 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.actorPubkey && ticCrypto.pubkey2address(this.actorPubkey)=== this.actorAddress // 必须检查发起人地址和公钥是匹配的,否则客户端能够造假 - && this.toAddress && this.toAddress != this.actorAddress - && this.amount && this.amount > 0 && (this.fee >= 0) - + return this.actorPubkey && this.toAddress && ticCrypto.pubkey2address(this.actorPubkey)!== this.toAddress // 不能转帐给自己。 + && this.amount && this.amount > 0 && (this.fee >= 0) } MOM.executableMe = async function() {