From 3466b47fb06dc0e76813628e8b1c544b31d562b7 Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Tue, 3 Dec 2024 08:08:32 -0500 Subject: [PATCH] add decode_tx_error --- Cargo.toml | 2 +- Makefile | 1 + examples/typescript/src/client.ts | 3 +++ .../solana-encoding-wasm/Cargo.lock | 2 +- .../solana-encoding-wasm/Cargo.toml | 2 +- .../solana-encoding-wasm/src/lib.rs | 15 +++++++++++++-- yellowstone-grpc-client-nodejs/src/index.ts | 10 ++++++++-- 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bc3b2795..040ca75f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ members = [ "yellowstone-grpc-proto", # 4.0.0 ] exclude = [ - "yellowstone-grpc-client-nodejs/solana-encoding-wasm", # 1.0.0 + "yellowstone-grpc-client-nodejs/solana-encoding-wasm", # 3.0.0 ] [workspace.package] diff --git a/Makefile b/Makefile index 97a64d4a..a41cc0f6 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ clean: clean-nodejs clean-rust + rm -rf test-ledger clean-nodejs: rm -rf examples/typescript/dist diff --git a/examples/typescript/src/client.ts b/examples/typescript/src/client.ts index 7068e30c..3c8633f5 100644 --- a/examples/typescript/src/client.ts +++ b/examples/typescript/src/client.ts @@ -6,6 +6,7 @@ import Client, { SubscribeRequestFilterAccountsFilterLamports, SubscribeUpdateTransactionInfo, txEncode, + txErrDecode, } from "@triton-one/yellowstone-grpc"; async function main() { @@ -92,6 +93,8 @@ async function subscribeCommand(client, args) { console.log( `TX filters: ${data.filters}, slot#${slot}, tx: ${JSON.stringify(tx)}` ); + const err = txErrDecode.decode(data.transaction.transaction.meta.err.err); + console.log(`TX error: ${err}`); return; } diff --git a/yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.lock b/yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.lock index e0ca9859..271f3ab6 100644 --- a/yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.lock +++ b/yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.lock @@ -3273,7 +3273,7 @@ dependencies = [ [[package]] name = "yellowstone-grpc-solana-encoding-wasm" -version = "2.0.0" +version = "3.0.0" dependencies = [ "serde_json", "solana-transaction-status", diff --git a/yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.toml b/yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.toml index 9bdf2828..ada23c27 100644 --- a/yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.toml +++ b/yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yellowstone-grpc-solana-encoding-wasm" -version = "2.0.0" +version = "3.0.0" authors = ["Triton One"] edition = "2021" homepage = "https://triton.one" diff --git a/yellowstone-grpc-client-nodejs/solana-encoding-wasm/src/lib.rs b/yellowstone-grpc-client-nodejs/solana-encoding-wasm/src/lib.rs index 703fa9cd..ff890290 100644 --- a/yellowstone-grpc-client-nodejs/solana-encoding-wasm/src/lib.rs +++ b/yellowstone-grpc-client-nodejs/solana-encoding-wasm/src/lib.rs @@ -2,7 +2,9 @@ use { solana_transaction_status::{TransactionWithStatusMeta, UiTransactionEncoding}, wasm_bindgen::prelude::*, yellowstone_grpc_proto::{ - convert_from, prelude::SubscribeUpdateTransactionInfo, prost::Message, + convert_from, + prelude::{SubscribeUpdateTransactionInfo, TransactionError as TransactionErrorProto}, + prost::Message, }, }; @@ -29,7 +31,7 @@ impl From for UiTransactionEncoding { } #[wasm_bindgen] -pub fn encode( +pub fn tx_encode( data: &[u8], encoding: WasmUiTransactionEncoding, max_supported_transaction_version: Option, @@ -49,3 +51,12 @@ pub fn encode( Err(JsError::new("tx with missing metadata")) } } + +#[wasm_bindgen] +pub fn decode_tx_error(err: Vec) -> Result { + match convert_from::create_tx_error(Some(&TransactionErrorProto { err })) { + Ok(Some(err)) => serde_json::to_string(&err).map_err(Into::into), + Ok(None) => Err(JsError::new("unexpected")), + Err(error) => Err(JsError::new(error)), + } +} diff --git a/yellowstone-grpc-client-nodejs/src/index.ts b/yellowstone-grpc-client-nodejs/src/index.ts index 5a0421f7..62571b66 100644 --- a/yellowstone-grpc-client-nodejs/src/index.ts +++ b/yellowstone-grpc-client-nodejs/src/index.ts @@ -61,7 +61,7 @@ import * as wasm from "./encoding/yellowstone_grpc_solana_encoding_wasm"; import { MapTransactionEncodingToReturnType } from "./types"; export const txEncode = { encoding: wasm.WasmUiTransactionEncoding, - encode_raw: wasm.encode, + encode_raw: wasm.tx_encode, encode: ( message: SubscribeUpdateTransactionInfo, encoding: T, @@ -69,7 +69,7 @@ export const txEncode = { show_rewards: boolean ): MapTransactionEncodingToReturnType[T] => { return JSON.parse( - wasm.encode( + wasm.tx_encode( SubscribeUpdateTransactionInfo.encode(message).finish(), encoding, max_supported_transaction_version, @@ -78,6 +78,12 @@ export const txEncode = { ); }, }; +export const txErrDecode = { + decode_raw: wasm.decode_tx_error, + decode: (buf: any): any => { + return wasm.decode_tx_error(buf); + } +}; export default class Client { _client: GeyserClient;