Skip to content

Commit

Permalink
Add messages_sent
Browse files Browse the repository at this point in the history
  • Loading branch information
zolting committed Nov 26, 2024
1 parent 13e655b commit f64db59
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 19 deletions.
8 changes: 6 additions & 2 deletions blocks/starknet/src/map_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ pub fn map_events(clock: Clock, block: Block) -> Result<EventsOutput, Error> {
let mut events = EventsOutput {
blocks: vec![collect_block(&block, &timestamp, &block_hashes)],
transactions: vec![],
access_lists: vec![],
messages_sent: vec![],
events: vec![],
calls: vec![],
};

for (index, transaction) in block.transactions.iter().enumerate() {
events.transactions.push(collect_transaction(&block, transaction, index as u32, &timestamp, &block_hashes));
// messages_sent should be a field in `transaction` when complex arrays are supported by substreams-sink-files
let (trx, messages_sent) = collect_transaction(&block, transaction, index as u32, &timestamp, &block_hashes);

events.transactions.push(trx);
events.messages_sent.extend(messages_sent);
}

Ok(events)
Expand Down
40 changes: 26 additions & 14 deletions blocks/starknet/src/pb/pinax.starknet.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct EventsOutput {
#[prost(message, repeated, tag="2")]
pub transactions: ::prost::alloc::vec::Vec<Transaction>,
#[prost(message, repeated, tag="3")]
pub access_lists: ::prost::alloc::vec::Vec<AccessList>,
pub messages_sent: ::prost::alloc::vec::Vec<MessageSent>,
#[prost(message, repeated, tag="4")]
pub events: ::prost::alloc::vec::Vec<Events>,
#[prost(message, repeated, tag="5")]
Expand Down Expand Up @@ -159,7 +159,7 @@ pub struct Transaction {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AccessList {
pub struct MessageSent {
/// clock
#[prost(message, optional, tag="1")]
pub block_time: ::core::option::Option<::prost_types::Timestamp>,
Expand All @@ -169,19 +169,31 @@ pub struct AccessList {
pub block_date: ::prost::alloc::string::String,
#[prost(string, tag="4")]
pub block_hash: ::prost::alloc::string::String,
/// transaction
/// block
#[prost(string, tag="5")]
pub tx_hash: ::prost::alloc::string::String,
#[prost(bool, tag="6")]
pub tx_success: bool,
/// Index of the access list entry in the transaction
#[prost(uint32, tag="7")]
pub index: u32,
/// access list
#[prost(string, tag="8")]
pub address: ::prost::alloc::string::String,
#[prost(string, repeated, tag="9")]
pub storage_keys: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
pub block_l1_da_mode: ::prost::alloc::string::String,
#[prost(bytes="vec", tag="6")]
pub block_l1_data_gas_price_in_fri: ::prost::alloc::vec::Vec<u8>,
#[prost(bytes="vec", tag="7")]
pub block_l1_data_gas_price_in_wei: ::prost::alloc::vec::Vec<u8>,
#[prost(bytes="vec", tag="8")]
pub block_l1_gas_price_in_fri: ::prost::alloc::vec::Vec<u8>,
#[prost(bytes="vec", tag="9")]
pub block_l1_gas_price_in_wei: ::prost::alloc::vec::Vec<u8>,
#[prost(string, tag="10")]
pub block_starknet_version: ::prost::alloc::string::String,
/// transaction
#[prost(uint32, tag="11")]
pub tx_index: u32,
#[prost(string, tag="12")]
pub tx_type: ::prost::alloc::string::String,
/// message sent
#[prost(string, tag="13")]
pub from_address: ::prost::alloc::string::String,
#[prost(string, repeated, tag="14")]
pub payload: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
#[prost(string, tag="15")]
pub to_address: ::prost::alloc::string::String,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
30 changes: 27 additions & 3 deletions blocks/starknet/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use common::{
use crate::{
blocks::l1_da_mode_to_string,
pb::{
pinax::starknet::v1::Transaction,
pinax::starknet::v1::{MessageSent, Transaction},
sf::starknet::r#type::v1::{transaction_with_receipt::Transaction as TrxType, Block, TransactionWithReceipt},
},
utils::BlockHashes,
};

pub fn collect_transaction(block: &Block, transaction: &TransactionWithReceipt, tx_index: u32, timestamp: &BlockTimestamp, block_hashes: &BlockHashes) -> Transaction {
pub fn collect_transaction(block: &Block, transaction: &TransactionWithReceipt, tx_index: u32, timestamp: &BlockTimestamp, block_hashes: &BlockHashes) -> (Transaction, Vec<MessageSent>) {
let receipt = transaction.receipt.as_ref().expect("Receipt is missing");

let actual_fee = receipt.actual_fee.as_ref().expect("Actual fee missing");
Expand All @@ -25,7 +25,7 @@ pub fn collect_transaction(block: &Block, transaction: &TransactionWithReceipt,

let tx_data = extract_fields_from_transaction(transaction);

Transaction {
let transaction = Transaction {
block_date: timestamp.date.clone(),
block_time: Some(timestamp.time.clone()),
block_number: timestamp.number,
Expand Down Expand Up @@ -82,7 +82,31 @@ pub fn collect_transaction(block: &Block, transaction: &TransactionWithReceipt,
signature: tx_data.signature,
message_hash: receipt.message_hash.clone(),
revert_reason: receipt.revert_reason.clone(),
};

let mut messages_sent: Vec<MessageSent> = Vec::new();

for message in receipt.messages_sent.iter() {
messages_sent.push(MessageSent {
block_date: timestamp.date.clone(),
block_time: Some(timestamp.time.clone()),
block_number: timestamp.number,
block_hash: block_hashes.new_root.clone(),
block_l1_da_mode: l1_da_mode_to_string(block.l1_da_mode),
block_l1_data_gas_price_in_fri: l1_data_gas_price.price_in_fri.clone(),
block_l1_data_gas_price_in_wei: l1_data_gas_price.price_in_wei.clone(),
block_l1_gas_price_in_fri: l1_gas_price.price_in_fri.clone(),
block_l1_gas_price_in_wei: l1_gas_price.price_in_wei.clone(),
block_starknet_version: block.starknet_version.clone(),
tx_index,
tx_type: tx_type_to_string(receipt.r#type),
from_address: bytes_to_hex(&message.from_address),
to_address: bytes_to_hex(&message.to_address),
payload: u8_2d_vec_to_string_array(&message.payload),
});
}

(transaction, messages_sent)
}

pub fn extract_fields_from_transaction(transaction: &TransactionWithReceipt) -> TransactionData {
Expand Down
26 changes: 26 additions & 0 deletions proto/starknet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ option go_package = "github.com/streamingfast/firehose-starknet/pb/sf/starknet/t
message EventsOutput {
repeated Block blocks = 1;
repeated Transaction transactions = 2;
repeated MessageSent messages_sent = 3;
repeated Events events = 4;
repeated Call calls = 5;
}
Expand Down Expand Up @@ -89,6 +90,31 @@ message Transaction {
string revert_reason = 52;
}

message MessageSent {
// clock
google.protobuf.Timestamp block_time = 1;
uint64 block_number = 2;
string block_date = 3;
string block_hash = 4;

// block
string block_l1_da_mode = 5;
bytes block_l1_data_gas_price_in_fri = 6;
bytes block_l1_data_gas_price_in_wei = 7;
bytes block_l1_gas_price_in_fri = 8;
bytes block_l1_gas_price_in_wei = 9;
string block_starknet_version = 10;

// transaction
uint32 tx_index = 11;
string tx_type = 12;

// message sent
string from_address = 13;
repeated string payload = 14;
string to_address = 15;
}

message Events {
// clock
google.protobuf.Timestamp block_time = 1;
Expand Down

0 comments on commit f64db59

Please sign in to comment.