virtualeconomy / js-v-sdk

[DEPRECATED and please use https://github.com/virtualeconomy/js-vsys instead] Java Script library for V Systems
https://www.npmjs.com/package/@virtualeconomy/js-v-sdk
MIT License
10 stars 5 forks source link

Load more transactions? #44

Closed vipertechofficial closed 3 years ago

vipertechofficial commented 3 years ago

Hey guys, I am wondering if it would be possible to implement a functionality that would enable the query of transactions from a specific trxID to the number of record to be returned?

SheldonYS commented 3 years ago

This API may help. But it use offset number, not txID, to do paging.

Screenshot 2021-01-18 at 11 49 23 AM
vipertechofficial commented 3 years ago

I am reopening this issue because in the documentation the method chain.getTxHistoryrefuse to take more than two parameters (address and num).

I have tested to provide a third parameter which is offset and it doesn't work :/

vipertechofficial commented 3 years ago

This API may help. But it use offset number, not txID, to do paging.

Screenshot 2021-01-18 at 11 49 23 AM

@SheldonYS Could it be possible to update the file (js-v-sdk/src/blockchain.js) ? :)

SheldonYS commented 3 years ago

You can use getTxByType(...) method in chain object. Here is sample code:

const vsys = require("@virtualeconomy/js-v-sdk");
const constants = vsys.constants;
const node_address = "https://wallet.v.systems/api"; // change to your node address
const network_byte = constants.MAINNET_BYTE;
let chain = new vsys.Blockchain(node_address, network_byte);
let type_id = 2;
chain.getTxByType("<address>", "<limit>", type_id);
vipertechofficial commented 3 years ago

@SheldonYS

If I remember type one, two or three aren't offset but "payment transaction", "lease transaction", and "contract transaction", the issue motionned by @Haynar216 seem to answers it. getTxByType could take more than address, limit, type, it could take offset, now if we look at getTxByType it doesn't consider the offset dimension to it's query when it is called...

Maybe one could add:

    async getTxByType(address, record_limit, type, offset = 0) {
        let response = await getRequest(this.host_ip, '/transactions/list?address=' + address + '&limit=' + record_limit + '&txType=' + type + '&offset=' + offset)
        let keys =['amount']
        return textToSafeJson(response, keys)
    }
SheldonYS commented 3 years ago

@vipertechofficial js-v-sdk v2.0.6 is released. In new version, offset is added (see https://github.com/virtualeconomy/js-v-sdk/blob/master/src/blockchain.js#L95 ). You can update SDK version and use it now.

vipertechofficial commented 3 years ago

Thanks @SheldonYS