diff --git a/crates/rooch/src/commands/statedb/commands/genesis_verify.rs b/crates/rooch/src/commands/statedb/commands/genesis_verify.rs index d29a1dec0..5fce79506 100644 --- a/crates/rooch/src/commands/statedb/commands/genesis_verify.rs +++ b/crates/rooch/src/commands/statedb/commands/genesis_verify.rs @@ -4,30 +4,36 @@ use std::fs::File; use std::io::{BufRead, BufReader, Read}; use std::path::PathBuf; +use std::str::FromStr; use std::sync::Arc; use std::thread; use std::time::Instant; +use bitcoin::OutPoint; use clap::Parser; use move_vm_types::values::Value; use rustc_hash::FxHashSet; use moveos_store::MoveOSStore; +use moveos_types::move_std::string::MoveString; use moveos_types::moveos_std::object::ObjectMeta; use moveos_types::state::MoveState; use moveos_types::state_resolver::{RootObjectResolver, StatelessResolver}; use rooch_config::R_OPT_NET_HELP; use rooch_types::bitcoin::ord::InscriptionStore; -use rooch_types::bitcoin::utxo::BitcoinUTXOStore; +use rooch_types::bitcoin::utxo::{BitcoinUTXOStore, UTXO}; use rooch_types::error::RoochResult; use rooch_types::framework::address_mapping::RoochToBitcoinAddressMapping; +use rooch_types::into_address::IntoAddress; use rooch_types::rooch_network::RoochChainID; use crate::commands::statedb::commands::inscription::{ - gen_inscription_ids_update, InscriptionSource, + derive_inscription_ids, gen_inscription_ids_update, InscriptionSource, }; use crate::commands::statedb::commands::utxo::UTXORawData; -use crate::commands::statedb::commands::{init_job, OutpointInscriptionsMap}; +use crate::commands::statedb::commands::{ + get_values_by_key, init_job, OutpointInscriptionsMap, UTXO_SEAL_INSCRIPTION_PROTOCOL, +}; /// Import BTC ordinals & UTXO for genesis #[derive(Debug, Parser)] @@ -172,7 +178,25 @@ fn verify_utxo( .unwrap() .unwrap(); assert_eq!(act_utxo_state, state); - + let act_utxo_value = + Value::simple_deserialize(&act_utxo_state.value, &UTXO::type_layout()).unwrap(); + let act_utxo = UTXO::from_runtime_value(act_utxo_value).unwrap(); + assert_eq!(utxo_raw.amount, act_utxo.value); + assert_eq!(utxo_raw.vout, act_utxo.vout); + assert_eq!(utxo_raw.txid.into_address(), act_utxo.txid); + let inscriptions = + outpoint_inscriptions_map.search(&OutPoint::new(utxo_raw.txid, utxo_raw.vout)); + let inscriptions_obj_ids = derive_inscription_ids(inscriptions); + let act_inscriptions = get_values_by_key( + act_utxo.seals, + MoveString::from_str(UTXO_SEAL_INSCRIPTION_PROTOCOL).unwrap(), + ); + if inscriptions_obj_ids.is_empty() { + assert!(act_inscriptions.is_none()); + } else { + let act_inscriptions = act_inscriptions.unwrap(); + assert_eq!(act_inscriptions, inscriptions_obj_ids); + } if addr_updates.is_some() { let (addr_key, addr_state) = addr_updates.unwrap(); let act_address_state = resolver diff --git a/crates/rooch/src/commands/statedb/commands/mod.rs b/crates/rooch/src/commands/statedb/commands/mod.rs index 4041fbdd3..0c6729808 100644 --- a/crates/rooch/src/commands/statedb/commands/mod.rs +++ b/crates/rooch/src/commands/statedb/commands/mod.rs @@ -341,6 +341,21 @@ impl OutpointInscriptionsMap { } } +pub(crate) fn get_values_by_key( + map: SimpleMultiMap, + key: Key, +) -> Option> +where + Key: PartialEq, +{ + for element in map.data { + if element.key == key { + return Some(element.value); + } + } + None +} + #[cfg(test)] mod tests { use std::collections::HashSet; diff --git a/crates/rooch/src/commands/statedb/commands/utxo.rs b/crates/rooch/src/commands/statedb/commands/utxo.rs index daacb02a4..522ac1f9d 100644 --- a/crates/rooch/src/commands/statedb/commands/utxo.rs +++ b/crates/rooch/src/commands/statedb/commands/utxo.rs @@ -28,9 +28,9 @@ const SCRIPT_TYPE_NON_STANDARD: &str = "non-standard"; #[derive(Debug, Clone, PartialEq, Eq)] pub struct UTXORawData { - txid: Txid, - vout: u32, - amount: u64, + pub(crate) txid: Txid, + pub(crate) vout: u32, + pub(crate) amount: u64, script: String, script_type: String, address: String,