|
9 | 9 | "strings" |
10 | 10 | "time" |
11 | 11 |
|
| 12 | + "github.com/ethereum/go-ethereum/ethclient" |
| 13 | + |
12 | 14 | "github.com/ethereum/go-ethereum/common" |
13 | 15 | "github.com/ethereum/go-ethereum/crypto" |
14 | 16 |
|
@@ -77,27 +79,29 @@ func deployEvmContract(bytecode string, cmd *cobra.Command) { |
77 | 79 | err = signedTx.EncodeRLP(&buf) |
78 | 80 | utils.ExitOnErr(err, "failed to encode tx") |
79 | 81 |
|
| 82 | + fmt.Println("Tx hash", signedTx.Hash()) |
| 83 | + |
80 | 84 | err = ethClient8545.SendTransaction(context.Background(), signedTx) |
81 | 85 | utils.ExitOnErr(err, "failed to send tx") |
82 | 86 |
|
83 | | - fmt.Println("Tx hash", signedTx.Hash()) |
| 87 | + if tx := waitForEthTx(ethClient8545, signedTx.Hash()); tx != nil { |
| 88 | + fmt.Println("New contract deployed at:") |
| 89 | + } else { |
| 90 | + fmt.Println("Timed-out waiting for tx to be mined, contract may have been deployed.") |
| 91 | + fmt.Println("Expected contract address:") |
| 92 | + } |
| 93 | + fmt.Println(newContractAddress) |
| 94 | +} |
84 | 95 |
|
85 | | - var found bool |
| 96 | +func waitForEthTx(ethClient8545 *ethclient.Client, txHash common.Hash) *ethtypes.Transaction { |
86 | 97 | for try := 1; try <= 6; try++ { |
87 | | - txByHash, pending, err := ethClient8545.TransactionByHash(context.Background(), signedTx.Hash()) |
88 | | - if err == nil && !pending && txByHash != nil { |
89 | | - found = true |
90 | | - break |
| 98 | + tx, _, err := ethClient8545.TransactionByHash(context.Background(), txHash) |
| 99 | + if err == nil && tx != nil { |
| 100 | + return tx |
91 | 101 | } |
92 | 102 |
|
93 | 103 | time.Sleep(time.Second) |
94 | 104 | } |
95 | 105 |
|
96 | | - if found { |
97 | | - fmt.Println("New contract deployed at:") |
98 | | - } else { |
99 | | - fmt.Println("Timed-out waiting for tx to be mined, contract may have been deployed.") |
100 | | - fmt.Println("Expected contract address:") |
101 | | - } |
102 | | - fmt.Println(newContractAddress) |
| 106 | + return nil |
103 | 107 | } |
0 commit comments