Skip to content

Instantly share code, notes, and snippets.

@dgarcia360
Last active September 15, 2018 09:44
Show Gist options
  • Save dgarcia360/e076b07f7cb28940179fb72e85a4421e to your computer and use it in GitHub Desktop.
Save dgarcia360/e076b07f7cb28940179fb72e85a4421e to your computer and use it in GitHub Desktop.
Gets all transactions given an account recursively - NEM2-SDK + rxjs
import {AccountHttp, NetworkType, PublicAccount, QueryParams} from "nem2-sdk";
import {concatMap, expand, toArray} from "rxjs/operators";
import {EMPTY} from 'rxjs'
const nodeUrl = 'http://localhost:3000';
const accountHttp = new AccountHttp(nodeUrl);
const pageSize = 100;
const allTransactions = true;
const publicKey = process.env.PUBLIC_KEY as string; //Replace with your public key
const publicAccount = PublicAccount
.createFromPublicKey(publicKey, NetworkType.MIJIN_TEST);
accountHttp
.transactions(publicAccount, new QueryParams(pageSize, null))
.pipe(
expand( (transactions) => transactions.length >= pageSize && allTransactions
? accountHttp.transactions(publicAccount, new QueryParams(pageSize, transactions[transactions.length - 1].transactionInfo.id))
: EMPTY),
concatMap(transactions => transactions),
toArray()
)
.subscribe(transactions => {
console.log(transactions);
console.log(transactions.length);
},
err => console.log(err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment