forked from rubblelabs/ripple
/
factory.go
126 lines (109 loc) · 4.26 KB
/
factory.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
package data
// Horrible look up tables
// Could all this be one big map?
type LedgerEntryType uint16
type TransactionType uint16
const (
ACCOUNT_ROOT LedgerEntryType = 0x61 // 'a'
DIRECTORY LedgerEntryType = 0x64 // 'd'
AMENDMENTS LedgerEntryType = 0x66 // 'f'
LEDGER_HASHES LedgerEntryType = 0x68 // 'h'
OFFER LedgerEntryType = 0x6f // 'o'
RIPPLE_STATE LedgerEntryType = 0x72 // 'r'
FEE_SETTINGS LedgerEntryType = 0x73 // 's'
PAYMENT TransactionType = 0
ACCOUNT_SET TransactionType = 3
SET_REGULAR_KEY TransactionType = 5
OFFER_CREATE TransactionType = 7
OFFER_CANCEL TransactionType = 8
TRUST_SET TransactionType = 20
AMENDMENT TransactionType = 100
SET_FEE TransactionType = 101
)
var LedgerFactory = [...]func() Hashable{
func() Hashable { return &Ledger{} },
}
var LedgerEntryFactory = [...]func() LedgerEntry{
ACCOUNT_ROOT: func() LedgerEntry { return &AccountRoot{leBase: leBase{LedgerEntryType: ACCOUNT_ROOT}} },
DIRECTORY: func() LedgerEntry { return &Directory{leBase: leBase{LedgerEntryType: DIRECTORY}} },
AMENDMENTS: func() LedgerEntry { return &Amendments{leBase: leBase{LedgerEntryType: AMENDMENTS}} },
LEDGER_HASHES: func() LedgerEntry { return &LedgerHashes{leBase: leBase{LedgerEntryType: LEDGER_HASHES}} },
OFFER: func() LedgerEntry { return &Offer{leBase: leBase{LedgerEntryType: OFFER}} },
RIPPLE_STATE: func() LedgerEntry { return &RippleState{leBase: leBase{LedgerEntryType: RIPPLE_STATE}} },
FEE_SETTINGS: func() LedgerEntry { return &FeeSettings{leBase: leBase{LedgerEntryType: FEE_SETTINGS}} },
}
var TxFactory = [...]func() Transaction{
PAYMENT: func() Transaction { return &Payment{TxBase: TxBase{TransactionType: PAYMENT}} },
ACCOUNT_SET: func() Transaction { return &AccountSet{TxBase: TxBase{TransactionType: ACCOUNT_SET}} },
SET_REGULAR_KEY: func() Transaction { return &SetRegularKey{TxBase: TxBase{TransactionType: SET_REGULAR_KEY}} },
OFFER_CREATE: func() Transaction { return &OfferCreate{TxBase: TxBase{TransactionType: OFFER_CREATE}} },
OFFER_CANCEL: func() Transaction { return &OfferCancel{TxBase: TxBase{TransactionType: OFFER_CANCEL}} },
TRUST_SET: func() Transaction { return &TrustSet{TxBase: TxBase{TransactionType: TRUST_SET}} },
AMENDMENT: func() Transaction { return &Amendment{TxBase: TxBase{TransactionType: AMENDMENT}} },
SET_FEE: func() Transaction { return &SetFee{TxBase: TxBase{TransactionType: SET_FEE}} },
}
var ledgerEntryNames = [...]string{
ACCOUNT_ROOT: "AccountRoot",
DIRECTORY: "DirectoryNode",
AMENDMENTS: "Amendments",
LEDGER_HASHES: "LedgerHashes",
OFFER: "Offer",
RIPPLE_STATE: "RippleState",
FEE_SETTINGS: "FeeSettings",
}
var ledgerEntryTypes = map[string]LedgerEntryType{
"AccountRoot": ACCOUNT_ROOT,
"DirectoryNode": DIRECTORY,
"Amendments": AMENDMENTS,
"LedgerHashes": LEDGER_HASHES,
"Offer": OFFER,
"RippleState": RIPPLE_STATE,
"FeeSettings": FEE_SETTINGS,
}
var txNames = [...]string{
PAYMENT: "Payment",
ACCOUNT_SET: "AccountSet",
SET_REGULAR_KEY: "SetRegularKey",
OFFER_CREATE: "OfferCreate",
OFFER_CANCEL: "OfferCancel",
TRUST_SET: "TrustSet",
AMENDMENT: "Amendment",
SET_FEE: "SetFee",
}
var txTypes = map[string]TransactionType{
"Payment": PAYMENT,
"AccountSet": ACCOUNT_SET,
"SetRegularKey": SET_REGULAR_KEY,
"OfferCreate": OFFER_CREATE,
"OfferCancel": OFFER_CANCEL,
"TrustSet": TRUST_SET,
"Amendment": AMENDMENT,
"SetFee": SET_FEE,
}
var HashableTypes []string
func init() {
HashableTypes = append(HashableTypes, NT_TRANSACTION_NODE.String())
for _, typ := range txNames {
if len(typ) > 0 {
HashableTypes = append(HashableTypes, typ)
}
}
HashableTypes = append(HashableTypes, NT_ACCOUNT_NODE.String())
for _, typ := range ledgerEntryNames {
if len(typ) > 0 {
HashableTypes = append(HashableTypes, typ)
}
}
}
func (t TransactionType) String() string {
return txNames[t]
}
func (le LedgerEntryType) String() string {
return ledgerEntryNames[le]
}
func GetTxFactoryByType(txType string) func() Transaction {
return TxFactory[txTypes[txType]]
}
func GetLedgerEntryFactoryByType(leType string) func() LedgerEntry {
return LedgerEntryFactory[ledgerEntryTypes[leType]]
}