|
|
@@ -43,36 +43,62 @@ func (h *HistoryArbitrage) callReturnRealResult(a abi.ABI, from string, to strin
|
|
|
return realResult, nil
|
|
|
}
|
|
|
|
|
|
-func (h *HistoryArbitrage) sendTest(e *EasyWallet) {
|
|
|
+type ArbTx struct {
|
|
|
+ Nonce int64
|
|
|
+ Gas int64
|
|
|
+ GasPrice int64
|
|
|
+ Data hexutil.Bytes
|
|
|
+ Value big.Int
|
|
|
+ From common.Address
|
|
|
+ To common.Address
|
|
|
+}
|
|
|
+
|
|
|
+func (h *HistoryArbitrage) sendTransaction(arbTx *ArbTx) {
|
|
|
ctx := context.Background()
|
|
|
blockOrNbr := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber)
|
|
|
|
|
|
- // 获取nonce
|
|
|
- nonce, err := h.txApi.GetTransactionCount(ctx, e.account.Address, blockOrNbr)
|
|
|
- if err != nil {
|
|
|
- HistoryError("Get transaction count error.", "error", err.Error())
|
|
|
- return
|
|
|
+ // nonce
|
|
|
+ finalNonce := hexutil.Uint64(arbTx.Nonce)
|
|
|
+ if arbTx.Nonce == 0 {
|
|
|
+ nonce, err := h.txApi.GetTransactionCount(ctx, arbTx.From, blockOrNbr)
|
|
|
+ if err != nil {
|
|
|
+ HistoryError("Get transaction count error.", "error", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ finalNonce = *nonce
|
|
|
}
|
|
|
|
|
|
- gasLimit := hexutil.Uint64(uint64(21000))
|
|
|
- gasPrice, err := h.ethereumApi.GasPrice(ctx)
|
|
|
- if err != nil {
|
|
|
- HistoryError("Get gas price error.", "error", err.Error())
|
|
|
- return
|
|
|
+ // gasLimit
|
|
|
+ finalGasLimit := hexutil.Uint64(arbTx.Gas)
|
|
|
+ if arbTx.Gas == 0 {
|
|
|
+ finalGasLimit = hexutil.Uint64(21000)
|
|
|
}
|
|
|
- callData := hexutil.Bytes{}
|
|
|
- value := hexutil.Big(*big.NewInt(1))
|
|
|
- fromAddr := e.account.Address
|
|
|
- toAddr := e.account.Address
|
|
|
|
|
|
+ // gasPrice
|
|
|
+ finalGasPrice := hexutil.Big(*big.NewInt(arbTx.GasPrice))
|
|
|
+ if arbTx.GasPrice == 0 {
|
|
|
+ gasPrice, err := h.ethereumApi.GasPrice(ctx)
|
|
|
+ if err != nil {
|
|
|
+ HistoryError("Get gas price error.", "error", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ finalGasPrice = *gasPrice
|
|
|
+ }
|
|
|
+
|
|
|
+ // value
|
|
|
+ finalValue := hexutil.Big(arbTx.Value)
|
|
|
+
|
|
|
+ // final tx
|
|
|
sendArgs := ethapi.SendTxArgs{
|
|
|
- Nonce: nonce,
|
|
|
- Gas: &gasLimit,
|
|
|
- GasPrice: gasPrice,
|
|
|
- Data: &callData,
|
|
|
- Value: &value,
|
|
|
- From: fromAddr,
|
|
|
- To: &toAddr,
|
|
|
+ Nonce: &finalNonce,
|
|
|
+ Gas: &finalGasLimit,
|
|
|
+ GasPrice: &finalGasPrice,
|
|
|
+ Data: &arbTx.Data,
|
|
|
+ Value: &finalValue,
|
|
|
+ From: arbTx.From,
|
|
|
+ To: &arbTx.To,
|
|
|
}
|
|
|
|
|
|
hash, err := h.accountApi.SignAndSendTransaction(ctx, sendArgs, "")
|