@@ -24,7 +24,7 @@ func GetExRelayerFee(relayer common.Address, statedb *state.StateDB) *big.Int {
24
24
locBig := GetLocMappingAtKey (relayer .Hash (), slot )
25
25
locBig = new (big.Int ).Add (locBig , RelayerStructMappingSlot ["_fee" ])
26
26
locHash := common .BigToHash (locBig )
27
- return statedb .GetState (common .HexToAddress ( common . RelayerRegistrationSMC ) , locHash ).Big ()
27
+ return statedb .GetState (common .RelayerRegistrationSMC , locHash ).Big ()
28
28
}
29
29
30
30
func GetRelayerOwner (relayer common.Address , statedb * state.StateDB ) common.Address {
@@ -33,23 +33,23 @@ func GetRelayerOwner(relayer common.Address, statedb *state.StateDB) common.Addr
33
33
log .Debug ("GetRelayerOwner" , "relayer" , relayer .Hex (), "slot" , slot , "locBig" , locBig )
34
34
locBig = new (big.Int ).Add (locBig , RelayerStructMappingSlot ["_owner" ])
35
35
locHash := common .BigToHash (locBig )
36
- return common .BytesToAddress (statedb .GetState (common .HexToAddress ( common . RelayerRegistrationSMC ) , locHash ).Bytes ())
36
+ return common .BytesToAddress (statedb .GetState (common .RelayerRegistrationSMC , locHash ).Bytes ())
37
37
}
38
38
39
39
// return true if relayer request to resign and have not withdraw locked fund
40
40
func IsResignedRelayer (relayer common.Address , statedb * state.StateDB ) bool {
41
41
slot := RelayerMappingSlot ["RESIGN_REQUESTS" ]
42
42
locBig := GetLocMappingAtKey (relayer .Hash (), slot )
43
43
locHash := common .BigToHash (locBig )
44
- return statedb .GetState (common .HexToAddress ( common . RelayerRegistrationSMC ) , locHash ) != (common.Hash {})
44
+ return statedb .GetState (common .RelayerRegistrationSMC , locHash ) != (common.Hash {})
45
45
}
46
46
47
47
func GetBaseTokenLength (relayer common.Address , statedb * state.StateDB ) uint64 {
48
48
slot := RelayerMappingSlot ["RELAYER_LIST" ]
49
49
locBig := GetLocMappingAtKey (relayer .Hash (), slot )
50
50
locBig = new (big.Int ).Add (locBig , RelayerStructMappingSlot ["_fromTokens" ])
51
51
locHash := common .BigToHash (locBig )
52
- return statedb .GetState (common .HexToAddress ( common . RelayerRegistrationSMC ) , locHash ).Big ().Uint64 ()
52
+ return statedb .GetState (common .RelayerRegistrationSMC , locHash ).Big ().Uint64 ()
53
53
}
54
54
55
55
func GetBaseTokenAtIndex (relayer common.Address , statedb * state.StateDB , index uint64 ) common.Address {
@@ -58,15 +58,15 @@ func GetBaseTokenAtIndex(relayer common.Address, statedb *state.StateDB, index u
58
58
locBig = new (big.Int ).Add (locBig , RelayerStructMappingSlot ["_fromTokens" ])
59
59
locHash := common .BigToHash (locBig )
60
60
loc := state .GetLocDynamicArrAtElement (locHash , index , 1 )
61
- return common .BytesToAddress (statedb .GetState (common .HexToAddress ( common . RelayerRegistrationSMC ) , loc ).Bytes ())
61
+ return common .BytesToAddress (statedb .GetState (common .RelayerRegistrationSMC , loc ).Bytes ())
62
62
}
63
63
64
64
func GetQuoteTokenLength (relayer common.Address , statedb * state.StateDB ) uint64 {
65
65
slot := RelayerMappingSlot ["RELAYER_LIST" ]
66
66
locBig := GetLocMappingAtKey (relayer .Hash (), slot )
67
67
locBig = new (big.Int ).Add (locBig , RelayerStructMappingSlot ["_toTokens" ])
68
68
locHash := common .BigToHash (locBig )
69
- return statedb .GetState (common .HexToAddress ( common . RelayerRegistrationSMC ) , locHash ).Big ().Uint64 ()
69
+ return statedb .GetState (common .RelayerRegistrationSMC , locHash ).Big ().Uint64 ()
70
70
}
71
71
72
72
func GetQuoteTokenAtIndex (relayer common.Address , statedb * state.StateDB , index uint64 ) common.Address {
@@ -75,13 +75,13 @@ func GetQuoteTokenAtIndex(relayer common.Address, statedb *state.StateDB, index
75
75
locBig = new (big.Int ).Add (locBig , RelayerStructMappingSlot ["_toTokens" ])
76
76
locHash := common .BigToHash (locBig )
77
77
loc := state .GetLocDynamicArrAtElement (locHash , index , 1 )
78
- return common .BytesToAddress (statedb .GetState (common .HexToAddress ( common . RelayerRegistrationSMC ) , loc ).Bytes ())
78
+ return common .BytesToAddress (statedb .GetState (common .RelayerRegistrationSMC , loc ).Bytes ())
79
79
}
80
80
81
81
func GetRelayerCount (statedb * state.StateDB ) uint64 {
82
82
slot := RelayerMappingSlot ["RelayerCount" ]
83
83
slotHash := common .BigToHash (new (big.Int ).SetUint64 (slot ))
84
- valueHash := statedb .GetState (common .HexToAddress ( common . RelayerRegistrationSMC ) , slotHash )
84
+ valueHash := statedb .GetState (common .RelayerRegistrationSMC , slotHash )
85
85
return new (big.Int ).SetBytes (valueHash .Bytes ()).Uint64 ()
86
86
}
87
87
@@ -90,7 +90,7 @@ func GetAllCoinbases(statedb *state.StateDB) []common.Address {
90
90
slot := RelayerMappingSlot ["RELAYER_COINBASES" ]
91
91
coinbases := []common.Address {}
92
92
for i := uint64 (0 ); i < relayerCount ; i ++ {
93
- valueHash := statedb .GetState (common .HexToAddress ( common . RelayerRegistrationSMC ) , common .BytesToHash (state .GetLocMappingAtKey (common .BigToHash (big .NewInt (int64 (i ))), slot ).Bytes ()))
93
+ valueHash := statedb .GetState (common .RelayerRegistrationSMC , common .BytesToHash (state .GetLocMappingAtKey (common .BigToHash (big .NewInt (int64 (i ))), slot ).Bytes ()))
94
94
coinbases = append (coinbases , common .BytesToAddress (valueHash .Bytes ()))
95
95
}
96
96
return coinbases
@@ -102,21 +102,21 @@ func GetAllTradingPairs(statedb *state.StateDB) (map[common.Hash]bool, error) {
102
102
for _ , coinbase := range coinbases {
103
103
locBig := GetLocMappingAtKey (coinbase .Hash (), slot )
104
104
fromTokenSlot := new (big.Int ).Add (locBig , RelayerStructMappingSlot ["_fromTokens" ])
105
- fromTokenLength := statedb .GetState (common .HexToAddress ( common . RelayerRegistrationSMC ) , common .BigToHash (fromTokenSlot )).Big ().Uint64 ()
105
+ fromTokenLength := statedb .GetState (common .RelayerRegistrationSMC , common .BigToHash (fromTokenSlot )).Big ().Uint64 ()
106
106
toTokenSlot := new (big.Int ).Add (locBig , RelayerStructMappingSlot ["_toTokens" ])
107
- toTokenLength := statedb .GetState (common .HexToAddress ( common . RelayerRegistrationSMC ) , common .BigToHash (toTokenSlot )).Big ().Uint64 ()
107
+ toTokenLength := statedb .GetState (common .RelayerRegistrationSMC , common .BigToHash (toTokenSlot )).Big ().Uint64 ()
108
108
if toTokenLength != fromTokenLength {
109
109
return map [common.Hash ]bool {}, fmt .Errorf ("invalid length from token & to token: from :%d , to :%d " , fromTokenLength , toTokenLength )
110
110
}
111
111
fromTokens := []common.Address {}
112
112
fromTokenSlotHash := common .BytesToHash (fromTokenSlot .Bytes ())
113
113
for i := uint64 (0 ); i < fromTokenLength ; i ++ {
114
- fromToken := common .BytesToAddress (statedb .GetState (common .HexToAddress ( common . RelayerRegistrationSMC ) , state .GetLocDynamicArrAtElement (fromTokenSlotHash , i , uint64 (1 ))).Bytes ())
114
+ fromToken := common .BytesToAddress (statedb .GetState (common .RelayerRegistrationSMC , state .GetLocDynamicArrAtElement (fromTokenSlotHash , i , uint64 (1 ))).Bytes ())
115
115
fromTokens = append (fromTokens , fromToken )
116
116
}
117
117
toTokenSlotHash := common .BytesToHash (toTokenSlot .Bytes ())
118
118
for i := uint64 (0 ); i < toTokenLength ; i ++ {
119
- toToken := common .BytesToAddress (statedb .GetState (common .HexToAddress ( common . RelayerRegistrationSMC ) , state .GetLocDynamicArrAtElement (toTokenSlotHash , i , uint64 (1 ))).Bytes ())
119
+ toToken := common .BytesToAddress (statedb .GetState (common .RelayerRegistrationSMC , state .GetLocDynamicArrAtElement (toTokenSlotHash , i , uint64 (1 ))).Bytes ())
120
120
121
121
log .Debug ("GetAllTradingPairs all pair info" , "from" , fromTokens [i ].Hex (), "toToken" , toToken .Hex ())
122
122
allPairs [GetTradingOrderBookHash (fromTokens [i ], toToken )] = true
@@ -132,14 +132,14 @@ func SubRelayerFee(relayer common.Address, fee *big.Int, statedb *state.StateDB)
132
132
133
133
locBigDeposit := new (big.Int ).SetUint64 (uint64 (0 )).Add (locBig , RelayerStructMappingSlot ["_deposit" ])
134
134
locHashDeposit := common .BigToHash (locBigDeposit )
135
- balance := statedb .GetState (common .HexToAddress ( common . RelayerRegistrationSMC ) , locHashDeposit ).Big ()
135
+ balance := statedb .GetState (common .RelayerRegistrationSMC , locHashDeposit ).Big ()
136
136
log .Debug ("ApplyXDCXMatchedTransaction settle balance: SubRelayerFee BEFORE" , "relayer" , relayer .String (), "balance" , balance )
137
137
if balance .Cmp (fee ) < 0 {
138
138
return errors .Errorf ("relayer %s isn't enough XDC fee" , relayer .String ())
139
139
} else {
140
140
balance = new (big.Int ).Sub (balance , fee )
141
- statedb .SetState (common .HexToAddress ( common . RelayerRegistrationSMC ) , locHashDeposit , common .BigToHash (balance ))
142
- statedb .SubBalance (common .HexToAddress ( common . RelayerRegistrationSMC ) , fee )
141
+ statedb .SetState (common .RelayerRegistrationSMC , locHashDeposit , common .BigToHash (balance ))
142
+ statedb .SubBalance (common .RelayerRegistrationSMC , fee )
143
143
log .Debug ("ApplyXDCXMatchedTransaction settle balance: SubRelayerFee AFTER" , "relayer" , relayer .String (), "balance" , balance )
144
144
return nil
145
145
}
@@ -151,7 +151,7 @@ func CheckRelayerFee(relayer common.Address, fee *big.Int, statedb *state.StateD
151
151
152
152
locBigDeposit := new (big.Int ).SetUint64 (uint64 (0 )).Add (locBig , RelayerStructMappingSlot ["_deposit" ])
153
153
locHashDeposit := common .BigToHash (locBigDeposit )
154
- balance := statedb .GetState (common .HexToAddress ( common . RelayerRegistrationSMC ) , locHashDeposit ).Big ()
154
+ balance := statedb .GetState (common .RelayerRegistrationSMC , locHashDeposit ).Big ()
155
155
if new (big.Int ).Sub (balance , fee ).Cmp (new (big.Int ).Mul (common .BasePrice , common .RelayerLockedFund )) < 0 {
156
156
return errors .Errorf ("relayer %s isn't enough XDC fee : balance %d , fee : %d " , relayer .Hex (), balance .Uint64 (), fee .Uint64 ())
157
157
}
@@ -295,7 +295,7 @@ func CheckSubRelayerFee(relayer common.Address, fee *big.Int, statedb *state.Sta
295
295
locBig := GetLocMappingAtKey (relayer .Hash (), slot )
296
296
locBigDeposit := new (big.Int ).SetUint64 (uint64 (0 )).Add (locBig , RelayerStructMappingSlot ["_deposit" ])
297
297
locHashDeposit := common .BigToHash (locBigDeposit )
298
- balance = statedb .GetState (common .HexToAddress ( common . RelayerRegistrationSMC ) , locHashDeposit ).Big ()
298
+ balance = statedb .GetState (common .RelayerRegistrationSMC , locHashDeposit ).Big ()
299
299
}
300
300
log .Debug ("CheckSubRelayerFee settle balance: SubRelayerFee " , "relayer" , relayer .String (), "balance" , balance , "fee" , fee )
301
301
if balance .Cmp (fee ) < 0 {
@@ -343,6 +343,6 @@ func SetSubRelayerFee(relayer common.Address, balance *big.Int, fee *big.Int, st
343
343
locBig := GetLocMappingAtKey (relayer .Hash (), slot )
344
344
locBigDeposit := new (big.Int ).SetUint64 (uint64 (0 )).Add (locBig , RelayerStructMappingSlot ["_deposit" ])
345
345
locHashDeposit := common .BigToHash (locBigDeposit )
346
- statedb .SetState (common .HexToAddress ( common . RelayerRegistrationSMC ) , locHashDeposit , common .BigToHash (balance ))
347
- statedb .SubBalance (common .HexToAddress ( common . RelayerRegistrationSMC ) , fee )
346
+ statedb .SetState (common .RelayerRegistrationSMC , locHashDeposit , common .BigToHash (balance ))
347
+ statedb .SubBalance (common .RelayerRegistrationSMC , fee )
348
348
}
0 commit comments