Skip to content

Commit c50a4c2

Browse files
author
Ludo Galabru
committed
feat: support for more address formats in btc transfers
1 parent 9f410e3 commit c50a4c2

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

components/clarinet-cli/src/deployments/bitcoin_deployment.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use base58::FromBase58;
44
use bitcoin::blockdata::opcodes;
55
use bitcoin::blockdata::script::Builder;
66
use bitcoin::consensus::encode;
7-
use bitcoin::{OutPoint, Script, Transaction, TxIn, TxOut, Txid, Witness};
7+
use bitcoin::{OutPoint, Script, Transaction, TxIn, TxOut, Txid, Witness, PubkeyHash, WPubkeyHash};
88
use bitcoincore_rpc::bitcoin::secp256k1::{Message, PublicKey, Secp256k1, SecretKey};
99
use bitcoincore_rpc::bitcoin::Address;
1010
use bitcoincore_rpc::Client;
@@ -61,20 +61,19 @@ pub fn build_transaction_spec(
6161
selected_utxos.push(utxo);
6262
}
6363

64+
6465
// Prepare Recipient output
65-
let recipient_pub_key_hash = tx_spec
66-
.recipient
67-
.from_base58()
68-
.expect("Unable to get bytes recipient btc address");
66+
let address = {
67+
use bitcoin::Address;
68+
match Address::from_str(&tx_spec.recipient) {
69+
Ok(address) => address,
70+
Err(e) => panic!("{:?}", e),
71+
}
72+
};
73+
6974
let txout = TxOut {
7075
value: tx_spec.sats_amount,
71-
script_pubkey: Builder::new()
72-
.push_opcode(opcodes::all::OP_DUP)
73-
.push_opcode(opcodes::all::OP_HASH160)
74-
.push_slice(&recipient_pub_key_hash[1..21])
75-
.push_opcode(opcodes::all::OP_EQUALVERIFY)
76-
.push_opcode(opcodes::all::OP_CHECKSIG)
77-
.into_script(),
76+
script_pubkey: address.script_pubkey()
7877
};
7978
transaction.output.push(txout);
8079

components/clarinet-cli/src/deployments/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ fn sign_transaction_payload(
160160
Ok(signed_tx)
161161
}
162162

163-
#[allow(dead_code)]
164163
pub fn encode_contract_call(
165164
contract_id: &QualifiedContractIdentifier,
166165
function_name: ClarityName,

0 commit comments

Comments
 (0)