Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion XDCx/XDCx.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func (XDCx *XDCX) SyncDataToSDKNode(takerOrderInTx *tradingstate.OrderItem, txHa
tradeRecord := &tradingstate.Trade{}
quantity := tradingstate.ToBigInt(trade[tradingstate.TradeQuantity])
price := tradingstate.ToBigInt(trade[tradingstate.TradePrice])
if price.Cmp(big.NewInt(0)) <= 0 || quantity.Cmp(big.NewInt(0)) <= 0 {
if price.Sign() <= 0 || quantity.Sign() <= 0 {
return fmt.Errorf("trade misses important information. tradedPrice %v, tradedQuantity %v", price, quantity)
}
tradeRecord.Amount = quantity
Expand Down
4 changes: 2 additions & 2 deletions XDCx/tradingstate/orderitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (o *OrderItem) encodedSide() *big.Int {

// verifyPrice make sure price is a positive number
func (o *OrderItem) verifyPrice() error {
if o.Price == nil || o.Price.Cmp(big.NewInt(0)) <= 0 {
if o.Price == nil || o.Price.Sign() <= 0 {
log.Debug("Invalid price", "price", o.Price.String())
return ErrInvalidPrice
}
Expand All @@ -297,7 +297,7 @@ func (o *OrderItem) verifyPrice() error {

// verifyQuantity make sure quantity is a positive number
func (o *OrderItem) verifyQuantity() error {
if o.Quantity == nil || o.Quantity.Cmp(big.NewInt(0)) <= 0 {
if o.Quantity == nil || o.Quantity.Sign() <= 0 {
log.Debug("Invalid quantity", "quantity", o.Quantity.String())
return ErrInvalidQuantity
}
Expand Down
4 changes: 2 additions & 2 deletions XDCx/tradingstate/settle_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func GetSettleBalance(quotePrice *big.Int, takerSide string, takerFeeRate *big.I
log.Debug("quantity trade too small", "quoteTokenQuantity", quoteTokenQuantity, "makerFee", makerFee, "defaultFee", defaultFee)
return result, ErrQuantityTradeTooSmall
}
if quoteToken != common.XDCNativeAddressBinary && quotePrice != nil && quotePrice.Cmp(common.Big0) > 0 {
if quoteToken != common.XDCNativeAddressBinary && quotePrice != nil && quotePrice.Sign() > 0 {
// defaultFeeInXDC
defaultFeeInXDC := new(big.Int).Mul(defaultFee, quotePrice)
defaultFeeInXDC = new(big.Int).Div(defaultFeeInXDC, quoteTokenDecimal)
Expand Down Expand Up @@ -108,7 +108,7 @@ func GetSettleBalance(quotePrice *big.Int, takerSide string, takerFeeRate *big.I
log.Debug("quantity trade too small", "quoteTokenQuantity", quoteTokenQuantity, "takerFee", takerFee)
return result, ErrQuantityTradeTooSmall
}
if quoteToken != common.XDCNativeAddressBinary && quotePrice != nil && quotePrice.Cmp(common.Big0) > 0 {
if quoteToken != common.XDCNativeAddressBinary && quotePrice != nil && quotePrice.Sign() > 0 {
// defaultFeeInXDC
defaultFeeInXDC := new(big.Int).Mul(defaultFee, quotePrice)
defaultFeeInXDC = new(big.Int).Div(defaultFeeInXDC, quoteTokenDecimal)
Expand Down
6 changes: 3 additions & 3 deletions XDCxlending/lendingstate/settle_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func GetSettleBalance(isXDCXLendingFork bool,
log.Debug("quantity lending too small", "quantityToLend", quantityToLend, "takerFee", takerFee)
return result, ErrQuantityTradeTooSmall
}
if lendingToken != common.XDCNativeAddressBinary && lendTokenXDCPrice != nil && lendTokenXDCPrice.Cmp(common.Big0) > 0 {
if lendingToken != common.XDCNativeAddressBinary && lendTokenXDCPrice != nil && lendTokenXDCPrice.Sign() > 0 {
exTakerReceivedFee := new(big.Int).Mul(takerFee, lendTokenXDCPrice)
exTakerReceivedFee = new(big.Int).Div(exTakerReceivedFee, lendTokenDecimal)

Expand Down Expand Up @@ -122,7 +122,7 @@ func GetSettleBalance(isXDCXLendingFork bool,
log.Debug("quantity lending too small", "quantityToLend", quantityToLend, "makerFee", makerFee)
return result, ErrQuantityTradeTooSmall
}
if lendingToken != common.XDCNativeAddressBinary && lendTokenXDCPrice != nil && lendTokenXDCPrice.Cmp(common.Big0) > 0 {
if lendingToken != common.XDCNativeAddressBinary && lendTokenXDCPrice != nil && lendTokenXDCPrice.Sign() > 0 {
exMakerReceivedFee := new(big.Int).Mul(makerFee, lendTokenXDCPrice)
exMakerReceivedFee = new(big.Int).Div(exMakerReceivedFee, lendTokenDecimal)

Expand Down Expand Up @@ -172,7 +172,7 @@ func GetSettleBalance(isXDCXLendingFork bool,
log.Debug("quantity lending too small", "quantityToLend", quantityToLend, "borrowFee", borrowFee)
return result, ErrQuantityTradeTooSmall
}
if lendingToken != common.XDCNativeAddressBinary && lendTokenXDCPrice != nil && lendTokenXDCPrice.Cmp(common.Big0) > 0 {
if lendingToken != common.XDCNativeAddressBinary && lendTokenXDCPrice != nil && lendTokenXDCPrice.Sign() > 0 {
// exReceivedFee: the fee amount which borrowingRelayer will receive
exReceivedFee := new(big.Int).Mul(borrowFee, lendTokenXDCPrice)
exReceivedFee = new(big.Int).Div(exReceivedFee, lendTokenDecimal)
Expand Down
4 changes: 2 additions & 2 deletions contracts/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func TestStatedbUtils(t *testing.T) {
if cap.Cmp(cap_statedb) != 0 {
t.Fatalf("cap not equal, statedb utils is wrong")
}
if cap.Cmp(big.NewInt(0)) == 0 {
if cap.Sign() == 0 {
t.Fatalf("cap should not be zero")
}
owner, err := validator.GetCandidateOwner(it)
Expand Down Expand Up @@ -368,7 +368,7 @@ func TestStatedbUtils(t *testing.T) {
if cap.Cmp(cap_statedb) != 0 {
t.Fatalf("cap not equal, statedb utils is wrong")
}
if cap.Cmp(big.NewInt(0)) == 0 {
if cap.Sign() == 0 {
t.Fatalf("cap should not be zero")
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/txpool/order_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,11 @@ func (pool *OrderPool) validateOrder(tx *types.OrderTransaction) error {
cloneXDCXStateDb := pool.currentOrderState.Copy()

if !tx.IsCancelledOrder() {
if quantity == nil || quantity.Cmp(big.NewInt(0)) <= 0 {
if quantity == nil || quantity.Sign() <= 0 {
return ErrInvalidOrderQuantity
}
if orderType != OrderTypeMarket {
if price == nil || price.Cmp(big.NewInt(0)) <= 0 {
if price == nil || price.Sign() <= 0 {
return ErrInvalidOrderPrice
}
}
Expand Down
6 changes: 3 additions & 3 deletions core/vm/privacy/bulletproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ func (ipp *InnerProdArg) Serialize() []byte {
spa = serializePointArray(ipp.R, false)
proof = append(proof, spa[:]...)

if ipp.A.Cmp(big.NewInt(0)) < 0 {
if ipp.A.Sign() < 0 {
ipp.A.Mod(ipp.A, EC.N)
}
sp := PadTo32Bytes(ipp.A.Bytes())
Expand Down Expand Up @@ -833,7 +833,7 @@ func (mrp *MultiRangeProof) Serialize() []byte {
sp = PadTo32Bytes(mrp.Tau.Bytes())
proof = append(proof, sp[:]...)

if mrp.Th.Cmp(big.NewInt(0)) < 0 {
if mrp.Th.Sign() < 0 {
mrp.Th.Mod(mrp.Th, EC.N)
}
sp = PadTo32Bytes(mrp.Th.Bytes())
Expand Down Expand Up @@ -975,7 +975,7 @@ func MRPProve(values []*big.Int) (MultiRangeProof, error) {

for j := range values {
v := values[j]
if v.Cmp(big.NewInt(0)) == -1 {
if v.Sign() == -1 {
return MultiRangeProof{}, errors.New("value is below range! Not proving")
}

Expand Down