mirror of
https://github.com/alexgo-io/bitcoin-indexer.git
synced 2026-06-13 16:19:01 +08:00
feat: draft naive inscription detection
This commit is contained in:
@@ -107,11 +107,32 @@ pub fn standardize_bitcoin_block(
|
||||
) -> Result<BitcoinBlockData, String> {
|
||||
let mut transactions = vec![];
|
||||
|
||||
let expected_magic_bytes = get_canonical_magic_bytes(&indexer_config.bitcoin_network);
|
||||
let expected_magic_bytes = get_stacks_canonical_magic_bytes(&indexer_config.bitcoin_network);
|
||||
let pox_config = get_canonical_pox_config(&indexer_config.bitcoin_network);
|
||||
|
||||
for mut tx in block.txdata.into_iter() {
|
||||
let txid = tx.txid().to_string();
|
||||
ctx.try_log(|logger| slog::info!(logger, "Start processing Bitcoin block {}", block.hash,));
|
||||
|
||||
for mut tx in block.tx.into_iter() {
|
||||
let txid = tx.txid.to_string();
|
||||
|
||||
ctx.try_log(|logger| slog::info!(logger, "Start processing Bitcoin transaction {txid}"));
|
||||
|
||||
let mut stacks_operations = vec![];
|
||||
if let Some(op) = try_parse_stacks_operation(
|
||||
&tx.vout,
|
||||
&pox_config,
|
||||
&expected_magic_bytes,
|
||||
block_height,
|
||||
ctx,
|
||||
) {
|
||||
stacks_operations.push(op);
|
||||
}
|
||||
|
||||
let mut ordinal_operations = vec![];
|
||||
if let Some(op) = try_parse_ordinal_operation(&tx, block_height, ctx) {
|
||||
ordinal_operations.push(op);
|
||||
}
|
||||
|
||||
let mut inputs = vec![];
|
||||
for input in tx.vin.drain(..) {
|
||||
if input.is_coinbase() {
|
||||
@@ -141,17 +162,6 @@ pub fn standardize_bitcoin_block(
|
||||
}
|
||||
|
||||
let mut outputs = vec![];
|
||||
let mut stacks_operations = vec![];
|
||||
|
||||
if let Some(op) = try_parse_stacks_operation(
|
||||
&tx.output,
|
||||
&pox_config,
|
||||
&expected_magic_bytes,
|
||||
block_height,
|
||||
ctx,
|
||||
) {
|
||||
stacks_operations.push(op);
|
||||
}
|
||||
for output in tx.vout.drain(..) {
|
||||
outputs.push(TxOut {
|
||||
value: output.value.to_sat(),
|
||||
@@ -168,6 +178,7 @@ pub fn standardize_bitcoin_block(
|
||||
inputs,
|
||||
outputs,
|
||||
stacks_operations,
|
||||
ordinal_operations,
|
||||
proof: None,
|
||||
},
|
||||
};
|
||||
@@ -189,6 +200,39 @@ pub fn standardize_bitcoin_block(
|
||||
})
|
||||
}
|
||||
|
||||
fn try_parse_ordinal_operation(
|
||||
tx: &GetRawTransactionResult,
|
||||
block_height: u64,
|
||||
ctx: &Context,
|
||||
) -> Option<OrdinalOperation> {
|
||||
let (pos, magic_bytes) = get_ordinal_canonical_magic_bytes();
|
||||
let limit = pos + magic_bytes.len();
|
||||
|
||||
for input in tx.vin.iter() {
|
||||
if let Some(ref witnesses) = input.txinwitness {
|
||||
for witness in witnesses.iter() {
|
||||
if witness.len() > limit && witness[pos..limit] == magic_bytes {
|
||||
ctx.try_log(|logger| {
|
||||
slog::info!(
|
||||
logger,
|
||||
"Ordinal operation detected in transaction {}",
|
||||
tx.txid,
|
||||
)
|
||||
});
|
||||
return Some(OrdinalOperation::InscriptionReveal(
|
||||
OrdinalInscriptionRevealData {
|
||||
satoshi_point: "".into(),
|
||||
content_type: "".into(),
|
||||
content: vec![],
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn try_parse_stacks_operation(
|
||||
outputs: &Vec<GetRawTransactionResultVout>,
|
||||
pox_config: &PoxConfig,
|
||||
|
||||
@@ -204,3 +204,22 @@ fn test_bitcoin_vector_040() {
|
||||
// fn test_bitcoin_vector_041() {
|
||||
// process_bitcoin_blocks_and_check_expectations(helpers::shapes::get_vector_041());
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn test_ordinal_inscription_parsing() {
|
||||
use clarity_repl::clarity::util::hash::hex_bytes;
|
||||
|
||||
let witness = hex_bytes("208737bc46923c3e64c7e6768c0346879468bf3aba795a5f5f56efca288f50ed2aac0063036f7264010118746578742f706c61696e3b636861727365743d7574662d38004c9948656c6c6f2030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030300a68").unwrap();
|
||||
|
||||
let (pos, magic_bytes) = super::get_ordinal_canonical_magic_bytes();
|
||||
let limit = pos + magic_bytes.len();
|
||||
|
||||
println!("{:?}", &magic_bytes);
|
||||
|
||||
// println!("{:?}", &witness);
|
||||
println!("{:?}", &witness[pos..limit]);
|
||||
if witness.len() > limit && witness[pos..limit] == magic_bytes {
|
||||
} else {
|
||||
panic!();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +104,7 @@ pub fn generate_test_tx_bitcoin_p2pkh_transfer(
|
||||
metadata: BitcoinTransactionMetadata {
|
||||
inputs: vec![],
|
||||
outputs,
|
||||
ordinal_operations: vec![],
|
||||
stacks_operations: vec![],
|
||||
proof: None,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user