Last active
September 15, 2018 09:44
-
-
Save dgarcia360/e076b07f7cb28940179fb72e85a4421e to your computer and use it in GitHub Desktop.
Gets all transactions given an account recursively - NEM2-SDK + rxjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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