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

R0.18.3 add stats fields #2

Open
wants to merge 4 commits into
base: R0.18.3_minor_update
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix mintable does not set false
  • Loading branch information
nhathuyle2002 committed Apr 26, 2024
commit 991ba122b64d168bd8f30900ee3730dcc56f7807
3 changes: 2 additions & 1 deletion migrations/2024-04-24-105512_statistic_addition/down.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
ALTER TABLE rune_stats DROP tx_count;
ALTER TABLE transaction_rune_entries DROP total_tx_count;

ALTER TABLE transaction_rune_entries DROP total_holders;
ALTER TABLE transaction_rune_entries DROP total_holders;
ALTER TABLE rune_stats DROP total_holders;
3 changes: 2 additions & 1 deletion migrations/2024-04-24-105512_statistic_addition/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
ALTER TABLE rune_stats ADD tx_count Int8 NOT NULL DEFAULT 0;
ALTER TABLE transaction_rune_entries ADD total_tx_count Int8 NOT NULL DEFAULT 0;

ALTER TABLE transaction_rune_entries ADD total_holders Int8 NOT NULL DEFAULT 0;
ALTER TABLE transaction_rune_entries ADD total_holders Int8 NOT NULL DEFAULT 0;
ALTER TABLE rune_stats ADD total_holders Int8 NOT NULL DEFAULT 0;
1 change: 1 addition & 0 deletions src/runebeta/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,5 @@ pub struct NewRuneStats {
pub remaining: BigDecimal,
pub aggregated: bool,
pub tx_count: i64,
pub total_holders: i64,
}
1 change: 1 addition & 0 deletions src/runebeta/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ diesel::table! {
remaining -> Numeric,
aggregated -> Bool,
tx_count -> Int8,
total_holders -> Int8,
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/runebeta/table_rune_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{calculate_chunk_size, split_input, InsertRecords};

use super::models::NewRuneStats;
use super::table_transaction_rune_entry::{create_update_rune_mintable, create_update_rune_total_holders};
pub const NUMBER_OF_FIELDS: u16 = 9;
pub const NUMBER_OF_FIELDS: u16 = 10;

pub fn create_update_rune_entry(height: &u64) -> SqlQuery {
let query = format!(
Expand Down Expand Up @@ -53,10 +53,10 @@ pub fn create_update_rune_stats_total_holders(height: &u64) -> SqlQuery {
WHERE balance_value > 0 AND block_height <= {}
GROUP BY rune_id
)
UPDATE transaction_rune_entries
UPDATE rune_stats
SET total_holders = rtd.total_holders
FROM rune_total_holders rtd
WHERE transaction_rune_entries.rune_id = rtd.rune_id;
WHERE rune_stats.rune_id = rtd.rune_id;
",
height);
diesel::sql_query(query)
Expand Down
16 changes: 9 additions & 7 deletions src/runebeta/table_transaction_rune_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ pub const RUNE_MINT_TYPE_FIXED_CAP: &str = "fixed-cap";
pub const RUNE_MINT_TYPE_FAIRMINT: &str = "fairmint";

pub fn create_update_rune_mintable(height: &u64) -> SqlQuery {
//
let query = format!(
r#"UPDATE transaction_rune_entries
SET mintable = COALESCE (offset_start , -block_height) + block_height <= {0}
AND COALESCE (height_start, 0) <= {0}
AND COALESCE (offset_end , {0} - block_height) + block_height >= {0}
AND COALESCE(height_end, {0} ) >= {0}
AND cap > mints
WHERE terms IS NOT NULL;"#,
r#"
UPDATE transaction_rune_entries
SET mintable = COALESCE (offset_start , -block_height) + block_height <= {0}
AND COALESCE (height_start, 0) <= {0}
AND COALESCE (offset_end , {0} - block_height) + block_height >= {0}
AND COALESCE(height_end, {0} ) >= {0}
AND cap > mints
WHERE terms IS NOT NULL AND ((mintable OR (IS NOT mintable AND (mints <= cap)));"#,
height
);
diesel::sql_query(query)
Expand Down