all: fix staticcheck warning SA4006: never used value

This commit is contained in:
Daniel Liu 2024-10-24 17:32:56 +08:00
parent e52b8a2de2
commit c6e4e880ea
16 changed files with 46 additions and 78 deletions

View file

@ -656,9 +656,10 @@ func (XDCx *XDCX) ProcessCancelOrder(header *types.Header, tradingStateDB *tradi
}
log.Debug("ProcessCancelOrder", "baseToken", originOrder.BaseToken, "quoteToken", originOrder.QuoteToken)
feeRate := tradingstate.GetExRelayerFee(originOrder.ExchangeAddress, statedb)
tokenCancelFee, tokenPriceInXDC := common.Big0, common.Big0
var tokenCancelFee, tokenPriceInXDC *big.Int
if !chain.Config().IsTIPXDCXCancellationFee(header.Number) {
tokenCancelFee = getCancelFeeV1(baseTokenDecimal, feeRate, &originOrder)
tokenPriceInXDC = common.Big0
} else {
tokenCancelFee, tokenPriceInXDC = XDCx.getCancelFee(chain, statedb, tradingStateDB, &originOrder, feeRate)
}
@ -721,7 +722,7 @@ func (XDCx *XDCX) ProcessCancelOrder(header *types.Header, tradingStateDB *tradi
// cancellation fee = 1/10 trading fee
// deprecated after hardfork at TIPXDCXCancellationFee
func getCancelFeeV1(baseTokenDecimal *big.Int, feeRate *big.Int, order *tradingstate.OrderItem) *big.Int {
cancelFee := big.NewInt(0)
var cancelFee *big.Int
if order.Side == tradingstate.Ask {
// SELL 1 BTC => XDC ,,
// order.Quantity =1 && fee rate =2
@ -748,8 +749,7 @@ func (XDCx *XDCX) getCancelFee(chain consensus.ChainContext, statedb *state.Stat
if feeRate == nil || feeRate.Sign() == 0 {
return common.Big0, common.Big0
}
cancelFee := big.NewInt(0)
tokenPriceInXDC := big.NewInt(0)
var cancelFee, tokenPriceInXDC *big.Int
var err error
if order.Side == tradingstate.Ask {
cancelFee, tokenPriceInXDC, err = XDCx.ConvertXDCToToken(chain, statedb, tradingStateDb, order.BaseToken, common.RelayerCancelFee)

View file

@ -311,7 +311,7 @@ func (l *Lending) SyncDataToSDKNode(chain consensus.ChainContext, statedb *state
}
// maker dirty order
makerFilledAmount := big.NewInt(0)
makerOrderHash := common.Hash{}
var makerOrderHash common.Hash
if updatedTakerLendingItem.Side == lendingstate.Borrowing {
makerOrderHash = tradeRecord.InvestingOrderHash
} else {

View file

@ -411,7 +411,7 @@ func VerifyBalance(isXDCXLendingFork bool, statedb *state.StateDB, lendingStateD
if lendTokenXDCPrice != nil && lendTokenXDCPrice.Sign() > 0 {
defaultFee := new(big.Int).Mul(quantity, new(big.Int).SetUint64(DefaultFeeRate))
defaultFee = new(big.Int).Div(defaultFee, common.XDCXBaseFee)
defaultFeeInXDC := common.Big0
var defaultFeeInXDC *big.Int
if lendingToken != common.XDCNativeAddressBinary {
defaultFeeInXDC = new(big.Int).Mul(defaultFee, lendTokenXDCPrice)
defaultFeeInXDC = new(big.Int).Div(defaultFeeInXDC, lendingTokenDecimal)
@ -429,8 +429,7 @@ func VerifyBalance(isXDCXLendingFork bool, statedb *state.StateDB, lendingStateD
// make sure actualBalance >= cancel fee
lendingBook := GetLendingOrderBookHash(lendingToken, term)
item := lendingStateDb.GetLendingOrder(lendingBook, common.BigToHash(new(big.Int).SetUint64(lendingId)))
cancelFee := big.NewInt(0)
cancelFee = new(big.Int).Mul(item.Quantity, borrowingFeeRate)
cancelFee := new(big.Int).Mul(item.Quantity, borrowingFeeRate)
cancelFee = new(big.Int).Div(cancelFee, common.XDCXBaseCancelFee)
actualBalance := GetTokenBalance(userAddress, lendingToken, statedb)
@ -459,9 +458,8 @@ func VerifyBalance(isXDCXLendingFork bool, statedb *state.StateDB, lendingStateD
case LendingStatusCancelled:
lendingBook := GetLendingOrderBookHash(lendingToken, term)
item := lendingStateDb.GetLendingOrder(lendingBook, common.BigToHash(new(big.Int).SetUint64(lendingId)))
cancelFee := big.NewInt(0)
// Fee == quantityToLend/base lend token decimal *price*borrowFee/LendingCancelFee
cancelFee = new(big.Int).Div(item.Quantity, collateralPrice)
cancelFee := new(big.Int).Div(item.Quantity, collateralPrice)
cancelFee = new(big.Int).Mul(cancelFee, borrowingFeeRate)
cancelFee = new(big.Int).Div(cancelFee, common.XDCXBaseCancelFee)
actualBalance := GetTokenBalance(userAddress, collateralToken, statedb)

View file

@ -727,9 +727,10 @@ func (l *Lending) ProcessCancelOrder(header *types.Header, lendingStateDB *lendi
}
}
feeRate := lendingstate.GetFee(statedb, originOrder.Relayer)
tokenCancelFee, tokenPriceInXDC := common.Big0, common.Big0
var tokenCancelFee, tokenPriceInXDC *big.Int
if !chain.Config().IsTIPXDCXCancellationFee(header.Number) {
tokenCancelFee = getCancelFeeV1(collateralTokenDecimal, collateralPrice, feeRate, &originOrder)
tokenPriceInXDC = common.Big0
} else {
tokenCancelFee, tokenPriceInXDC = l.getCancelFee(chain, statedb, tradingStateDb, &originOrder, feeRate)
}
@ -927,7 +928,7 @@ func (l *Lending) LiquidationTrade(lendingStateDB *lendingstate.LendingStateDB,
// cancellation fee = 1/10 borrowing fee
// deprecated after hardfork at TIPXDCXCancellationFee
func getCancelFeeV1(collateralTokenDecimal *big.Int, collateralPrice, borrowFee *big.Int, order *lendingstate.LendingItem) *big.Int {
cancelFee := big.NewInt(0)
var cancelFee *big.Int
if order.Side == lendingstate.Investing {
// cancel fee = quantityToLend*borrowFee/LendingCancelFee
cancelFee = new(big.Int).Mul(order.Quantity, borrowFee)
@ -947,7 +948,7 @@ func (l *Lending) getCancelFee(chain consensus.ChainContext, statedb *state.Stat
if feeRate == nil || feeRate.Sign() == 0 {
return common.Big0, common.Big0
}
cancelFee, tokenPriceInXDC := common.Big0, common.Big0
var cancelFee, tokenPriceInXDC *big.Int
var err error
if order.Side == lendingstate.Investing {
cancelFee, tokenPriceInXDC, err = l.XDCx.ConvertXDCToToken(chain, statedb, tradingStateDb, order.LendingToken, common.RelayerLendingCancelFee)

View file

@ -394,7 +394,7 @@ func (self *Hasher) ReadFrom(r io.Reader) (m int64, err error) {
if err != nil {
break
}
n, err = self.Write(buf[:n])
_, err = self.Write(buf[:n])
if err != nil {
break
}

View file

@ -43,7 +43,7 @@ func airDropTokenToAccountNoXDC() {
fmt.Println("wait 10s to airdrop success ", tx.Hash().Hex())
time.Sleep(10 * time.Second)
_, receiptRpc, err := client.GetTransactionReceiptResult(context.Background(), tx.Hash())
_, receiptRpc, _ := client.GetTransactionReceiptResult(context.Background(), tx.Hash())
receipt := map[string]interface{}{}
err = json.Unmarshal(receiptRpc, &receipt)
if err != nil {
@ -80,8 +80,8 @@ func testTransferTRC21TokenWithAccountNoXDC() {
trc21IssuerInstance, _ := trc21issuer.NewTRC21Issuer(airDropAccount, common.TRC21IssuerSMC, client)
remainFee, _ := trc21IssuerInstance.GetTokenCapacity(trc21TokenAddr)
airDropBalanceBefore, err := trc21Instance.BalanceOf(simulation.AirdropAddr)
receiverBalanceBefore, err := trc21Instance.BalanceOf(simulation.ReceiverAddr)
airDropBalanceBefore, _ := trc21Instance.BalanceOf(simulation.AirdropAddr)
receiverBalanceBefore, _ := trc21Instance.BalanceOf(simulation.ReceiverAddr)
// execute transferAmount trc to other address
tx, err := trc21Instance.Transfer(simulation.ReceiverAddr, simulation.TransferAmount)
if err != nil {
@ -105,7 +105,7 @@ func testTransferTRC21TokenWithAccountNoXDC() {
if err != nil || balance.Cmp(remainAirDrop) != 0 {
log.Fatal("check balance after fail transferAmount in tr21: ", err, "get", balance, "wanted", remainAirDrop)
}
_, receiptRpc, err := client.GetTransactionReceiptResult(context.Background(), tx.Hash())
_, receiptRpc, _ := client.GetTransactionReceiptResult(context.Background(), tx.Hash())
receipt := map[string]interface{}{}
err = json.Unmarshal(receiptRpc, &receipt)
if err != nil {
@ -140,15 +140,15 @@ func testTransferTrc21Fail() {
airDropAccount.GasPrice = big.NewInt(0).Mul(common.TRC21GasPrice, big.NewInt(2))
trc21Instance, _ := trc21issuer.NewTRC21(airDropAccount, trc21TokenAddr, client)
trc21IssuerInstance, _ := trc21issuer.NewTRC21Issuer(airDropAccount, common.TRC21IssuerSMC, client)
balanceIssuerFee, err := trc21IssuerInstance.GetTokenCapacity(trc21TokenAddr)
balanceIssuerFee, _ := trc21IssuerInstance.GetTokenCapacity(trc21TokenAddr)
minFee, err := trc21Instance.MinFee()
if err != nil {
log.Fatal("can't get minFee of trc21 smart contract:", err)
}
ownerBalance, err := trc21Instance.BalanceOf(simulation.MainAddr)
remainFee, err := trc21IssuerInstance.GetTokenCapacity(trc21TokenAddr)
airDropBalanceBefore, err := trc21Instance.BalanceOf(simulation.AirdropAddr)
ownerBalance, _ := trc21Instance.BalanceOf(simulation.MainAddr)
remainFee, _ := trc21IssuerInstance.GetTokenCapacity(trc21TokenAddr)
airDropBalanceBefore, _ := trc21Instance.BalanceOf(simulation.AirdropAddr)
tx, err := trc21Instance.Transfer(common.Address{}, big.NewInt(1))
if err != nil {
@ -171,7 +171,7 @@ func testTransferTrc21Fail() {
if err != nil || balance.Cmp(ownerBalance) != 0 {
log.Fatal("can't get balance token fee in smart contract: ", err, "got", balanceIssuerFee, "wanted", remainFee)
}
_, receiptRpc, err := client.GetTransactionReceiptResult(context.Background(), tx.Hash())
_, receiptRpc, _ := client.GetTransactionReceiptResult(context.Background(), tx.Hash())
receipt := map[string]interface{}{}
err = json.Unmarshal(receiptRpc, &receipt)
if err != nil {

View file

@ -1271,8 +1271,6 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
if current := block.NumberU64(); current > triesInMemory {
// Find the next state trie we need to commit
chosen := current - triesInMemory
oldTradingRoot := common.Hash{}
oldLendingRoot := common.Hash{}
// Only write to disk if we exceeded our memory allowance *and* also have at
// least a given number of tries gapped.
//
@ -1308,8 +1306,8 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
if tradingTrieDb != nil && lendingTrieDb != nil {
b := bc.GetBlock(header.Hash(), current-triesInMemory)
author, _ := bc.Engine().Author(b.Header())
oldTradingRoot, _ = tradingService.GetTradingStateRoot(b, author)
oldLendingRoot, _ = lendingService.GetLendingStateRoot(b, author)
oldTradingRoot, _ := tradingService.GetTradingStateRoot(b, author)
oldLendingRoot, _ := lendingService.GetLendingStateRoot(b, author)
tradingTrieDb.Commit(oldTradingRoot, true)
lendingTrieDb.Commit(oldLendingRoot, true)
}
@ -1647,8 +1645,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
}
// liquidate / finalize open lendingTrades
if block.Number().Uint64()%bc.chainConfig.XDPoS.Epoch == common.LiquidateLendingTradeBlock {
finalizedTrades := map[common.Hash]*lendingstate.LendingTrade{}
finalizedTrades, _, _, _, _, err = lendingService.ProcessLiquidationData(block.Header(), bc, statedb, tradingState, lendingState)
finalizedTrades, _, _, _, _, err := lendingService.ProcessLiquidationData(block.Header(), bc, statedb, tradingState, lendingState)
if err != nil {
return i, events, coalescedLogs, fmt.Errorf("failed to ProcessLiquidationData. Err: %v ", err)
}

View file

@ -527,7 +527,7 @@ func testInsertNonceError(t *testing.T, full bool) {
blockchain.engine = ethash.NewFakeFailer(failNum)
blockchain.hc.engine = blockchain.engine
failRes, err = blockchain.InsertHeaderChain(headers, 1)
failRes, _ = blockchain.InsertHeaderChain(headers, 1)
// Check that the returned error indicates the failure.
if failRes != failAt {
t.Errorf("test %d: failure index mismatch: have %d, want %d", i, failRes, failAt)

View file

@ -58,7 +58,7 @@ func getLendingNonce(userAddress common.Address) (uint64, error) {
s := result.(string)
s = strings.TrimPrefix(s, "0x")
n, err := strconv.ParseUint(s, 16, 32)
return uint64(n), nil
return uint64(n), err
}
func (l *LendingMsg) computeHash() common.Hash {

View file

@ -49,7 +49,6 @@ var (
EOSAddress = common.HexToAddress("0xd9bb01454c85247B2ef35BB5BE57384cC275a8cf")
USDAddress = common.HexToAddress("0x45c25041b8e6CBD5c963E7943007187C3673C7c9")
_1E18 = new(big.Int).Mul(big.NewInt(10000000000000000), big.NewInt(100))
_1E17 = new(big.Int).Mul(big.NewInt(10000000000000000), big.NewInt(10))
_1E8 = big.NewInt(100000000)
_1E7 = big.NewInt(10000000)
)
@ -72,7 +71,7 @@ func getNonce(t *testing.T, userAddress common.Address) (uint64, error) {
s := result.(string)
s = strings.TrimPrefix(s, "0x")
n, err := strconv.ParseUint(s, 16, 32)
return uint64(n), nil
return uint64(n), err
}
func testSendOrder(t *testing.T, amount, price *big.Int, side string, status string, orderID uint64) {

View file

@ -608,8 +608,6 @@ Delta is a helper function that is used in the range proof
*/
func Delta(y []*big.Int, z *big.Int) *big.Int {
result := big.NewInt(0)
// (z-z^2)<1^n, y^n>
z2 := new(big.Int).Mod(new(big.Int).Mul(z, z), EC.N)
t1 := new(big.Int).Mod(new(big.Int).Sub(z, z2), EC.N)
@ -620,21 +618,14 @@ func Delta(y []*big.Int, z *big.Int) *big.Int {
po2sum := new(big.Int).Sub(new(big.Int).Exp(big.NewInt(2), big.NewInt(int64(EC.V)), EC.N), big.NewInt(1))
t3 := new(big.Int).Mod(new(big.Int).Mul(z3, po2sum), EC.N)
result = new(big.Int).Mod(new(big.Int).Sub(t2, t3), EC.N)
return result
return new(big.Int).Mod(new(big.Int).Sub(t2, t3), EC.N)
}
// Calculates (aL - z*1^n) + sL*x
func CalculateL(aL, sL []*big.Int, z, x *big.Int) []*big.Int {
result := make([]*big.Int, len(aL))
tmp1 := VectorAddScalar(aL, new(big.Int).Neg(z))
tmp2 := ScalarVectorMul(sL, x)
result = VectorAdd(tmp1, tmp2)
return result
return VectorAdd(tmp1, tmp2)
}
func CalculateR(aR, sR, y, po2 []*big.Int, z, x *big.Int) []*big.Int {
@ -642,29 +633,20 @@ func CalculateR(aR, sR, y, po2 []*big.Int, z, x *big.Int) []*big.Int {
log.Info("CalculateR: Arrays not of the same length")
}
result := make([]*big.Int, len(aR))
z2 := new(big.Int).Exp(z, big.NewInt(2), EC.N)
tmp11 := VectorAddScalar(aR, z)
tmp12 := ScalarVectorMul(sR, x)
tmp1 := VectorHadamard(y, VectorAdd(tmp11, tmp12))
tmp2 := ScalarVectorMul(po2, z2)
result = VectorAdd(tmp1, tmp2)
return result
return VectorAdd(tmp1, tmp2)
}
// Calculates (aL - z*1^n) + sL*x
func CalculateLMRP(aL, sL []*big.Int, z, x *big.Int) []*big.Int {
result := make([]*big.Int, len(aL))
tmp1 := VectorAddScalar(aL, new(big.Int).Neg(z))
tmp2 := ScalarVectorMul(sL, x)
result = VectorAdd(tmp1, tmp2)
return result
return VectorAdd(tmp1, tmp2)
}
func CalculateRMRP(aR, sR, y, zTimesTwo []*big.Int, z, x *big.Int) []*big.Int {
@ -672,15 +654,11 @@ func CalculateRMRP(aR, sR, y, zTimesTwo []*big.Int, z, x *big.Int) []*big.Int {
log.Info("CalculateRMRP: Arrays not of the same length")
}
result := make([]*big.Int, len(aR))
tmp11 := VectorAddScalar(aR, z)
tmp12 := ScalarVectorMul(sR, x)
tmp1 := VectorHadamard(y, VectorAdd(tmp11, tmp12))
result = VectorAdd(tmp1, zTimesTwo)
return result
return VectorAdd(tmp1, zTimesTwo)
}
/*
@ -689,8 +667,6 @@ DeltaMRP is a helper function that is used in the multi range proof
*/
func DeltaMRP(y []*big.Int, z *big.Int, m int) *big.Int {
result := big.NewInt(0)
// (z-z^2)<1^n, y^n>
z2 := new(big.Int).Mod(new(big.Int).Mul(z, z), EC.N)
t1 := new(big.Int).Mod(new(big.Int).Sub(z, z2), EC.N)
@ -709,9 +685,7 @@ func DeltaMRP(y []*big.Int, z *big.Int, m int) *big.Int {
t3 = new(big.Int).Mod(new(big.Int).Add(t3, tmp1), EC.N)
}
result = new(big.Int).Mod(new(big.Int).Sub(t2, t3), EC.N)
return result
return new(big.Int).Mod(new(big.Int).Sub(t2, t3), EC.N)
}
type MultiRangeProof struct {

View file

@ -21,7 +21,7 @@ func TestSign(t *testing.T) {
ringSize := 10
s := 9
fmt.Println("Generate random ring parameter ")
rings, privkeys, m, err := GenerateMultiRingParams(numRing, ringSize, s)
rings, privkeys, m, _ := GenerateMultiRingParams(numRing, ringSize, s)
fmt.Println("numRing ", numRing)
fmt.Println("ringSize ", ringSize)
@ -57,7 +57,7 @@ func TestDeserialize(t *testing.T) {
numRing := 5
ringSize := 10
s := 5
rings, privkeys, m, err := GenerateMultiRingParams(numRing, ringSize, s)
rings, privkeys, m, _ := GenerateMultiRingParams(numRing, ringSize, s)
ringSignature, err := Sign(m, rings, privkeys, s)
if err != nil {
@ -235,7 +235,7 @@ func TestOnCurveVerify(t *testing.T) {
numRing := 5
ringSize := 10
s := 5
rings, privkeys, m, err := GenerateMultiRingParams(numRing, ringSize, s)
rings, privkeys, m, _ := GenerateMultiRingParams(numRing, ringSize, s)
ringSignature, err := Sign(m, rings, privkeys, s)
if err != nil {
t.Error("Failed to create Ring signature")
@ -259,7 +259,7 @@ func TestOnCurveDeserialize(t *testing.T) {
numRing := 5
ringSize := 10
s := 5
rings, privkeys, m, err := GenerateMultiRingParams(numRing, ringSize, s)
rings, privkeys, m, _ := GenerateMultiRingParams(numRing, ringSize, s)
ringSignature, err := Sign(m, rings, privkeys, s)
if err != nil {
t.Error("Failed to create Ring signature")
@ -304,7 +304,7 @@ func TestNilPointerDereferencePanic(t *testing.T) {
numRing := 5
ringSize := 10
s := 7
rings, privkeys, m, err := GenerateMultiRingParams(numRing, ringSize, s)
rings, privkeys, m, _ := GenerateMultiRingParams(numRing, ringSize, s)
ringSig, err := Sign(m, rings, privkeys, s)
if err != nil {
@ -318,7 +318,7 @@ func TestNilPointerDereferencePanic(t *testing.T) {
t.Error("Failed to Serialize input Ring signature")
}
_ , err = Deserialize(sig)
_, err = Deserialize(sig)
// Should failed to verify Ring signature as the signature is invalid
assert.EqualError(t, err, "failed to deserialize, invalid ring signature")
}

View file

@ -199,9 +199,8 @@ func miller(q *twistPoint, p *curvePoint) *gfP12 {
r = newR
r2.Square(&minusQ2.y)
a, b, c, newR = lineFunctionAdd(r, minusQ2, bAffine, r2)
a, b, c, _ = lineFunctionAdd(r, minusQ2, bAffine, r2)
mulLine(ret, a, b, c)
r = newR
return ret
}

View file

@ -270,7 +270,7 @@ func TestChildPrefixedRegistryOfChildRegister(t *testing.T) {
if err != nil {
t.Fatal(err.Error())
}
err = r2.Register("baz", NewCounter())
r2.Register("baz", NewCounter())
c := NewCounter()
Register("bars", c)
@ -293,7 +293,7 @@ func TestWalkRegistries(t *testing.T) {
if err != nil {
t.Fatal(err.Error())
}
err = r2.Register("baz", NewCounter())
r2.Register("baz", NewCounter())
c := NewCounter()
Register("bars", c)

View file

@ -169,7 +169,7 @@ func singleRequest(t *testing.T, server *WMailServer, env *whisper.Envelope, p *
}
src[0]++
ok, lower, upper, bloom = server.validateRequest(src, request)
ok, lower, upper, _ = server.validateRequest(src, request)
if !ok {
// request should be valid regardless of signature
t.Fatalf("request validation false negative, seed: %d (lower: %d, upper: %d).", seed, lower, upper)

View file

@ -309,7 +309,7 @@ func TestMatchEnvelope(t *testing.T) {
if err != nil {
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
}
env, err := msg.Wrap(params)
_, err = msg.Wrap(params)
if err != nil {
t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
}
@ -322,7 +322,7 @@ func TestMatchEnvelope(t *testing.T) {
if err != nil {
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
}
env, err = msg.Wrap(params)
env, err := msg.Wrap(params)
if err != nil {
t.Fatalf("failed Wrap() with seed %d: %s.", seed, err)
}