Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: testnet support #208

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion components/ordhook-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ struct RepairStorageCommand {
/// Cascade to observers
#[clap(short, long, action = clap::ArgAction::SetTrue)]
pub repair_observers: Option<bool>,
/// Display debug logs
#[clap(short, long, action = clap::ArgAction::SetTrue)]
pub debug: Option<bool>,
}

impl RepairStorageCommand {
Expand Down Expand Up @@ -714,7 +717,28 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
10_000,
&ctx,
)
.await?
.await?;
if let Some(true) = cmd.debug {
let blocks_db = open_ordhook_db_conn_rocks_db_loop(false, &config.get_ordhook_config().db_path, ctx);
for i in cmd.get_blocks().into_iter() {
let block = find_lazy_block_at_block_height(i as u32, 10, false, &blocks_db, ctx).expect("unable to retrieve block {i}");
info!(
ctx.expect_logger(),
"--------------------"
);
info!(
ctx.expect_logger(),
"Block: {i}"
);
for tx in block.iter_tx() {
info!(
ctx.expect_logger(),
"Tx: {}",
ordhook::hex::encode(tx.txid)
);
}
}
}
}
RepairCommand::Inscriptions(cmd) => {
let config = ConfigFile::default(false, false, false, &cmd.config_path)?;
Expand Down
12 changes: 11 additions & 1 deletion components/ordhook-core/src/core/protocol/satoshi_numbering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,17 @@ pub fn compute_satoshi_number(
// isolate the target transaction
let lazy_tx = match lazy_block.find_and_serialize_transaction_with_txid(&txid) {
Some(entry) => entry,
None => break,
None => {
ctx.try_log(|logger| {
error!(
logger,
"fatal: unable to retrieve tx ancestor {} in block {ordinal_block_number} (satpoint {}:{inscription_input_index})",
hex::encode(txid),
transaction_identifier.get_hash_bytes_str(),
)
});
std::process::exit(1);
},
};

let mut sats_out = 0;
Expand Down
31 changes: 27 additions & 4 deletions components/ordhook-core/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1300,9 +1300,18 @@ impl LazyBlock {
let tx_len = block.tx.len() as u16 - 1;
buffer.write(&tx_len.to_be_bytes())?;
// For each transaction:
let u16_max = u16::MAX as usize;
for tx in block.tx.iter().skip(1) {
let inputs_len = tx.vin.len() as u16;
let outputs_len = tx.vout.len() as u16;
let inputs_len = if tx.vin.len() > u16_max {
0
} else {
tx.vin.len() as u16
};
let outputs_len = if tx.vout.len() > u16_max {
0
} else {
tx.vout.len() as u16
};
// Number of inputs
buffer.write(&inputs_len.to_be_bytes())?;
// Number of outputs
Expand Down Expand Up @@ -1332,8 +1341,21 @@ impl LazyBlock {
]
};
buffer.write_all(&txid)?;

let inputs_len = if tx.vin.len() > u16_max {
0
} else {
tx.vin.len() as usize
};
let outputs_len = if tx.vout.len() > u16_max {
0
} else {
tx.vout.len() as usize
};

// For each transaction input:
for input in tx.vin.iter() {
for i in 0..inputs_len {
let input = &tx.vin[i];
// txin - 8 first bytes
let txin = {
let txid = hex::decode(input.txid.as_ref().unwrap().to_string()).unwrap();
Expand All @@ -1353,7 +1375,8 @@ impl LazyBlock {
buffer.write(&sats.to_be_bytes())?;
}
// For each transaction output:
for output in tx.vout.iter() {
for i in 0..outputs_len {
let output = &tx.vout[i];
let sats = output.value.to_sat();
buffer.write(&sats.to_be_bytes())?;
}
Expand Down
1 change: 1 addition & 0 deletions components/ordhook-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extern crate serde_derive;
extern crate serde;

pub extern crate chainhook_sdk;
pub extern crate hex;

pub mod config;
pub mod core;
Expand Down
Loading