client: add tx pretty print to rust (#189)
This commit is contained in:
parent
f559fa8f60
commit
ed4350d316
|
@ -13,6 +13,7 @@ The minor version will be incremented upon a breaking change and the patch versi
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- proto: add mod `convert_to`, `convert_from` ([#190](https://github.com/rpcpool/yellowstone-grpc/pull/190)).
|
- proto: add mod `convert_to`, `convert_from` ([#190](https://github.com/rpcpool/yellowstone-grpc/pull/190)).
|
||||||
|
- client: add tx pretty print to rust ([#189](https://github.com/rpcpool/yellowstone-grpc/pull/189)).
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
|
|
||||||
|
|
|
@ -4493,7 +4493,9 @@ dependencies = [
|
||||||
"hex",
|
"hex",
|
||||||
"log",
|
"log",
|
||||||
"maplit",
|
"maplit",
|
||||||
|
"serde_json",
|
||||||
"solana-sdk",
|
"solana-sdk",
|
||||||
|
"solana-transaction-status",
|
||||||
"tokio",
|
"tokio",
|
||||||
"yellowstone-grpc-client",
|
"yellowstone-grpc-client",
|
||||||
"yellowstone-grpc-proto",
|
"yellowstone-grpc-proto",
|
||||||
|
|
|
@ -20,7 +20,9 @@ futures = "0.3.24"
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
log = { version = "0.4.14", features = ["std"] }
|
log = { version = "0.4.14", features = ["std"] }
|
||||||
maplit = "1.0.2"
|
maplit = "1.0.2"
|
||||||
|
serde_json = "1.0.86"
|
||||||
solana-sdk = "=1.16.14"
|
solana-sdk = "=1.16.14"
|
||||||
|
solana-transaction-status = "=1.16.14"
|
||||||
tokio = { version = "1.21.2", features = ["rt-multi-thread", "macros", "time"] }
|
tokio = { version = "1.21.2", features = ["rt-multi-thread", "macros", "time"] }
|
||||||
yellowstone-grpc-client = { path = "../../yellowstone-grpc-client" }
|
yellowstone-grpc-client = { path = "../../yellowstone-grpc-client" }
|
||||||
yellowstone-grpc-proto = { path = "../../yellowstone-grpc-proto" }
|
yellowstone-grpc-proto = { path = "../../yellowstone-grpc-proto" }
|
||||||
|
|
|
@ -3,10 +3,11 @@ use {
|
||||||
clap::{Parser, Subcommand, ValueEnum},
|
clap::{Parser, Subcommand, ValueEnum},
|
||||||
futures::{future::TryFutureExt, sink::SinkExt, stream::StreamExt},
|
futures::{future::TryFutureExt, sink::SinkExt, stream::StreamExt},
|
||||||
log::{error, info},
|
log::{error, info},
|
||||||
solana_sdk::pubkey::Pubkey,
|
solana_sdk::{pubkey::Pubkey, signature::Signature},
|
||||||
|
solana_transaction_status::{EncodedTransactionWithStatusMeta, UiTransactionEncoding},
|
||||||
std::{
|
std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
env,
|
env, fmt,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
},
|
},
|
||||||
|
@ -20,7 +21,7 @@ use {
|
||||||
SubscribeRequestFilterAccountsFilter, SubscribeRequestFilterAccountsFilterMemcmp,
|
SubscribeRequestFilterAccountsFilter, SubscribeRequestFilterAccountsFilterMemcmp,
|
||||||
SubscribeRequestFilterBlocks, SubscribeRequestFilterBlocksMeta,
|
SubscribeRequestFilterBlocks, SubscribeRequestFilterBlocksMeta,
|
||||||
SubscribeRequestFilterEntry, SubscribeRequestFilterSlots,
|
SubscribeRequestFilterEntry, SubscribeRequestFilterSlots,
|
||||||
SubscribeRequestFilterTransactions, SubscribeUpdateAccount,
|
SubscribeRequestFilterTransactions, SubscribeUpdateAccount, SubscribeUpdateTransaction,
|
||||||
},
|
},
|
||||||
tonic::service::Interceptor,
|
tonic::service::Interceptor,
|
||||||
},
|
},
|
||||||
|
@ -353,6 +354,48 @@ impl From<SubscribeUpdateAccount> for AccountPretty {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub struct TransactionPretty {
|
||||||
|
slot: u64,
|
||||||
|
signature: Signature,
|
||||||
|
is_vote: bool,
|
||||||
|
tx: EncodedTransactionWithStatusMeta,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for TransactionPretty {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
struct TxWrap<'a>(&'a EncodedTransactionWithStatusMeta);
|
||||||
|
impl<'a> fmt::Debug for TxWrap<'a> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
let serialized = serde_json::to_string(self.0).expect("failed to serialize");
|
||||||
|
fmt::Display::fmt(&serialized, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
f.debug_struct("TransactionPretty")
|
||||||
|
.field("slot", &self.slot)
|
||||||
|
.field("signature", &self.signature)
|
||||||
|
.field("is_vote", &self.is_vote)
|
||||||
|
.field("tx", &TxWrap(&self.tx))
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<SubscribeUpdateTransaction> for TransactionPretty {
|
||||||
|
fn from(SubscribeUpdateTransaction { transaction, slot }: SubscribeUpdateTransaction) -> Self {
|
||||||
|
let tx = transaction.expect("should be defined");
|
||||||
|
Self {
|
||||||
|
slot,
|
||||||
|
signature: Signature::try_from(tx.signature.as_slice()).expect("valid signature"),
|
||||||
|
is_vote: tx.is_vote,
|
||||||
|
tx: yellowstone_grpc_proto::convert_from::create_tx_with_meta(tx)
|
||||||
|
.expect("valid tx with meta")
|
||||||
|
.encode(UiTransactionEncoding::Base64, Some(u8::MAX), true)
|
||||||
|
.expect("failed to encode"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
env::set_var(
|
env::set_var(
|
||||||
|
@ -485,6 +528,14 @@ async fn geyser_subscribe(
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Some(UpdateOneof::Transaction(tx)) => {
|
||||||
|
let tx: TransactionPretty = tx.into();
|
||||||
|
info!(
|
||||||
|
"new transaction update: filters {:?}, transaction: {:#?}",
|
||||||
|
msg.filters, tx
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
info!("new message: {msg:?}")
|
info!("new message: {msg:?}")
|
||||||
|
|
Loading…
Reference in New Issue