javascript - BitGO-JS Exceed Transaction 250 limit -
i'm trying simulate of test.bitgo.com more 250 transactions current limit set api... tried , tried again different methods achieve same results , after 1 week still can't find proper way transaction data in 1 go .
one of devs said promise has nested while-loop adds count:250 skip:0 , run function again , again until there nothing left sum because count gets 0 @ end , gets 852 transactions.
this i'm using https://www.bitgo.com/api/#list-wallet-transactions. gives object has 250 transactions , keeps count this.
var walletid = '2nb96fbwy8eohttuzttbwvvheyrbwz494ov'; bitgo.wallets().get({ "id": walletid }, function callback(err, wallet) { if (err) { throw err; } wallet.transactions({limit:2, skip:0}, function callback(err, transactions) { // handle transactions console.log(json.stringify(transactions, null, 4)); }); }); // result { "transactions": [ { "id": "71fb53e7d70ce27dced2eb327ac544b8f046e66480342ba81533046f3267e6f4", "normalizedhash": "80116b194b58b494d85b2a831815a978ec6f0fe617cfd020880ff1ad76b2bacc", "date": "2016-04-17t20:06:56.474z", "fee": 4480, "inputs": [ { "previoushash": "1f4145b615f5d067160184a3e9660396f826614c3fcae9abdcb7192c615b843a", "previousoutputindex": 0 } ], "outputs": [ { "vout": 0, "account": "2n5jr87jhtuahab37vkwnphoh1wuehkvg1q", "value": 625000000, "ismine": true, "chain": 0, "chainindex": 0 }, { "vout": 1, "account": "mpntsjwk116jf58vrdxemmwr4gc7afvekt", "value": 390110612 } ], "entries": [ { "account": "2n5jr87jhtuahab37vkwnphoh1wuehkvg1q", "value": 625000000 }, { "account": "mqrsjr8szt5xtslm3cu7i9epa7kwnc2vws", "value": -1015115092 }, { "account": "mpntsjwk116jf58vrdxemmwr4gc7afvekt", "value": 390110612 } ], "confirmations": 487, "pending": false, "instant": false, "blockhash": "000000000000020f526fe18af7536fa4e816694c4dec865e0d87d6b722b643d9", "height": 786821 }, { "id": "e5216ffaaa2a37bcc14380db07f06c85a65bcdc4e1fcab2bd5523f0b8a11bc15", "normalizedhash": "0709c99097386a3c0130f3d6b002acf6a4e37978406704268fc9d308eec4c2b8", "date": "2016-04-17t20:07:03.700z", "fee": 7440, "inputs": [ { "previoushash": "6d043a06ade4eac5315967c463fcd65deb4ed9bff23ee3e73ff82c9cf72360e9", "previousoutputindex": 1 }, { "previoushash": "b6e566cbee0f23bee7b321eda7f6159a165101e77e7f1e75bd9eb6e31540b391", "previousoutputindex": 0 } ], "outputs": [ { "vout": 0, "account": "2n5jr87jhtuahab37vkwnphoh1wuehkvg1q", "value": 312500000, "ismine": true, "chain": 0, "chainindex": 0 }, { "vout": 1, "account": "mmruajwq2xpyqw4gjxz8pq2fufjtf7fvye", "value": 3831779 } ], "entries": [ { "account": "2n5jr87jhtuahab37vkwnphoh1wuehkvg1q", "value": 312500000 }, { "account": "mueepzzkrwx3rnlwhxtx6r8t3mmrutgmgg", "value": -312084680 }, { "account": "mmruajwq2xpyqw4gjxz8pq2fufjtf7fvye", "value": 3831779 }, { "account": "n47gd5d3xfbg41twkx4yhnc9gboywu9yjg", "value": -4254539 } ], "confirmations": 487, "pending": false, "instant": false, "blockhash": "000000000000020f526fe18af7536fa4e816694c4dec865e0d87d6b722b643d9", "height": 786821 } ], "start": 0, "count": 2, "total": 852 }
as can see have total of "total":852 transactions, skip parameter equal "start":0 , limit equal "count":2
legend: limit:250 display 250 transactions total of 852 skip:250 skip first 250 transactions , start display 251 >= 500
the main problem can maximum of 250 transactions @ time , tried push results array , concatenate of lodash failed. tried make work having tons of requests skip:250 500 750 etc , still failed cleaning , saving everything.
hope had climb hill , willing spend few minutes point me in right direction. thank !
what want recursive asynchronous function repeatedly calls wallet.transactions({skip: skip}) larger , larger values "skip", allow traverse through transactions on wallet. take @ code below:
var bitgojs = require('bitgo'); var user = 'octavian@l.com'; var loginpassword = 'supersecretpassword'; var otp = '0000000'; var walletid = 'yourwalletid'; var bitgo = new bitgojs.bitgo(); var printtxs = function() { // wallet bitgo.wallets().get({ id: walletid }, function(err, wallet) { if (err) { console.log("error getting wallet!"); console.dir(err); return process.exit(-1); } var alltxs = []; /** * fetch transactions wallet using skip index array of * transactions on wallet * @param skip {number} number of transactions should skip ahead */ var gettransactionbatch = function(skip, callback) { wallet.transactions({ skip: skip }, function(err, res) { if (err) { console.log("error getting transactions!"); console.dir(err); return process.exit(-1); } res.transactions.foreach(function(tx) { alltxs.push(tx); }); var totaltxcount = res.total; if (totaltxcount && totaltxcount > alltxs.length) { var newskip = skip + res.count; // add number of tx's fetched number skipped ahead return gettransactionbatch(newskip, callback); } return callback(); }); }; gettransactionbatch(0, function() { console.log('all transactions\n'); console.log(json.stringify(alltxs, null, 2)); }) }); }; // authenticate first bitgo.authenticate({ username: user, password: loginpassword, otp: otp }, function(err, result) { if (err) { console.dir(err); throw new error("could not authenticate!"); } console.log("unlocking account.." ); bitgo.unlock({ otp: otp }, function(err) { if (err) { console.dir(err); throw new error("could not unlock!"); } printtxs(); }); });
once fill in login credentials , walletid @ top appropriate values, function make repeated calls bitgo , each time add transactions receives in response alltxs
array. once array equal in size total number of tx's on wallet, print out transactions. replace console.log call whatever processing want on transactions, , you'll golden!
Comments
Post a Comment