Skip to content

Commit 19f663c

Browse files
committed
adjusts to return bytes
1 parent b2bae1e commit 19f663c

File tree

5 files changed

+32
-18
lines changed

5 files changed

+32
-18
lines changed

Cargo.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ solana-transaction-status = { workspace = true }
2828
async-trait = { workspace = true }
2929
borsh = { version = "0.10.4" }
3030
bs58 = { workspace = true }
31+
base64 = { workspace = true }
3132
log = { workspace = true }
3233
serde = { workspace = true }
3334
serde_json = { workspace = true }

crates/core/src/instruction.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ enum LogType {
7070
}
7171

7272
impl InstructionMetadata {
73-
/// Extracts the `data` log messages associated with this instruction.
73+
/// Extracts the `data` from log messages associated with this instruction.
7474
///
7575
/// This method filters the transaction's log messages to return only those
7676
/// that correspond to the current instruction, based on its stack height and
7777
/// absolute path within the instruction stack.
7878
///
79-
/// Returns `Vec<String>` containing the `data` log messages.
80-
pub fn extract_logs(&self) -> Vec<String> {
79+
/// Returns `Vec<Vec<u8>>` containing the `data` bytes (base64 encoded) from log messages.
80+
pub fn extract_logs(&self) -> Vec<Vec<u8>> {
8181
let logs = match &self.transaction_metadata.meta.log_messages {
8282
Some(logs) => logs,
8383
None => return Vec::new(),
@@ -128,7 +128,13 @@ impl InstructionMetadata {
128128

129129
// Extract if we're on target path and it's a data log
130130
if current_path == self.absolute_path && matches!(parsed_log, LogType::Data) {
131-
extracted_logs.push(log.clone());
131+
if let Some(data) = log.split_whitespace().last() {
132+
if let Ok(buf) =
133+
base64::Engine::decode(&base64::engine::general_purpose::STANDARD, data)
134+
{
135+
extracted_logs.push(buf);
136+
}
137+
}
132138
}
133139
}
134140

examples/log-events-example/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = { workspace = true }
55

66
[dependencies]
77
carbon-core = { workspace = true }
8-
carbon-jupiter-swap-decoder = { workspace = true }
8+
carbon-raydium-cpmm-decoder = { workspace = true }
99
carbon-log-metrics = { workspace = true }
1010
carbon-yellowstone-grpc-datasource = { workspace = true }
1111

@@ -15,6 +15,7 @@ env_logger = { workspace = true }
1515
solana-instruction = { workspace = true }
1616
tokio = { workspace = true, features = ["full"] }
1717
yellowstone-grpc-proto = { workspace = true }
18+
base64 = { workspace = true }
1819

1920
[dependencies.rustls]
2021
default-features = false

examples/log-events-example/src/main.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
use {
22
async_trait::async_trait,
33
carbon_core::{
4+
borsh::BorshDeserialize,
45
error::CarbonResult,
56
instruction::{DecodedInstruction, InstructionMetadata, NestedInstructions},
67
metrics::MetricsCollection,
78
processor::Processor,
89
},
9-
carbon_jupiter_swap_decoder::{
10-
instructions::JupiterSwapInstruction, JupiterSwapDecoder,
11-
PROGRAM_ID as JUPITER_SWAP_PROGRAM_ID,
12-
},
1310
carbon_log_metrics::LogMetrics,
11+
carbon_raydium_cpmm_decoder::{
12+
instructions::RaydiumCpmmInstruction, types::SwapEvent, RaydiumCpmmDecoder,
13+
PROGRAM_ID as RAYDIUM_CPMM_PROGRAM_ID,
14+
},
1415
carbon_yellowstone_grpc_datasource::{
1516
YellowstoneGrpcClientConfig, YellowstoneGrpcGeyserClient,
1617
},
@@ -39,7 +40,7 @@ pub async fn main() -> CarbonResult<()> {
3940
failed: Some(false),
4041
account_include: vec![],
4142
account_exclude: vec![],
42-
account_required: vec![JUPITER_SWAP_PROGRAM_ID.to_string().clone()],
43+
account_required: vec![RAYDIUM_CPMM_PROGRAM_ID.to_string().clone()],
4344
signature: None,
4445
};
4546

@@ -75,7 +76,7 @@ pub async fn main() -> CarbonResult<()> {
7576
.datasource(yellowstone_grpc)
7677
.metrics(Arc::new(LogMetrics::new()))
7778
.metrics_flush_interval(3)
78-
.instruction(JupiterSwapDecoder, JupiterSwapInstructionProcessor)
79+
.instruction(RaydiumCpmmDecoder, RaydiumCpmmInstructionProcessor)
7980
.shutdown_strategy(carbon_core::pipeline::ShutdownStrategy::Immediate)
8081
.build()?
8182
.run()
@@ -84,13 +85,13 @@ pub async fn main() -> CarbonResult<()> {
8485
Ok(())
8586
}
8687

87-
pub struct JupiterSwapInstructionProcessor;
88+
pub struct RaydiumCpmmInstructionProcessor;
8889

8990
#[async_trait]
90-
impl Processor for JupiterSwapInstructionProcessor {
91+
impl Processor for RaydiumCpmmInstructionProcessor {
9192
type InputType = (
9293
InstructionMetadata,
93-
DecodedInstruction<JupiterSwapInstruction>,
94+
DecodedInstruction<RaydiumCpmmInstruction>,
9495
NestedInstructions,
9596
solana_instruction::Instruction,
9697
);
@@ -107,9 +108,12 @@ impl Processor for JupiterSwapInstructionProcessor {
107108
"Processing instruction - Index: {}, Stack Height: {}, Path: {:?}",
108109
metadata.index, metadata.stack_height, metadata.absolute_path
109110
);
110-
println!("Extracted {} logs:", logs.len());
111-
for (i, log) in logs.iter().enumerate() {
112-
println!(" {}: {}", i, log);
111+
for log in logs {
112+
if log.len() > 8 {
113+
if let Ok(swap_event) = SwapEvent::deserialize(&mut &log[8..]) {
114+
println!("SwapEvent: {:?}", swap_event);
115+
}
116+
}
113117
}
114118
println!("--------------------------------");
115119
}

0 commit comments

Comments
 (0)