Skip to content

Commit

Permalink
Mint with destination (#3497)
Browse files Browse the repository at this point in the history
  • Loading branch information
ynohtna92 authored Apr 11, 2024
1 parent 17696f3 commit 02fed68
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/subcommand/wallet/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub(crate) struct Mint {
fee_rate: FeeRate,
#[clap(long, help = "Mint <RUNE>. May contain `.` or `•`as spacers.")]
rune: SpacedRune,
#[clap(long, help = "Send minted runes to <DESTINATION>.")]
destination: Option<Address<NetworkUnchecked>>,
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -36,7 +38,12 @@ impl Mint {
.mintable(block_height)
.map_err(|err| anyhow!("rune {rune} {err}"))?;

let destination = wallet.get_change_address()?;
let chain = wallet.chain();

let destination = match self.destination {
Some(destination) => destination.require_network(chain.network())?,
None => wallet.get_change_address()?,
};

let runestone = Runestone {
mint: Some(id),
Expand Down
105 changes: 105 additions & 0 deletions tests/wallet/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,108 @@ fn minting_rune_and_then_sending_works() {
.ord(&ord)
.run_and_deserialize_output::<ord::subcommand::wallet::send::Output>();
}

#[test]
fn minting_rune_with_destination() {
let core = mockcore::builder().network(Network::Regtest).build();

let ord = TestServer::spawn_with_server_args(&core, &["--index-runes", "--regtest"], &[]);

core.mine_blocks(1);

create_wallet(&core, &ord);

batch(
&core,
&ord,
batch::File {
etching: Some(batch::Etching {
divisibility: 0,
rune: SpacedRune {
rune: Rune(RUNE),
spacers: 0,
},
premine: "0".parse().unwrap(),
supply: "21".parse().unwrap(),
symbol: '¢',
turbo: false,
terms: Some(batch::Terms {
cap: 1,
offset: Some(batch::Range {
end: Some(10),
start: None,
}),
amount: "21".parse().unwrap(),
height: None,
}),
}),
inscriptions: vec![batch::Entry {
file: Some("inscription.jpeg".into()),
..default()
}],
..default()
},
);

let destination: Address<NetworkUnchecked> = "bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw"
.parse()
.unwrap();

let output = CommandBuilder::new(format!(
"--chain regtest --index-runes wallet mint --fee-rate 1 --rune {} --destination {}",
Rune(RUNE),
destination.clone().assume_checked()
))
.core(&core)
.ord(&ord)
.run_and_deserialize_output::<mint::Output>();

pretty_assert_eq!(
output.pile,
Pile {
amount: 21,
divisibility: 0,
symbol: Some('¢'),
}
);

assert_eq!(
core.mempool()[0].output[1].script_pubkey,
destination.payload.script_pubkey()
);

core.mine_blocks(1);

let balance = CommandBuilder::new("--chain regtest --index-runes wallet balance")
.core(&core)
.ord(&ord)
.run_and_deserialize_output::<ord::subcommand::wallet::balance::Output>();

assert_eq!(balance.runic, Some(0));

assert_eq!(
CommandBuilder::new("--regtest --index-runes balances")
.core(&core)
.run_and_deserialize_output::<ord::subcommand::balances::Output>(),
ord::subcommand::balances::Output {
runes: vec![(
SpacedRune::new(Rune(RUNE), 0),
vec![(
OutPoint {
txid: output.mint,
vout: 1
},
Pile {
amount: 21,
divisibility: 0,
symbol: Some('¢')
},
)]
.into_iter()
.collect()
)]
.into_iter()
.collect(),
}
);
}

0 comments on commit 02fed68

Please sign in to comment.