u
This commit is contained in:
75
ActionTac.js
75
ActionTac.js
@@ -1,15 +1,30 @@
|
||||
const Action = require('./Action.js')
|
||||
const ticc = require('tic-crypto')
|
||||
|
||||
const Methods = ['create', 'transfer', 'exchange', 'mount']
|
||||
async function actValidator (action) {
|
||||
switch (action.data.method) {
|
||||
case 'create':
|
||||
if (action.data.name && action.data.symbol && action.data.decimals &&
|
||||
Number.isSafeInteger(Number(action.data.decimals)) &&
|
||||
!await wo.Tac.getOne({ Tac: { name: action.data.name, symbol: action.data.symbol } })
|
||||
) { return true }
|
||||
if (
|
||||
action.data.name &&
|
||||
action.data.symbol &&
|
||||
action.data.decimals &&
|
||||
Number.isSafeInteger(Number(action.data.decimals)) &&
|
||||
!(await wo.Tac.getOne({
|
||||
Tac: { name: action.data.name, symbol: action.data.symbol }
|
||||
}))
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
case 'transfer':
|
||||
return action.amount && action.amount > 0 && action.actorAddress && action.toAddress && action.actorAddress !== action.toAddress
|
||||
return (
|
||||
action.amount &&
|
||||
action.amount > 0 &&
|
||||
action.actorAddress &&
|
||||
action.toAddress &&
|
||||
action.actorAddress !== action.toAddress
|
||||
)
|
||||
case 'exchange':
|
||||
return true
|
||||
case 'mount':
|
||||
@@ -27,38 +42,52 @@ class ActionTac extends Action {
|
||||
enumerable: true,
|
||||
writable: false
|
||||
}),
|
||||
Object.defineProperty(this, 'type', {
|
||||
value: 'ActionTac',
|
||||
enumerable: true,
|
||||
writable: false
|
||||
}),
|
||||
Object.defineProperty(this, 'data', {
|
||||
value: prop,
|
||||
enumerable: true,
|
||||
writable: false
|
||||
})
|
||||
Object.defineProperty(this, 'type', {
|
||||
value: 'ActionTac',
|
||||
enumerable: true,
|
||||
writable: false
|
||||
}),
|
||||
Object.defineProperty(this, 'data', {
|
||||
value: prop,
|
||||
enumerable: true,
|
||||
writable: false
|
||||
})
|
||||
}
|
||||
static async validate (action) { // todo 20190409: MOM.validateMe
|
||||
return Methods.includes(action.data.method) && await actValidator(action)
|
||||
static async validate (action) {
|
||||
// todo 20190409: MOM.validateMe
|
||||
return Methods.includes(action.data.method) && (await actValidator(action))
|
||||
}
|
||||
|
||||
static async execute (action) { // todo 20190409: MOM.executeMe
|
||||
static async execute (action) {
|
||||
// todo 20190409: MOM.executeMe
|
||||
if (action && action.data.method) {
|
||||
switch (action.data.method) {
|
||||
case 'create':
|
||||
delete action._class
|
||||
let tac = new wo.Tac(
|
||||
Object.assign(action.data,
|
||||
Object.assign(
|
||||
action.data,
|
||||
action.actorAddress,
|
||||
action.actorPubkey,
|
||||
action.actorSignature
|
||||
))
|
||||
tac.address = wo.Crypto.pubkey2address(wo.Crypto.hash(action.actorSignature, action.hash))
|
||||
)
|
||||
)
|
||||
tac.address = ticc.pubkey_to_address({
|
||||
pubkey: ticc.hash(action.actorSignature, action.hash)
|
||||
})
|
||||
return await tac.addMe()
|
||||
case 'transfer':
|
||||
// 内部交易,转发到应用链进程来处理
|
||||
await wo.Store.decrease(action.actorAddress, 0 - action.amount, action.address)
|
||||
await wo.Store.increase(action.toAddress, action.amount, action.address)
|
||||
await wo.Store.decrease(
|
||||
action.actorAddress,
|
||||
0 - action.amount,
|
||||
action.address
|
||||
)
|
||||
await wo.Store.increase(
|
||||
action.toAddress,
|
||||
action.amount,
|
||||
action.address
|
||||
)
|
||||
return true
|
||||
case 'exchange':
|
||||
// Bancor类型
|
||||
|
||||
Reference in New Issue
Block a user