-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Populate memo in bigtable transaction structs (#19512) * Populate memo in bigtable transaction structs * Preface memos with len (cherry picked from commit f4ae450) # Conflicts: # transaction-status/src/parse_instruction.rs * Fix conflicts Co-authored-by: Tyera Eulberg <[email protected]> Co-authored-by: Tyera Eulberg <[email protected]>
- Loading branch information
1 parent
fe1c20c
commit db65b4e
Showing
4 changed files
with
65 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use { | ||
crate::parse_instruction::parse_memo_data, | ||
solana_sdk::{message::Message, pubkey::Pubkey}, | ||
}; | ||
|
||
// A helper function to convert spl_memo::v1::id() as spl_sdk::pubkey::Pubkey to | ||
// solana_sdk::pubkey::Pubkey | ||
pub fn spl_memo_id_v1() -> Pubkey { | ||
Pubkey::new_from_array(spl_memo::v1::id().to_bytes()) | ||
} | ||
|
||
// A helper function to convert spl_memo::id() as spl_sdk::pubkey::Pubkey to | ||
// solana_sdk::pubkey::Pubkey | ||
pub fn spl_memo_id_v3() -> Pubkey { | ||
Pubkey::new_from_array(spl_memo::id().to_bytes()) | ||
} | ||
|
||
pub fn extract_and_fmt_memos(message: &Message) -> Option<String> { | ||
let memos = extract_memos(message); | ||
if memos.is_empty() { | ||
None | ||
} else { | ||
Some(memos.join("; ")) | ||
} | ||
} | ||
|
||
fn extract_memos(message: &Message) -> Vec<String> { | ||
let mut memos = vec![]; | ||
if message.account_keys.contains(&spl_memo_id_v1()) | ||
|| message.account_keys.contains(&spl_memo_id_v3()) | ||
{ | ||
for instruction in &message.instructions { | ||
let program_id = message.account_keys[instruction.program_id_index as usize]; | ||
if program_id == spl_memo_id_v1() || program_id == spl_memo_id_v3() { | ||
let memo_len = instruction.data.len(); | ||
let parsed_memo = parse_memo_data(&instruction.data) | ||
.unwrap_or_else(|_| "(unparseable)".to_string()); | ||
memos.push(format!("[{}] {}", memo_len, parsed_memo)); | ||
} | ||
} | ||
} | ||
memos | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters