CheckTransaction return an error if the transaction is failed
(client *ethclient.Client, tx *types.Transaction)
| 269 | |
| 270 | // CheckTransaction return an error if the transaction is failed |
| 271 | func 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. |
| 301 | func GetBalance(client *ethclient.Client, key *keystore.Key) (balance *big.Float, err error) { |