Skip to content

Commit 48788ca

Browse files
committed
Cargo fmt pass
1 parent f8de846 commit 48788ca

File tree

7 files changed

+113
-96
lines changed

7 files changed

+113
-96
lines changed

node/src/bin/space-cli.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use jsonrpsee::{
99
};
1010
use protocol::{
1111
bitcoin::{Amount, FeeRate, OutPoint, Txid},
12-
hasher::{KeyHasher},
12+
hasher::KeyHasher,
1313
slabel::SLabel,
1414
};
1515
use serde::{Deserialize, Serialize};
@@ -224,9 +224,7 @@ enum Commands {
224224
},
225225
/// DNS encodes the space and calculates the SHA-256 hash
226226
#[command(name = "hashspace")]
227-
HashSpace {
228-
space: String,
229-
},
227+
HashSpace { space: String },
230228
}
231229

232230
struct SpaceCli {
@@ -395,7 +393,7 @@ async fn handle_commands(
395393
let response = cli.client.get_spaceout(outpoint).await?;
396394
println!("{}", serde_json::to_string_pretty(&response)?);
397395
}
398-
Commands::CreateWallet => {
396+
Commands::CreateWallet => {
399397
cli.client.wallet_create(&cli.wallet).await?;
400398
}
401399
Commands::LoadWallet => {
@@ -410,10 +408,11 @@ async fn handle_commands(
410408
Commands::ExportWallet { path } => {
411409
let result = cli.client.wallet_export(&cli.wallet).await?;
412410
let content = serde_json::to_string_pretty(&result).expect("result");
413-
fs::write(path, content).map_err(|e|
414-
ClientError::Custom(format!("Could not save to path: {}", e.to_string())))?;
411+
fs::write(path, content).map_err(|e| {
412+
ClientError::Custom(format!("Could not save to path: {}", e.to_string()))
413+
})?;
415414
}
416-
Commands::GetWalletInfo => {
415+
Commands::GetWalletInfo => {
417416
let result = cli.client.wallet_get_info(&cli.wallet).await?;
418417
println!("{}", serde_json::to_string_pretty(&result).expect("result"));
419418
}

node/src/rpc.rs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::store::RolloutEntry;
21
use std::{
32
collections::BTreeMap, fs, io::Write, net::SocketAddr, path::PathBuf, str::FromStr, sync::Arc,
43
};
@@ -23,8 +22,9 @@ use protocol::{
2322
OutPoint,
2423
},
2524
constants::ChainAnchor,
26-
hasher::{BaseHash, SpaceKey},
25+
hasher::{BaseHash, KeyHasher, SpaceKey},
2726
prepare::DataSource,
27+
slabel::SLabel,
2828
FullSpaceOut, SpaceOut,
2929
};
3030
use serde::{Deserialize, Serialize};
@@ -33,8 +33,6 @@ use tokio::{
3333
sync::{broadcast, mpsc, oneshot, RwLock},
3434
task::JoinSet,
3535
};
36-
use protocol::hasher::KeyHasher;
37-
use protocol::slabel::SLabel;
3836
use wallet::{
3937
bdk_wallet as bdk, bdk_wallet::template::Bip86, bitcoin::hashes::Hash, export::WalletExport,
4038
DoubleUtxo, SpacesWallet, WalletConfig, WalletDescriptors, WalletInfo,
@@ -44,12 +42,11 @@ use crate::{
4442
config::ExtendedNetwork,
4543
node::{BlockMeta, TxEntry},
4644
source::BitcoinRpc,
47-
store::{ChainState, LiveSnapshot},
45+
store::{ChainState, LiveSnapshot, RolloutEntry, Sha256},
4846
wallets::{
4947
AddressKind, Balance, RpcWallet, TxResponse, WalletCommand, WalletOutput, WalletResponse,
5048
},
5149
};
52-
use crate::store::Sha256;
5350

5451
pub(crate) type Responder<T> = oneshot::Sender<T>;
5552

@@ -59,8 +56,6 @@ pub struct ServerInfo {
5956
pub tip: ChainAnchor,
6057
}
6158

62-
63-
6459
pub enum ChainStateCommand {
6560
GetTip {
6661
resp: Responder<anyhow::Result<ChainAnchor>>,
@@ -107,11 +102,16 @@ pub trait Rpc {
107102
async fn get_server_info(&self) -> Result<ServerInfo, ErrorObjectOwned>;
108103

109104
#[method(name = "getspace")]
110-
async fn get_space(&self, space_or_hash: &str) -> Result<Option<FullSpaceOut>, ErrorObjectOwned>;
105+
async fn get_space(
106+
&self,
107+
space_or_hash: &str,
108+
) -> Result<Option<FullSpaceOut>, ErrorObjectOwned>;
111109

112110
#[method(name = "getspaceowner")]
113-
async fn get_space_owner(&self, space_or_hash: &str)
114-
-> Result<Option<OutPoint>, ErrorObjectOwned>;
111+
async fn get_space_owner(
112+
&self,
113+
space_or_hash: &str,
114+
) -> Result<Option<OutPoint>, ErrorObjectOwned>;
115115

116116
#[method(name = "getspaceout")]
117117
async fn get_spaceout(&self, outpoint: OutPoint) -> Result<Option<SpaceOut>, ErrorObjectOwned>;
@@ -178,7 +178,7 @@ pub trait Rpc {
178178

179179
#[method(name = "walletlistspaces")]
180180
async fn wallet_list_spaces(&self, wallet: &str)
181-
-> Result<Vec<WalletOutput>, ErrorObjectOwned>;
181+
-> Result<Vec<WalletOutput>, ErrorObjectOwned>;
182182

183183
#[method(name = "walletlistunspent")]
184184
async fn wallet_list_unspent(
@@ -187,10 +187,7 @@ pub trait Rpc {
187187
) -> Result<Vec<WalletOutput>, ErrorObjectOwned>;
188188

189189
#[method(name = "walletlistbidouts")]
190-
async fn wallet_list_bidouts(
191-
&self,
192-
wallet: &str,
193-
) -> Result<Vec<DoubleUtxo>, ErrorObjectOwned>;
190+
async fn wallet_list_bidouts(&self, wallet: &str) -> Result<Vec<DoubleUtxo>, ErrorObjectOwned>;
194191

195192
#[method(name = "walletgetbalance")]
196193
async fn wallet_get_balance(&self, wallet: &str) -> Result<Balance, ErrorObjectOwned>;
@@ -573,7 +570,10 @@ impl RpcServer for RpcServerImpl {
573570
Ok(ServerInfo { chain, tip })
574571
}
575572

576-
async fn get_space(&self, space_or_hash: &str) -> Result<Option<FullSpaceOut>, ErrorObjectOwned> {
573+
async fn get_space(
574+
&self,
575+
space_or_hash: &str,
576+
) -> Result<Option<FullSpaceOut>, ErrorObjectOwned> {
577577
let space_hash = get_space_key(space_or_hash)?;
578578

579579
let info = self
@@ -764,10 +764,7 @@ impl RpcServer for RpcServerImpl {
764764
.map_err(|error| ErrorObjectOwned::owned(-1, error.to_string(), None::<String>))
765765
}
766766

767-
async fn wallet_list_bidouts(
768-
&self,
769-
wallet: &str,
770-
) -> Result<Vec<DoubleUtxo>, ErrorObjectOwned> {
767+
async fn wallet_list_bidouts(&self, wallet: &str) -> Result<Vec<DoubleUtxo>, ErrorObjectOwned> {
771768
self.wallet(&wallet)
772769
.await?
773770
.send_list_bidouts()
@@ -992,17 +989,17 @@ impl AsyncChainState {
992989

993990
fn get_space_key(space_or_hash: &str) -> Result<SpaceKey, ErrorObjectOwned> {
994991
if space_or_hash.len() != 64 {
995-
return Ok(
996-
SpaceKey::from(
997-
Sha256::hash(SLabel::try_from(space_or_hash).map_err(|_| {
992+
return Ok(SpaceKey::from(Sha256::hash(
993+
SLabel::try_from(space_or_hash)
994+
.map_err(|_| {
998995
ErrorObjectOwned::owned(
999996
-1,
1000997
"expected a space name prefixed with @ or a hex encoded space hash",
1001998
None::<String>,
1002999
)
1003-
})?.as_ref())
1004-
)
1005-
);
1000+
})?
1001+
.as_ref(),
1002+
)));
10061003
}
10071004

10081005
let mut hash = [0u8; 32];

node/src/store.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ use std::{
1111
use anyhow::Result;
1212
use bincode::{config, Decode, Encode};
1313
use jsonrpsee::core::Serialize;
14+
use protocol::{
15+
bitcoin::OutPoint,
16+
constants::{ChainAnchor, ROLLOUT_BATCH_SIZE},
17+
hasher::{BidKey, KeyHash, OutpointKey, SpaceKey},
18+
prepare::DataSource,
19+
Covenant, FullSpaceOut, SpaceOut,
20+
};
1421
use serde::Deserialize;
15-
use protocol::{bitcoin::OutPoint, constants::{ChainAnchor, ROLLOUT_BATCH_SIZE}, hasher::{BidKey, KeyHash, OutpointKey, SpaceKey}, prepare::DataSource, Covenant, FullSpaceOut, SpaceOut};
1622
use spacedb::{
1723
db::{Database, SnapshotIterator},
1824
fs::FileBackend,
@@ -23,7 +29,7 @@ use spacedb::{
2329
#[derive(Debug, Clone, Serialize, Deserialize)]
2430
pub struct RolloutEntry {
2531
pub space: String,
26-
pub value: u32
32+
pub value: u32,
2733
}
2834

2935
type SpaceDb = Database<Sha256Hasher>;
@@ -334,7 +340,13 @@ impl LiveSnapshot {
334340
let outpoint = self.get_space_outpoint(&spacehash)?;
335341
if let Some(outpoint) = outpoint {
336342
if let Some(spaceout) = self.get_spaceout(&outpoint)? {
337-
spaceouts.push((priority, FullSpaceOut { txid: outpoint.txid, spaceout }));
343+
spaceouts.push((
344+
priority,
345+
FullSpaceOut {
346+
txid: outpoint.txid,
347+
spaceout,
348+
},
349+
));
338350
}
339351
}
340352
}

node/src/wallets.rs

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
use std::{collections::BTreeMap, str::FromStr, time::Duration};
2+
23
use anyhow::anyhow;
34
use clap::ValueEnum;
45
use futures::{stream::FuturesUnordered, StreamExt};
56
use log::{info, warn};
6-
use protocol::{bitcoin::Txid, constants::ChainAnchor, hasher::{KeyHasher, SpaceKey}, prepare::DataSource, script::SpaceScript, slabel::SLabel, FullSpaceOut, Space};
7+
use protocol::{
8+
bitcoin::Txid,
9+
constants::ChainAnchor,
10+
hasher::{KeyHasher, SpaceKey},
11+
prepare::DataSource,
12+
script::SpaceScript,
13+
slabel::SLabel,
14+
FullSpaceOut, Space,
15+
};
716
use serde::{Deserialize, Serialize};
817
use serde_json::json;
918
use tokio::{
@@ -15,17 +24,18 @@ use wallet::{
1524
bdk_wallet,
1625
bdk_wallet::{
1726
chain::{local_chain::CheckPoint, BlockId},
27+
wallet::tx_builder::TxOrdering,
1828
KeychainKind, LocalOutput,
1929
},
2030
bitcoin,
2131
bitcoin::{Address, Amount, FeeRate, OutPoint},
2232
builder::{
23-
CoinTransfer, SpaceTransfer, SpacesAwareCoinSelection, TransactionTag, TransferRequest,
33+
CoinTransfer, SelectionOutput, SpaceTransfer, SpacesAwareCoinSelection, TransactionTag,
34+
TransferRequest,
2435
},
2536
DoubleUtxo, SpacesWallet, WalletInfo,
2637
};
27-
use wallet::bdk_wallet::wallet::tx_builder::TxOrdering;
28-
use wallet::builder::SelectionOutput;
38+
2939
use crate::{
3040
config::ExtendedNetwork,
3141
node::BlockSource,
@@ -46,7 +56,6 @@ pub struct TxResponse {
4656
pub raw: Option<String>,
4757
}
4858

49-
5059
#[derive(Debug, Clone, Serialize, Deserialize)]
5160
pub struct WalletResponse {
5261
pub result: Vec<TxResponse>,
@@ -176,11 +185,11 @@ impl RpcWallet {
176185
fee_rate: FeeRate,
177186
) -> anyhow::Result<Vec<TxResponse>> {
178187
let coin_selection = Self::get_spaces_coin_selection(
179-
wallet,
180-
state,
181-
false /* generally bdk won't use unconfirmed for replacements anyways */
188+
wallet, state,
189+
false, /* generally bdk won't use unconfirmed for replacements anyways */
182190
)?;
183-
let mut builder = wallet.spaces
191+
let mut builder = wallet
192+
.spaces
184193
.build_fee_bump(txid)?
185194
.coin_selection(coin_selection);
186195

@@ -212,13 +221,9 @@ impl RpcWallet {
212221
output: OutPoint,
213222
fee_rate: FeeRate,
214223
) -> anyhow::Result<TxResponse> {
215-
let coin_selection =
216-
Self::get_spaces_coin_selection(wallet, state, true)?;
224+
let coin_selection = Self::get_spaces_coin_selection(wallet, state, true)?;
217225
let addre = wallet.spaces.next_unused_address(KeychainKind::External);
218-
let mut builder = wallet
219-
.spaces
220-
.build_tx()
221-
.coin_selection(coin_selection);
226+
let mut builder = wallet.spaces.build_tx().coin_selection(coin_selection);
222227

223228
builder.ordering(TxOrdering::Untouched);
224229
builder.fee_rate(fee_rate);
@@ -268,7 +273,8 @@ impl RpcWallet {
268273
fee_rate,
269274
resp,
270275
} => {
271-
let result = Self::handle_force_spend_output(source, &mut state, wallet, outpoint, fee_rate);
276+
let result =
277+
Self::handle_force_spend_output(source, &mut state, wallet, outpoint, fee_rate);
272278
_ = resp.send(result);
273279
}
274280
WalletCommand::GetNewAddress { kind, resp } => {
@@ -300,8 +306,7 @@ impl RpcWallet {
300306
}
301307
}
302308
WalletCommand::ListBidouts { resp } => {
303-
let sel =
304-
Self::get_spaces_coin_selection(wallet, state, false)?;
309+
let sel = Self::get_spaces_coin_selection(wallet, state, false)?;
305310
let result = wallet.list_bidouts(&sel);
306311
_ = resp.send(result);
307312
}
@@ -505,13 +510,16 @@ impl RpcWallet {
505510

506511
fn replaces_unconfirmed_bid(wallet: &SpacesWallet, bid_spaceout: &FullSpaceOut) -> bool {
507512
let outpoint = bid_spaceout.outpoint();
508-
wallet.spaces.transactions().filter(
509-
|tx|
510-
!tx.chain_position.is_confirmed()
511-
).any(
512-
|tx|
513-
tx.tx_node.input.iter().any(|input| input.previous_output == outpoint)
514-
)
513+
wallet
514+
.spaces
515+
.transactions()
516+
.filter(|tx| !tx.chain_position.is_confirmed())
517+
.any(|tx| {
518+
tx.tx_node
519+
.input
520+
.iter()
521+
.any(|input| input.previous_output == outpoint)
522+
})
515523
}
516524

517525
fn batch_tx(
@@ -745,7 +753,8 @@ impl RpcWallet {
745753
error_data.insert(
746754
"hint".to_string(),
747755
"Competing bid in mempool but wallet has no confirmed bid \
748-
outputs (required to replace mempool bids)".to_string(),
756+
outputs (required to replace mempool bids)"
757+
.to_string(),
749758
);
750759
}
751760

@@ -773,9 +782,7 @@ impl RpcWallet {
773782
}
774783
}
775784

776-
Ok(WalletResponse {
777-
result: result_set,
778-
})
785+
Ok(WalletResponse { result: result_set })
779786
}
780787

781788
pub async fn service(

protocol/src/constants.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,9 @@ impl ChainAnchor {
6868
};
6969

7070
// Testnet4 activation block
71-
pub const TESTNET4: fn() -> Self = || {
72-
Self {
73-
hash: BlockHash::all_zeros(),
74-
height: 50_000,
75-
}
71+
pub const TESTNET4: fn() -> Self = || Self {
72+
hash: BlockHash::all_zeros(),
73+
height: 50_000,
7674
};
7775

7876
// Testnet activation block

0 commit comments

Comments
 (0)