升级到目前最新的 node.server/modules/Action/*.js,其中重要的是,把 var Ling = wo&&wo.Ling?wo.Ling:require('fon.ling') 改成 var Ling = require('fon.ling')。原来的写法有 bug! 钱包前端引用了 tic.tool4chain 再引用了 tic.action,在浏览器里报错 "wo 不存在"。
This commit is contained in:
@@ -1,40 +1,28 @@
|
||||
const Action = require('./Action.js')
|
||||
const Ticrypto = wo&&wo.Crypto?wo.Crypto:require('tic.crypto')
|
||||
|
||||
/******************** Public of instance ********************/
|
||||
|
||||
const DAD=module.exports=function ActTransfer(prop) {
|
||||
this._class='ActTransfer'
|
||||
this.setProp(prop) // 没有定义 ActTransfer.prototype._model,因此继承了上级Action.prototype._model,因此通过this.setProp,继承了上级Action定义的实例自有数据。另一个方案是,调用 Action.call(this, prop)
|
||||
this.type='ActTransfer'
|
||||
}
|
||||
DAD.__proto__= Action
|
||||
// DAD._table=DAD.name // 注释掉,从而继承父类Action的数据库表格名
|
||||
const MOM=DAD.prototype
|
||||
MOM.__proto__=Action.prototype
|
||||
|
||||
/******************** Shared by instances ********************/
|
||||
|
||||
MOM.validate=function(){
|
||||
// return Ticrypto.isAddress(this.toAddress)
|
||||
return Ticrypto.isAddress(this.toAddress) && this.fee>=wo.Config.MIN_FEE_ActTransfer
|
||||
// && wo.Account.accountPool[this.actorAddress].balance>this.amount+this.fee //Todo:引入缓存账户
|
||||
&&this.toAddress != this.actorAddress
|
||||
}
|
||||
|
||||
MOM.execute=async function(){
|
||||
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
|
||||
}
|
||||
|
||||
/******************** Public of class ********************/
|
||||
|
||||
DAD.api={}
|
||||
const Action = require('./Action.js')
|
||||
|
||||
const DAD = module.exports = function ActTransfer (prop) {
|
||||
this._class = 'ActTransfer'
|
||||
this.setProp(prop) // 没有定义 ActTransfer.prototype._model,因此继承了上级Action.prototype._model,因此通过this.setProp,继承了上级Action定义的实例自有数据。另一个方案是,调用 Action.call(this, prop)
|
||||
this.type = 'ActTransfer'
|
||||
}
|
||||
DAD.__proto__ = Action
|
||||
const MOM = DAD.prototype
|
||||
MOM.__proto__ = Action.prototype
|
||||
|
||||
DAD.validate = async function (action) {
|
||||
// if (sender && sender.type !== 'multisig' && action.toAddress != action.actorAddress && sender.balance >= action.amount + action.fee){
|
||||
let sender = await wo.Store.getBalance(action.actorAddress)
|
||||
return action.actorAddress && action.toAddress && action.toAddress != action.actorAddress && action.amount && action.amount > 0 && sender >= action.amount + action.fee && action.fee >= wo.Config.MIN_FEE_ActTransfer
|
||||
}
|
||||
|
||||
DAD.execute = async function (action) {
|
||||
let sender = await wo.Store.getBalance(action.actorAddress)
|
||||
if (sender >= action.amount + action.fee) {
|
||||
await wo.Store.decrease(action.actorAddress, action.amount + action.fee)
|
||||
await wo.Store.increase(action.toAddress, action.amount)
|
||||
return true
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
DAD.api = {}
|
||||
|
||||
Reference in New Issue
Block a user