-
Notifications
You must be signed in to change notification settings - Fork 3
/
types.go
141 lines (111 loc) · 3.26 KB
/
types.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// 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 管理插件相关的定义
package types
import (
"reflect"
"github.com/assetcloud/chain/types"
)
// action类型id和name,这些常量可以自定义修改
const (
// TyCommitDelayTxAction commit delay transaction action id
TyCommitDelayTxAction = iota + 101
// UnknownActionName 存证类型交易
UnknownActionName = "notary"
// NameCommitDelayTxAction commit delay transaction action name
NameCommitDelayTxAction = "CommitDelayTx"
)
// log类型id值
const (
// TyCommitDelayTxLog commit delay transaction log id
TyCommitDelayTxLog = iota + 100
// NameCommitDelayTxLog commit delay transaction log name
NameCommitDelayTxLog = "CommitDelayTxLog"
)
// query func name
const (
// QueryGetDelayTxInfo query func name
QueryGetDelayTxInfo = "GetDelayTxInfo"
)
// fork
const (
// ForkUseTimeDelay use block time as delay type, instead of block height
ForkUseTimeDelay = "ForkUseTimeDelay"
)
var (
// NoneX driver name
NoneX = "none"
actionName = map[string]int32{
NameCommitDelayTxAction: TyCommitDelayTxAction,
}
logmap = map[int64]*types.LogInfo{
TyCommitDelayTxLog: {Ty: reflect.TypeOf(CommitDelayTxLog{}), Name: NameCommitDelayTxLog},
}
)
func init() {
types.AllowUserExec = append(types.AllowUserExec, []byte(NoneX))
types.RegFork(NoneX, InitFork)
types.RegExec(NoneX, InitExecutor)
}
// InitFork init
func InitFork(cfg *types.ChainConfig) {
cfg.RegisterDappFork(NoneX, ForkUseTimeDelay, 0)
}
// InitExecutor init Executor
func InitExecutor(cfg *types.ChainConfig) {
types.RegistorExecutor(NoneX, NewType(cfg))
}
// NoneType defines NoneType
type NoneType struct {
types.ExecTypeBase
}
// NewType new a NoneType object
func NewType(cfg *types.ChainConfig) *NoneType {
c := &NoneType{}
c.SetChild(c)
c.SetConfig(cfg)
return c
}
// GetPayload return manageaction
func (n *NoneType) GetPayload() types.Message {
return &NoneAction{}
}
// DecodePayloadValue decode payload value
func (n *NoneType) DecodePayloadValue(tx *types.Transaction) (string, reflect.Value, error) {
name, value, err := decodeNonePayload(tx)
return name, value, err
}
// ActionName return action a string name
func (n *NoneType) ActionName(tx *types.Transaction) string {
return ActionName(tx)
}
// ActionName return action a string name
func ActionName(tx *types.Transaction) string {
name, _, _ := decodeNonePayload(tx)
return name
}
// decodeNonePayload decode payload
func decodeNonePayload(tx *types.Transaction) (string, reflect.Value, error) {
action := &NoneAction{}
err := types.Decode(tx.Payload, action)
if err != nil {
return UnknownActionName, reflect.ValueOf(nil), types.ErrActionNotSupport
}
if action.Ty == TyCommitDelayTxAction {
return NameCommitDelayTxAction, reflect.ValueOf(action.GetCommitDelayTx()), nil
}
return UnknownActionName, reflect.ValueOf(nil), types.ErrActionNotSupport
}
// GetLogMap get log for map
func (n *NoneType) GetLogMap() map[int64]*types.LogInfo {
return logmap
}
// GetTypeMap return typename of actionname
func (n NoneType) GetTypeMap() map[string]int32 {
return actionName
}
// GetName reset name
func (n *NoneType) GetName() string {
return NoneX
}