Skip to content

Commit

Permalink
nodejs: add parse tx function (#471)
Browse files Browse the repository at this point in the history
Co-authored-by: Dmitry Rybalchenko <[email protected]>
  • Loading branch information
fanatid and dm-rybalchenko committed Dec 1, 2024
1 parent c4ae964 commit 75df985
Show file tree
Hide file tree
Showing 16 changed files with 3,352 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ indent_size = 2
[*.rs]
indent_style = space
indent_size = 4

[{Makefile,**.mk}]
indent_style = tab
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:

- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
toolchain: ${{ env.RUST_STABLE }}

- name: Install dependencies
Expand All @@ -78,16 +79,37 @@ jobs:
git checkout Cargo.lock
cargo tree --frozen
- name: cargo tree wasm
run: |
cd yellowstone-grpc-client-nodejs/solana-encoding-wasm
cargo tree
git checkout Cargo.lock
cargo tree --frozen
- name: cargo fmt
run: cargo +nightly fmt --all -- --check

- name: cargo fmt wasm
run: |
cd yellowstone-grpc-client-nodejs/solana-encoding-wasm
cargo +nightly fmt --all -- --check
- name: cargo deny check advisories
uses: EmbarkStudios/cargo-deny-action@v1
with:
command: check advisories
- name: cargo deny check advisories wasm
uses: EmbarkStudios/cargo-deny-action@v1
with:
command: check advisories
manifest-path: ./yellowstone-grpc-client-nodejs/solana-encoding-wasm/Cargo.toml

- name: cargo clippy
run: cargo clippy --workspace --all-targets
- name: cargo clippy wasm
run: |
cd yellowstone-grpc-client-nodejs/solana-encoding-wasm
cargo clippy --target wasm32-unknown-unknown --all-targets
- name: check features in `client`
run: cargo check -p yellowstone-grpc-client --all-targets
Expand Down
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- proto: add tonic feature ([#474](https://github.com/rpcpool/yellowstone-grpc/pull/474))
- geyser: use default compression as gzip and zstd ([#475](https://github.com/rpcpool/yellowstone-grpc/pull/475))
- example: add connection options to Rust client ([#478](https://github.com/rpcpool/yellowstone-grpc/pull/478))
- nodejs: add parse tx function ([#471](https://github.com/rpcpool/yellowstone-grpc/pull/471))

### Breaking

Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ members = [
"yellowstone-grpc-geyser", # 3.0.1
"yellowstone-grpc-proto", # 3.0.0
]
exclude = [
"yellowstone-grpc-client-nodejs/solana-encoding-wasm", # 1.0.0
]

[workspace.package]
authors = ["Triton One"]
Expand Down
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
clean: clean-nodejs clean-rust

clean-nodejs:
rm -rf examples/typescript/dist
rm -rf examples/typescript/node_modules
rm -rf yellowstone-grpc-client-nodejs/dist
rm -rf yellowstone-grpc-client-nodejs/node_modules
rm -rf yellowstone-grpc-client-nodejs/src/encoding
rm -rf yellowstone-grpc-client-nodejs/src/grpc

clean-rust:
rm -rf target
rm -rf yellowstone-grpc-client-nodejs/solana-encoding-wasm/target

solana-encoding-wasm-clippy:
cd yellowstone-grpc-client-nodejs/solana-encoding-wasm && \
cargo clippy --target wasm32-unknown-unknown --all-targets

solana-encoding-wasm-build:
# RUSTFLAGS to disable `mold`
cd yellowstone-grpc-client-nodejs/solana-encoding-wasm && \
RUSTFLAGS="" cargo build \
--target wasm32-unknown-unknown \
--release

cd yellowstone-grpc-client-nodejs/solana-encoding-wasm && \
rm -rf ../src/encoding/ && \
wasm-bindgen \
--target nodejs \
--out-dir ../src/encoding/ \
target/wasm32-unknown-unknown/release/yellowstone_grpc_solana_encoding_wasm.wasm && \
mkdir -p ../dist/encoding/ && \
cp -ap ../src/encoding/ ../dist/
8 changes: 6 additions & 2 deletions examples/typescript/package-lock.json

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

17 changes: 17 additions & 0 deletions examples/typescript/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Client, {
SubscribeRequest,
SubscribeRequestFilterAccountsFilter,
SubscribeRequestFilterAccountsFilterLamports,
SubscribeUpdateTransactionInfo,
txEncode,
} from "@triton-one/yellowstone-grpc";

async function main() {
Expand Down Expand Up @@ -83,6 +85,16 @@ async function subscribeCommand(client, args) {

// Handle updates
stream.on("data", (data) => {
if (data.transaction && args.transactionsParsed) {
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;
}

console.log("data", data);
});

Expand Down Expand Up @@ -374,6 +386,11 @@ function parseCommandLineArgs() {
description: "filter required account in transactions",
type: "array",
},
"transactions-parsed": {
default: false,
describe: "parse transaction to json",
type: "boolean",
},
"transactions-status": {
default: false,
describe: "subscribe on transactionsStatus updates",
Expand Down
Loading

0 comments on commit 75df985

Please sign in to comment.