|
|
@@ -1,91 +1,46 @@
|
|
|
package arbitrage
|
|
|
|
|
|
import (
|
|
|
- "context"
|
|
|
"github.com/ethereum/go-ethereum/accounts"
|
|
|
- "github.com/ethereum/go-ethereum/common/hexutil"
|
|
|
- "github.com/ethereum/go-ethereum/core/types"
|
|
|
- "github.com/ethereum/go-ethereum/internal/ethapi"
|
|
|
- "github.com/ethereum/go-ethereum/params"
|
|
|
- "github.com/ethereum/go-ethereum/rpc"
|
|
|
- "math/big"
|
|
|
)
|
|
|
|
|
|
type EasyWallet struct {
|
|
|
- wallet accounts.Wallet
|
|
|
- account accounts.Account
|
|
|
+ wallet *accounts.Wallet
|
|
|
+ account *accounts.Account
|
|
|
}
|
|
|
|
|
|
-func NewEasyWallet(wallet accounts.Wallet, account accounts.Account) *EasyWallet {
|
|
|
+func NewEasyWallet(wallet *accounts.Wallet, account *accounts.Account) *EasyWallet {
|
|
|
return &EasyWallet{
|
|
|
wallet: wallet,
|
|
|
account: account,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (e *EasyWallet) SendTest(accountApi *ethapi.PrivateAccountAPI, txApi *ethapi.PublicTransactionPoolAPI) {
|
|
|
- ctx := context.Background()
|
|
|
- blockOrNbr := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber)
|
|
|
-
|
|
|
- // 获取nonce
|
|
|
- nonce, err := txApi.GetTransactionCount(ctx, e.account.Address, blockOrNbr)
|
|
|
- if err != nil {
|
|
|
- HistoryError("Get transaction count error.", "error", err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- HistoryInfo("Get transaction count", "addr", e.account.Address, "nonce", nonce)
|
|
|
-
|
|
|
- gasLimit := hexutil.Uint64(uint64(21000))
|
|
|
- gasPrice := hexutil.Big(*big.NewInt(30 * 1e9))
|
|
|
- callData := hexutil.Bytes{}
|
|
|
- value := hexutil.Big(*big.NewInt(1))
|
|
|
- fromAddr := e.account.Address
|
|
|
- toAddr := e.account.Address
|
|
|
-
|
|
|
- sendArgs := ethapi.SendTxArgs{
|
|
|
- Nonce: nonce,
|
|
|
- Gas: &gasLimit,
|
|
|
- GasPrice: &gasPrice,
|
|
|
- Data: &callData,
|
|
|
- Value: &value,
|
|
|
- From: fromAddr,
|
|
|
- To: &toAddr,
|
|
|
- }
|
|
|
-
|
|
|
- hash, err := accountApi.SignAndSendTransaction(ctx, sendArgs, "")
|
|
|
- if err != nil {
|
|
|
- HistoryError("Send error.", "error", err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- HistoryInfo("Send ok.", "hash", hash)
|
|
|
-}
|
|
|
-
|
|
|
-func (e *EasyWallet) OnlySignTest() {
|
|
|
- chainId := params.CoreChainConfig.ChainID
|
|
|
- nonce := uint64(0)
|
|
|
- gasLimit := uint64(21000)
|
|
|
- gasPrice := big.NewInt(30 * 1e9)
|
|
|
- callData := []byte{}
|
|
|
- value := big.NewInt(1)
|
|
|
- toAddr := e.account.Address
|
|
|
-
|
|
|
- tx := types.NewTx(&types.LegacyTx{
|
|
|
- Nonce: nonce,
|
|
|
- To: &toAddr,
|
|
|
- Value: value,
|
|
|
- Gas: gasLimit,
|
|
|
- GasPrice: gasPrice,
|
|
|
- Data: callData,
|
|
|
- })
|
|
|
-
|
|
|
- tx, err := e.wallet.SignTx(e.account, tx, chainId)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- HistoryError("Sign test err", "err", err)
|
|
|
-
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- HistoryInfo("Sign test", "tx", tx.Hash())
|
|
|
-}
|
|
|
+//func (e *EasyWallet) OnlySignTest() {
|
|
|
+// chainId := params.CoreChainConfig.ChainID
|
|
|
+// nonce := uint64(0)
|
|
|
+// gasLimit := uint64(21000)
|
|
|
+// gasPrice := big.NewInt(30 * 1e9)
|
|
|
+// callData := []byte{}
|
|
|
+// value := big.NewInt(1)
|
|
|
+// toAddr := e.account.Address
|
|
|
+//
|
|
|
+// tx := types.NewTx(&types.LegacyTx{
|
|
|
+// Nonce: nonce,
|
|
|
+// To: &toAddr,
|
|
|
+// Value: value,
|
|
|
+// Gas: gasLimit,
|
|
|
+// GasPrice: gasPrice,
|
|
|
+// Data: callData,
|
|
|
+// })
|
|
|
+//
|
|
|
+// tx, err := e.wallet.SignTx(e.account, tx, chainId)
|
|
|
+//
|
|
|
+// if err != nil {
|
|
|
+// HistoryError("Sign test err", "err", err)
|
|
|
+//
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// HistoryInfo("Sign test", "tx", tx.Hash())
|
|
|
+//}
|