|
|
@@ -7,6 +7,7 @@ import (
|
|
|
"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"
|
|
|
)
|
|
|
|
|
|
@@ -22,8 +23,18 @@ func NewEasyWallet(wallet accounts.Wallet, account accounts.Account) *EasyWallet
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (e *EasyWallet) SendTest(api *ethapi.PrivateAccountAPI) {
|
|
|
- nonce := hexutil.Uint64(uint64(0))
|
|
|
+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{}
|
|
|
@@ -32,7 +43,7 @@ func (e *EasyWallet) SendTest(api *ethapi.PrivateAccountAPI) {
|
|
|
toAddr := e.account.Address
|
|
|
|
|
|
sendArgs := ethapi.SendTxArgs{
|
|
|
- Nonce: &nonce,
|
|
|
+ Nonce: nonce,
|
|
|
Gas: &gasLimit,
|
|
|
GasPrice: &gasPrice,
|
|
|
Data: &callData,
|
|
|
@@ -41,12 +52,13 @@ func (e *EasyWallet) SendTest(api *ethapi.PrivateAccountAPI) {
|
|
|
To: &toAddr,
|
|
|
}
|
|
|
|
|
|
- hash, err := api.SignAndSendTransaction(context.Background(), sendArgs, "")
|
|
|
+ hash, err := accountApi.SignAndSendTransaction(ctx, sendArgs, "")
|
|
|
if err != nil {
|
|
|
HistoryError("Send error.", "error", err.Error())
|
|
|
- } else {
|
|
|
- HistoryInfo("Send ok.", "hash", hash)
|
|
|
+ return
|
|
|
}
|
|
|
+
|
|
|
+ HistoryInfo("Send ok.", "hash", hash)
|
|
|
}
|
|
|
|
|
|
func (e *EasyWallet) OnlySignTest() {
|