@@ -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,18 @@ func readDeposits(rawDeposits []byte, depositNumber uint32) error {
11131114 return nil
11141115}
11151116
1117+ func ensureCodePresent (ctx context.Context , client * ethclient.Client , address string ) error {
1118+ code , err := client .CodeAt (ctx , common .HexToAddress (address ), nil )
1119+ if err != nil {
1120+ log .Error ().Err (err ).Str ("address" , address ).Msg ("error getting code at address" )
1121+ return err
1122+ }
1123+ if len (code ) == 0 {
1124+ return fmt .Errorf ("address %s has no code" , address )
1125+ }
1126+ return nil
1127+ }
1128+
11161129// String will create the json representation of the proof
11171130func String [T any ](p T ) string {
11181131 jsonBytes , err := json .Marshal (p )
@@ -1308,6 +1321,13 @@ func generateEmptyHashes(height uint8) []common.Hash {
13081321}
13091322
13101323func 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 ) {
1324+ // checks if bridge address has code
1325+ err = ensureCodePresent (ctx , client , ulxlyInputArgBridge )
1326+ if err != nil {
1327+ err = fmt .Errorf ("bridge code check err: %w" , err )
1328+ return
1329+ }
1330+
13111331 ulxlyInputArgPvtKey = strings .TrimPrefix (ulxlyInputArgPvtKey , "0x" )
13121332 bridgeV2 , err = ulxly .NewUlxly (common .HexToAddress (ulxlyInputArgBridge ), client )
13131333 if err != nil {
0 commit comments