From 15ef0d85c8114c6dfc9a09d619fe43ad808e1464 Mon Sep 17 00:00:00 2001 From: JukLee0ira Date: Mon, 9 Dec 2024 19:45:21 +0800 Subject: [PATCH] tmp --- XDCx/tradingstate/relayer_state.go | 6 +++--- XDCxlending/lendingstate/relayer.go | 6 +++--- accounts/abi/bind/backends/simulated.go | 2 +- common/big.go | 8 +++++++- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/XDCx/tradingstate/relayer_state.go b/XDCx/tradingstate/relayer_state.go index d5b79bf0c0c4d..c45f4857e4ce1 100644 --- a/XDCx/tradingstate/relayer_state.go +++ b/XDCx/tradingstate/relayer_state.go @@ -223,7 +223,7 @@ func CheckSubTokenBalance(addr common.Address, value *big.Int, token common.Addr if value := mapBalances[token][addr]; value != nil { balance = value } else { - balance = statedb.GetBalance(addr) + balance = statedb.GetBalance(addr).ToBig() } if balance.Cmp(value) < 0 { return nil, errors.Errorf("value %s in token %s not enough , have : %s , want : %s ", addr.String(), token.String(), balance, value) @@ -260,7 +260,7 @@ func CheckAddTokenBalance(addr common.Address, value *big.Int, token common.Addr if value := mapBalances[token][addr]; value != nil { balance = value } else { - balance = statedb.GetBalance(addr) + balance = statedb.GetBalance(addr).ToBig() } newBalance := new(big.Int).Add(balance, value) log.Debug("CheckAddTokenBalance settle balance: ADD XDC NATIVE BALANCE ", "token", token.String(), "address", addr.String(), "balance", balance, "value", value, "newBalance", newBalance) @@ -308,7 +308,7 @@ func CheckSubRelayerFee(relayer common.Address, fee *big.Int, statedb *state.Sta func GetTokenBalance(addr common.Address, token common.Address, statedb *state.StateDB) *big.Int { // XDC native if token == common.XDCNativeAddressBinary { - return statedb.GetBalance(addr) + return statedb.GetBalance(addr).ToBig() } // TRC tokens if statedb.Exist(token) { diff --git a/XDCxlending/lendingstate/relayer.go b/XDCxlending/lendingstate/relayer.go index e7ca282d1b175..0a89cc36ed448 100644 --- a/XDCxlending/lendingstate/relayer.go +++ b/XDCxlending/lendingstate/relayer.go @@ -176,7 +176,7 @@ func CheckSubTokenBalance(addr common.Address, value *big.Int, token common.Addr if value := mapBalances[token][addr]; value != nil { balance = value } else { - balance = statedb.GetBalance(addr) + balance = statedb.GetBalance(addr).ToBig() } if balance.Cmp(value) < 0 { return nil, errors.Errorf("value %s in token %s not enough , have : %s , want : %s ", addr.String(), common.XDCNativeAddress, balance, value) @@ -213,7 +213,7 @@ func CheckAddTokenBalance(addr common.Address, value *big.Int, token common.Addr if value := mapBalances[token][addr]; value != nil { balance = value } else { - balance = statedb.GetBalance(addr) + balance = statedb.GetBalance(addr).ToBig() } newBalance := new(big.Int).Add(balance, value) log.Debug("CheckAddTokenBalance settle balance: ADD XDC NATIVE BALANCE ", "token", common.XDCNativeAddress, "address", addr.String(), "balance", balance, "value", value, "newBalance", newBalance) @@ -261,7 +261,7 @@ func CheckSubRelayerFee(relayer common.Address, fee *big.Int, statedb *state.Sta func GetTokenBalance(addr common.Address, token common.Address, statedb *state.StateDB) *big.Int { // XDC native if token == common.XDCNativeAddressBinary { - return statedb.GetBalance(addr) + return statedb.GetBalance(addr).ToBig() } // TRC tokens if statedb.Exist(token) { diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index c4223e4873913..e0a9cae413c5a 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -215,7 +215,7 @@ func (b *SimulatedBackend) BalanceAt(ctx context.Context, contract common.Addres return nil, errBlockNumberUnsupported } statedb, _ := b.blockchain.State() - return statedb.GetBalance(contract), nil + return statedb.GetBalance(contract).ToBig(), nil } // NonceAt returns the nonce of a certain account in the blockchain. diff --git a/common/big.go b/common/big.go index 65d4377bf70c7..cbb562a28ef81 100644 --- a/common/big.go +++ b/common/big.go @@ -16,7 +16,11 @@ package common -import "math/big" +import ( + "math/big" + + "github.com/holiman/uint256" +) // Common big integers often used var ( @@ -27,4 +31,6 @@ var ( Big32 = big.NewInt(32) Big256 = big.NewInt(256) Big257 = big.NewInt(257) + + U2560 = uint256.NewInt(0) )