Skip to content

Commit

Permalink
feat: allow multiple runes in edict txW (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso authored Aug 22, 2024
1 parent 37ee134 commit 661c064
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "ord-rs"
categories = ["cryptography::cryptocurrencies"]
license = "MIT"
version = "0.1.7"
version = "0.2.0"
authors = ["Finity Technologies"]
description = "A library for working with Ordinal inscriptions."
repository = "https://github.com/bitfinity-network/ord-rs"
Expand Down
3 changes: 1 addition & 2 deletions examples/edict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,11 @@ async fn main() -> anyhow::Result<()> {
let destination = Address::from_str(&args.destination)?.assume_checked();

let unsigned_tx = builder.create_edict_transaction(&CreateEdictTxArgs {
rune: args.rune_id,
runes: vec![(args.rune_id, amount)],
inputs: inputs.clone(),
destination,
change_address: sender_address.clone(),
rune_change_address: sender_address,
amount,
fee_rate: FeeRate::from_sat_per_vb(10).unwrap(),
})?;

Expand Down
25 changes: 14 additions & 11 deletions src/wallet/builder/rune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ impl From<Runestone> for OrdRunestone {

/// Arguments for the [`OrdTransactionBuilder::create_edict_transaction`] method.
pub struct CreateEdictTxArgs {
/// Identifier of the rune to be transferred.
pub rune: RuneId,
/// Identifier and amount of the runes to be transferred.
pub runes: Vec<(RuneId, u128)>,
/// Inputs that contain rune and funding BTC balances.
pub inputs: Vec<TxInputInfo>,
/// Address of the recipient of the rune transfer.
Expand All @@ -51,8 +51,6 @@ pub struct CreateEdictTxArgs {
pub change_address: Address,
/// Address that will receive leftovers of runes.
pub rune_change_address: Address,
/// Amount of the rune to be transferred.
pub amount: u128,
/// Current BTC fee rate.
pub fee_rate: FeeRate,
}
Expand Down Expand Up @@ -90,12 +88,18 @@ impl OrdTransactionBuilder {
/// * Returns [`OrdError::InsufficientBalance`] if the inputs BTC amount is not enough
/// to cover the outputs and transaction fee.
pub fn create_edict_transaction(&self, args: &CreateEdictTxArgs) -> OrdResult<Transaction> {
let runestone = OrdRunestone {
edicts: vec![Edict {
id: args.rune,
amount: args.amount,
let edicts = args
.runes
.iter()
.map(|(rune, amount)| Edict {
id: *rune,
amount: *amount,
output: 2,
}],
})
.collect();

let runestone = OrdRunestone {
edicts,
etching: None,
mint: None,
pointer: None,
Expand Down Expand Up @@ -263,7 +267,7 @@ mod tests {
let builder = OrdTransactionBuilder::new(public_key, ScriptType::P2WSH, wallet);

let args = CreateEdictTxArgs {
rune: RuneId::new(219, 1).unwrap(),
runes: vec![(RuneId::new(219, 1).unwrap(), 9500)],
inputs: vec![
TxInputInfo {
outpoint: OutPoint::new(
Expand Down Expand Up @@ -332,7 +336,6 @@ mod tests {
)
.unwrap()
.assume_checked(),
amount: 9500,
fee_rate: FeeRate::from_sat_per_vb(10).unwrap(),
};
let unsigned_tx = builder
Expand Down

0 comments on commit 661c064

Please sign in to comment.