MCPcopy Create free account
hub / github.com/DOSNetwork/core / CheckTransaction

Function CheckTransaction

onchain/eth_helpers.go:271–298  ·  view source on GitHub ↗

CheckTransaction return an error if the transaction is failed

(client *ethclient.Client, tx *types.Transaction)

Source from the content-addressed store, hash-verified

269
270// CheckTransaction return an error if the transaction is failed
271func CheckTransaction(client *ethclient.Client, tx *types.Transaction) (err error) {
272 start := time.Now()
273 receipt, err := client.TransactionReceipt(context.Background(), tx.Hash())
274 for err == ethereum.NotFound {
275 fmt.Println("ethereum.NotFound ", err)
276 if time.Since(start).Minutes() > 30 {
277 err = errors.New("transaction not found")
278 fmt.Println("transaction failed. tx ", fmt.Sprintf("%x", tx.Hash()))
279 return
280 }
281
282 time.Sleep(1 * time.Second)
283 receipt, err = client.TransactionReceipt(context.Background(), tx.Hash())
284 }
285 if err != nil {
286 fmt.Println("CheckTransaction ", err)
287 return
288 }
289
290 if receipt.Status == 1 {
291 fmt.Println("transaction confirmed. tx ", fmt.Sprintf("%x", tx.Hash()))
292 } else {
293 err = errors.New("transaction failed")
294 fmt.Println("transaction Status != 0 . tx ", fmt.Sprintf("%x", tx.Hash()))
295 }
296
297 return
298}
299
300// GetBalance returns the wei balance of the given account.
301func GetBalance(client *ethclient.Client, key *keystore.Key) (balance *big.Float, err error) {

Callers

nothing calls this directly

Calls 2

NewMethod · 0.65
HashMethod · 0.45

Tested by

no test coverage detected