/
types.go
executable file
·88 lines (74 loc) · 2.03 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
// 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"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/types"
)
func init() {
// init executor type
types.RegistorExecutor(RetrieveX, NewType())
types.RegisterDappFork(RetrieveX, "Enable", 0)
types.RegisterDappFork(RetrieveX, "ForkRetrive", 180000)
}
// RetrieveType def
type RetrieveType struct {
types.ExecTypeBase
}
// NewType for retrieve
func NewType() *RetrieveType {
c := &RetrieveType{}
c.SetChild(c)
return c
}
// GetRealToAddr 避免老的,没有To字段的交易分叉
func (r RetrieveType) GetRealToAddr(tx *types.Transaction) string {
if len(tx.To) == 0 {
return address.ExecAddress(string(tx.Execer))
}
return tx.To
}
// GetPayload method
func (r *RetrieveType) GetPayload() types.Message {
return &RetrieveAction{}
}
// GetName method
func (r *RetrieveType) GetName() string {
return RetrieveX
}
// GetLogMap method
func (r *RetrieveType) GetLogMap() map[int64]*types.LogInfo {
return nil
}
// GetTypeMap method
func (r *RetrieveType) GetTypeMap() map[string]int32 {
return actionName
}
// ActionName method
func (r RetrieveType) ActionName(tx *types.Transaction) string {
var action RetrieveAction
err := types.Decode(tx.Payload, &action)
if err != nil {
return "unknown-err"
}
if action.Ty == RetrieveActionPrepare && action.GetPrepare() != nil {
return "prepare"
} else if action.Ty == RetrieveActionPerform && action.GetPerform() != nil {
return "perform"
} else if action.Ty == RetrieveActionBackup && action.GetBackup() != nil {
return "backup"
} else if action.Ty == RetrieveActionCancel && action.GetCancel() != nil {
return "cancel"
}
return "unknown"
}
// Amount method
func (r RetrieveType) Amount(tx *types.Transaction) (int64, error) {
return 0, nil
}
// CreateTx method
func (r RetrieveType) CreateTx(action string, message json.RawMessage) (*types.Transaction, error) {
return nil, nil
}