action.packMe(keypair)调用有个无关紧要的小错:输入参数是 {seckey, pubkey} 即可,不需要传入 address,因为 address 是 packMe 内部自己根据 pubkey 生成的。
This commit is contained in:
parent
044c2175d6
commit
3cf673af6f
17
Action.js
17
Action.js
@ -1,5 +1,5 @@
|
|||||||
var Ling = require('fon.ling')
|
var Ling = require('fon.ling')
|
||||||
var Ticrypto = require('tic.crypto')
|
var ticCrypto = require('tic.crypto')
|
||||||
|
|
||||||
/** ****************** Public of instance ********************/
|
/** ****************** Public of instance ********************/
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ MOM._model = {
|
|||||||
|
|
||||||
MOM.packMe = function (keypair) { // 由前端调用,后台不创建
|
MOM.packMe = function (keypair) { // 由前端调用,后台不创建
|
||||||
this.actorPubkey = keypair.pubkey
|
this.actorPubkey = keypair.pubkey
|
||||||
this.actorAddress = Ticrypto.pubkey2address(keypair.pubkey)
|
this.actorAddress = ticCrypto.pubkey2address(keypair.pubkey)
|
||||||
this.timestamp = new Date()
|
this.timestamp = new Date()
|
||||||
|
|
||||||
this.signMe(keypair.seckey)
|
this.signMe(keypair.seckey)
|
||||||
@ -45,12 +45,12 @@ MOM.packMe = function (keypair) { // 由前端调用,后台不创建
|
|||||||
|
|
||||||
MOM.signMe = function (seckey) { // 由前端调用,后台不该进行签名
|
MOM.signMe = function (seckey) { // 由前端调用,后台不该进行签名
|
||||||
let json = this.getJson({ exclude: ['hash', 'blockHash', 'actorSignature'] }) // 是前端用户发起事务时签字,这时候还不知道进入哪个区块,所以不能计入blockHash
|
let json = this.getJson({ exclude: ['hash', 'blockHash', 'actorSignature'] }) // 是前端用户发起事务时签字,这时候还不知道进入哪个区块,所以不能计入blockHash
|
||||||
this.actorSignature = Ticrypto.sign(json, seckey)
|
this.actorSignature = ticCrypto.sign(json, seckey)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
MOM.hashMe = function () {
|
MOM.hashMe = function () {
|
||||||
this.hash = Ticrypto.hash(this.getJson({ exclude: ['hash', 'blockHash'] })) // block.hash 受到所包含的actionList影响,所以action不能受blockHash影响,否则循环了
|
this.hash = ticCrypto.hash(this.getJson({ exclude: ['hash', 'blockHash'] })) // block.hash 受到所包含的actionList影响,所以action不能受blockHash影响,否则循环了
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,16 +67,16 @@ DAD.getJson = function (action, option = {}) {
|
|||||||
|
|
||||||
DAD.verifySig = function (action) {
|
DAD.verifySig = function (action) {
|
||||||
let json = DAD.getJson(action, { exclude: ['hash', 'blockHash', 'actorSignature'] })
|
let json = DAD.getJson(action, { exclude: ['hash', 'blockHash', 'actorSignature'] })
|
||||||
let res = Ticrypto.verify(json, action.actorSignature, action.actorPubkey)
|
let res = ticCrypto.verify(json, action.actorSignature, action.actorPubkey)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
DAD.verifyAddress = function (action) {
|
DAD.verifyAddress = function (action) {
|
||||||
return action.actorAddress === Ticrypto.pubkey2address(action.actorPubkey)
|
return action.actorAddress === ticCrypto.pubkey2address(action.actorPubkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
DAD.verifyHash = function (action) {
|
DAD.verifyHash = function (action) {
|
||||||
return action.hash === Ticrypto.hash(DAD.getJson(action, { exclude: ['hash', 'blockHash'] }))
|
return action.hash === ticCrypto.hash(DAD.getJson(action, { exclude: ['hash', 'blockHash'] }))
|
||||||
}
|
}
|
||||||
|
|
||||||
MOM.validateMe = async function() { // 子类应当覆盖本方法。
|
MOM.validateMe = async function() { // 子类应当覆盖本方法。
|
||||||
@ -100,6 +100,9 @@ DAD.execute = async function (action) {
|
|||||||
let typedAction = new wo[action.type](action)
|
let typedAction = new wo[action.type](action)
|
||||||
return await typedAction.executeMe()
|
return await typedAction.executeMe()
|
||||||
}
|
}
|
||||||
|
// [todo 20190411] 执行事务池中的所有事务
|
||||||
|
// DAD.executePool = async function() {
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取一批交易,在出块时调用。调用actionPool的内容被深拷贝到currentActionPool后自动清空。
|
* 获取一批交易,在出块时调用。调用actionPool的内容被深拷贝到currentActionPool后自动清空。
|
||||||
|
Loading…
Reference in New Issue
Block a user