Skip to content

Commit

Permalink
add decode_tx_error
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Dec 3, 2024
1 parent 8513ac4 commit 3466b47
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
clean: clean-nodejs clean-rust
rm -rf test-ledger

clean-nodejs:
rm -rf examples/typescript/dist
Expand Down
3 changes: 3 additions & 0 deletions examples/typescript/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Client, {
SubscribeRequestFilterAccountsFilterLamports,
SubscribeUpdateTransactionInfo,
txEncode,
txErrDecode,
} from "@triton-one/yellowstone-grpc";

async function main() {
Expand Down Expand Up @@ -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;
}

Expand Down

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

Original file line number Diff line number Diff line change
@@ -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"
Expand Down
15 changes: 13 additions & 2 deletions yellowstone-grpc-client-nodejs/solana-encoding-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};

Expand All @@ -29,7 +31,7 @@ impl From<WasmUiTransactionEncoding> for UiTransactionEncoding {
}

#[wasm_bindgen]
pub fn encode(
pub fn tx_encode(
data: &[u8],
encoding: WasmUiTransactionEncoding,
max_supported_transaction_version: Option<u8>,
Expand All @@ -49,3 +51,12 @@ pub fn encode(
Err(JsError::new("tx with missing metadata"))
}
}

#[wasm_bindgen]
pub fn decode_tx_error(err: Vec<u8>) -> Result<String, JsError> {
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)),
}
}
10 changes: 8 additions & 2 deletions yellowstone-grpc-client-nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ 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: <T extends wasm.WasmUiTransactionEncoding>(
message: SubscribeUpdateTransactionInfo,
encoding: T,
max_supported_transaction_version: number | undefined,
show_rewards: boolean
): MapTransactionEncodingToReturnType[T] => {
return JSON.parse(
wasm.encode(
wasm.tx_encode(
SubscribeUpdateTransactionInfo.encode(message).finish(),
encoding,
max_supported_transaction_version,
Expand All @@ -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;
Expand Down

0 comments on commit 3466b47

Please sign in to comment.