Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/split build and sign for commit tx #17

Merged
merged 16 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions examples/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use argh::FromArgs;
use bitcoin::secp256k1::Secp256k1;
use bitcoin::{Address, Network, PrivateKey};
use log::{debug, info};
use ord_rs::wallet::{CreateCommitTransactionArgsV2, RevealTransactionArgs};
use ord_rs::wallet::{
CreateCommitTransactionArgsV2, RevealTransactionArgs, SignCommitTransactionArgs,
};
use ord_rs::{Brc20, OrdTransactionBuilder};
use utils::rpc_client;

Expand Down Expand Up @@ -83,26 +85,37 @@ async fn main() -> anyhow::Result<()> {
_ => panic!("invalid script type"),
};

let commit_tx = builder
.build_commit_transaction_with_fixed_fees(
network,
CreateCommitTransactionArgsV2 {
let commit_tx = builder.build_commit_transaction_with_fixed_fees(
network,
CreateCommitTransactionArgsV2 {
inputs: inputs.clone(),
inscription: Brc20::deploy(ticker, amount, Some(limit), None),
txin_script_pubkey: sender_address.script_pubkey(),
leftovers_recipient: sender_address.clone(),
commit_fee,
reveal_fee,
},
)?;
let signed_commit_tx = builder
.sign_commit_transaction(
commit_tx.unsigned_tx,
SignCommitTransactionArgs {
inputs,
inscription: Brc20::deploy(ticker, amount, Some(limit), None),
txin_script_pubkey: sender_address.script_pubkey(),
leftovers_recipient: sender_address.clone(),
commit_fee,
reveal_fee,
},
)
.await?;
debug!("commit transaction: {commit_tx:?}");

debug!("commit transaction: {signed_commit_tx:?}");

let commit_txid = if args.dry_run {
commit_tx.tx.txid()
signed_commit_tx.txid()
} else {
info!("broadcasting Commit transaction: {}", commit_tx.tx.txid());
rpc_client::broadcast_transaction(&commit_tx.tx, network).await?
info!(
"broadcasting Commit transaction: {}",
signed_commit_tx.txid()
);
rpc_client::broadcast_transaction(&signed_commit_tx, network).await?
};
info!("Commit transaction broadcasted: {}", commit_txid);

Expand Down
39 changes: 26 additions & 13 deletions examples/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use argh::FromArgs;
use bitcoin::secp256k1::Secp256k1;
use bitcoin::{Address, Network, PrivateKey};
use log::{debug, info};
use ord_rs::wallet::{CreateCommitTransactionArgsV2, RevealTransactionArgs};
use ord_rs::wallet::{
CreateCommitTransactionArgsV2, RevealTransactionArgs, SignCommitTransactionArgs,
};
use ord_rs::{Brc20, OrdTransactionBuilder};

use self::utils::rpc_client;
Expand Down Expand Up @@ -78,26 +80,37 @@ async fn main() -> anyhow::Result<()> {
_ => panic!("invalid script type"),
};

let commit_tx = builder
.build_commit_transaction_with_fixed_fees(
network,
CreateCommitTransactionArgsV2 {
let commit_tx = builder.build_commit_transaction_with_fixed_fees(
network,
CreateCommitTransactionArgsV2 {
inputs: inputs.clone(),
inscription: Brc20::mint(ticker, amount),
txin_script_pubkey: sender_address.script_pubkey(),
leftovers_recipient: sender_address.clone(),
commit_fee,
reveal_fee,
},
)?;

let signed_commit_tx = builder
.sign_commit_transaction(
commit_tx.unsigned_tx,
SignCommitTransactionArgs {
inputs,
inscription: Brc20::mint(ticker, amount),
txin_script_pubkey: sender_address.script_pubkey(),
leftovers_recipient: sender_address.clone(),
commit_fee,
reveal_fee,
},
)
.await?;
debug!("commit transaction: {commit_tx:?}");
debug!("commit transaction: {signed_commit_tx:?}");

let commit_txid = if args.dry_run {
commit_tx.tx.txid()
signed_commit_tx.txid()
} else {
info!("broadcasting Commit transaction: {}", commit_tx.tx.txid());
rpc_client::broadcast_transaction(&commit_tx.tx, network).await?
info!(
"broadcasting Commit transaction: {}",
signed_commit_tx.txid()
);
rpc_client::broadcast_transaction(&signed_commit_tx, network).await?
};
info!("Commit transaction broadcasted: {}", commit_txid);

Expand Down
39 changes: 26 additions & 13 deletions examples/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use argh::FromArgs;
use bitcoin::secp256k1::Secp256k1;
use bitcoin::{Address, Network, PrivateKey};
use log::{debug, info};
use ord_rs::wallet::{CreateCommitTransactionArgsV2, RevealTransactionArgs};
use ord_rs::wallet::{
CreateCommitTransactionArgsV2, RevealTransactionArgs, SignCommitTransactionArgs,
};
use ord_rs::{Brc20, OrdTransactionBuilder};

use self::utils::rpc_client;
Expand Down Expand Up @@ -77,26 +79,37 @@ async fn main() -> anyhow::Result<()> {
_ => panic!("invalid script type"),
};

let commit_tx = builder
.build_commit_transaction_with_fixed_fees(
network,
CreateCommitTransactionArgsV2 {
let commit_tx = builder.build_commit_transaction_with_fixed_fees(
network,
CreateCommitTransactionArgsV2 {
inputs: inputs.clone(),
inscription: Brc20::transfer(ticker, amount),
txin_script_pubkey: sender_address.script_pubkey(),
leftovers_recipient: sender_address.clone(),
commit_fee,
reveal_fee,
},
)?;
debug!("commit transaction: {commit_tx:?}");

let signed_commit_tx = builder
.sign_commit_transaction(
commit_tx.unsigned_tx,
SignCommitTransactionArgs {
inputs,
inscription: Brc20::transfer(ticker, amount),
txin_script_pubkey: sender_address.script_pubkey(),
leftovers_recipient: sender_address.clone(),
commit_fee,
reveal_fee,
},
)
.await?;
debug!("commit transaction: {commit_tx:?}");

let commit_txid = if args.dry_run {
commit_tx.tx.txid()
signed_commit_tx.txid()
} else {
info!("broadcasting Commit transaction: {}", commit_tx.tx.txid());
rpc_client::broadcast_transaction(&commit_tx.tx, network).await?
info!(
"broadcasting Commit transaction: {}",
signed_commit_tx.txid()
);
rpc_client::broadcast_transaction(&signed_commit_tx, network).await?
};
info!("Commit transaction broadcasted: {}", commit_txid);

Expand Down
4 changes: 0 additions & 4 deletions rust-toolchain.toml

This file was deleted.

4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ pub use inscription::brc20::Brc20;
pub use inscription::nft::Nft;
pub use inscription::Inscription;
pub use result::OrdResult;
pub use utils::constants;
pub use utils::fees::{self, MultisigConfig};
pub use wallet::{
CreateCommitTransaction, CreateCommitTransactionArgs, ExternalSigner, OrdParser,
OrdTransactionBuilder, RevealTransactionArgs, Utxo, Wallet, WalletType,
OrdTransactionBuilder, RevealTransactionArgs, SignCommitTransactionArgs, Utxo, Wallet,
WalletType,
};
3 changes: 2 additions & 1 deletion src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod parser;
pub use builder::signer::{ExternalSigner, Wallet, WalletType};
pub use builder::{
CreateCommitTransaction, CreateCommitTransactionArgs, CreateCommitTransactionArgsV2,
OrdTransactionBuilder, RedeemScriptPubkey, RevealTransactionArgs, ScriptType, Utxo,
OrdTransactionBuilder, RedeemScriptPubkey, RevealTransactionArgs, ScriptType,
SignCommitTransactionArgs, Utxo,
};
pub use parser::OrdParser;
Loading
Loading