From 780dcc99c70b86d84440fe0e02c0c911ea321b7d Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Mon, 12 Jun 2023 17:18:56 -0300 Subject: [PATCH 1/3] wip: add validation --- src/subcommand/wallet/inscribe.rs | 54 +++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/src/subcommand/wallet/inscribe.rs b/src/subcommand/wallet/inscribe.rs index a9c2cd867a..6209dc361c 100644 --- a/src/subcommand/wallet/inscribe.rs +++ b/src/subcommand/wallet/inscribe.rs @@ -1,4 +1,9 @@ -use bitcoin::SchnorrSig; +use std::process::exit; + +use bitcoin::{ + util::amount::serde::{as_btc::opt::serialize, as_sat::serialize}, + SchnorrSig, +}; use bitcoincore_rpc::RawTx; use { @@ -198,31 +203,46 @@ impl Inscribe { Inscribe::backup_recovery_key(&client, recovery_key_pair, options.chain().network())?; } - let commit = if let Some(commit) = self.commit { - commit.txid - } else { - let signed_raw_commit_tx = client + let commit_to_broadcast: Option<&Vec>; + let reveal_to_broadcast: Option<&Vec>; + let commit: Txid; + let reveal_txid: Txid; + + if self.commit.is_none() { + let signed_commit = client .sign_raw_transaction_with_wallet(&unsigned_commit_tx, None, None)? .hex; - client - .send_raw_transaction(&signed_raw_commit_tx) - .context("Failed to send commit transaction")? - }; + commit_to_broadcast = Some(&signed_commit); + } else { + commit = self.commit.unwrap().txid; + } - let reveal = if self.parent.is_some() { + if self.parent.is_some() { let fully_signed_raw_reveal_tx = client .sign_raw_transaction_with_wallet(&partially_signed_reveal_tx, None, None)? .hex; - client - .send_raw_transaction(&fully_signed_raw_reveal_tx) - .context("Failed to send reveal transaction")? + reveal_to_broadcast = Some(&fully_signed_raw_reveal_tx); } else { - client - .send_raw_transaction(&partially_signed_reveal_tx) - .context("Failed to send reveal transaction")? - }; + let signed_reveal = hex::decode(partially_signed_reveal_tx.raw_hex())?; + reveal_to_broadcast = Some(&signed_reveal); + } + + let txns_to_broadcast: Vec<&Vec>; + + if let Some(commit) = commit_to_broadcast { + txns_to_broadcast.push(commit); + } + if let Some(reveal) = reveal_to_broadcast { + txns_to_broadcast.push(reveal); + } + + let test_mempool_accept = client.test_mempool_accept(txns_to_broadcast.as_slice())?; + + print_json(test_mempool_accept)?; + + //exit(1); let inscription = InscriptionId { txid: reveal, From 11d329c969d3c8ffc536376cbb465278ce0a87ff Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Mon, 12 Jun 2023 17:55:24 -0300 Subject: [PATCH 2/3] fix cmd --- src/subcommand/wallet/inscribe.rs | 52 ++++++++++++++++++------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/subcommand/wallet/inscribe.rs b/src/subcommand/wallet/inscribe.rs index 6209dc361c..4456baa003 100644 --- a/src/subcommand/wallet/inscribe.rs +++ b/src/subcommand/wallet/inscribe.rs @@ -1,9 +1,4 @@ -use std::process::exit; - -use bitcoin::{ - util::amount::serde::{as_btc::opt::serialize, as_sat::serialize}, - SchnorrSig, -}; +use bitcoin::SchnorrSig; use bitcoincore_rpc::RawTx; use { @@ -203,19 +198,17 @@ impl Inscribe { Inscribe::backup_recovery_key(&client, recovery_key_pair, options.chain().network())?; } - let commit_to_broadcast: Option<&Vec>; - let reveal_to_broadcast: Option<&Vec>; + let mut commit_to_broadcast: Option> = None; + let reveal_to_broadcast: Vec; let commit: Txid; - let reveal_txid: Txid; + let reveal: Txid; if self.commit.is_none() { let signed_commit = client .sign_raw_transaction_with_wallet(&unsigned_commit_tx, None, None)? .hex; - commit_to_broadcast = Some(&signed_commit); - } else { - commit = self.commit.unwrap().txid; + commit_to_broadcast = Some(signed_commit); } if self.parent.is_some() { @@ -223,26 +216,43 @@ impl Inscribe { .sign_raw_transaction_with_wallet(&partially_signed_reveal_tx, None, None)? .hex; - reveal_to_broadcast = Some(&fully_signed_raw_reveal_tx); + reveal_to_broadcast = fully_signed_raw_reveal_tx; } else { let signed_reveal = hex::decode(partially_signed_reveal_tx.raw_hex())?; - reveal_to_broadcast = Some(&signed_reveal); + reveal_to_broadcast = signed_reveal; } - let txns_to_broadcast: Vec<&Vec>; + let mut txns_to_broadcast: Vec<&Vec> = Vec::new(); - if let Some(commit) = commit_to_broadcast { + if let Some(commit) = &commit_to_broadcast { txns_to_broadcast.push(commit); } - if let Some(reveal) = reveal_to_broadcast { - txns_to_broadcast.push(reveal); - } + + txns_to_broadcast.push(&reveal_to_broadcast); let test_mempool_accept = client.test_mempool_accept(txns_to_broadcast.as_slice())?; + let is_mempool_accepted = test_mempool_accept + .clone() + .into_iter() + .map(|x| x.allowed) + .fold(true, |acc, item| acc && item); + + if !is_mempool_accepted { + print_json(test_mempool_accept)?; + bail!("testmempoolaccept failed!"); + } - print_json(test_mempool_accept)?; + commit = if let Some(commit) = commit_to_broadcast { + client + .send_raw_transaction(&commit) + .context("Failed to send commit transaction")? + } else { + self.commit.unwrap().txid + }; - //exit(1); + reveal = client + .send_raw_transaction(&reveal_to_broadcast) + .context("Failed to send reveal transaction")?; let inscription = InscriptionId { txid: reveal, From 8c0b40470c189f906f0f032cc0b480afd2312648 Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Mon, 12 Jun 2023 18:11:05 -0300 Subject: [PATCH 3/3] add expect --- src/subcommand/wallet/inscribe.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/subcommand/wallet/inscribe.rs b/src/subcommand/wallet/inscribe.rs index 4456baa003..22a467cde3 100644 --- a/src/subcommand/wallet/inscribe.rs +++ b/src/subcommand/wallet/inscribe.rs @@ -230,7 +230,9 @@ impl Inscribe { txns_to_broadcast.push(&reveal_to_broadcast); - let test_mempool_accept = client.test_mempool_accept(txns_to_broadcast.as_slice())?; + let test_mempool_accept = client + .test_mempool_accept(txns_to_broadcast.as_slice()) + .expect("Failed to test mempool accept"); let is_mempool_accepted = test_mempool_accept .clone() .into_iter()