vechain-sdk-js icon indicating copy to clipboard operation
vechain-sdk-js copied to clipboard

🐛 [BUG] - `transactions.getTransaction()` does not respect `pending` options

Open ifavo opened this issue 10 months ago • 0 comments

Description

When requesting pending options, the thorClient does ignore the pending flag and returns no data.

The query builder internally seem to not map correctly the pending option to the client request:

https://github.com/vechain/vechain-sdk-js/blob/main/packages/network/src/thor-client/transactions/transactions-module.ts#L68

This should be:

pending: options?.pending

Reproduction URL

No response

Reproduction steps

Use the following snippet to listen for new transactions:

import { subscriptions, ThorClient } from '@vechain/sdk-network';
import WebSocket from 'ws';

const ws = new WebSocket(subscriptions.getNewTransactionsSubscriptionUrl('https://mainnet.vechain.org'));
const thor = ThorClient.fromUrl('https://mainnet.vechain.org');

ws.onmessage = async (message) => {
  const addedTx = JSON.parse(message.data);

  console.log('New transaction', addedTx);
  const tx = await thor.transactions.getTransaction(addedTx.id, {
    pending: true,
  });

  // always returns null, if delayed until next block, will return data
  console.log(tx);
};

// some helper to debug the websocket activity
ws.onopen = () => {
  console.log('Connected, listening for new Transactions');
};
ws.onclose = () => {
  console.log('Disconnected');
};
ws.onerror = (err) => {
  console.error(err);
};

Screenshots

![DESCRIPTION](LINK.png)

Logs

No response

OS

No response

ifavo avatar Apr 24 '24 08:04 ifavo