From 47fca1db7ee0a760e0035dc20c64a7cdfa498324 Mon Sep 17 00:00:00 2001 From: veeso Date: Tue, 12 Mar 2024 15:05:58 +0100 Subject: [PATCH] fix: renamed TxInput to Utxo --- examples/deploy.rs | 2 +- examples/mint.rs | 2 +- examples/transfer.rs | 2 +- examples/utils/rpc_client.rs | 6 +++--- examples/utils/transaction.rs | 6 +++--- src/lib.rs | 2 +- src/wallet.rs | 2 +- src/wallet/builder.rs | 17 +++++++++-------- src/wallet/builder/signer.rs | 8 ++++---- 9 files changed, 24 insertions(+), 23 deletions(-) diff --git a/examples/deploy.rs b/examples/deploy.rs index 345a363..cff42f5 100644 --- a/examples/deploy.rs +++ b/examples/deploy.rs @@ -109,7 +109,7 @@ async fn main() -> anyhow::Result<()> { debug!("getting reveal transaction..."); let reveal_transaction = builder .build_reveal_transaction(RevealTransactionArgs { - input: ord_rs::wallet::TxInput { + input: ord_rs::wallet::Utxo { id: commit_txid, index: 0, amount: commit_tx.reveal_balance, diff --git a/examples/mint.rs b/examples/mint.rs index ddbcd16..6c9244d 100644 --- a/examples/mint.rs +++ b/examples/mint.rs @@ -104,7 +104,7 @@ async fn main() -> anyhow::Result<()> { debug!("getting reveal transaction..."); let reveal_transaction = builder .build_reveal_transaction(RevealTransactionArgs { - input: ord_rs::wallet::TxInput { + input: ord_rs::wallet::Utxo { id: commit_txid, index: 0, amount: commit_tx.reveal_balance, diff --git a/examples/transfer.rs b/examples/transfer.rs index 83f5cd5..50d40eb 100644 --- a/examples/transfer.rs +++ b/examples/transfer.rs @@ -103,7 +103,7 @@ async fn main() -> anyhow::Result<()> { debug!("getting reveal transaction..."); let reveal_transaction = builder .build_reveal_transaction(RevealTransactionArgs { - input: ord_rs::wallet::TxInput { + input: ord_rs::wallet::Utxo { id: commit_txid, index: 0, amount: commit_tx.reveal_balance, diff --git a/examples/utils/rpc_client.rs b/examples/utils/rpc_client.rs index f84f901..8ae9d2c 100644 --- a/examples/utils/rpc_client.rs +++ b/examples/utils/rpc_client.rs @@ -3,7 +3,7 @@ use std::time::Duration; use bitcoin::{Amount, Network, Transaction, Txid}; use log::{debug, info}; -use ord_rs::wallet::TxInput; +use ord_rs::wallet::Utxo; pub async fn broadcast_transaction( transaction: &Transaction, @@ -43,7 +43,7 @@ pub async fn broadcast_transaction( pub async fn sats_amount_from_tx_inputs( inputs: &[(Txid, u32)], network: Network, -) -> anyhow::Result> { +) -> anyhow::Result> { let mut output_inputs = Vec::with_capacity(inputs.len()); for (txid, index) in inputs { let tx = get_tx_by_hash(txid, network).await?; @@ -52,7 +52,7 @@ pub async fn sats_amount_from_tx_inputs( .get(*index as usize) .ok_or_else(|| anyhow::anyhow!("invalid index {} for txid {}", index, txid))?; - output_inputs.push(TxInput { + output_inputs.push(Utxo { id: *txid, index: *index, amount: Amount::from_sat(output.value), diff --git a/examples/utils/transaction.rs b/examples/utils/transaction.rs index 8c26e0b..a19afaa 100644 --- a/examples/utils/transaction.rs +++ b/examples/utils/transaction.rs @@ -6,7 +6,7 @@ use bitcoin::transaction::Version; use bitcoin::{ Address, Amount, OutPoint, PrivateKey, ScriptBuf, Sequence, Transaction, TxIn, TxOut, Witness, }; -use ord_rs::wallet::TxInput; +use ord_rs::wallet::Utxo; use ord_rs::OrdError; #[allow(dead_code)] @@ -14,7 +14,7 @@ pub fn spend_utxo_transaction( private_key: &PrivateKey, recipient: Address, utxo_value: Amount, - inputs: Vec, + inputs: Vec, fee: Amount, ) -> anyhow::Result { let secp = Secp256k1::new(); @@ -74,7 +74,7 @@ fn sign_transaction( unsigned_tx: Transaction, private_key: &PrivateKey, secp: &Secp256k1, - inputs: Vec, + inputs: Vec, sender_script_pubkey: &ScriptBuf, ) -> anyhow::Result { let mut hash = SighashCache::new(unsigned_tx); diff --git a/src/lib.rs b/src/lib.rs index e8a0d9a..010dead 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,5 +33,5 @@ pub use inscription::Inscription; pub use result::OrdResult; pub use wallet::{ CreateCommitTransaction, CreateCommitTransactionArgs, ExternalSigner, OrdParser, - OrdTransactionBuilder, RevealTransactionArgs, TxInput, Wallet, WalletType, + OrdTransactionBuilder, RevealTransactionArgs, Utxo, Wallet, WalletType, }; diff --git a/src/wallet.rs b/src/wallet.rs index 67314d7..16265dd 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -4,6 +4,6 @@ mod parser; pub use builder::signer::{ExternalSigner, Wallet, WalletType}; pub use builder::{ CreateCommitTransaction, CreateCommitTransactionArgs, OrdTransactionBuilder, - RevealTransactionArgs, ScriptType, TxInput, + RevealTransactionArgs, ScriptType, Utxo, }; pub use parser::OrdParser; diff --git a/src/wallet/builder.rs b/src/wallet/builder.rs index 872fbeb..a8775a3 100644 --- a/src/wallet/builder.rs +++ b/src/wallet/builder.rs @@ -35,8 +35,8 @@ pub struct CreateCommitTransactionArgs where T: Inscription, { - /// Inputs of the transaction - pub inputs: Vec, + /// UTXOs to be used as Inputs of the transaction + pub inputs: Vec, /// Inscription to write pub inscription: T, /// Address to send the leftovers BTC of the trasnsaction @@ -62,7 +62,7 @@ pub struct CreateCommitTransaction { /// Arguments for creating a reveal transaction pub struct RevealTransactionArgs { /// Transaction input (output of commit transaction) - pub input: TxInput, + pub input: Utxo, /// Recipient address of the inscription, only support P2PKH pub recipient_address: Address, /// The redeem script returned by `create_commit_transaction` @@ -306,8 +306,9 @@ impl OrdTransactionBuilder { } } +/// Unspent transaction output to be used as input of a transaction #[derive(Debug, Clone)] -pub struct TxInput { +pub struct Utxo { pub id: Txid, pub index: u32, pub amount: Amount, @@ -349,7 +350,7 @@ mod test { let mut builder = OrdTransactionBuilder::p2wsh(private_key); let commit_transaction_args = CreateCommitTransactionArgs { - inputs: vec![TxInput { + inputs: vec![Utxo { id: Txid::from_str( "791b415dc6946d864d368a0e5ec5c09ee2ad39cf298bc6e3f9aec293732cfda7", ) @@ -410,7 +411,7 @@ mod test { let reveal_transaction = builder .build_reveal_transaction(RevealTransactionArgs { - input: TxInput { + input: Utxo { id: tx_id, index: 0, amount: tx_result.reveal_balance, @@ -453,7 +454,7 @@ mod test { let mut builder = OrdTransactionBuilder::p2tr(private_key); let commit_transaction_args = CreateCommitTransactionArgs { - inputs: vec![TxInput { + inputs: vec![Utxo { id: Txid::from_str( "791b415dc6946d864d368a0e5ec5c09ee2ad39cf298bc6e3f9aec293732cfda7", ) @@ -505,7 +506,7 @@ mod test { let reveal_transaction = builder .build_reveal_transaction(RevealTransactionArgs { - input: TxInput { + input: Utxo { id: tx_id, index: 0, amount: tx_result.reveal_balance, diff --git a/src/wallet/builder/signer.rs b/src/wallet/builder/signer.rs index af9a385..097f74e 100644 --- a/src/wallet/builder/signer.rs +++ b/src/wallet/builder/signer.rs @@ -8,7 +8,7 @@ use bitcoin::{ PrivateKey, PublicKey, ScriptBuf, TapLeafHash, TapSighashType, Transaction, Witness, }; -use super::super::builder::TxInput; +use super::super::builder::Utxo; use super::taproot::TaprootPayload; use crate::{OrdError, OrdResult}; @@ -58,7 +58,7 @@ impl Wallet { pub async fn sign_commit_transaction( &mut self, own_pubkey: &PublicKey, - inputs: &[TxInput], + inputs: &[Utxo], transaction: Transaction, txin_script: &ScriptBuf, ) -> OrdResult { @@ -75,7 +75,7 @@ impl Wallet { pub async fn sign_reveal_transaction_ecdsa( &mut self, own_pubkey: &PublicKey, - input: &TxInput, + input: &Utxo, transaction: Transaction, redeem_script: &bitcoin::ScriptBuf, ) -> OrdResult { @@ -134,7 +134,7 @@ impl Wallet { async fn sign_ecdsa( &mut self, own_pubkey: &PublicKey, - utxos: &[TxInput], + utxos: &[Utxo], transaction: Transaction, script: &ScriptBuf, transaction_type: TransactionType,