Skip to content

Commit

Permalink
Merge pull request #9 from bitfinity-network/rename-txinput-to-utxo
Browse files Browse the repository at this point in the history
fix: renamed TxInput to Utxo
  • Loading branch information
kobby-pentangeli committed Mar 12, 2024
2 parents 0139d4e + 47fca1d commit d72d482
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion examples/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions examples/utils/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -43,7 +43,7 @@ pub async fn broadcast_transaction(
pub async fn sats_amount_from_tx_inputs(
inputs: &[(Txid, u32)],
network: Network,
) -> anyhow::Result<Vec<TxInput>> {
) -> anyhow::Result<Vec<Utxo>> {
let mut output_inputs = Vec::with_capacity(inputs.len());
for (txid, index) in inputs {
let tx = get_tx_by_hash(txid, network).await?;
Expand All @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions examples/utils/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ 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)]
pub fn spend_utxo_transaction(
private_key: &PrivateKey,
recipient: Address,
utxo_value: Amount,
inputs: Vec<TxInput>,
inputs: Vec<Utxo>,
fee: Amount,
) -> anyhow::Result<Transaction> {
let secp = Secp256k1::new();
Expand Down Expand Up @@ -74,7 +74,7 @@ fn sign_transaction(
unsigned_tx: Transaction,
private_key: &PrivateKey,
secp: &Secp256k1<secp256k1::All>,
inputs: Vec<TxInput>,
inputs: Vec<Utxo>,
sender_script_pubkey: &ScriptBuf,
) -> anyhow::Result<Transaction> {
let mut hash = SighashCache::new(unsigned_tx);
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
2 changes: 1 addition & 1 deletion src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
17 changes: 9 additions & 8 deletions src/wallet/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub struct CreateCommitTransactionArgs<T>
where
T: Inscription,
{
/// Inputs of the transaction
pub inputs: Vec<TxInput>,
/// UTXOs to be used as Inputs of the transaction
pub inputs: Vec<Utxo>,
/// Inscription to write
pub inscription: T,
/// Address to send the leftovers BTC of the trasnsaction
Expand All @@ -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`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
)
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/wallet/builder/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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<Transaction> {
Expand All @@ -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<Transaction> {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d72d482

Please sign in to comment.