Skip to content

Commit

Permalink
Remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Mar 1, 2025
1 parent a6a589a commit 423c776
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 123 deletions.
3 changes: 0 additions & 3 deletions src/subcommand/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ pub mod transactions;
pub(crate) struct WalletCommand {
#[arg(long, default_value = "ord", help = "Use wallet named <WALLET>.")]
pub(crate) name: String,
#[arg(long, alias = "nosync", help = "Do not update index.")]
pub(crate) no_sync: bool,
#[arg(
long,
help = "Use ord running at <SERVER_URL>. [default: http://localhost:80]"
Expand Down Expand Up @@ -106,7 +104,6 @@ impl WalletCommand {

let wallet = WalletConstructor::construct(
self.name.clone(),
self.no_sync,
settings.clone(),
self
.server_url
Expand Down
121 changes: 1 addition & 120 deletions src/wallet/wallet_constructor.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
use super::*;

#[allow(dead_code)]
#[derive(Clone)]
pub(crate) struct WalletConstructor {
ord_client: reqwest::blocking::Client,
name: String,
no_sync: bool,
rpc_url: Url,
settings: Settings,
}

#[allow(dead_code)]
impl WalletConstructor {
pub(crate) fn construct(
name: String,
no_sync: bool,
settings: Settings,
rpc_url: Url,
) -> Result<Wallet> {
pub(crate) fn construct(name: String, settings: Settings, rpc_url: Url) -> Result<Wallet> {
let mut headers = HeaderMap::new();
headers.insert(
reqwest::header::ACCEPT,
Expand All @@ -38,7 +30,6 @@ impl WalletConstructor {
.default_headers(headers.clone())
.build()?,
name,
no_sync,
rpc_url,
settings,
}
Expand Down Expand Up @@ -94,106 +85,6 @@ impl WalletConstructor {
})
}

fn get_output_info(&self, outputs: Vec<OutPoint>) -> Result<BTreeMap<OutPoint, api::Output>> {
let response = self.post("/outputs", &outputs)?;

if !response.status().is_success() {
bail!("wallet failed get outputs: {}", response.text()?);
}

let response_outputs = serde_json::from_str::<Vec<api::Output>>(&response.text()?)?;

ensure! {
response_outputs.len() == outputs.len(),
"unexpected server `/outputs` response length",
}

let output_info: BTreeMap<OutPoint, api::Output> =
outputs.into_iter().zip(response_outputs).collect();

for (output, info) in &output_info {
if !info.indexed {
bail!("output in wallet but not in ord server: {output}");
}
}

Ok(output_info)
}

fn get_inscriptions(
&self,
inscriptions: &Vec<InscriptionId>,
) -> Result<(
BTreeMap<SatPoint, Vec<InscriptionId>>,
BTreeMap<InscriptionId, api::Inscription>,
)> {
let response = self.post("/inscriptions", inscriptions)?;

if !response.status().is_success() {
bail!("wallet failed get inscriptions: {}", response.text()?);
}

let mut inscriptions = BTreeMap::new();
let mut inscription_infos = BTreeMap::new();
for info in serde_json::from_str::<Vec<api::Inscription>>(&response.text()?)? {
inscriptions
.entry(info.satpoint)
.or_insert_with(Vec::new)
.push(info.id);

inscription_infos.insert(info.id, info);
}

Ok((inscriptions, inscription_infos))
}

fn get_utxos(bitcoin_client: &Client) -> Result<BTreeMap<OutPoint, TxOut>> {
Ok(
bitcoin_client
.list_unspent(None, None, None, None, None)?
.into_iter()
.map(|utxo| {
let outpoint = OutPoint::new(utxo.txid, utxo.vout);
let txout = TxOut {
script_pubkey: utxo.script_pub_key,
value: utxo.amount,
};

(outpoint, txout)
})
.collect(),
)
}

fn get_locked_utxos(bitcoin_client: &Client) -> Result<BTreeMap<OutPoint, TxOut>> {
#[derive(Deserialize)]
pub(crate) struct JsonOutPoint {
txid: Txid,
vout: u32,
}

let outpoints = bitcoin_client.call::<Vec<JsonOutPoint>>("listlockunspent", &[])?;

let mut utxos = BTreeMap::new();

for outpoint in outpoints {
let Some(tx_out) = bitcoin_client.get_tx_out(&outpoint.txid, outpoint.vout, Some(false))?
else {
continue;
};

utxos.insert(
OutPoint::new(outpoint.txid, outpoint.vout),
TxOut {
value: tx_out.value,
script_pubkey: ScriptBuf::from_bytes(tx_out.script_pub_key.hex),
},
);
}

Ok(utxos)
}

fn get_server_status(&self) -> Result<api::Status> {
let response = self.get("/status")?;

Expand All @@ -211,14 +102,4 @@ impl WalletConstructor {
.send()
.map_err(|err| anyhow!(err))
}

pub fn post(&self, path: &str, body: &impl Serialize) -> Result<reqwest::blocking::Response> {
self
.ord_client
.post(self.rpc_url.join(path)?)
.json(body)
.header(reqwest::header::ACCEPT, "application/json")
.send()
.map_err(|err| anyhow!(err))
}
}

0 comments on commit 423c776

Please sign in to comment.