From 57eca8d015f503ea64e88be16b0081a35897b594 Mon Sep 17 00:00:00 2001 From: raph Date: Mon, 25 Mar 2024 20:12:46 +0100 Subject: [PATCH] Disambiguate when sending runes (#3368) --- src/outgoing.rs | 26 +++++++++++++------------- tests/wallet/mint.rs | 2 +- tests/wallet/selection.rs | 2 +- tests/wallet/send.rs | 20 ++++++++++---------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/outgoing.rs b/src/outgoing.rs index 538ca21265..f1cad9acde 100644 --- a/src/outgoing.rs +++ b/src/outgoing.rs @@ -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), } @@ -36,7 +36,7 @@ impl FromStr for Outgoing { | \d+\.\d+ ) - \ * + \ ? (bit|btc|cbtc|mbtc|msat|nbtc|pbtc|sat|satoshi|ubtc) (s)? $ @@ -53,7 +53,7 @@ impl FromStr for Outgoing { | \d+\.\d+ ) - \ * + \s*:\s* ( [A-Z•.]+ ) @@ -120,7 +120,7 @@ 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(), @@ -128,7 +128,7 @@ mod tests { ); case( - "0XYZ", + "0:XYZ", Outgoing::Rune { rune: "XYZ".parse().unwrap(), decimal: "0".parse().unwrap(), @@ -136,7 +136,7 @@ mod tests { ); case( - "0.0XYZ", + "0.0:XYZ", Outgoing::Rune { rune: "XYZ".parse().unwrap(), decimal: "0.0".parse().unwrap(), @@ -144,7 +144,7 @@ mod tests { ); case( - ".0XYZ", + ".0:XYZ", Outgoing::Rune { rune: "XYZ".parse().unwrap(), decimal: ".0".parse().unwrap(), @@ -152,7 +152,7 @@ mod tests { ); case( - "1.1XYZ", + "1.1:XYZ", Outgoing::Rune { rune: "XYZ".parse().unwrap(), decimal: "1.1".parse().unwrap(), @@ -160,7 +160,7 @@ mod tests { ); case( - "1.1X.Y.Z", + "1.1:X.Y.Z", Outgoing::Rune { rune: "X.Y.Z".parse().unwrap(), decimal: "1.1".parse().unwrap(), @@ -201,7 +201,7 @@ 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(), @@ -209,7 +209,7 @@ mod tests { ); case( - "1.1 XYZ", + "1.1:XYZ", Outgoing::Rune { rune: "XYZ".parse().unwrap(), decimal: "1.1".parse().unwrap(), @@ -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(), diff --git a/tests/wallet/mint.rs b/tests/wallet/mint.rs index 055c21404e..aeeb1440e3 100644 --- a/tests/wallet/mint.rs +++ b/tests/wallet/mint.rs @@ -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) diff --git a/tests/wallet/selection.rs b/tests/wallet/selection.rs index 0a370524ea..85e3bbb099 100644 --- a/tests/wallet/selection.rs +++ b/tests/wallet/selection.rs @@ -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) diff --git a/tests/wallet/send.rs b/tests/wallet/send.rs index bb4bee5708..fbc4e9c1c9 100644 --- a/tests/wallet/send.rs +++ b/tests/wallet/send.rs @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -1045,7 +1045,7 @@ fn sending_rune_creates_transaction_with_expected_runestone() { wallet send --fee-rate 1 - bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 750{} + bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw 750:{} ", Rune(RUNE), )) @@ -1129,7 +1129,7 @@ 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) @@ -1137,7 +1137,7 @@ fn error_messages_use_spaced_runes() { .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)