Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mainnet restrictions #1170

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 4 additions & 24 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,35 +135,15 @@ impl Options {
Ok(client)
}

pub(crate) fn bitcoin_rpc_client_mainnet_forbidden(&self, command: &str) -> Result<Client> {
let client = self.bitcoin_rpc_client()?;

if self.chain() == Chain::Mainnet {
bail!("`{command}` is unstable and not yet supported on mainnet.");
}
Ok(client)
}

pub(crate) fn bitcoin_rpc_client_for_wallet_command(&self, command: &str) -> Result<Client> {
let client = self.bitcoin_rpc_client()?;

if self.chain() == Chain::Mainnet {
let wallet_info = client.get_wallet_info()?;

if !(wallet_info.wallet_name == "ord" || wallet_info.wallet_name.starts_with("ord-")) {
bail!("`{command}` may only be used on mainnet with a wallet named `ord` or whose name starts with `ord-`");
}

let balances = client.get_balances()?;
let wallet_info = client.get_wallet_info()?;

let total = balances.mine.trusted + balances.mine.untrusted_pending + balances.mine.immature;

if total > Amount::from_sat(1_000_000) {
bail!(
"`{command}` may not be used on mainnet with wallets containing more than 1,000,000 sats"
);
}
if !(wallet_info.wallet_name == "ord" || wallet_info.wallet_name.starts_with("ord-")) {
bail!("`{command}` may only be used on mainnet with a wallet named `ord` or whose name starts with `ord-`");
}

Ok(client)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/wallet/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::*;

pub(crate) fn run(options: Options) -> Result {
options
.bitcoin_rpc_client_mainnet_forbidden("ord wallet create")?
.bitcoin_rpc_client()?
.create_wallet("ord", None, None, None, None)?;
Ok(())
}
2 changes: 1 addition & 1 deletion src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub(crate) struct Inscribe {

impl Inscribe {
pub(crate) fn run(self, options: Options) -> Result {
let client = options.bitcoin_rpc_client_mainnet_forbidden("ord wallet inscribe")?;
let client = options.bitcoin_rpc_client_for_wallet_command("ord wallet inscribe")?;

let bitcoin_version = client.version()?;
if bitcoin_version < MIN_BITCOIN_VERSION {
Expand Down
26 changes: 0 additions & 26 deletions tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,6 @@ fn send_on_mainnnet_works_with_wallet_whose_name_starts_with_ord() {
assert_eq!(format!("{}\n", txid), stdout);
}

#[test]
fn send_on_mainnnet_refuses_to_work_with_wallet_with_high_balance() {
let rpc_server = test_bitcoincore_rpc::builder().build();
let txid = rpc_server.mine_blocks_with_subsidy(1, 1_000_001)[0].txdata[0].txid();

CommandBuilder::new(format!("wallet send ord1qcqgs2pps4u4yedfyl5pysdjjncs8et5u8gcumw {txid}:0:0"))
.rpc_server(&rpc_server)
.expected_stderr(
"error: `ord wallet send` may not be used on mainnet with wallets containing more than 1,000,000 sats\n",
)
.expected_exit_code(1)
.run();
}

#[test]
fn inscribe_fails_if_bitcoin_core_is_too_old() {
let rpc_server = test_bitcoincore_rpc::builder()
Expand Down Expand Up @@ -279,18 +265,6 @@ fn inscribe_no_backup() {
assert_eq!(rpc_server.descriptors(), 0);
}

#[test]
fn inscribe_forbidden_on_mainnet() {
let rpc_server = test_bitcoincore_rpc::builder().build();
let txid = rpc_server.mine_blocks(1)[0].txdata[0].txid();

CommandBuilder::new(format!("wallet inscribe --satpoint {txid}:0:0 hello.txt"))
.rpc_server(&rpc_server)
.expected_exit_code(1)
.expected_stderr("error: `ord wallet inscribe` is unstable and not yet supported on mainnet.\n")
.run();
}

#[test]
fn inscribe() {
let rpc_server = test_bitcoincore_rpc::builder()
Expand Down