Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use {
metrics::Metrics,
okx::{
brc20::entry::{
BRC20BalanceValue, BRC20LowerCaseTickerValue, BRC20ReceiptsValue, BRC20TickerInfoValue,
BRC20TransferAssetValue,
BRC20BalanceValue, BRC20LowerCaseTickerValue, BRC20PredeployValue, BRC20ReceiptsValue,
BRC20TickerInfoValue, BRC20TransferAssetValue,
},
entry::{AddressTickerKeyValue, InscriptionReceiptsValue},
},
Expand Down Expand Up @@ -96,6 +96,7 @@ define_table! { BTC_DOMAIN_TO_SEQUENCE_NUMBER, &str, u32}

// BRC-20 tables
define_table! { BRC20_BALANCES, &AddressTickerKeyValue, &BRC20BalanceValue }
define_table! { BRC20_PREDEPLOYS, &str, &BRC20PredeployValue }
define_table! { BRC20_TICKER_ENTRY, &BRC20LowerCaseTickerValue, &BRC20TickerInfoValue }
define_table! { BRC20_TRANSACTION_ID_TO_RECEIPTS, &TxidValue, &BRC20ReceiptsValue }
define_table! { BRC20_SATPOINT_TO_TRANSFER_ASSETS, &SatPointValue, &BRC20TransferAssetValue }
Expand Down
2 changes: 2 additions & 0 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ impl Updater<'_> {
// BRC20 tables
let mut brc20_ticker_info = wtx.open_table(BRC20_TICKER_ENTRY)?;
let mut brc20_balances = wtx.open_table(BRC20_BALANCES)?;
let mut brc20_predeploys = wtx.open_table(BRC20_PREDEPLOYS)?;
let mut brc20_receipts = wtx.open_table(BRC20_TRANSACTION_ID_TO_RECEIPTS)?;
let mut brc20_satpoint_to_transfer_assets =
wtx.open_table(BRC20_SATPOINT_TO_TRANSFER_ASSETS)?;
Expand Down Expand Up @@ -753,6 +754,7 @@ impl Updater<'_> {
let mut context = TableContext::new(
&mut inscription_receipts,
&mut brc20_balances,
&mut brc20_predeploys,
&mut brc20_ticker_info,
&mut brc20_receipts,
&mut brc20_satpoint_to_transfer_assets,
Expand Down
37 changes: 34 additions & 3 deletions src/okx/brc20.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{entry::DynamicEntry, *};
use crate::index::Curse;
use crate::Chain;
use crate::{index::Curse, okx::brc20::operation::Predeploy};
use fixed_point::FixedPoint;
use once_cell::sync::Lazy;
use operation::{BRC20OperationExtractor, Deploy, Mint, RawOperation, Transfer};
Expand All @@ -25,9 +25,15 @@ pub(crate) use self::{
ticker::{BRC20LowerCaseTicker, BRC20Ticker},
};
const SELF_ISSUANCE_TICKER_LENGTH: usize = 5;
const PREDEPLOYED_TICKER_LENGTH: usize = 6;

#[derive(Debug, Clone)]
pub enum BRC20Operation {
Deploy(Deploy),
Predeploy(Predeploy),
Deploy {
deploy: Deploy,
parent: Option<InscriptionId>,
},
Mint {
op: Mint,
parent: Option<InscriptionId>,
Expand Down Expand Up @@ -108,6 +114,17 @@ impl BRC20CreationOperationExtractor for CreatedInscription<'_> {
self.pre_jubilant_curse_reason,
) {
match self.inscription.extract_brc20_operation() {
Ok(RawOperation::Predeploy(predeploy)) => {
if height < HardForks::predeploy_activation_height(&chain) {
log::debug!(
"Pre-deploy feature is not activated at height: {} for inscription: {}",
height,
self.inscription_id
);
return None;
}
Some(BRC20Operation::Predeploy(predeploy))
}
Ok(RawOperation::Deploy(mut deploy)) => {
// Filter out invalid deployments with a 5-byte ticker.
// proposal for issuance self mint token.
Expand All @@ -132,7 +149,21 @@ impl BRC20CreationOperationExtractor for CreatedInscription<'_> {
} else {
deploy.self_mint = None;
}
Some(BRC20Operation::Deploy(deploy))
if deploy.tick.len() == PREDEPLOYED_TICKER_LENGTH {
if height < HardForks::six_byte_deploy_activation_height(&chain) {
log::debug!(
"Pre-deployed 6-byte tickers are not activated at height: {} for inscription: {} with ticker length: {}",
height,
self.inscription_id,
PREDEPLOYED_TICKER_LENGTH
);
return None;
}
}
Some(BRC20Operation::Deploy {
deploy,
parent: self.parents.first().cloned(),
})
}
Ok(RawOperation::Mint(mint)) => Some(BRC20Operation::Mint {
op: mint,
Expand Down
25 changes: 25 additions & 0 deletions src/okx/brc20/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ impl_bincode_dynamic_entry!(BRC20Ticker, BRC20TickerValue);
pub type BRC20LowerCaseTickerValue = [u8];
impl_bincode_dynamic_entry!(BRC20LowerCaseTicker, BRC20LowerCaseTickerValue);

pub type BRC20PredeployValue = [u8];
impl_bincode_dynamic_entry!(BRC20Predeploy, BRC20PredeployValue);
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct BRC20Predeploy {
pub hash: [u8; 32],
pub predeployer: UtxoAddress,
pub block_height: u32,
}

pub(crate) type BRC20TickerInfoValue = [u8];
impl_bincode_dynamic_entry!(BRC20TickerInfo, BRC20TickerInfoValue);
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -106,6 +115,22 @@ mod tests {
);
}

#[test]
fn test_predeploy_store_load() {
let predeploy = BRC20Predeploy {
hash: [1u8; 32],
predeployer: UtxoAddress::from_str(
"bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
bitcoin::Network::Bitcoin,
)
.unwrap(),
block_height: 100,
};
let value = predeploy.store();
let loaded_predeploy = BRC20Predeploy::load(&value);
assert_eq!(predeploy, loaded_predeploy);
}

#[test]
fn test_lower_case_ticker_as_key() {
define_table!(LOWER_CASE_TICKER, &BRC20LowerCaseTickerValue, u32);
Expand Down
15 changes: 15 additions & 0 deletions src/okx/brc20/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ pub enum BRC20Error {
#[error("Self-mint operation denied: insufficient permissions")]
SelfMintPermissionDenied,

#[error("Salt not found for ticker: {0}")]
SaltNotFound(String),

#[error("Salt is an invalid hex string for ticker: {0}")]
SaltInvalidHex(String),

#[error("Predeploy not found for ticker: {0}")]
PredeployNotFound(String),

#[error("Predeploy too young for ticker: {0}, block height: {1}")]
PredeployTooYoung(String, u32),

#[error("Predeploy hash invalid for ticker: {0}")]
PredeployHashInvalid(String),

#[error("Numeric error occurred: {0}")]
NumericError(#[from] fixed_point::NumParseError),
}
12 changes: 11 additions & 1 deletion src/okx/brc20/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use super::*;
#[derive(Debug, Clone, Copy, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum BRC20OpType {
Predeploy,
Deploy,
Mint,
InscribeTransfer,
Expand All @@ -12,7 +13,8 @@ pub enum BRC20OpType {
impl From<&BRC20Operation> for BRC20OpType {
fn from(value: &BRC20Operation) -> Self {
match value {
BRC20Operation::Deploy(_) => BRC20OpType::Deploy,
BRC20Operation::Predeploy(_) => BRC20OpType::Predeploy,
BRC20Operation::Deploy { .. } => BRC20OpType::Deploy,
BRC20Operation::Mint { .. } => BRC20OpType::Mint,
BRC20Operation::InscribeTransfer(_) => BRC20OpType::InscribeTransfer,
BRC20Operation::Transfer { .. } => BRC20OpType::Transfer,
Expand All @@ -22,12 +24,20 @@ impl From<&BRC20Operation> for BRC20OpType {

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub enum BRC20Event {
Predeploy(PredeployEvent),
Deploy(DeployEvent),
Mint(MintEvent),
InscribeTransfer(InscribeTransferEvent),
Transfer(TransferEvent),
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct PredeployEvent {
pub hash: [u8; 32],
pub predeployer: UtxoAddress,
pub block_height: u32,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct DeployEvent {
pub ticker: BRC20Ticker,
Expand Down
4 changes: 3 additions & 1 deletion src/okx/brc20/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::{
mod deploy;
mod inscribe_transfer;
mod mint;
mod predeploy;
mod transfer;

/// Represents a message used for executing BRC20 operations.
Expand Down Expand Up @@ -72,7 +73,8 @@ impl BRC20ExecutionMessage {
blocktime: u32,
) -> Result<BRC20Receipt> {
let result = match &self.operation {
BRC20Operation::Deploy(..) => self.execute_deploy(context, height, blocktime),
BRC20Operation::Predeploy(_) => self.execute_predeploy(context, height),
BRC20Operation::Deploy { .. } => self.execute_deploy(context, height, blocktime),
BRC20Operation::Mint { .. } => self.execute_mint(context, height),
BRC20Operation::InscribeTransfer(_) => self.execute_inscribe_transfer(context),
BRC20Operation::Transfer { .. } => self.execute_transfer(context),
Expand Down
Loading