-
Notifications
You must be signed in to change notification settings - Fork 1
/
exec.go
85 lines (75 loc) · 2.86 KB
/
exec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package executor
import (
"github.com/assetcloud/chain/account"
"github.com/assetcloud/chain/types"
tokenty "github.com/assetcloud/plugin/plugin/dapp/token/types"
)
func (t *token) Exec_Transfer(payload *types.AssetsTransfer, tx *types.Transaction, index int) (*types.Receipt, error) {
token := payload.GetCointoken()
cfg := t.GetAPI().GetConfig()
db, err := account.NewAccountDB(cfg, t.GetName(), token, t.GetStateDB())
if err != nil {
return nil, err
}
tokenAction := tokenty.TokenAction{
Ty: tokenty.ActionTransfer,
Value: &tokenty.TokenAction_Transfer{
Transfer: payload,
},
}
return t.ExecTransWithdraw(db, tx, &tokenAction, index)
}
func (t *token) Exec_Withdraw(payload *types.AssetsWithdraw, tx *types.Transaction, index int) (*types.Receipt, error) {
token := payload.GetCointoken()
cfg := t.GetAPI().GetConfig()
db, err := account.NewAccountDB(cfg, t.GetName(), token, t.GetStateDB())
if err != nil {
return nil, err
}
tokenAction := tokenty.TokenAction{
Ty: tokenty.ActionWithdraw,
Value: &tokenty.TokenAction_Withdraw{
Withdraw: payload,
},
}
return t.ExecTransWithdraw(db, tx, &tokenAction, index)
}
func (t *token) Exec_TokenPreCreate(payload *tokenty.TokenPreCreate, tx *types.Transaction, index int) (*types.Receipt, error) {
action := newTokenAction(t, "", tx)
return action.preCreate(payload)
}
func (t *token) Exec_TokenFinishCreate(payload *tokenty.TokenFinishCreate, tx *types.Transaction, index int) (*types.Receipt, error) {
cfg := t.GetAPI().GetConfig()
action := newTokenAction(t, cfg.MGStr("mver.consensus.fundKeyAddr", t.GetHeight()), tx)
return action.finishCreate(payload)
}
func (t *token) Exec_TokenRevokeCreate(payload *tokenty.TokenRevokeCreate, tx *types.Transaction, index int) (*types.Receipt, error) {
action := newTokenAction(t, "", tx)
return action.revokeCreate(payload)
}
func (t *token) Exec_TransferToExec(payload *types.AssetsTransferToExec, tx *types.Transaction, index int) (*types.Receipt, error) {
token := payload.GetCointoken()
cfg := t.GetAPI().GetConfig()
db, err := account.NewAccountDB(cfg, t.GetName(), token, t.GetStateDB())
if err != nil {
return nil, err
}
tokenAction := tokenty.TokenAction{
Ty: tokenty.TokenActionTransferToExec,
Value: &tokenty.TokenAction_TransferToExec{
TransferToExec: payload,
},
}
return t.ExecTransWithdraw(db, tx, &tokenAction, index)
}
func (t *token) Exec_TokenMint(payload *tokenty.TokenMint, tx *types.Transaction, index int) (*types.Receipt, error) {
action := newTokenAction(t, "", tx)
return action.mint(payload)
}
func (t *token) Exec_TokenBurn(payload *tokenty.TokenBurn, tx *types.Transaction, index int) (*types.Receipt, error) {
action := newTokenAction(t, "", tx)
return action.burn(payload)
}