Skip to content

Commit f664298

Browse files
authored
Merge pull request #34 from buffrr/more-wallet-stuff
Clean up bid replacements and output selection
2 parents e05d5b2 + 0777d65 commit f664298

File tree

7 files changed

+206
-117
lines changed

7 files changed

+206
-117
lines changed

node/src/bin/space-cli.rs

Lines changed: 10 additions & 11 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 {
@@ -262,7 +260,7 @@ impl SpaceCli {
262260
async fn send_request(
263261
&self,
264262
req: Option<RpcWalletRequest>,
265-
auction_outputs: Option<u8>,
263+
bidouts: Option<u8>,
266264
fee_rate: Option<u64>,
267265
) -> Result<(), ClientError> {
268266
let fee_rate = fee_rate.map(|fee| FeeRate::from_sat_per_vb(fee).unwrap());
@@ -271,7 +269,7 @@ impl SpaceCli {
271269
.wallet_send_request(
272270
&self.wallet,
273271
RpcWalletTxBuilder {
274-
auction_outputs,
272+
bidouts,
275273
requests: match req {
276274
None => vec![],
277275
Some(req) => vec![req],
@@ -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
}
@@ -533,7 +532,7 @@ async fn handle_commands(
533532
println!("{}", serde_json::to_string_pretty(&spaces)?);
534533
}
535534
Commands::ListBidOuts => {
536-
let spaces = cli.client.wallet_list_auction_outputs(&cli.wallet).await?;
535+
let spaces = cli.client.wallet_list_bidouts(&cli.wallet).await?;
537536
println!("{}", serde_json::to_string_pretty(&spaces)?);
538537
}
539538
Commands::ListSpaces => {

node/src/rpc.rs

Lines changed: 27 additions & 30 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,19 +178,16 @@ 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(
185185
&self,
186186
wallet: &str,
187187
) -> Result<Vec<WalletOutput>, ErrorObjectOwned>;
188188

189-
#[method(name = "walletlistauctionoutputs")]
190-
async fn wallet_list_auction_outputs(
191-
&self,
192-
wallet: &str,
193-
) -> Result<Vec<DoubleUtxo>, ErrorObjectOwned>;
189+
#[method(name = "walletlistbidouts")]
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>;
@@ -199,7 +196,7 @@ pub trait Rpc {
199196
#[derive(Clone, Serialize, Deserialize)]
200197
pub struct RpcWalletTxBuilder {
201198
#[serde(skip_serializing_if = "Option::is_none")]
202-
pub auction_outputs: Option<u8>,
199+
pub bidouts: Option<u8>,
203200
pub requests: Vec<RpcWalletRequest>,
204201
pub fee_rate: Option<FeeRate>,
205202
pub dust: Option<Amount>,
@@ -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,13 +764,10 @@ impl RpcServer for RpcServerImpl {
764764
.map_err(|error| ErrorObjectOwned::owned(-1, error.to_string(), None::<String>))
765765
}
766766

767-
async fn wallet_list_auction_outputs(
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?
773-
.send_list_auction_outputs()
770+
.send_list_bidouts()
774771
.await
775772
.map_err(|error| ErrorObjectOwned::owned(-1, error.to_string(), None::<String>))
776773
}
@@ -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
}

0 commit comments

Comments
 (0)