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

[Bitcoin] Handle Curse Inscription #1865

Merged
merged 14 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
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
12 changes: 3 additions & 9 deletions crates/rooch-open-rpc-spec/schemas/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,7 @@
"index",
"metadata",
"offset",
"parents",
"txid"
],
"properties": {
Expand Down Expand Up @@ -1472,15 +1473,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 Down
6 changes: 3 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 @@ -91,7 +91,7 @@ pub struct InscriptionView {
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 @@ -107,7 +107,7 @@ impl From<Inscription> for InscriptionView {
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
96 changes: 81 additions & 15 deletions crates/rooch-types/src/bitcoin/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ use crate::addresses::BITCOIN_MOVE_ADDRESS;
use crate::indexer::state::IndexerObjectState;
use crate::into_address::IntoAddress;
use anyhow::Result;
use move_core_types::language_storage::StructTag;
use move_core_types::language_storage::{StructTag, TypeTag};
use move_core_types::value::MoveTypeLayout;
use move_core_types::{
account_address::AccountAddress, ident_str, identifier::IdentStr, value::MoveValue,
};
use moveos_types::state::{MoveState, MoveStructState, MoveStructType};
use moveos_types::{
module_binding::{ModuleBinding, MoveFunctionCaller},
move_std::{option::MoveOption, string::MoveString},
moveos_std::{
object::{self, ObjectID},
tx_context::TxContext,
},
state::{MoveState, MoveStructState, MoveStructType},
};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use std::fmt;
use std::fmt::{Display, Formatter};
Expand Down Expand Up @@ -57,7 +59,6 @@ impl MoveStructState for InscriptionID {
pub struct Inscription {
pub txid: AccountAddress,
pub index: u32,
pub input: u32,
pub offset: u64,
pub sequence_number: u32,
pub inscription_number: u32,
Expand All @@ -67,8 +68,9 @@ pub struct Inscription {
pub content_type: MoveOption<MoveString>,
pub metadata: Vec<u8>,
pub metaprotocol: MoveOption<MoveString>,
pub parent: MoveOption<ObjectID>,
pub parents: Vec<ObjectID>,
pub pointer: MoveOption<u64>,
pub rune: Option<u128>,
}

impl MoveStructType for Inscription {
Expand All @@ -82,7 +84,6 @@ impl MoveStructState for Inscription {
move_core_types::value::MoveStructLayout::new(vec![
AccountAddress::type_layout(),
u32::type_layout(),
u32::type_layout(),
u64::type_layout(),
u32::type_layout(),
u32::type_layout(),
Expand All @@ -92,8 +93,9 @@ impl MoveStructState for Inscription {
MoveOption::<MoveString>::type_layout(),
Vec::<u8>::type_layout(),
MoveOption::<MoveString>::type_layout(),
MoveOption::<ObjectID>::type_layout(),
Vec::<ObjectID>::type_layout(),
MoveOption::<u64>::type_layout(),
MoveOption::<u128>::type_layout(),
])
}
}
Expand All @@ -106,6 +108,52 @@ pub fn derive_inscription_id(inscription_id: &InscriptionID) -> ObjectID {
)
}

#[derive(Eq, PartialEq, Debug, Clone, Deserialize, Serialize)]
pub struct Envelope<T> {
pub input: u32,
pub offset: u32,
pub pushnum: bool,
pub stutter: bool,
pub payload: T,
}

impl<T> MoveStructType for Envelope<T>
where
T: MoveStructType + DeserializeOwned,
{
const ADDRESS: AccountAddress = BITCOIN_MOVE_ADDRESS;
const MODULE_NAME: &'static IdentStr = MODULE_NAME;
const STRUCT_NAME: &'static IdentStr = ident_str!("Envelope");

fn type_params() -> Vec<TypeTag> {
vec![TypeTag::Struct(Box::new(T::struct_tag()))]
}

fn struct_tag() -> StructTag {
StructTag {
address: Self::ADDRESS,
module: Self::MODULE_NAME.to_owned(),
name: Self::STRUCT_NAME.to_owned(),
type_params: vec![T::struct_tag().into()],
}
}
}

impl<T> MoveStructState for Envelope<T>
where
T: MoveStructState,
{
fn struct_layout() -> move_core_types::value::MoveStructLayout {
move_core_types::value::MoveStructLayout::new(vec![
u32::type_layout(),
u32::type_layout(),
bool::type_layout(),
bool::type_layout(),
MoveTypeLayout::Struct(T::struct_layout()),
])
}
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq, Default)]
pub struct InscriptionRecord {
pub body: Vec<u8>,
Expand All @@ -115,9 +163,10 @@ pub struct InscriptionRecord {
pub incomplete_field: bool,
pub metadata: Vec<u8>,
pub metaprotocol: MoveOption<MoveString>,
pub parent: MoveOption<InscriptionID>,
pub parents: Vec<InscriptionID>,
pub pointer: MoveOption<u64>,
pub unrecognized_even_field: bool,
pub rune: Option<u128>,
}

impl MoveStructType for InscriptionRecord {
Expand All @@ -136,21 +185,24 @@ impl MoveStructState for InscriptionRecord {
bool::type_layout(),
Vec::<u8>::type_layout(),
MoveOption::<MoveString>::type_layout(),
MoveOption::<InscriptionID>::type_layout(),
Vec::<InscriptionID>::type_layout(),
MoveOption::<u64>::type_layout(),
bool::type_layout(),
MoveOption::<u128>::type_layout(),
])
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InscriptionStore {
/// The latest transaction index has been processed
pub latest_tx_index: u64,
/// The inscriptions table id
/// The inscriptions ids table_vec object id
pub inscriptions: ObjectID,
/// The inscription ids table_vec id
pub inscription_ids: ObjectID,
/// cursed inscription number generator
pub cursed_inscription_count: u32,
/// blessed inscription number generator
pub blessed_inscription_count: u32,
/// sequence number generator
pub next_sequence_number: u32,
}

impl InscriptionStore {
Expand All @@ -168,9 +220,10 @@ impl MoveStructType for InscriptionStore {
impl MoveStructState for InscriptionStore {
fn struct_layout() -> move_core_types::value::MoveStructLayout {
move_core_types::value::MoveStructLayout::new(vec![
u64::type_layout(),
ObjectID::type_layout(),
ObjectID::type_layout(),
u32::type_layout(),
u32::type_layout(),
u32::type_layout(),
])
}
}
Expand Down Expand Up @@ -283,3 +336,16 @@ impl From<BitcoinInscriptionID> for InscriptionID {
}
}
}

#[derive(Debug, PartialEq, Clone)]
pub enum Curse {
DuplicateField,
IncompleteField,
NotAtOffsetZero,
NotInFirstInput,
Pointer,
Pushnum,
Reinscription,
Stutter,
UnrecognizedEvenField,
}
3 changes: 1 addition & 2 deletions examples/bitcoin_plants/sources/plants.move
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,12 @@ module bitcoin_plants::plants {
@0x3232423,
0,
0,
0,
vector[],
option::none(),
option::none(),
vector[],
option::none(),
option::none(),
vector[],
option::none(),
);

Expand Down
Loading
Loading