forked from 33cn/plugin
/
type.go
110 lines (93 loc) · 3.43 KB
/
type.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// 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 types
import (
"encoding/json"
"reflect"
log "github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/types"
)
var (
// ParaX paracross exec name
ParaX = "paracross"
glog = log.New("module", ParaX)
)
func init() {
// init executor type
types.AllowUserExec = append(types.AllowUserExec, []byte(ParaX))
types.RegistorExecutor(ParaX, NewType())
types.RegisterDappFork(ParaX, "Enable", 0)
types.RegisterDappFork(ParaX, "ForkParacrossWithdrawFromParachain", 1298600)
}
// GetExecName get para exec name
func GetExecName() string {
return types.ExecName(ParaX)
}
// ParacrossType base paracross type
type ParacrossType struct {
types.ExecTypeBase
}
// NewType get paracross type
func NewType() *ParacrossType {
c := &ParacrossType{}
c.SetChild(c)
return c
}
// GetName 获取执行器名称
func (p *ParacrossType) GetName() string {
return ParaX
}
// GetLogMap get receipt log map
func (p *ParacrossType) GetLogMap() map[int64]*types.LogInfo {
return map[int64]*types.LogInfo{
TyLogParacrossCommit: {Ty: reflect.TypeOf(ReceiptParacrossCommit{}), Name: "LogParacrossCommit"},
TyLogParacrossCommitDone: {Ty: reflect.TypeOf(ReceiptParacrossDone{}), Name: "LogParacrossCommitDone"},
TyLogParacrossCommitRecord: {Ty: reflect.TypeOf(ReceiptParacrossRecord{}), Name: "LogParacrossCommitRecord"},
TyLogParaAssetWithdraw: {Ty: reflect.TypeOf(types.ReceiptAccountTransfer{}), Name: "LogParaAssetWithdraw"},
TyLogParaAssetTransfer: {Ty: reflect.TypeOf(types.ReceiptAccountTransfer{}), Name: "LogParaAssetTransfer"},
TyLogParaAssetDeposit: {Ty: reflect.TypeOf(types.ReceiptAccountTransfer{}), Name: "LogParaAssetDeposit"},
TyLogParacrossMiner: {Ty: reflect.TypeOf(ReceiptParacrossMiner{}), Name: "LogParacrossMiner"},
}
}
// GetTypeMap get action type
func (p *ParacrossType) GetTypeMap() map[string]int32 {
return map[string]int32{
"Commit": ParacrossActionCommit,
"Miner": ParacrossActionMiner,
"AssetTransfer": ParacrossActionAssetTransfer,
"AssetWithdraw": ParacrossActionAssetWithdraw,
"Transfer": ParacrossActionTransfer,
"Withdraw": ParacrossActionWithdraw,
"TransferToExec": ParacrossActionTransferToExec,
}
}
// GetPayload paracross get action payload
func (p *ParacrossType) GetPayload() types.Message {
return &ParacrossAction{}
}
// CreateTx paracross create tx by different action
func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types.Transaction, error) {
if action == "ParacrossCommit" {
var param paracrossCommitTx
err := json.Unmarshal(message, ¶m)
if err != nil {
glog.Error("CreateTx", "Error", err)
return nil, types.ErrInvalidParam
}
return createRawParacrossCommitTx(¶m)
} else if action == "ParacrossAssetTransfer" || action == "ParacrossAssetWithdraw" {
var param types.CreateTx
err := json.Unmarshal(message, ¶m)
if err != nil {
glog.Error("CreateTx", "Error", err)
return nil, types.ErrInvalidParam
}
return CreateRawAssetTransferTx(¶m)
} else if action == "ParacrossTransfer" || action == "Transfer" ||
action == "ParacrossWithdraw" || action == "Withdraw" ||
action == "ParacrossTransferToExec" || action == "TransferToExec" {
return p.CreateRawTransferTx(action, message)
}
return nil, types.ErrNotSupport
}