@@ -222,31 +222,31 @@ func (w *Erc20Worker) GetHeight() (int64, error) {
222222}
223223
224224// Vote ...
225- func (w * Erc20Worker ) Vote (depositNonce uint64 , originchainID [8 ]byte , destinationChainID [8 ]byte , resourceID [32 ]byte , receiptAddr string , amount string ) (string , error ) {
225+ func (w * Erc20Worker ) Vote (depositNonce uint64 , originchainID [8 ]byte , destinationChainID [8 ]byte , resourceID [32 ]byte , receiptAddr string , amount string ) (string , uint64 , error ) {
226226 auth , err := w .getTransactor ()
227227 if err != nil {
228- return "" , err
228+ return "" , 0 , err
229229 }
230230
231231 instance , err := labr .NewLabr (w .swapContractAddr , w .client )
232232 if err != nil {
233- return "" , err
233+ return "" , 0 , err
234234 }
235235
236236 value , _ := new (big.Int ).SetString (amount , 10 )
237237 tx , err := instance .VoteProposal (auth , originchainID , destinationChainID , depositNonce , resourceID , common .HexToAddress (receiptAddr ), value )
238238 if err != nil {
239- return "" , err
239+ return "" , 0 , err
240240 }
241241
242- return tx .Hash ().String (), nil
242+ return tx .Hash ().String (), auth . Nonce . Uint64 (), nil
243243}
244244
245245func (w * Erc20Worker ) GetTxCountLatest () (uint64 , error ) {
246246 var result hexutil.Uint64
247247 rpcClient := jsonrpc .NewClient (w .provider )
248248
249- resp , err := rpcClient .Call ("eth_getTransactionCount" , w .config .WorkerAddr .Hex (), "pending " )
249+ resp , err := rpcClient .Call ("eth_getTransactionCount" , w .config .WorkerAddr .Hex (), "latest " )
250250 if err != nil {
251251 return 0 , err
252252 }
@@ -301,17 +301,25 @@ func (w *Erc20Worker) GetWorkerAddress() string {
301301}
302302
303303// GetSentTxStatus ...
304- func (w * Erc20Worker ) GetSentTxStatus (hash string ) storage.TxStatus {
304+ func (w * Erc20Worker ) GetSentTxStatus (hash string , nonce uint64 ) storage.TxStatus {
305305 txReceipt , err := w .client .TransactionReceipt (context .Background (), common .HexToHash (hash ))
306306 if err != nil {
307- _ , isPending , err := w .client .TransactionByHash (context .Background (), common .HexToHash (hash ))
308- if err != nil {
309- if err == ethereum .NotFound {
310- return storage .TxSentStatusLost
307+ if nonce == 0 {
308+ _ , isPending , err := w .client .TransactionByHash (context .Background (), common .HexToHash (hash ))
309+ if err != nil {
310+ if err == ethereum .NotFound {
311+ return storage .TxSentStatusLost
312+ }
313+ return storage .TxSentStatusNotFound
314+ }
315+ if isPending {
316+ return storage .TxSentStatusPending
311317 }
312318 return storage .TxSentStatusNotFound
313319 }
314- if isPending {
320+
321+ txCount , _ := w .GetTxCountLatest ()
322+ if nonce >= txCount {
315323 return storage .TxSentStatusPending
316324 }
317325 return storage .TxSentStatusNotFound
0 commit comments