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 d7ed05e
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"gas_unit_price": "100",
"timestamp": "2022-10-18T23:10:04.331016",
"entry_function_id_str": "0xa3f6a53c57395401ce64f09a188e2259dc9b156387e76c88a7a80a8fe5254476::momentum_safe::register",
"epoch": 75
"epoch": 75,
"contract_address": "0xa3f6a53c57395401ce64f09a188e2259dc9b156387e76c88a7a80a8fe5254476",
"module_name": "momentum_safe",
"function_name": "register"
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"gas_unit_price": "100",
"timestamp": "2024-10-16T17:07:21.987832",
"entry_function_id_str": "0x1::aptos_account::transfer",
"epoch": 8870
"epoch": 8870,
"contract_address": "0x1",
"module_name": "aptos_account",
"function_name": "transfer"
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"gas_unit_price": "100",
"timestamp": "2022-10-12T21:26:20.299882",
"entry_function_id_str": "0x1::stake::update_network_and_fullnode_addresses",
"epoch": 2
"epoch": 2,
"contract_address": "0x1",
"module_name": "stake",
"function_name": "update_network_and_fullnode_addresses"
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"gas_unit_price": "100",
"timestamp": "2024-02-23T22:21:53.482262",
"entry_function_id_str": "0x1::coin::transfer",
"epoch": 6013
"epoch": 6013,
"contract_address": "0x1",
"module_name": "coin",
"function_name": "transfer"
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"gas_unit_price": "100",
"timestamp": "2024-01-16T09:35:08.981259",
"entry_function_id_str": "0x1::coin::transfer",
"epoch": 5547
"epoch": 5547,
"contract_address": "0x1",
"module_name": "coin",
"function_name": "transfer"
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"gas_unit_price": "100",
"timestamp": "2024-05-09T01:18:59.975711",
"entry_function_id_str": "0x1::aptos_account::transfer_coins",
"epoch": 6924
"epoch": 6924,
"contract_address": "0x1",
"module_name": "aptos_account",
"function_name": "transfer_coins"
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"gas_unit_price": "100",
"timestamp": "2024-06-10T15:51:10.170250",
"entry_function_id_str": "0x1::aptos_account::transfer_coins",
"epoch": 7324
"epoch": 7324,
"contract_address": "0x1",
"module_name": "aptos_account",
"function_name": "transfer_coins"
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"gas_unit_price": "100",
"timestamp": "2024-03-29T13:51:13.448212",
"entry_function_id_str": "0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::scripts_v2::swap",
"epoch": 6429
"epoch": 6429,
"contract_address": "0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12",
"module_name": "scripts_v2",
"function_name": "swap"
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"gas_unit_price": "100",
"timestamp": "2024-04-13T17:59:30.751467",
"entry_function_id_str": "0x1::aptos_account::transfer_coins",
"epoch": 6620
"epoch": 6620,
"contract_address": "0x1",
"module_name": "aptos_account",
"function_name": "transfer_coins"
}
]
]
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 d7ed05e

Please sign in to comment.