Skip to content

Commit

Permalink
Merge pull request #25 from buffrr/structure-update
Browse files Browse the repository at this point in the history
Structure update
  • Loading branch information
buffrr authored Nov 7, 2024
2 parents 8070608 + 9aed182 commit 13139f0
Show file tree
Hide file tree
Showing 16 changed files with 721 additions and 715 deletions.
12 changes: 9 additions & 3 deletions node/src/bin/space-cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use jsonrpsee::{
};
use protocol::{
bitcoin::{Amount, FeeRate, OutPoint, Txid},
hasher::{KeyHasher, SpaceHash},
hasher::{KeyHasher, SpaceKey},
opcodes::OP_SETALL,
sname::{NameLike, SName},
Covenant, FullSpaceOut,
Expand Down Expand Up @@ -372,7 +372,7 @@ async fn main() -> anyhow::Result<()> {
fn space_hash(spaceish: &str) -> anyhow::Result<String> {
let space = normalize_space(&spaceish);
let sname = SName::from_str(&space)?;
let spacehash = SpaceHash::from(Sha256::hash(sname.to_bytes()));
let spacehash = SpaceKey::from(Sha256::hash(sname.to_bytes()));
Ok(hex::encode(spacehash.as_slice()))
}

Expand All @@ -394,7 +394,13 @@ async fn handle_commands(

if let Some(outpoint) = outpoint {
if let Some(spaceout) = cli.client.get_spaceout(outpoint).await? {
spaceouts.push((priority, FullSpaceOut { outpoint, spaceout }));
spaceouts.push((
priority,
FullSpaceOut {
txid: outpoint.txid,
spaceout,
},
));
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions node/src/bin/spaced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use log::error;
use spaced::{
config::{safe_exit, Args},
rpc::{AsyncChainState, LoadedWallet, RpcServerImpl, WalletManager},
source::BitcoinBlockSource,
source::{BitcoinBlockSource, BitcoinRpc},
store,
sync::Spaced,
wallets::RpcWallet,
Expand Down Expand Up @@ -82,6 +82,7 @@ impl Composer {
};

let (async_chain_state, async_chain_state_handle) = create_async_store(
spaced.rpc.clone(),
spaced.chain.state.clone(),
spaced.block_index.as_ref().map(|index| index.state.clone()),
self.shutdown.subscribe(),
Expand Down Expand Up @@ -140,15 +141,16 @@ impl Composer {
}

async fn create_async_store(
rpc: BitcoinRpc,
chain_state: LiveSnapshot,
block_index: Option<LiveSnapshot>,
shutdown: broadcast::Receiver<()>,
) -> (AsyncChainState, JoinHandle<()>) {
let (tx, rx) = mpsc::channel(32);
let async_store = AsyncChainState::new(tx);

let client = reqwest::Client::new();
let handle = tokio::spawn(async move {
AsyncChainState::handler(chain_state, block_index, rx, shutdown).await
AsyncChainState::handler(&client, rpc, chain_state, block_index, rx, shutdown).await
});
(async_store, handle)
}
38 changes: 28 additions & 10 deletions node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,41 @@ impl Args {
bitcoin_rpc_auth,
);

std::fs::create_dir_all(data_dir.clone())?;
fs::create_dir_all(data_dir.clone())?;

let chain_store = Store::open(data_dir.join("protocol.sdb"))?;
let proto_db_path = data_dir.join("protocol.sdb");
let initial_sync = !proto_db_path.exists();

let chain_store = Store::open(proto_db_path)?;
let chain = LiveStore {
state: chain_store.begin(&genesis)?,
store: chain_store,
};

let block_index = match args.block_index {
true => {
let block_store = Store::open(data_dir.join("blocks.sdb"))?;
Some(LiveStore {
state: block_store.begin(&genesis).expect("begin block index"),
store: block_store,
})
let block_index = if args.block_index {
let block_db_path = data_dir.join("block_index.sdb");
if !initial_sync && !block_db_path.exists() {
return Err(anyhow::anyhow!(
"Block index must be enabled from the initial sync."
));
}
false => None,
let block_store = Store::open(block_db_path)?;
let index = LiveStore {
state: block_store.begin(&genesis).expect("begin block index"),
store: block_store,
};
{
let tip_1 = index.state.tip.read().expect("index");
let tip_2 = chain.state.tip.read().expect("tip");
if tip_1.height != tip_2.height || tip_1.hash != tip_2.hash {
return Err(anyhow::anyhow!(
"Protocol and block index states don't match."
));
}
}
Some(index)
} else {
None
};

Ok(Spaced {
Expand Down
Loading

0 comments on commit 13139f0

Please sign in to comment.