Skip to content

Commit

Permalink
Add writable status and slot
Browse files Browse the repository at this point in the history
  • Loading branch information
ChewingGlass committed Feb 28, 2024
1 parent 43a3b88 commit 800dae7
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 11 deletions.
2 changes: 1 addition & 1 deletion solana-explorer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions solana-explorer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "substreams-solana-explorer"
version = "0.1.0"
version = "0.3.0"
description = "Substreams showcasing the building blocks of Solana"
edition = "2021"
repository = "https://github.com/streamingfast/substreams-explorers"
Expand Down Expand Up @@ -30,4 +30,4 @@ getrandom = { version = "0.2", features = ["custom"] }
[profile.release]
lto = true
opt-level = 's'
strip = "debuginfo"
strip = "debuginfo"
9 changes: 8 additions & 1 deletion solana-explorer/proto/transactions.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ package sol.transactions.v1;

message Instructions {
repeated Instruction instructions = 1;
uint64 slot = 2;
}

message Instruction {
string program_id = 1;
repeated string accounts = 2;
repeated AccountMeta accounts = 2;
string data = 3;
}

message AccountMeta {
string pubkey = 1;
bool is_writable = 2;
bool is_signer = 3;
}

message Transactions {
repeated Transaction transactions = 1;
}
Expand Down
28 changes: 25 additions & 3 deletions solana-explorer/src/map_filter_instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fn map_filter_instructions(params: String, blk: Block) -> Result<Instructions, s
let ConfirmedTransaction { transaction, meta } = tx;
let inner_instructions = &meta.as_ref().unwrap().inner_instructions;
let msg = transaction.as_ref().unwrap().message.as_ref().unwrap();
let header = msg.header.as_ref().unwrap();
let inner_instructions_by_index = inner_instructions
.into_iter()
.map(|i| (i.index, &i.instructions))
Expand Down Expand Up @@ -51,7 +52,16 @@ fn map_filter_instructions(params: String, blk: Block) -> Result<Instructions, s
accounts: inst
.accounts
.iter()
.map(|acct| bs58::encode(resolved_accounts[*acct as usize].to_vec()).into_string())
.map(|acct| crate::pb::sol::transactions::v1::AccountMeta {
pubkey: bs58::encode(resolved_accounts[*acct as usize].to_vec()).into_string(),
is_writable: u32::from(*acct)
< (header.num_required_signatures - header.num_readonly_signed_accounts)
|| (u32::from(*acct) >= header.num_required_signatures
&& u32::from(*acct)
< ((msg.account_keys.len() as u32)
- header.num_readonly_unsigned_accounts)),
is_signer: u32::from(*acct) < header.num_required_signatures,
})
.collect(),
data: bs58::encode(&inst.data).into_string(),
})
Expand All @@ -74,7 +84,16 @@ fn map_filter_instructions(params: String, blk: Block) -> Result<Instructions, s
accounts: ix
.accounts
.iter()
.map(|acct| bs58::encode(resolved_accounts[*acct as usize].to_vec()).into_string())
.map(|acct| crate::pb::sol::transactions::v1::AccountMeta {
pubkey: bs58::encode(resolved_accounts[*acct as usize].to_vec()).into_string(),
is_writable: u32::from(*acct)
< (header.num_required_signatures - header.num_readonly_signed_accounts)
|| (u32::from(*acct) >= header.num_required_signatures
&& u32::from(*acct)
< ((msg.account_keys.len() as u32)
- header.num_readonly_unsigned_accounts)),
is_signer: u32::from(*acct) < header.num_required_signatures,
})
.collect(),
data: bs58::encode(&ix.data).into_string(),
}),
Expand All @@ -85,7 +104,10 @@ fn map_filter_instructions(params: String, blk: Block) -> Result<Instructions, s
})
.collect::<Vec<_>>();

Ok(Instructions { instructions })
Ok(Instructions {
instructions,
slot: blk.slot,
})
}

fn parse_filters_from_params(params: String) -> Result<InstructionFilterParams, substreams::errors::Error> {
Expand Down
11 changes: 10 additions & 1 deletion solana-explorer/src/map_filter_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fn map_filter_transactions(params: String, blk: Block) -> Result<Transactions, V
.filter(|tx| apply_filter(tx, &filters))
.for_each(|tx| {
let msg = tx.transaction.as_ref().unwrap().message.as_ref().unwrap();
let header = msg.header.as_ref().unwrap();
let acct_keys = tx.resolved_accounts();

let insts: Vec<Instruction> = msg
Expand All @@ -29,7 +30,15 @@ fn map_filter_transactions(params: String, blk: Block) -> Result<Transactions, V
accounts: inst
.accounts
.iter()
.map(|acct| bs58::encode(acct_keys[*acct as usize].to_vec()).into_string())
.map(|acct| crate::pb::sol::transactions::v1::AccountMeta {
pubkey: bs58::encode(acct_keys[*acct as usize].to_vec()).into_string(),
is_writable: u32::from(*acct)
< (header.num_required_signatures - header.num_readonly_signed_accounts)
|| (u32::from(*acct) >= header.num_required_signatures
&& u32::from(*acct)
< ((msg.account_keys.len() as u32) - header.num_readonly_unsigned_accounts)),
is_signer: u32::from(*acct) < header.num_required_signatures,
})
.collect(),
data: bs58::encode(&inst.data).into_string(),
})
Expand Down
16 changes: 14 additions & 2 deletions solana-explorer/src/pb/sol.transactions.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,31 @@
pub struct Instructions {
#[prost(message, repeated, tag="1")]
pub instructions: ::prost::alloc::vec::Vec<Instruction>,
#[prost(uint64, tag="2")]
pub slot: u64,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Instruction {
#[prost(string, tag="1")]
pub program_id: ::prost::alloc::string::String,
#[prost(string, repeated, tag="2")]
pub accounts: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
#[prost(message, repeated, tag="2")]
pub accounts: ::prost::alloc::vec::Vec<AccountMeta>,
#[prost(string, tag="3")]
pub data: ::prost::alloc::string::String,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AccountMeta {
#[prost(string, tag="1")]
pub pubkey: ::prost::alloc::string::String,
#[prost(bool, tag="2")]
pub is_writable: bool,
#[prost(bool, tag="3")]
pub is_signer: bool,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Transactions {
#[prost(message, repeated, tag="1")]
pub transactions: ::prost::alloc::vec::Vec<Transaction>,
Expand Down
2 changes: 1 addition & 1 deletion solana-explorer/substreams.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
specVersion: v0.1.0
package:
name: "solana_explorer"
version: v0.2.0
version: v0.3.0
url: https://github.com/streamingfast/substreams-explorers/
image: ./solana.png
doc: |
Expand Down

0 comments on commit 800dae7

Please sign in to comment.