Skip to content

Commit

Permalink
Disambiguate when sending runes (ordinals#3368)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph authored Mar 25, 2024
1 parent 6f7653e commit 5bdbe41
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
26 changes: 13 additions & 13 deletions src/outgoing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Display for Outgoing {
match self {
Self::Amount(amount) => write!(f, "{}", amount.to_string().to_lowercase()),
Self::InscriptionId(inscription_id) => inscription_id.fmt(f),
Self::Rune { decimal, rune } => write!(f, "{decimal} {rune}"),
Self::Rune { decimal, rune } => write!(f, "{decimal}:{rune}"),
Self::Sat(sat) => write!(f, "{}", sat.name()),
Self::SatPoint(satpoint) => satpoint.fmt(f),
}
Expand All @@ -36,7 +36,7 @@ impl FromStr for Outgoing {
|
\d+\.\d+
)
\ *
\ ?
(bit|btc|cbtc|mbtc|msat|nbtc|pbtc|sat|satoshi|ubtc)
(s)?
$
Expand All @@ -53,7 +53,7 @@ impl FromStr for Outgoing {
|
\d+\.\d+
)
\ *
\s*:\s*
(
[A-Z•.]+
)
Expand Down Expand Up @@ -120,47 +120,47 @@ mod tests {
case(".0btc", Outgoing::Amount("0 btc".parse().unwrap()));

case(
"0 XYZ",
"0 : XYZ",
Outgoing::Rune {
rune: "XYZ".parse().unwrap(),
decimal: "0".parse().unwrap(),
},
);

case(
"0XYZ",
"0:XYZ",
Outgoing::Rune {
rune: "XYZ".parse().unwrap(),
decimal: "0".parse().unwrap(),
},
);

case(
"0.0XYZ",
"0.0:XYZ",
Outgoing::Rune {
rune: "XYZ".parse().unwrap(),
decimal: "0.0".parse().unwrap(),
},
);

case(
".0XYZ",
".0:XYZ",
Outgoing::Rune {
rune: "XYZ".parse().unwrap(),
decimal: ".0".parse().unwrap(),
},
);

case(
"1.1XYZ",
"1.1:XYZ",
Outgoing::Rune {
rune: "XYZ".parse().unwrap(),
decimal: "1.1".parse().unwrap(),
},
);

case(
"1.1X.Y.Z",
"1.1:X.Y.Z",
Outgoing::Rune {
rune: "X.Y.Z".parse().unwrap(),
decimal: "1.1".parse().unwrap(),
Expand Down Expand Up @@ -201,15 +201,15 @@ mod tests {
case("1.2 btc", Outgoing::Amount("1.2 btc".parse().unwrap()));

case(
"0 XY•Z",
"0:XY•Z",
Outgoing::Rune {
rune: "XY•Z".parse().unwrap(),
decimal: "0".parse().unwrap(),
},
);

case(
"1.1 XYZ",
"1.1:XYZ",
Outgoing::Rune {
rune: "XYZ".parse().unwrap(),
decimal: "1.1".parse().unwrap(),
Expand Down Expand Up @@ -260,8 +260,8 @@ mod tests {
);

case(
"6.66 HELL.MONEY",
"\"6.66 HELL•MONEY\"",
"6.66:HELL.MONEY",
"\"6.66:HELL•MONEY\"",
Outgoing::Rune {
rune: "HELL•MONEY".parse().unwrap(),
decimal: "6.66".parse().unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion tests/wallet/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ fn minting_rune_and_then_sending_works() {
);

CommandBuilder::new(format!(
"--regtest --index-runes wallet send bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 5{} --fee-rate 1",
"--regtest --index-runes wallet send bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 5:{} --fee-rate 1",
Rune(RUNE)
))
.bitcoin_rpc_server(&bitcoin_rpc_server)
Expand Down
2 changes: 1 addition & 1 deletion tests/wallet/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn sending_rune_does_not_send_inscription() {
wallet send
--fee-rate 0
bcrt1pyrmadgg78e38ewfv0an8c6eppk2fttv5vnuvz04yza60qau5va0saknu8k
1000{rune}
1000:{rune}
",
))
.bitcoin_rpc_server(&bitcoin_rpc_server)
Expand Down
20 changes: 10 additions & 10 deletions tests/wallet/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ fn sending_rune_that_has_not_been_etched_is_an_error() {

bitcoin_rpc_server.lock(outpoint);

CommandBuilder::new("--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 1FOO")
CommandBuilder::new("--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 1:FOO")
.bitcoin_rpc_server(&bitcoin_rpc_server)
.ord_rpc_server(&ord_rpc_server)
.expected_exit_code(1)
Expand All @@ -724,7 +724,7 @@ fn sending_rune_with_excessive_precision_is_an_error() {
etch(&bitcoin_rpc_server, &ord_rpc_server, Rune(RUNE));

CommandBuilder::new(format!(
"--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 1.1{}",
"--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 1.1:{}",
Rune(RUNE)
))
.bitcoin_rpc_server(&bitcoin_rpc_server)
Expand All @@ -748,7 +748,7 @@ fn sending_rune_with_insufficient_balance_is_an_error() {
etch(&bitcoin_rpc_server, &ord_rpc_server, Rune(RUNE));

CommandBuilder::new(format!(
"--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 1001{}",
"--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 1001:{}",
Rune(RUNE)
))
.bitcoin_rpc_server(&bitcoin_rpc_server)
Expand All @@ -772,7 +772,7 @@ fn sending_rune_works() {
etch(&bitcoin_rpc_server, &ord_rpc_server, Rune(RUNE));

let output = CommandBuilder::new(format!(
"--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 1000{}",
"--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 1000:{}",
Rune(RUNE)
))
.bitcoin_rpc_server(&bitcoin_rpc_server)
Expand Down Expand Up @@ -825,7 +825,7 @@ fn sending_spaced_rune_works() {
etch(&bitcoin_rpc_server, &ord_rpc_server, Rune(RUNE));

let output = CommandBuilder::new(
"--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 1000A•AAAAAAAAAAAA",
"--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 1000:A•AAAAAAAAAAAA",
)
.bitcoin_rpc_server(&bitcoin_rpc_server)
.ord_rpc_server(&ord_rpc_server)
Expand Down Expand Up @@ -898,7 +898,7 @@ fn sending_rune_with_divisibility_works() {
);

let output = CommandBuilder::new(format!(
"--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 10.1{}",
"--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 10.1:{}",
rune
))
.bitcoin_rpc_server(&bitcoin_rpc_server)
Expand Down Expand Up @@ -964,7 +964,7 @@ fn sending_rune_leaves_unspent_runes_in_wallet() {
etch(&bitcoin_rpc_server, &ord_rpc_server, Rune(RUNE));

let output = CommandBuilder::new(format!(
"--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 750{}",
"--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 750:{}",
Rune(RUNE)
))
.bitcoin_rpc_server(&bitcoin_rpc_server)
Expand Down Expand Up @@ -1045,7 +1045,7 @@ fn sending_rune_creates_transaction_with_expected_runestone() {
wallet
send
--fee-rate 1
bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 750{}
bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 750:{}
",
Rune(RUNE),
))
Expand Down Expand Up @@ -1129,15 +1129,15 @@ fn error_messages_use_spaced_runes() {
etch(&bitcoin_rpc_server, &ord_rpc_server, Rune(RUNE));

CommandBuilder::new(
"--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 1001A•AAAAAAAAAAAA",
"--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 1001:A•AAAAAAAAAAAA",
)
.bitcoin_rpc_server(&bitcoin_rpc_server)
.ord_rpc_server(&ord_rpc_server)
.expected_exit_code(1)
.expected_stderr("error: insufficient `A•AAAAAAAAAAAA` balance, only 1000\u{A0}¢ in wallet\n")
.run_and_extract_stdout();

CommandBuilder::new("--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 1F•OO")
CommandBuilder::new("--chain regtest --index-runes wallet send --fee-rate 1 bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 1:F•OO")
.bitcoin_rpc_server(&bitcoin_rpc_server)
.ord_rpc_server(&ord_rpc_server)
.expected_exit_code(1)
Expand Down

0 comments on commit 5bdbe41

Please sign in to comment.