diff --git a/Cargo.lock b/Cargo.lock
index 785d429ac4..dcb6960a68 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2323,12 +2323,15 @@ dependencies = [
"mime_guess",
"miniscript",
"mp4",
+ "once_cell",
"ord-bitcoincore-rpc",
"pretty_assertions",
"pulldown-cmark",
+ "rayon",
"redb",
"regex",
"reqwest",
+ "rmp-serde",
"rss",
"rust-embed",
"rustls 0.22.1",
@@ -2439,6 +2442,12 @@ dependencies = [
"windows-targets 0.48.5",
]
+[[package]]
+name = "paste"
+version = "1.0.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
+
[[package]]
name = "pem"
version = "1.1.1"
@@ -2818,6 +2827,28 @@ dependencies = [
"windows-sys 0.48.0",
]
+[[package]]
+name = "rmp"
+version = "0.8.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7f9860a6cc38ed1da53456442089b4dfa35e7cedaa326df63017af88385e6b20"
+dependencies = [
+ "byteorder",
+ "num-traits",
+ "paste",
+]
+
+[[package]]
+name = "rmp-serde"
+version = "1.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bffea85eea980d8a74453e5d02a8d93028f3c34725de143085a844ebe953258a"
+dependencies = [
+ "byteorder",
+ "rmp",
+ "serde",
+]
+
[[package]]
name = "rss"
version = "2.0.6"
diff --git a/Cargo.toml b/Cargo.toml
index bc3b936ad4..b9d64d66c0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -26,7 +26,6 @@ axum-server = "0.5.0"
base64 = "0.21.0"
bech32 = "0.9.1"
bigdecimal = "0.4.2"
-bincode = "1.3.3"
bip39 = "2.0.0"
bitcoin = { version = "0.30.1", features = ["rand"] }
boilerplate = { version = "1.0.0", features = ["axum"] }
@@ -39,6 +38,7 @@ derive_more = "0.99.17"
dirs = "5.0.0"
env_logger = "0.10.0"
futures = "0.3.21"
+bincode = "1.3.3"
hex = "0.4.3"
html-escaper = "0.2.0"
http = "0.2.6"
@@ -72,6 +72,9 @@ tower-http = { version = "0.4.0", features = ["compression-br", "compression-gzi
utoipa = "4.1.0"
thiserror = "1.0.51"
log4rs = { version = "1.2.0", features = ["gzip"] }
+once_cell = "1.19.0"
+rmp-serde = "1.1.2"
+rayon = "1.8.0"
[dev-dependencies]
executable-path = "1.0.0"
@@ -95,3 +98,7 @@ path = "tests/lib.rs"
[build-dependencies]
pulldown-cmark = "0.9.2"
shadow-rs = "0.25.0"
+
+[features]
+default = []
+cache = []
diff --git a/src/chain.rs b/src/chain.rs
index 1186ac63ad..230687d29b 100644
--- a/src/chain.rs
+++ b/src/chain.rs
@@ -47,6 +47,15 @@ impl Chain {
}
}
+ pub(crate) fn first_brc20_height(self) -> u32 {
+ match self {
+ Self::Mainnet => 779832,
+ Self::Regtest => 0,
+ Self::Signet => 0,
+ Self::Testnet => 0,
+ }
+ }
+
pub(crate) fn first_rune_height(self) -> u32 {
SUBSIDY_HALVING_INTERVAL
* match self {
diff --git a/src/index.rs b/src/index.rs
index 32f0ddb1a7..b409255c0b 100644
--- a/src/index.rs
+++ b/src/index.rs
@@ -1,10 +1,18 @@
+use crate::okx::datastore::brc20::redb::table::{
+ get_balance, get_balances, get_token_info, get_tokens_info, get_transaction_receipts,
+ get_transferable, get_transferable_by_tick,
+};
+use crate::okx::datastore::ord::redb::table::{
+ get_collection_inscription_id, get_collections_of_inscription, get_transaction_operations,
+ get_txout_by_outpoint,
+};
+use crate::okx::datastore::{brc20, ScriptKey};
+use crate::okx::protocol::zeroindexer::datastore::get_zero_indexer_txs;
+use crate::okx::protocol::zeroindexer::zerodata::ZeroData;
use bitcoincore_rpc::bitcoincore_rpc_json::GetBlockResult;
use {
self::{
- entry::{
- BlockHashValue, Entry, InscriptionIdValue, OutPointValue, RuneEntryValue, RuneIdValue,
- SatPointValue, SatRange, TxidValue,
- },
+ entry::{BlockHashValue, Entry, RuneEntryValue, RuneIdValue, SatPointValue, SatRange},
reorg::*,
runes::{Rune, RuneId},
updater::Updater,
@@ -17,10 +25,7 @@ use {
chrono::SubsecRound,
indicatif::{ProgressBar, ProgressStyle},
log::log_enabled,
- okx::datastore::ord::{
- self, bitmap::District, collections::CollectionKind, redb::try_init_tables as try_init_ord,
- DataStoreReadOnly,
- },
+ okx::datastore::ord::{self, bitmap::District, collections::CollectionKind},
redb::{
Database, DatabaseError, MultimapTable, MultimapTableDefinition, MultimapTableHandle,
ReadableMultimapTable, ReadableTable, RedbKey, RedbValue, StorageError, Table, TableDefinition,
@@ -34,14 +39,16 @@ use {
};
pub(crate) use self::entry::RuneEntry;
-pub(super) use self::entry::{InscriptionEntry, InscriptionEntryValue};
+pub(super) use self::entry::{
+ InscriptionEntry, InscriptionEntryValue, InscriptionIdValue, OutPointValue, TxidValue,
+};
pub(super) use self::updater::BlockData;
pub(crate) mod entry;
mod fetcher;
mod reorg;
mod rtx;
-mod updater;
+pub(crate) mod updater;
#[cfg(test)]
pub(crate) mod testing;
@@ -56,7 +63,7 @@ macro_rules! define_table {
macro_rules! define_multimap_table {
($name:ident, $key:ty, $value:ty) => {
- const $name: MultimapTableDefinition<$key, $value> =
+ pub const $name: MultimapTableDefinition<$key, $value> =
MultimapTableDefinition::new(stringify!($name));
};
}
@@ -82,6 +89,20 @@ define_table! { STATISTIC_TO_COUNT, u64, u64 }
define_table! { TRANSACTION_ID_TO_RUNE, &TxidValue, u128 }
define_table! { WRITE_TRANSACTION_STARTING_BLOCK_COUNT_TO_TIMESTAMP, u32, u128 }
+// new
+define_table! { ORD_TX_TO_OPERATIONS, &TxidValue, &[u8] }
+define_table! { COLLECTIONS_KEY_TO_INSCRIPTION_ID, &str, InscriptionIdValue }
+define_table! { COLLECTIONS_INSCRIPTION_ID_TO_KINDS, InscriptionIdValue, &[u8] }
+
+define_table! { BRC20_BALANCES, &str, &[u8] }
+define_table! { BRC20_TOKEN, &str, &[u8] }
+define_multimap_table! { BRC20_EVENTS, &TxidValue, &[u8] }
+define_table! { BRC20_TRANSFERABLELOG, &str, &[u8] }
+define_table! { BRC20_INSCRIBE_TRANSFER, InscriptionIdValue, &[u8] }
+
+define_table! { ZERO_INSCRIPTION_ID_TO_INSCRIPTION, InscriptionIdValue, &[u8] }
+define_table! { ZERO_HEIGHT_TO_TXS, u64, &[u8] }
+
#[derive(Debug, PartialEq)]
pub enum List {
Spent,
@@ -312,6 +333,18 @@ impl Index {
tx.open_table(TRANSACTION_ID_TO_RUNE)?;
tx.open_table(WRITE_TRANSACTION_STARTING_BLOCK_COUNT_TO_TIMESTAMP)?;
+ // new ord tables
+ tx.open_table(ORD_TX_TO_OPERATIONS)?;
+ tx.open_table(COLLECTIONS_KEY_TO_INSCRIPTION_ID)?;
+ tx.open_table(COLLECTIONS_INSCRIPTION_ID_TO_KINDS)?;
+
+ // brc20 tables
+ tx.open_table(BRC20_BALANCES)?;
+ tx.open_table(BRC20_TOKEN)?;
+ tx.open_multimap_table(BRC20_EVENTS)?;
+ tx.open_table(BRC20_TRANSFERABLELOG)?;
+ tx.open_table(BRC20_INSCRIBE_TRANSFER)?;
+
{
let mut outpoint_to_sat_ranges = tx.open_table(OUTPOINT_TO_SAT_RANGES)?;
let mut statistics = tx.open_table(STATISTIC_TO_COUNT)?;
@@ -340,13 +373,7 @@ impl Index {
Err(error) => bail!("failed to open index: {error}"),
};
- {
- let wtx = database.begin_write()?;
- let rtx = database.begin_read()?;
- try_init_ord(&wtx, &rtx)?;
- wtx.commit()?;
- log::info!("Options:\n{:#?}", options);
- }
+ log::info!("Options:\n{:#?}", options);
let genesis_block_coinbase_transaction =
options.chain().genesis_block().coinbase().unwrap().clone();
@@ -700,7 +727,7 @@ impl Index {
match updater.update_index() {
Ok(ok) => return Ok(ok),
Err(err) => {
- log::info!("{}", err.to_string());
+ log::error!("{}", err.to_string());
match err.downcast_ref() {
Some(&ReorgError::Recoverable { height, depth }) => {
@@ -1438,10 +1465,9 @@ impl Index {
&self,
inscription_id: InscriptionId,
) -> Result