mirror of
https://github.com/alexgo-io/bitcoin-indexer.git
synced 2026-01-13 08:40:17 +08:00
feat!: keep original deployed ticker for brc20 tokens (#349)
This commit is contained in:
@@ -167,6 +167,7 @@ impl Brc20MemoryCache {
|
||||
inscription_number: reveal.inscription_number.jubilee as u64,
|
||||
block_height: block_identifier.index,
|
||||
tick: data.tick.clone(),
|
||||
display_tick: data.display_tick.clone(),
|
||||
max: data.max,
|
||||
lim: data.lim,
|
||||
dec: data.dec,
|
||||
@@ -365,6 +366,7 @@ mod test {
|
||||
cache.insert_token_deploy(
|
||||
&VerifiedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
@@ -480,6 +482,7 @@ mod test {
|
||||
cache.insert_token_deploy(
|
||||
&VerifiedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
|
||||
@@ -23,6 +23,7 @@ pub struct Brc20DbTokenRow {
|
||||
pub inscription_number: u64,
|
||||
pub block_height: u64,
|
||||
pub tick: String,
|
||||
pub display_tick: String,
|
||||
pub max: f64,
|
||||
pub lim: f64,
|
||||
pub dec: u64,
|
||||
@@ -59,6 +60,7 @@ pub fn initialize_brc20_db(base_dir: Option<&PathBuf>, ctx: &Context) -> Connect
|
||||
inscription_number INTEGER NOT NULL,
|
||||
block_height INTEGER NOT NULL,
|
||||
tick TEXT NOT NULL,
|
||||
display_tick TEXT NOT NULL,
|
||||
max REAL NOT NULL,
|
||||
lim REAL NOT NULL,
|
||||
dec INTEGER NOT NULL,
|
||||
@@ -174,20 +176,21 @@ pub fn delete_activity_in_block_range(
|
||||
pub fn get_token(tick: &str, db_tx: &Connection, ctx: &Context) -> Option<Brc20DbTokenRow> {
|
||||
let args: &[&dyn ToSql] = &[&tick.to_sql().unwrap()];
|
||||
let query = "
|
||||
SELECT tick, max, lim, dec, address, inscription_id, inscription_number, block_height, self_mint
|
||||
SELECT tick, display_tick, max, lim, dec, address, inscription_id, inscription_number, block_height, self_mint
|
||||
FROM tokens
|
||||
WHERE tick = ?
|
||||
";
|
||||
perform_query_one(query, args, &db_tx, ctx, |row| Brc20DbTokenRow {
|
||||
tick: row.get(0).unwrap(),
|
||||
max: row.get(1).unwrap(),
|
||||
lim: row.get(2).unwrap(),
|
||||
dec: row.get(3).unwrap(),
|
||||
address: row.get(4).unwrap(),
|
||||
inscription_id: row.get(5).unwrap(),
|
||||
inscription_number: row.get(6).unwrap(),
|
||||
block_height: row.get(7).unwrap(),
|
||||
self_mint: row.get(8).unwrap(),
|
||||
display_tick: row.get(1).unwrap(),
|
||||
max: row.get(2).unwrap(),
|
||||
lim: row.get(3).unwrap(),
|
||||
dec: row.get(4).unwrap(),
|
||||
address: row.get(5).unwrap(),
|
||||
inscription_id: row.get(6).unwrap(),
|
||||
inscription_number: row.get(7).unwrap(),
|
||||
block_height: row.get(8).unwrap(),
|
||||
self_mint: row.get(9).unwrap(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -293,8 +296,8 @@ pub fn insert_ledger_rows(rows: &Vec<Brc20DbLedgerRow>, db_tx: &Connection, ctx:
|
||||
pub fn insert_token_rows(rows: &Vec<Brc20DbTokenRow>, db_tx: &Connection, ctx: &Context) {
|
||||
match db_tx.prepare_cached(
|
||||
"INSERT INTO tokens
|
||||
(inscription_id, inscription_number, block_height, tick, max, lim, dec, address, self_mint)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(inscription_id, inscription_number, block_height, tick, display_tick, max, lim, dec, address, self_mint)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
) {
|
||||
Ok(mut stmt) => {
|
||||
for row in rows.iter() {
|
||||
@@ -303,6 +306,7 @@ pub fn insert_token_rows(rows: &Vec<Brc20DbTokenRow>, db_tx: &Connection, ctx: &
|
||||
&row.inscription_number,
|
||||
&row.block_height,
|
||||
&row.tick,
|
||||
&row.display_tick,
|
||||
&row.max,
|
||||
&row.lim,
|
||||
&row.dec,
|
||||
@@ -355,6 +359,8 @@ pub fn get_brc20_operations_on_block(
|
||||
map
|
||||
}
|
||||
|
||||
/// Searches for the BRC-20 operation happening in this transaction in the `brc20.sqlite` DB and writes it to this transaction
|
||||
/// object's metadata if it exists.
|
||||
pub fn augment_transaction_with_brc20_operation_data(
|
||||
tx: &mut BitcoinTransactionData,
|
||||
token_map: &mut HashMap<String, Brc20DbTokenRow>,
|
||||
@@ -378,7 +384,7 @@ pub fn augment_transaction_with_brc20_operation_data(
|
||||
match entry.operation.as_str() {
|
||||
"deploy" => {
|
||||
tx.metadata.brc20_operation = Some(Brc20Operation::Deploy(Brc20TokenDeployData {
|
||||
tick: token.tick.clone(),
|
||||
tick: token.display_tick.clone(),
|
||||
max: format!("{:.precision$}", token.max, precision = dec),
|
||||
lim: format!("{:.precision$}", token.lim, precision = dec),
|
||||
dec: token.dec.to_string(),
|
||||
@@ -389,7 +395,7 @@ pub fn augment_transaction_with_brc20_operation_data(
|
||||
}
|
||||
"mint" => {
|
||||
tx.metadata.brc20_operation = Some(Brc20Operation::Mint(Brc20BalanceData {
|
||||
tick: entry.tick.clone(),
|
||||
tick: token.display_tick.clone(),
|
||||
amt: format!("{:.precision$}", entry.avail_balance, precision = dec),
|
||||
address: entry.address.clone(),
|
||||
inscription_id: entry.inscription_id.clone(),
|
||||
@@ -397,7 +403,7 @@ pub fn augment_transaction_with_brc20_operation_data(
|
||||
}
|
||||
"transfer" => {
|
||||
tx.metadata.brc20_operation = Some(Brc20Operation::Transfer(Brc20BalanceData {
|
||||
tick: entry.tick.clone(),
|
||||
tick: token.display_tick.clone(),
|
||||
amt: format!("{:.precision$}", entry.trans_balance, precision = dec),
|
||||
address: entry.address.clone(),
|
||||
inscription_id: entry.inscription_id.clone(),
|
||||
@@ -413,7 +419,7 @@ pub fn augment_transaction_with_brc20_operation_data(
|
||||
);
|
||||
};
|
||||
tx.metadata.brc20_operation = Some(Brc20Operation::TransferSend(Brc20TransferData {
|
||||
tick: entry.tick.clone(),
|
||||
tick: token.display_tick.clone(),
|
||||
amt: format!("{:.precision$}", entry.trans_balance.abs(), precision = dec),
|
||||
sender_address: entry.address.clone(),
|
||||
receiver_address,
|
||||
@@ -487,7 +493,8 @@ pub fn write_augmented_block_to_brc20_db(
|
||||
inscription_id: token.inscription_id.clone(),
|
||||
inscription_number: reveal.inscription_number.jubilee as u64,
|
||||
block_height: block.block_identifier.index,
|
||||
tick: token.tick.clone(),
|
||||
tick: token.tick.to_lowercase(),
|
||||
display_tick: token.tick.clone(),
|
||||
max: token.max.parse::<f64>().unwrap(),
|
||||
lim: token.lim.parse::<f64>().unwrap(),
|
||||
dec: token.dec.parse::<u64>().unwrap(),
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::ord::media::{Language, Media};
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
pub struct ParsedBrc20TokenDeployData {
|
||||
pub tick: String,
|
||||
pub display_tick: String,
|
||||
pub max: f64,
|
||||
pub lim: f64,
|
||||
pub dec: u64,
|
||||
@@ -119,6 +120,7 @@ pub fn parse_brc20_operation(
|
||||
}
|
||||
let mut deploy = ParsedBrc20TokenDeployData {
|
||||
tick: json.tick.to_lowercase(),
|
||||
display_tick: json.tick.clone(),
|
||||
max: 0.0,
|
||||
lim: 0.0,
|
||||
dec: 18,
|
||||
@@ -263,6 +265,7 @@ mod test {
|
||||
InscriptionBuilder::new().build()
|
||||
=> Ok(Some(ParsedBrc20Operation::Deploy(ParsedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 6,
|
||||
@@ -277,6 +280,7 @@ mod test {
|
||||
InscriptionBuilder::new().body(r#"{"p":"brc-20", "op": "deploy", "tick": "PEPE", "max": "21000000", "lim": "1000", "dec": "6"}"#).build()
|
||||
=> Ok(Some(ParsedBrc20Operation::Deploy(ParsedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "PEPE".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 6,
|
||||
@@ -287,6 +291,7 @@ mod test {
|
||||
InscriptionBuilder::new().body(r#"{"p":"brc-20", "op": "deploy", "tick": "pepe", "max": "21000000", "lim": "1000"}"#).build()
|
||||
=> Ok(Some(ParsedBrc20Operation::Deploy(ParsedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
@@ -297,6 +302,7 @@ mod test {
|
||||
InscriptionBuilder::new().body(r#"{"p":"brc-20", "op": "deploy", "tick": "pepe", "max": "21000000"}"#).build()
|
||||
=> Ok(Some(ParsedBrc20Operation::Deploy(ParsedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 21000000.0,
|
||||
dec: 18,
|
||||
@@ -307,6 +313,7 @@ mod test {
|
||||
InscriptionBuilder::new().body(r#"{"p":"brc-20", "op": "deploy", "tick": "pepe", "max": "21000000", "dec": "7"}"#).build()
|
||||
=> Ok(Some(ParsedBrc20Operation::Deploy(ParsedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 21000000.0,
|
||||
dec: 7,
|
||||
@@ -317,6 +324,7 @@ mod test {
|
||||
InscriptionBuilder::new().body(r#"{"p":"brc-20", "op": "deploy", "tick": "😉", "max": "21000000", "lim": "1000", "dec": "6"}"#).build()
|
||||
=> Ok(Some(ParsedBrc20Operation::Deploy(ParsedBrc20TokenDeployData {
|
||||
tick: "😉".to_string(),
|
||||
display_tick: "😉".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 6,
|
||||
@@ -327,6 +335,7 @@ mod test {
|
||||
InscriptionBuilder::new().body(r#"{"p":"brc-20", "op": "deploy", "tick": "a b", "max": "21000000", "lim": "1000", "dec": "6"}"#).build()
|
||||
=> Ok(Some(ParsedBrc20Operation::Deploy(ParsedBrc20TokenDeployData {
|
||||
tick: "a b".to_string(),
|
||||
display_tick: "a b".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 6,
|
||||
@@ -337,6 +346,7 @@ mod test {
|
||||
InscriptionBuilder::new().body(r#"{"p":"brc-20", "op": "deploy", "tick": "$pepe", "max": "21000000", "lim": "1000", "dec": "6", "self_mint": "true"}"#).build()
|
||||
=> Ok(Some(ParsedBrc20Operation::Deploy(ParsedBrc20TokenDeployData {
|
||||
tick: "$pepe".to_string(),
|
||||
display_tick: "$pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 6,
|
||||
@@ -347,6 +357,7 @@ mod test {
|
||||
InscriptionBuilder::new().body(r#"{"p":"brc-20", "op": "deploy", "tick": "$pepe", "max": "0", "lim": "1000", "dec": "6", "self_mint": "true"}"#).build()
|
||||
=> Ok(Some(ParsedBrc20Operation::Deploy(ParsedBrc20TokenDeployData {
|
||||
tick: "$pepe".to_string(),
|
||||
display_tick: "$pepe".to_string(),
|
||||
max: u64::MAX as f64,
|
||||
lim: 1000.0,
|
||||
dec: 6,
|
||||
@@ -361,6 +372,7 @@ mod test {
|
||||
InscriptionBuilder::new().body(r#"{"p":"brc-20", "op": "deploy", "tick": "pepe", "max": "21000000", "lim": "1000", "dec": "6", "foo": 99}"#).build()
|
||||
=> Ok(Some(ParsedBrc20Operation::Deploy(ParsedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 6,
|
||||
@@ -459,6 +471,7 @@ mod test {
|
||||
InscriptionBuilder::new().body(r#"{"p":"brc-20", "op": "deploy", "tick": "pepe", "max": "21000000", "lim": "1000", "dec": "0"}"#).build()
|
||||
=> Ok(Some(ParsedBrc20Operation::Deploy(ParsedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 0,
|
||||
|
||||
@@ -12,6 +12,7 @@ use super::parser::{amt_has_valid_decimals, ParsedBrc20Operation};
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct VerifiedBrc20TokenDeployData {
|
||||
pub tick: String,
|
||||
pub display_tick: String,
|
||||
pub max: f64,
|
||||
pub lim: f64,
|
||||
pub dec: u64,
|
||||
@@ -75,6 +76,7 @@ pub fn verify_brc20_operation(
|
||||
return Ok(VerifiedBrc20Operation::TokenDeploy(
|
||||
VerifiedBrc20TokenDeployData {
|
||||
tick: data.tick.clone(),
|
||||
display_tick: data.display_tick.clone(),
|
||||
max: data.max,
|
||||
lim: data.lim,
|
||||
dec: data.dec,
|
||||
@@ -234,6 +236,7 @@ mod test {
|
||||
#[test_case(
|
||||
ParsedBrc20Operation::Deploy(ParsedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
@@ -245,6 +248,7 @@ mod test {
|
||||
#[test_case(
|
||||
ParsedBrc20Operation::Deploy(ParsedBrc20TokenDeployData {
|
||||
tick: "$pepe".to_string(),
|
||||
display_tick: "$pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
@@ -257,6 +261,7 @@ mod test {
|
||||
#[test_case(
|
||||
ParsedBrc20Operation::Deploy(ParsedBrc20TokenDeployData {
|
||||
tick: "$pepe".to_string(),
|
||||
display_tick: "$pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
@@ -265,6 +270,7 @@ mod test {
|
||||
(Brc20RevealBuilder::new().build(), 840000)
|
||||
=> Ok(VerifiedBrc20Operation::TokenDeploy(VerifiedBrc20TokenDeployData {
|
||||
tick: "$pepe".to_string(),
|
||||
display_tick: "$pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
@@ -276,6 +282,7 @@ mod test {
|
||||
#[test_case(
|
||||
ParsedBrc20Operation::Deploy(ParsedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
@@ -287,6 +294,7 @@ mod test {
|
||||
#[test_case(
|
||||
ParsedBrc20Operation::Deploy(ParsedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
@@ -298,6 +306,7 @@ mod test {
|
||||
#[test_case(
|
||||
ParsedBrc20Operation::Deploy(ParsedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
@@ -307,6 +316,7 @@ mod test {
|
||||
=> Ok(
|
||||
VerifiedBrc20Operation::TokenDeploy(VerifiedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
@@ -358,6 +368,7 @@ mod test {
|
||||
#[test_case(
|
||||
ParsedBrc20Operation::Deploy(ParsedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
@@ -429,6 +440,7 @@ mod test {
|
||||
cache.insert_token_deploy(
|
||||
&VerifiedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
@@ -501,6 +513,7 @@ mod test {
|
||||
cache.insert_token_deploy(
|
||||
&VerifiedBrc20TokenDeployData {
|
||||
tick: "$pepe".to_string(),
|
||||
display_tick: "$pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
@@ -548,6 +561,7 @@ mod test {
|
||||
cache.insert_token_deploy(
|
||||
&VerifiedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
@@ -610,6 +624,7 @@ mod test {
|
||||
cache.insert_token_deploy(
|
||||
&VerifiedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
@@ -733,6 +748,7 @@ mod test {
|
||||
cache.insert_token_deploy(
|
||||
&VerifiedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
@@ -851,6 +867,7 @@ mod test {
|
||||
cache.insert_token_deploy(
|
||||
&VerifiedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
@@ -925,6 +942,7 @@ mod test {
|
||||
cache.insert_token_deploy(
|
||||
&VerifiedBrc20TokenDeployData {
|
||||
tick: "pepe".to_string(),
|
||||
display_tick: "pepe".to_string(),
|
||||
max: 21000000.0,
|
||||
lim: 1000.0,
|
||||
dec: 18,
|
||||
|
||||
@@ -18,8 +18,7 @@ use crate::{
|
||||
};
|
||||
|
||||
use crate::db::{
|
||||
find_last_block_inserted, find_latest_inscription_block_height, initialize_ordhook_db,
|
||||
open_readonly_ordhook_db_conn,
|
||||
find_last_block_inserted, find_latest_inscription_block_height, open_readonly_ordhook_db_conn,
|
||||
};
|
||||
|
||||
use crate::db::TransactionBytesCursor;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
use crate::config::Config;
|
||||
use crate::core::meta_protocols::brc20::db::open_readonly_brc20_db_conn;
|
||||
use crate::core::protocol::inscription_parsing::{
|
||||
get_inscriptions_revealed_in_block, get_inscriptions_transferred_in_block,
|
||||
parse_inscriptions_and_standardize_block,
|
||||
};
|
||||
use crate::core::protocol::inscription_sequencing::consolidate_block_with_pre_computed_ordinals_data;
|
||||
use crate::db::{get_any_entry_in_ordinal_activities, open_readonly_ordhook_db_conn};
|
||||
use crate::db::get_any_entry_in_ordinal_activities;
|
||||
use crate::download::download_ordinals_dataset_if_required;
|
||||
use crate::initialize_databases;
|
||||
use crate::service::observers::{
|
||||
|
||||
Reference in New Issue
Block a user