Skip to content

Commit

Permalink
add fn wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Nov 26, 2024
1 parent bb93f43 commit 7598f55
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ examples/typescript/dist
examples/typescript/node_modules
yellowstone-grpc-client-nodejs/dist
yellowstone-grpc-client-nodejs/node_modules
yellowstone-grpc-client-nodejs/src/encoding
yellowstone-grpc-client-nodejs/src/grpc

# Python
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ solana-encoding-wasm-build:
rm -rf ../src/encoding/ && \
wasm-bindgen \
--target nodejs \
--out-dir ../dist/encoding/ \
--out-dir ../src/encoding/ \
target/wasm32-unknown-unknown/release/yellowstone_grpc_solana_encoding_wasm.wasm
14 changes: 7 additions & 7 deletions examples/typescript/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import Client, {
SubscribeRequestFilterAccountsFilter,
SubscribeRequestFilterAccountsFilterLamports,
SubscribeUpdateTransactionInfo,
encode,
WasmUiTransactionEncoding,
txEncode,
} from "@triton-one/yellowstone-grpc";

async function main() {
Expand Down Expand Up @@ -87,11 +86,12 @@ async function subscribeCommand(client, args) {
// Handle updates
stream.on("data", (data) => {
if (data.transaction && args.transactionsParsed) {
const encoded = SubscribeUpdateTransactionInfo.encode(
data.transaction.transaction
).finish();
const tx = encode(encoded, WasmUiTransactionEncoding.Json, 255, true);
console.log(`TX filters: ${data.filters}, slot#${data.transaction.slot}, tx: ${tx}`);
const slot = data.transaction.slot;
const message = data.transaction.transaction;
const tx = txEncode.encode(message, txEncode.encoding.Json, 255, true);
console.log(
`TX filters: ${data.filters}, slot#${slot}, tx: ${JSON.stringify(tx)}`
);
return;
}

Expand Down
42 changes: 29 additions & 13 deletions yellowstone-grpc-client-nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
* TypeScript/JavaScript client for gRPC Geyser.
*/

import {
ChannelCredentials,
credentials,
ChannelOptions,
Metadata,
} from "@grpc/grpc-js";

// Import generated gRPC client and types.
import {
CommitmentLevel,
Expand All @@ -15,15 +22,9 @@ import {
SubscribeRequestFilterEntry,
SubscribeRequestFilterSlots,
SubscribeRequestFilterTransactions,
SubscribeUpdateTransactionInfo,
} from "./grpc/geyser";

import {
ChannelCredentials,
credentials,
ChannelOptions,
Metadata,
} from "@grpc/grpc-js";

// Reexport automatically generated types
export {
CommitmentLevel,
Expand Down Expand Up @@ -54,12 +55,27 @@ export {
SubscribeUpdateTransactionInfo,
} from "./grpc/geyser";

// Reexport Transaction encoding
export {
encode,
WasmUiTransactionEncoding,
// @ts-ignore
} from "./encoding/yellowstone_grpc_solana_encoding_wasm";
// Import transaction encoding function created in Rust
import * as wasm from "./encoding/yellowstone_grpc_solana_encoding_wasm";
export const txEncode = {
encoding: wasm.WasmUiTransactionEncoding,
encode_raw: wasm.encode,
encode: (
message: SubscribeUpdateTransactionInfo,
encoding: wasm.WasmUiTransactionEncoding,
max_supported_transaction_version: number | undefined,
show_rewards: boolean
): any => { // TODO: replace any
return JSON.parse(
wasm.encode(
SubscribeUpdateTransactionInfo.encode(message).finish(),
encoding,
max_supported_transaction_version,
show_rewards
)
);
},
};

export default class Client {
_client: GeyserClient;
Expand Down

0 comments on commit 7598f55

Please sign in to comment.