mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
remove lendingstate.EmptyAddress
This commit is contained in:
parent
fbb8c54d86
commit
f4154d0479
4 changed files with 18 additions and 18 deletions
|
|
@ -2,16 +2,15 @@ package lendingstate
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/XinFinOrg/XDPoSChain/crypto"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
"github.com/XinFinOrg/XDPoSChain/common"
|
||||
"github.com/XinFinOrg/XDPoSChain/crypto"
|
||||
)
|
||||
|
||||
var (
|
||||
EmptyAddress = "xdc0000000000000000000000000000000000000000"
|
||||
EmptyRoot = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
|
||||
EmptyRoot = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
|
||||
)
|
||||
|
||||
var EmptyHash = common.Hash{}
|
||||
|
|
|
|||
|
|
@ -2,14 +2,15 @@ package lendingstate
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/XinFinOrg/XDPoSChain/common"
|
||||
"github.com/XinFinOrg/XDPoSChain/core/state"
|
||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||
"github.com/XinFinOrg/XDPoSChain/crypto/sha3"
|
||||
"github.com/globalsign/mgo/bson"
|
||||
"math/big"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -243,7 +244,7 @@ func (l *LendingItem) VerifyLendingSide() error {
|
|||
}
|
||||
|
||||
func (l *LendingItem) VerifyCollateral(state *state.StateDB) error {
|
||||
if l.CollateralToken.String() == EmptyAddress || l.CollateralToken.String() == l.LendingToken.String() {
|
||||
if l.CollateralToken.IsZero() || l.CollateralToken == l.LendingToken {
|
||||
return fmt.Errorf("invalid collateral %s", l.CollateralToken.Hex())
|
||||
}
|
||||
validCollateral := false
|
||||
|
|
@ -329,7 +330,7 @@ func (l *LendingItem) EncodedSide() *big.Int {
|
|||
return big.NewInt(1)
|
||||
}
|
||||
|
||||
//verify signatures
|
||||
// verify signatures
|
||||
func (l *LendingItem) VerifyLendingSignature() error {
|
||||
V := big.NewInt(int64(l.Signature.V))
|
||||
R := l.Signature.R.Big()
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package XDCxlending
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/XinFinOrg/XDPoSChain/XDCx/tradingstate"
|
||||
"github.com/XinFinOrg/XDPoSChain/XDCxlending/lendingstate"
|
||||
"github.com/XinFinOrg/XDPoSChain/common"
|
||||
|
|
@ -10,7 +12,6 @@ import (
|
|||
"github.com/XinFinOrg/XDPoSChain/core/state"
|
||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||
"github.com/XinFinOrg/XDPoSChain/log"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
func (l *Lending) CommitOrder(header *types.Header, coinbase common.Address, chain consensus.ChainContext, statedb *state.StateDB, lendingStateDB *lendingstate.LendingStateDB, tradingStateDb *tradingstate.TradingStateDB, lendingOrderBook common.Hash, order *lendingstate.LendingItem) ([]*lendingstate.LendingTrade, []*lendingstate.LendingItem, error) {
|
||||
|
|
@ -262,10 +263,9 @@ func (l *Lending) processOrderList(header *types.Header, coinbase common.Address
|
|||
collateralToken = oldestOrder.CollateralToken
|
||||
borrowFee = lendingstate.GetFee(statedb, oldestOrder.Relayer)
|
||||
}
|
||||
if collateralToken.String() == lendingstate.EmptyAddress {
|
||||
if collateralToken.IsZero() {
|
||||
return nil, nil, nil, fmt.Errorf("empty collateral")
|
||||
}
|
||||
collateralPrice := common.BasePrice
|
||||
depositRate, liquidationRate, recallRate := lendingstate.GetCollateralDetail(statedb, collateralToken)
|
||||
if depositRate == nil || depositRate.Sign() <= 0 {
|
||||
return nil, nil, nil, fmt.Errorf("invalid depositRate %v", depositRate)
|
||||
|
|
@ -953,11 +953,11 @@ func (l *Lending) GetMediumTradePriceBeforeEpoch(chain consensus.ChainContext, s
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
//LendToken and CollateralToken must meet at least one of following conditions
|
||||
//- Have direct pair in XDCX: lendToken/CollateralToken or CollateralToken/LendToken
|
||||
//- Have pairs with XDC:
|
||||
//- lendToken/XDC and CollateralToken/XDC
|
||||
//- XDC/lendToken and XDC/CollateralToken
|
||||
// LendToken and CollateralToken must meet at least one of following conditions
|
||||
// - Have direct pair in XDCX: lendToken/CollateralToken or CollateralToken/LendToken
|
||||
// - Have pairs with XDC:
|
||||
// - lendToken/XDC and CollateralToken/XDC
|
||||
// - XDC/lendToken and XDC/CollateralToken
|
||||
func (l *Lending) GetCollateralPrices(header *types.Header, chain consensus.ChainContext, statedb *state.StateDB, tradingStateDb *tradingstate.TradingStateDB, collateralToken common.Address, lendingToken common.Address) (*big.Int, *big.Int, error) {
|
||||
// lendTokenXDCPrice: price of ticker lendToken/XDC
|
||||
// collateralXDCPrice: price of ticker collateralToken/XDC
|
||||
|
|
|
|||
|
|
@ -431,7 +431,7 @@ func (pool *LendingPool) validateNewLending(cloneStateDb *state.StateDB, cloneLe
|
|||
return ErrInvalidLendingType
|
||||
}
|
||||
if tx.Side() == lendingstate.Borrowing {
|
||||
if tx.CollateralToken().String() == lendingstate.EmptyAddress || tx.CollateralToken().String() == tx.LendingToken().String() {
|
||||
if tx.CollateralToken().IsZero() || tx.CollateralToken() == tx.LendingToken() {
|
||||
return ErrInvalidLendingCollateral
|
||||
}
|
||||
validCollateral := false
|
||||
|
|
@ -541,7 +541,7 @@ func (pool *LendingPool) validateBalance(cloneStateDb *state.StateDB, cloneLendi
|
|||
// collateralPrice = BTC/USD (eg: 8000 USD)
|
||||
// lendTokenXDCPrice: price of lendingToken in XDC quote
|
||||
var lendTokenXDCPrice, collateralPrice, collateralTokenDecimal *big.Int
|
||||
if collateralToken.String() != lendingstate.EmptyAddress {
|
||||
if !collateralToken.IsZero() {
|
||||
collateralTokenDecimal, err = XDCXServ.GetTokenDecimal(pool.chain, cloneStateDb, collateralToken)
|
||||
if err != nil {
|
||||
return fmt.Errorf("validateOrder: failed to get collateralTokenDecimal. err: %v", err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue