Skip to content

Commit

Permalink
[Bitcoin] Handle Curse Inscription (#1865)
Browse files Browse the repository at this point in the history
* processs inscription number and sequence number

* handle curse inscription

* fixup inscription test cases

* fixup test cases

* update docs

* [test] Add testcase to released genesis

* resolve native change compatibility and release framework v2

* Temporarily block out genesis test case

* Temporarily block out genesis test case

* fixup bitcoin examples

* Complete the curse field added in Inscriptionview

---------

Co-authored-by: jolestar <jolestar@gmail.com>
  • Loading branch information
baichuan3 and jolestar authored Jun 12, 2024
1 parent 94bbf95 commit b3ea896
Show file tree
Hide file tree
Showing 21 changed files with 901 additions and 287 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ homepage = "https://rooch.network"
license = "Apache-2.0"
publish = false
repository = "https://github.com/rooch-network/rooch"
rust-version = "1.77.1"
rust-version = "1.77.2"
version = "0.5.4"


Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-framework-tests/src/tests/bitcoin_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fn check_utxo(txs: Vec<Transaction>, binding_test: &binding_test::RustBindingTes
assert_eq!(inscription_object.value.index, index);
assert_eq!(
inscription_object.value.body,
inscription.body.unwrap_or_default()
inscription.payload.body.unwrap_or_default()
);
}
}
2 changes: 1 addition & 1 deletion crates/rooch-framework-tests/src/tests/ord_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn decode_inscription(btx_tx_hex: &str) {
{
debug!("{}. inscription: {:?}", i, inscription);
assert_eq!(
inscription.body.unwrap_or_default(),
inscription.payload.body.unwrap_or_default(),
inscription_from_move.body
);
}
Expand Down
53 changes: 42 additions & 11 deletions crates/rooch-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,11 @@ mod tests {
use rooch_types::rooch_network::RoochNetwork;
use tracing::info;

fn genesis_init_test_case(network: RoochNetwork) {
fn genesis_init_test_case(network: RoochNetwork, genesis: RoochGenesis) {
info!(
"genesis init test case for network: {:?}",
network.chain_id.id
);
let genesis =
super::RoochGenesis::build(network.clone()).expect("build rooch genesis failed");

let opt = RoochOpt::new_with_temp_store().expect("create rooch opt failed");
let rooch_db = RoochDB::init(&opt.store_config()).expect("init rooch db failed");
Expand All @@ -465,8 +463,18 @@ mod tests {
.expect("load gas parameter from chain failed");

assert_eq!(
FrameworksGasParameters::initial().to_gas_schedule_config(),
gas_parameter.to_gas_schedule_config()
genesis
.initial_gas_config
.entries
.into_iter()
.map(|entry| (entry.key, entry.val))
.collect::<BTreeMap<_, _>>(),
gas_parameter
.to_gas_schedule_config()
.entries
.into_iter()
.map(|entry| (entry.key, entry.val))
.collect::<BTreeMap<_, _>>(),
);

let module_store_state = resolver
Expand Down Expand Up @@ -523,13 +531,36 @@ mod tests {
);
}

// #[test]
// fn test_builtin_genesis_init() {
// let _ = tracing_subscriber::fmt::try_init();
// {
// let network = BuiltinChainID::Local.into();
// let genesis = RoochGenesis::load(BuiltinChainID::Local).unwrap();
// genesis_init_test_case(network, genesis);
// }
// {
// let network = BuiltinChainID::Dev.into();
// let genesis = RoochGenesis::load(BuiltinChainID::Dev).unwrap();
// genesis_init_test_case(network, genesis);
// }
// {
// let network = BuiltinChainID::Test.into();
// let genesis = RoochGenesis::load(BuiltinChainID::Test).unwrap();
// genesis_init_test_case(network, genesis);
// }
// {
// let network = BuiltinChainID::Main.into();
// let genesis = RoochGenesis::load(BuiltinChainID::Main).unwrap();
// genesis_init_test_case(network, genesis);
// }
// }

#[test]
fn test_genesis_init() {
let _ = tracing_subscriber::fmt::try_init();
genesis_init_test_case(RoochNetwork::local());
genesis_init_test_case(RoochNetwork::dev());
genesis_init_test_case(RoochNetwork::test());
genesis_init_test_case(RoochNetwork::main());
fn test_custom_genesis_init() {
let network = RoochNetwork::new(100.into(), BuiltinChainID::Local.genesis_config().clone());
let genesis = RoochGenesis::build(network.clone()).unwrap();
genesis_init_test_case(network, genesis);
}

#[test]
Expand Down
8 changes: 3 additions & 5 deletions crates/rooch-indexer/src/tests/test_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ use anyhow::Result;
use move_core_types::account_address::AccountAddress;
use move_core_types::vm_status::KeptVMStatus;
use moveos_types::h256::H256;
use moveos_types::move_types::random_type_tag;
use moveos_types::moveos_std::object::{ObjectEntity, ObjectID};
use moveos_types::moveos_std::tx_context::TxContext;
use moveos_types::state::{KeyState, MoveStructType, State};
use moveos_types::test_utils::random_bytes;
use moveos_types::state::MoveStructType;
use moveos_types::transaction::{TransactionExecutionInfo, VerifiedMoveOSTransaction};
use rand::{random, thread_rng, Rng};
use rooch_config::store_config::DEFAULT_DB_INDEXER_SUBDIR;
Expand All @@ -22,8 +20,8 @@ use rooch_types::indexer::event::{EventFilter, IndexerEvent};
use rooch_types::indexer::state::{IndexerObjectState, ObjectStateFilter};
use rooch_types::indexer::transaction::{IndexerTransaction, TransactionFilter};
use rooch_types::test_utils::{
random_event, random_function_calls, random_ledger_transaction, random_string,
random_table_object, random_verified_move_action,
random_event, random_function_calls, random_ledger_transaction, random_table_object,
random_verified_move_action,
};

fn random_update_object_states(states: Vec<IndexerObjectState>) -> Vec<IndexerObjectState> {
Expand Down
28 changes: 19 additions & 9 deletions crates/rooch-open-rpc-spec/schemas/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1418,8 +1418,12 @@
"bitcoin_txid",
"body",
"index",
"inscription_number",
"is_curse",
"metadata",
"offset",
"parents",
"sequence_number",
"txid"
],
"properties": {
Expand Down Expand Up @@ -1454,6 +1458,14 @@
"format": "uint32",
"minimum": 0.0
},
"inscription_number": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"is_curse": {
"type": "boolean"
},
"metadata": {
"$ref": "#/components/schemas/alloc::vec::Vec<u8>"
},
Expand All @@ -1472,15 +1484,8 @@
"format": "uint64",
"minimum": 0.0
},
"parent": {
"anyOf": [
{
"$ref": "#/components/schemas/ObjectID"
},
{
"type": "null"
}
]
"parents": {
"$ref": "#/components/schemas/alloc::vec::Vec<moveos_types::moveos_std::object::ObjectID>"
},
"pointer": {
"type": [
Expand All @@ -1490,6 +1495,11 @@
"format": "uint64",
"minimum": 0.0
},
"sequence_number": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"txid": {
"$ref": "#/components/schemas/primitive_types::H256"
}
Expand Down
12 changes: 9 additions & 3 deletions crates/rooch-rpc-api/src/jsonrpc_types/btc/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::jsonrpc_types::address::BitcoinAddressView;
use crate::jsonrpc_types::btc::transaction::{hex_to_txid, TxidView};
use crate::jsonrpc_types::{
BytesView, H256View, MoveStringView, RoochAddressView, StrView, StructTagView,
BytesView, H256View, MoveStringView, ObjectIDVecView, RoochAddressView, StrView, StructTagView,
};
use anyhow::Result;
use bitcoin::hashes::Hash;
Expand Down Expand Up @@ -86,12 +86,15 @@ pub struct InscriptionView {
pub bitcoin_txid: TxidView,
pub index: u32,
pub offset: u64,
pub sequence_number: u32,
pub inscription_number: u32,
pub is_curse: bool,
pub body: BytesView,
pub content_encoding: Option<MoveStringView>,
pub content_type: Option<MoveStringView>,
pub metadata: BytesView,
pub metaprotocol: Option<MoveStringView>,
pub parent: Option<ObjectID>,
pub parents: ObjectIDVecView,
pub pointer: Option<u64>,
}

Expand All @@ -102,12 +105,15 @@ impl From<Inscription> for InscriptionView {
bitcoin_txid: StrView(Txid::from_byte_array(inscription.txid.into_bytes())),
index: inscription.index,
offset: inscription.offset,
sequence_number: inscription.sequence_number,
inscription_number: inscription.inscription_number,
is_curse: inscription.is_curse,
body: StrView(inscription.body),
content_encoding: Option::<MoveString>::from(inscription.content_encoding).map(StrView),
content_type: Option::<MoveString>::from(inscription.content_type).map(StrView),
metadata: StrView(inscription.metadata),
metaprotocol: Option::<MoveString>::from(inscription.metaprotocol).map(StrView),
parent: Option::<ObjectID>::from(inscription.parent),
parents: inscription.parents.into(),
pointer: Option::<u64>::from(inscription.pointer),
}
}
Expand Down
Loading

0 comments on commit b3ea896

Please sign in to comment.