Skip to content

Commit

Permalink
Add ord wallet split command for splitting utxos (#4030)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Oct 30, 2024
1 parent cfc4de3 commit acf18ca
Show file tree
Hide file tree
Showing 25 changed files with 2,083 additions and 161 deletions.
15 changes: 15 additions & 0 deletions splits.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# example split file

# output fields:
# address: output recipient bitcoin address
# value: output bitcoin value (optional, defaults to minimal-non dust value for `address`)
# runes: output rune value map (values respect rune divisibility)
outputs:
- address: bc1p5d7rjq7g6rdk2yhzks9smlaqtedr4dekq08ge8ztwac72sfr9rusxg3297
value: 10 sat
runes:
UNCOMMON•GOODS: 1234
GRIEF•WAGE: 5000000
- address: 3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy
runes:
HELLO•WORLD: 22.5
2 changes: 1 addition & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ impl Index {
}

pub fn export(&self, filename: &String, include_addresses: bool) -> Result {
let mut writer = BufWriter::new(fs::File::create(filename)?);
let mut writer = BufWriter::new(File::create(filename)?);
let rtx = self.database.begin_read()?;

let blocks_indexed = rtx
Expand Down
1 change: 0 additions & 1 deletion src/inscriptions/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use {
self, BROTLI_MODE_FONT as FONT, BROTLI_MODE_GENERIC as GENERIC, BROTLI_MODE_TEXT as TEXT,
},
mp4::{MediaType, Mp4Reader, TrackType},
std::{fs::File, io::BufReader},
};

#[derive(Debug, PartialEq, Copy, Clone)]
Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use {
consensus::{self, Decodable, Encodable},
hash_types::{BlockHash, TxMerkleNode},
hashes::Hash,
policy::MAX_STANDARD_TX_WEIGHT,
script,
transaction::Version,
Amount, Block, Network, OutPoint, Script, ScriptBuf, Sequence, Transaction, TxIn, TxOut, Txid,
Expand All @@ -52,7 +53,7 @@ use {
clap::{ArgGroup, Parser},
error::{ResultExt, SnafuError},
html_escaper::{Escape, Trusted},
http::HeaderMap,
http::{HeaderMap, StatusCode},
lazy_static::lazy_static,
ordinals::{
varint, Artifact, Charm, Edict, Epoch, Etching, Height, Pile, Rarity, Rune, RuneId, Runestone,
Expand All @@ -70,8 +71,8 @@ use {
env,
ffi::OsString,
fmt::{self, Display, Formatter},
fs,
io::{self, Cursor, Read},
fs::{self, File},
io::{self, BufReader, Cursor, Read},
mem,
net::ToSocketAddrs,
path::{Path, PathBuf},
Expand Down
4 changes: 2 additions & 2 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Settings {
};

let config = if let Some(config_path) = config_path {
serde_yaml::from_reader(fs::File::open(&config_path).context(anyhow!(
serde_yaml::from_reader(File::open(&config_path).context(anyhow!(
"failed to open config file `{}`",
config_path.display()
))?)
Expand Down Expand Up @@ -994,7 +994,7 @@ mod tests {

#[test]
fn example_config_file_is_valid() {
let _: Settings = serde_yaml::from_reader(fs::File::open("ord.yaml").unwrap()).unwrap();
let _: Settings = serde_yaml::from_reader(File::open("ord.yaml").unwrap()).unwrap();
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Decode {
.bitcoin_rpc_client(None)?
.get_raw_transaction(&txid, None)?
} else if let Some(file) = self.file {
Transaction::consensus_decode(&mut io::BufReader::new(fs::File::open(file)?))?
Transaction::consensus_decode(&mut io::BufReader::new(File::open(file)?))?
} else {
Transaction::consensus_decode(&mut io::BufReader::new(io::stdin()))?
};
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ rpcport={bitcoind_port}
}

serde_json::to_writer_pretty(
fs::File::create(self.directory.join("env.json"))?,
File::create(self.directory.join("env.json"))?,
&Info {
bitcoind_port,
ord_port,
Expand Down
4 changes: 4 additions & 0 deletions src/subcommand/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub mod sats;
pub mod send;
mod shared_args;
pub mod sign;
pub mod split;
pub mod transactions;

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -85,6 +86,8 @@ pub(crate) enum Subcommand {
Send(send::Send),
#[command(about = "Sign message")]
Sign(sign::Sign),
#[command(about = "Split outputs")]
Split(split::Split),
#[command(about = "See wallet transactions")]
Transactions(transactions::Transactions),
}
Expand Down Expand Up @@ -131,6 +134,7 @@ impl WalletCommand {
Subcommand::Sats(sats) => sats.run(wallet),
Subcommand::Send(send) => send.run(wallet),
Subcommand::Sign(sign) => sign.run(wallet),
Subcommand::Split(split) => split.run(wallet),
Subcommand::Transactions(transactions) => transactions.run(wallet),
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/subcommand/wallet/batch_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ pub(crate) struct Batch {
shared: SharedArgs,
#[arg(
long,
help = "Inscribe multiple inscriptions and rune defined in YAML <BATCH_FILE>."
help = "Inscribe multiple inscriptions and rune defined in YAML <BATCH_FILE>.",
value_name = "BATCH_FILE"
)]
pub(crate) batch: PathBuf,
}
Expand Down
3 changes: 2 additions & 1 deletion src/subcommand/wallet/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ impl Burn {
self.fee_rate,
)?;

let (txid, psbt, fee) = wallet.sign_transaction(unsigned_transaction, self.dry_run)?;
let (txid, psbt, fee) =
wallet.sign_and_broadcast_transaction(unsigned_transaction, self.dry_run)?;

Ok(Some(Box::new(send::Output {
txid,
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl Inscribe {
Ok(Some(cbor))
} else if let Some(path) = json {
let value: serde_json::Value =
serde_json::from_reader(fs::File::open(path)?).context("failed to parse JSON metadata")?;
serde_json::from_reader(File::open(path)?).context("failed to parse JSON metadata")?;
let mut cbor = Vec::new();
ciborium::into_writer(&value, &mut cbor)?;

Expand Down
21 changes: 11 additions & 10 deletions src/subcommand/wallet/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ impl Send {
)?,
};

let (txid, psbt, fee) = wallet.sign_transaction(unsigned_transaction, self.dry_run)?;
let (txid, psbt, fee) =
wallet.sign_and_broadcast_transaction(unsigned_transaction, self.dry_run)?;

Ok(Some(Box::new(Output {
txid,
Expand Down Expand Up @@ -213,16 +214,16 @@ impl Send {
}

inputs.push(output);
}
}

if input_rune_balances
.get(&spaced_rune.rune)
.cloned()
.unwrap_or_default()
>= amount
{
break;
if input_rune_balances
.get(&spaced_rune.rune)
.cloned()
.unwrap_or_default()
>= amount
{
break;
}
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/subcommand/wallet/shared_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ pub(super) struct SharedArgs {
#[arg(
long,
alias = "nolimit",
help = "Do not check that transactions are equal to or below the MAX_STANDARD_TX_WEIGHT of 400,000 weight units. Transactions over this limit are currently nonstandard and will not be relayed by bitcoind in its default configuration. Do not use this flag unless you understand the implications."
help = "Allow transactions larger than MAX_STANDARD_TX_WEIGHT of 400,000 weight units and \
OP_RETURNs greater than 83 bytes. Transactions over this limit are nonstandard and will not be \
relayed by bitcoind in its default configuration. Do not use this flag unless you understand \
the implications."
)]
pub(crate) no_limit: bool,
}
Loading

0 comments on commit acf18ca

Please sign in to comment.