Skip to content

Commit

Permalink
add contract_address, module_name, and function_name columns to user_…
Browse files Browse the repository at this point in the history
…transactions table
  • Loading branch information
0xmaayan committed Jan 7, 2025
1 parent 0cad206 commit f6af779
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1 deletion.
3 changes: 3 additions & 0 deletions rust/integration-tests/src/models/user_transactions_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ pub struct UserTransaction {
pub entry_function_id_str: String,
pub inserted_at: chrono::NaiveDateTime,
pub epoch: i64,
pub contract_address: String,
pub module_name: String,
pub function_name: String,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- This file should undo anything in `up.sql`
ALTER TABLE user_transactions
DROP COLUMN IF EXISTS contract_address,
DROP COLUMN IF EXISTS module_name,
DROP COLUMN IF EXISTS function_name;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Your SQL goes here
ALTER TABLE user_transactions
ADD COLUMN contract_address VARCHAR(66) NOT NULL,
ADD COLUMN module_name VARCHAR(255) NOT NULL,
ADD COLUMN function_name VARCHAR(255) NOT NULL;
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use super::signatures::Signature;
use crate::{
schema::user_transactions,
utils::util::{
get_entry_function_from_user_request, parse_timestamp, standardize_address,
get_entry_function_contract_address_from_user_request,
get_entry_function_from_user_request, get_entry_function_function_name_from_user_request,
get_entry_function_module_name_from_user_request, parse_timestamp, standardize_address,
u64_to_bigdecimal,
},
};
Expand All @@ -38,6 +40,9 @@ pub struct UserTransaction {
pub timestamp: chrono::NaiveDateTime,
pub entry_function_id_str: String,
pub epoch: i64,
pub contract_address: String,
pub module_name: String,
pub function_name: String,
}

impl UserTransaction {
Expand Down Expand Up @@ -79,6 +84,14 @@ impl UserTransaction {
entry_function_id_str: get_entry_function_from_user_request(user_request)
.unwrap_or_default(),
epoch,
contract_address: get_entry_function_contract_address_from_user_request(
user_request,
)
.unwrap_or_default(),
module_name: get_entry_function_module_name_from_user_request(user_request)
.unwrap_or_default(),
function_name: get_entry_function_function_name_from_user_request(user_request)
.unwrap_or_default(),
},
Self::get_signatures(user_request, version, block_height),
)
Expand Down
6 changes: 6 additions & 0 deletions rust/processor/src/db/postgres/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,12 @@ diesel::table! {
entry_function_id_str -> Varchar,
inserted_at -> Timestamp,
epoch -> Int8,
#[max_length = 66]
contract_address -> Varchar,
#[max_length = 255]
module_name -> Varchar,
#[max_length = 255]
function_name -> Varchar,
}
}

Expand Down
28 changes: 28 additions & 0 deletions rust/processor/src/utils/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,34 @@ pub fn get_entry_function_from_user_request(
entry_function_id_str.map(|s| truncate_str(&s, MAX_ENTRY_FUNCTION_LENGTH))
}

pub fn get_entry_function_contract_address_from_user_request(
user_request: &UserTransactionRequest,
) -> Option<String> {
get_entry_function_from_user_request(user_request).and_then(|s| {
s.split("::").next().map(String::from) // Get the first element (contract address)
})
}

pub fn get_entry_function_module_name_from_user_request(
user_request: &UserTransactionRequest,
) -> Option<String> {
get_entry_function_from_user_request(user_request).and_then(|s| {
s.split("::")
.nth(1) // Get the second element (module name)
.map(String::from)
})
}

pub fn get_entry_function_function_name_from_user_request(
user_request: &UserTransactionRequest,
) -> Option<String> {
get_entry_function_from_user_request(user_request).and_then(|s| {
s.split("::")
.nth(2) // Get the third element (function name)
.map(String::from)
})
}

pub fn get_payload_type(payload: &TransactionPayload) -> String {
payload.r#type().as_str_name().to_string()
}
Expand Down

0 comments on commit f6af779

Please sign in to comment.