Mwni / xrplkit

Modular library for working with the XRP Ledger
7 stars 1 forks source link

read only property 'mantissa' error on extractExchanges #2

Closed tequdev closed 1 year ago

tequdev commented 1 year ago

The following codes error occurs.

file:///Users/tequ/Project/test/node_modules/@xrplkit/xfl/canonical.js:24
    xfl.mantissa = mantissa * sign
                 ^

TypeError: Cannot assign to read only property 'mantissa' of object '[object Object]'
import { Client } from "xrpl";
import { extractExchanges } from "@xrplkit/txmeta";

const client = new Client("wss://xrpl.ws");

const main = async () => {
  await client.connect();
  const response = await client.request({
    command: "tx",
    transaction:
      "460AB874BCF6B3D3C993ED44AD141A58E10DCF454D120CF2922E8EB014D5C0A5",
  });
  extractExchanges(response.result);
};

main();
import { Client } from "xrpl";
import { extractExchanges } from "@xrplkit/txmeta";

const client = new Client("wss://xrpl.ws");

const main = async () => {
  await client.connect();
  client.on("transaction", (stream) => {
      const exchanges = extractExchanges(stream);
  });
  client.request({
    command: "subscribe",
    streams: ["transactions"],
  })
};

main();
Mwni commented 1 year ago

Thank you for sending in the snippet to test.

As it turns out, this issue has already been resolved, but the public npm package txmeta is still an older version. It's published now under version txmeta@1.3.0.

On a side note, may I interest you in the xrplkit/socket package. It's an ultra lightweight client for websocket communications with rippled and clio. Auto reconnects. Your snippet would work like this:

import createSocket from "@xrplkit/socket";
import { extractExchanges } from "@xrplkit/txmeta";

const socket = createSocket({ url: "wss://xrpl.ws" });

const main = async () => {
    const result = await socket.request({
        command: "tx",
        transaction:
            "460AB874BCF6B3D3C993ED44AD141A58E10DCF454D120CF2922E8EB014D5C0A5",
    });
    extractExchanges(result);
};

main();
tequdev commented 1 year ago

I updated to 1.3.0, but the error does not seem to be resolved.

All these packages you have created are lightweight and very interesting!

Mwni commented 1 year ago

I see the issue now. xrplkit/amount was using an outdated version of xfl, which failed on class comparisons. https://github.com/Mwni/xrplkit/commit/b38f868208a8ce1ff1bb3ce4a6d06af9da5c972a

txmeta@1.3.1 has it figured out.

tequdev commented 1 year ago

It worked! Thank you for your help!