Skip to content

Commit 0f649c6

Browse files
committed
check if bridge address has code before preparing tx payload
1 parent 8aec852 commit 0f649c6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

cmd/ulxly/ulxly.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ func bridgeAsset(cmd *cobra.Command) error {
361361
return err
362362
}
363363
defer client.Close()
364+
364365
// Initialize and assign variables required to send transaction payload
365366
bridgeV2, toAddress, auth, err := generateTransactionPayload(cmd.Context(), client, bridgeAddress, privateKey, gasLimit, destinationAddress, chainID)
366367
if err != nil {
@@ -1113,6 +1114,17 @@ func readDeposits(rawDeposits []byte, depositNumber uint32) error {
11131114
return nil
11141115
}
11151116

1117+
func hasCode(client *ethclient.Client, address string) error {
1118+
code, err := client.CodeAt(context.Background(), common.HexToAddress(address), nil)
1119+
if err != nil {
1120+
log.Error().Err(err).Msg("error getting code at address")
1121+
}
1122+
if len(code) == 0 {
1123+
return fmt.Errorf("address %s has no code", address)
1124+
}
1125+
return nil
1126+
}
1127+
11161128
// String will create the json representation of the proof
11171129
func String[T any](p T) string {
11181130
jsonBytes, err := json.Marshal(p)
@@ -1308,6 +1320,13 @@ func generateEmptyHashes(height uint8) []common.Hash {
13081320
}
13091321

13101322
func generateTransactionPayload(ctx context.Context, client *ethclient.Client, ulxlyInputArgBridge string, ulxlyInputArgPvtKey string, ulxlyInputArgGasLimit uint64, ulxlyInputArgDestAddr string, ulxlyInputArgChainID string) (bridgeV2 *ulxly.Ulxly, toAddress common.Address, opts *bind.TransactOpts, err error) {
1323+
// checks if bridge address has code
1324+
err = hasCode(client, ulxlyInputArgBridge)
1325+
if err != nil {
1326+
err = fmt.Errorf("bridge err: %w", err)
1327+
return
1328+
}
1329+
13111330
ulxlyInputArgPvtKey = strings.TrimPrefix(ulxlyInputArgPvtKey, "0x")
13121331
bridgeV2, err = ulxly.NewUlxly(common.HexToAddress(ulxlyInputArgBridge), client)
13131332
if err != nil {

0 commit comments

Comments
 (0)