Skip to content

Commit

Permalink
Merge pull request #9 from AnduroProject/evm-address-fix
Browse files Browse the repository at this point in the history
updating changes related to extract_evm_address
  • Loading branch information
emailnjv authored Jun 26, 2024
2 parents 94a28b8 + a626488 commit 3747a8c
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions crates/federation/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod bitcoin_signing;
mod bitcoin_stream;
use thiserror::Error;

use bdk::bitcoin::hashes::hex::FromHex;
pub use bitcoin_stream::bitcoin;

use bitcoin::{Address as BitcoinAddress, BlockHash, Transaction, TxOut, Txid};
Expand Down Expand Up @@ -162,13 +162,31 @@ impl Bridge {
block_height: u32,
) -> Option<PegInInfo> {
fn extract_evm_address(tx_out: &TxOut) -> Option<H160> {
const OP_RETURN: u8 = 0x6a;
match tx_out.script_pubkey.as_bytes() {
&[OP_RETURN, 20, ref addr @ ..] if addr.len() == 20_usize => {
Some(H160::from_slice(addr))
if !tx_out.script_pubkey.is_provably_unspendable() || !tx_out.script_pubkey.is_op_return() {
return None;
}
let opreturn = tx_out.script_pubkey.to_asm_string();
let parts = opreturn.split(' ');
let op_return_parts = parts.collect::<Vec<&str>>();
let op_return_hex_string = op_return_parts[op_return_parts.len() - 1].to_string();
let data = Vec::from_hex(&op_return_hex_string);
if let Err(_e) = data {
return None;
}
let opreturn_data = String::from_utf8(data.clone().unwrap());
if let Err(_e) = opreturn_data.clone() {
let address = H160::from_str(&op_return_hex_string);
if let Err(_e) = address {
return None;
}
_ => None,
return Some(address.unwrap());
}
let address_str = opreturn_data.unwrap();
let address = H160::from_str(&address_str);
if let Err(_e) = address {
return None;
}
Some(address.unwrap())
}

let amount = tx
Expand Down

0 comments on commit 3747a8c

Please sign in to comment.