diff --git a/src/index/updater/inscription_updater.rs b/src/index/updater/inscription_updater.rs index 719d84a4b8..6342dd522d 100644 --- a/src/index/updater/inscription_updater.rs +++ b/src/index/updater/inscription_updater.rs @@ -656,16 +656,17 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> { cursed, fee: _, hidden: _, - parent: _, pointer: _, reinscription: _, unbound, + parent, inscription, vindicated, } => Action::New { cursed, unbound, vindicated, + parent, inscription, }, }, diff --git a/src/okx/datastore/ord/operation.rs b/src/okx/datastore/ord/operation.rs index 93ce131d3c..ba06e60f1e 100644 --- a/src/okx/datastore/ord/operation.rs +++ b/src/okx/datastore/ord/operation.rs @@ -23,111 +23,12 @@ pub enum Action { New { cursed: bool, unbound: bool, + #[serde(skip)] inscription: Inscription, - #[serde(default)] + #[serde(skip)] vindicated: bool, + #[serde(skip)] + parent: Option, }, Transfer, } - -#[cfg(test)] -mod tests { - - use super::*; - use crate::test::inscription; - use bitcoin::OutPoint; - use std::str::FromStr; - - #[test] - fn test_inscription_op_deserialize_with_default_vindicated() { - let txid = - Txid::from_str("b61b0172d95e266c18aea0c624db987e971a5d6d4ebc2aaed85da4642d635735").unwrap(); - - #[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] - struct OldInscriptionOp { - pub txid: Txid, - pub action: OldAction, - pub sequence_number: u32, - pub inscription_number: Option, - pub inscription_id: InscriptionId, - pub old_satpoint: SatPoint, - pub new_satpoint: Option, - } - - #[allow(clippy::large_enum_variant)] - #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] - enum OldAction { - New { - cursed: bool, - unbound: bool, - inscription: Inscription, - }, - Transfer, - } - - let old_action = OldAction::New { - cursed: true, - unbound: true, - inscription: inscription("text/plain;charset=utf-8", "foobar"), - }; - let bytes = rmp_serde::to_vec(&old_action).unwrap(); - let new_action: Action = rmp_serde::from_slice(&bytes).unwrap(); - assert_eq!( - new_action, - Action::New { - cursed: true, - unbound: true, - vindicated: false, - inscription: inscription("text/plain;charset=utf-8", "foobar"), - } - ); - - let old_operation = OldInscriptionOp { - txid, - action: OldAction::New { - cursed: true, - unbound: true, - inscription: inscription("text/plain;charset=utf-8", "foobar"), - }, - sequence_number: 100, - inscription_number: Some(100), - inscription_id: InscriptionId { txid, index: 0 }, - old_satpoint: SatPoint::from_str( - "1111111111111111111111111111111111111111111111111111111111111111:1:1", - ) - .unwrap(), - new_satpoint: Some(SatPoint { - outpoint: OutPoint { txid, vout: 0 }, - offset: 1, - }), - }; - - let bytes = rmp_serde::to_vec(&old_operation).unwrap(); - - let new_operation: InscriptionOp = rmp_serde::from_slice(&bytes).unwrap(); - - assert_eq!( - new_operation, - InscriptionOp { - txid, - action: Action::New { - cursed: true, - unbound: true, - vindicated: false, - inscription: inscription("text/plain;charset=utf-8", "foobar"), - }, - sequence_number: 100, - inscription_number: Some(100), - inscription_id: InscriptionId { txid, index: 0 }, - old_satpoint: SatPoint::from_str( - "1111111111111111111111111111111111111111111111111111111111111111:1:1", - ) - .unwrap(), - new_satpoint: Some(SatPoint { - outpoint: OutPoint { txid, vout: 0 }, - offset: 1, - }), - } - ); - } -} diff --git a/src/okx/datastore/ord/redb/table.rs b/src/okx/datastore/ord/redb/table.rs index 2f541867e5..ba5e0df347 100644 --- a/src/okx/datastore/ord/redb/table.rs +++ b/src/okx/datastore/ord/redb/table.rs @@ -164,6 +164,7 @@ mod tests { cursed: false, unbound: false, vindicated: false, + parent: None, inscription: inscription("text/plain;charset=utf-8", "foobar"), }, sequence_number: 100, diff --git a/src/okx/protocol/brc20/msg_resolver.rs b/src/okx/protocol/brc20/msg_resolver.rs index f0296cf88a..a2fd4dd192 100644 --- a/src/okx/protocol/brc20/msg_resolver.rs +++ b/src/okx/protocol/brc20/msg_resolver.rs @@ -1,7 +1,6 @@ use super::*; use crate::{ index::entry::{Entry, SatPointValue}, - inscriptions::Inscription, okx::{ datastore::{ brc20::TransferableLog, @@ -16,7 +15,6 @@ use std::collections::HashMap; impl Message { pub(crate) fn resolve( op: &InscriptionOp, - new_inscriptions: &[Inscription], transfer_assets_cache: HashMap, ) -> Result> { log::debug!("BRC20 resolving the message from {:?}", op); @@ -25,20 +23,16 @@ impl Message { .map(|satpoint| satpoint.outpoint.txid == op.txid) .unwrap_or(false); - let brc20_operation = match op.action { + let brc20_operation = match &op.action { // New inscription is not `cursed` or `unbound`. Action::New { cursed: false, unbound: false, vindicated: false, - inscription: _, + inscription, + .. } if sat_in_outputs => { - let Ok(brc20_opteration) = deserialize_brc20_operation( - new_inscriptions - .get(usize::try_from(op.inscription_id.index).unwrap()) - .unwrap(), - &op.action, - ) else { + let Ok(brc20_opteration) = deserialize_brc20_operation(inscription, &op.action) else { return Ok(None); }; brc20_opteration @@ -75,7 +69,10 @@ impl Message { #[cfg(test)] mod tests { use super::*; - use crate::okx::datastore::brc20::{Tick, TransferableLog}; + use crate::{ + okx::datastore::brc20::{Tick, TransferableLog}, + Inscription, + }; use bitcoin::{Address, OutPoint}; use std::str::FromStr; @@ -96,6 +93,7 @@ mod tests { cursed: false, unbound: false, inscription: inscriptions.first().unwrap().clone(), + parent: None, vindicated: false, }, sequence_number: 1, @@ -150,13 +148,10 @@ mod tests { #[test] fn test_invalid_protocol() { let transfer_assets_cache = HashMap::new(); - let (inscriptions, op) = create_inscribe_operation( + let (_inscriptions, op) = create_inscribe_operation( r#"{ "p": "brc-20s","op": "deploy", "tick": "ordi", "max": "1000", "lim": "10" }"#, ); - assert_matches!( - Message::resolve(&op, &inscriptions, transfer_assets_cache), - Ok(None) - ); + assert_matches!(Message::resolve(&op, transfer_assets_cache), Ok(None)); } #[test] @@ -171,12 +166,13 @@ mod tests { cursed: true, unbound: false, inscription: inscriptions.first().unwrap().clone(), + parent: None, vindicated: false, }, ..op }; assert_matches!( - Message::resolve(&op, &inscriptions, transfer_assets_cache.clone()), + Message::resolve(&op, transfer_assets_cache.clone()), Ok(None) ); @@ -185,12 +181,13 @@ mod tests { cursed: false, unbound: true, inscription: inscriptions.first().unwrap().clone(), + parent: None, vindicated: false, }, ..op }; assert_matches!( - Message::resolve(&op2, &inscriptions, transfer_assets_cache.clone()), + Message::resolve(&op2, transfer_assets_cache.clone()), Ok(None) ); let op3 = InscriptionOp { @@ -198,20 +195,18 @@ mod tests { cursed: true, unbound: true, inscription: inscriptions.first().unwrap().clone(), + parent: None, vindicated: false, }, ..op }; - assert_matches!( - Message::resolve(&op3, &inscriptions, transfer_assets_cache), - Ok(None) - ); + assert_matches!(Message::resolve(&op3, transfer_assets_cache), Ok(None)); } #[test] fn test_valid_inscribe_operation() { let transfer_assets_cache = HashMap::new(); - let (inscriptions, op) = create_inscribe_operation( + let (_inscriptions, op) = create_inscribe_operation( r#"{ "p": "brc-20","op": "deploy", "tick": "ordi", "max": "1000", "lim": "10" }"#, ); let _result_msg = Message { @@ -230,7 +225,7 @@ mod tests { sat_in_outputs: true, }; assert_matches!( - Message::resolve(&op, &inscriptions, transfer_assets_cache), + Message::resolve(&op, transfer_assets_cache), Ok(Some(_result_msg)) ); } @@ -242,7 +237,7 @@ mod tests { // inscribe transfer not found let op = create_transfer_operation(); assert_matches!( - Message::resolve(&op, &[], transfer_assets_cache.clone()), + Message::resolve(&op, transfer_assets_cache.clone()), Ok(None) ); @@ -258,7 +253,7 @@ mod tests { }, ..op }; - assert_matches!(Message::resolve(&op1, &[], transfer_assets_cache), Ok(None)); + assert_matches!(Message::resolve(&op1, transfer_assets_cache), Ok(None)); } #[test] @@ -292,9 +287,6 @@ mod tests { sat_in_outputs: true, }; - assert_matches!( - Message::resolve(&op, &[], transfer_assets_cache), - Ok(Some(_msg)) - ); + assert_matches!(Message::resolve(&op, transfer_assets_cache), Ok(Some(_msg))); } } diff --git a/src/okx/protocol/brc20/operation/mod.rs b/src/okx/protocol/brc20/operation/mod.rs index c4eb706fa4..755d5deee4 100644 --- a/src/okx/protocol/brc20/operation/mod.rs +++ b/src/okx/protocol/brc20/operation/mod.rs @@ -71,11 +71,11 @@ pub(crate) fn deserialize_brc20_operation( }; match action { - Action::New { .. } => match raw_operation { + Action::New { parent, .. } => match raw_operation { RawOperation::Deploy(deploy) => Ok(Operation::Deploy(deploy)), RawOperation::Mint(mint) => Ok(Operation::Mint { mint, - parent: inscription.parent(), + parent: *parent, }), RawOperation::Transfer(transfer) => Ok(Operation::InscribeTransfer(transfer)), }, @@ -219,6 +219,7 @@ mod tests { cursed: false, unbound: false, vindicated: false, + parent: None, inscription: inscription.clone() }, ) @@ -243,6 +244,7 @@ mod tests { cursed: false, unbound: false, vindicated: false, + parent: None, inscription: inscription.clone() }, ) @@ -267,6 +269,7 @@ mod tests { cursed: false, unbound: false, vindicated: false, + parent: None, inscription: inscription.clone() }, ) diff --git a/src/okx/protocol/ord/bitmap.rs b/src/okx/protocol/ord/bitmap.rs index cdb52e57b5..fa102bb9af 100644 --- a/src/okx/protocol/ord/bitmap.rs +++ b/src/okx/protocol/ord/bitmap.rs @@ -35,12 +35,7 @@ pub fn index_bitmap( for op in positive_inscriptions.into_iter() { match op.action { - Action::New { - cursed: _, - unbound: _, - vindicated: _, - inscription, - } => { + Action::New { inscription, .. } => { if let Some((inscription_id, district)) = index_district(context, inscription, op.inscription_id)? { diff --git a/src/okx/protocol/resolve_manager.rs b/src/okx/protocol/resolve_manager.rs index 3c1dd936d0..dc62a88410 100644 --- a/src/okx/protocol/resolve_manager.rs +++ b/src/okx/protocol/resolve_manager.rs @@ -2,7 +2,6 @@ use { super::*, crate::{ index::entry::{Entry, SatPointValue}, - inscriptions::ParsedEnvelope, okx::{ datastore::{ brc20::{redb::table::get_transferable_assets_by_outpoint, TransferableLog}, @@ -10,7 +9,7 @@ use { }, protocol::{context::Context, Message}, }, - Inscription, Result, + Result, }, bitcoin::Transaction, std::collections::HashMap, @@ -39,10 +38,6 @@ impl MsgResolveManager { ); let mut messages = Vec::new(); let mut operation_iter = operations.iter().peekable(); - let new_inscriptions = ParsedEnvelope::from_transaction(tx) - .into_iter() - .map(|v| v.payload) - .collect::>(); for input in &tx.input { // "operations" is a list of all the operations in the current block, and they are ordered. @@ -69,9 +64,7 @@ impl MsgResolveManager { .map(|(satpoint, asset)| (satpoint.store(), asset)) .collect(); - if let Some(msg) = - brc20::Message::resolve(operation, &new_inscriptions, satpoint_to_transfer_assets)? - { + if let Some(msg) = brc20::Message::resolve(operation, satpoint_to_transfer_assets)? { log::debug!( "BRC20 resolved the message from {:?}, msg {:?}", operation, diff --git a/src/subcommand/server/ord/inscription.rs b/src/subcommand/server/ord/inscription.rs index 376b4c29cd..0ac551596a 100644 --- a/src/subcommand/server/ord/inscription.rs +++ b/src/subcommand/server/ord/inscription.rs @@ -147,6 +147,13 @@ fn ord_get_inscription_by_id( .ord_inscription_id_to_collections(inscription_id)? .unwrap_or_default(); + let parent_inscription_id = match inscription_entry.parent { + Some(parent) => rtx + .sequence_number_to_inscription_entry(parent)? + .map(|entry| entry.id), + None => None, + }; + let charms: Vec = Charm::ALL .iter() .filter(|charm| charm.is_set(inscription_entry.charms)) @@ -187,7 +194,7 @@ fn ord_get_inscription_by_id( metadata: inscription .metadata() .and_then(|_| inscription.metadata.as_deref().map(hex::encode)), - parent: inscription.parent(), + parent: parent_inscription_id, pointer: inscription.pointer(), delegate: inscription.delegate(), owner: output.map(|vout| ScriptKey::from_script(&vout.script_pubkey, chain).into()),