Skip to content

Commit dae08b2

Browse files
nodejs: add parse err function (#483)
Co-authored-by: Dmitry Rybalchenko <[email protected]>
1 parent 8513ac4 commit dae08b2

File tree

12 files changed

+80
-25
lines changed

12 files changed

+80
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The minor version will be incremented upon a breaking change and the patch versi
1515
### Features
1616

1717
- proto: add tonic feature ([#474](https://github.com/rpcpool/yellowstone-grpc/pull/474))
18+
- nodejs: add parse err function ([#483](https://github.com/rpcpool/yellowstone-grpc/pull/483))
1819

1920
### Breaking
2021

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ members = [
77
"yellowstone-grpc-proto", # 4.0.0
88
]
99
exclude = [
10-
"yellowstone-grpc-client-nodejs/solana-encoding-wasm", # 1.0.0
10+
"yellowstone-grpc-client-nodejs/solana-encoding-wasm", # 3.0.0
1111
]
1212

1313
[workspace.package]

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
clean: clean-nodejs clean-rust
2+
rm -rf test-ledger
23

34
clean-nodejs:
45
rm -rf examples/typescript/dist

examples/typescript/package-lock.json

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

examples/typescript/src/client.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import yargs from "yargs";
2+
import { inspect } from "node:util";
23
import Client, {
34
CommitmentLevel,
45
SubscribeRequest,
56
SubscribeRequestFilterAccountsFilter,
67
SubscribeRequestFilterAccountsFilterLamports,
78
SubscribeUpdateTransactionInfo,
89
txEncode,
10+
txErrDecode,
911
} from "@triton-one/yellowstone-grpc";
1012

1113
async function main() {
@@ -85,13 +87,24 @@ async function subscribeCommand(client, args) {
8587

8688
// Handle updates
8789
stream.on("data", (data) => {
88-
if (data.transaction && args.transactionsParsed) {
90+
if (
91+
data.transaction &&
92+
(args.transactionsParsed || args.transactionsDecodeErr)
93+
) {
8994
const slot = data.transaction.slot;
9095
const message = data.transaction.transaction;
91-
const tx = txEncode.encode(message, txEncode.encoding.Json, 255, true);
92-
console.log(
93-
`TX filters: ${data.filters}, slot#${slot}, tx: ${JSON.stringify(tx)}`
94-
);
96+
if (args.transactionsParsed) {
97+
const tx = txEncode.encode(message, txEncode.encoding.Json, 255, true);
98+
console.log(
99+
`TX filters: ${data.filters}, slot#${slot}, tx: ${JSON.stringify(tx)}`
100+
);
101+
}
102+
if (message.meta.err && args.transactionsDecodeErr) {
103+
const err = txErrDecode.decode(message.meta.err.err);
104+
console.log(
105+
`TX filters: ${data.filters}, slot#${slot}, err: ${inspect(err)}}`
106+
);
107+
}
95108
return;
96109
}
97110

@@ -391,6 +404,11 @@ function parseCommandLineArgs() {
391404
describe: "parse transaction to json",
392405
type: "boolean",
393406
},
407+
"transactions-decode-err": {
408+
default: false,
409+
describe: "decode transactions errors",
410+
type: "boolean",
411+
},
394412
"transactions-status": {
395413
default: false,
396414
describe: "subscribe on transactionsStatus updates",

yellowstone-grpc-client-nodejs/package-lock.json

Lines changed: 18 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

yellowstone-grpc-client-nodejs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@triton-one/yellowstone-grpc",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"license": "Apache-2.0",
55
"author": "Triton One",
66
"description": "Yellowstone gRPC Geyser Node.js Client",

yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.lock

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

yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yellowstone-grpc-solana-encoding-wasm"
3-
version = "2.0.0"
3+
version = "3.0.0"
44
authors = ["Triton One"]
55
edition = "2021"
66
homepage = "https://triton.one"

yellowstone-grpc-client-nodejs/solana-encoding-wasm/src/lib.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ use {
22
solana_transaction_status::{TransactionWithStatusMeta, UiTransactionEncoding},
33
wasm_bindgen::prelude::*,
44
yellowstone_grpc_proto::{
5-
convert_from, prelude::SubscribeUpdateTransactionInfo, prost::Message,
5+
convert_from,
6+
prelude::{SubscribeUpdateTransactionInfo, TransactionError as TransactionErrorProto},
7+
prost::Message,
68
},
79
};
810

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

3133
#[wasm_bindgen]
32-
pub fn encode(
34+
pub fn encode_tx(
3335
data: &[u8],
3436
encoding: WasmUiTransactionEncoding,
3537
max_supported_transaction_version: Option<u8>,
@@ -49,3 +51,12 @@ pub fn encode(
4951
Err(JsError::new("tx with missing metadata"))
5052
}
5153
}
54+
55+
#[wasm_bindgen]
56+
pub fn decode_tx_error(err: Vec<u8>) -> Result<String, JsError> {
57+
match convert_from::create_tx_error(Some(&TransactionErrorProto { err })) {
58+
Ok(Some(err)) => serde_json::to_string(&err).map_err(Into::into),
59+
Ok(None) => Err(JsError::new("unexpected")),
60+
Err(error) => Err(JsError::new(error)),
61+
}
62+
}

0 commit comments

Comments
 (0)