Skip to content

Instantly share code, notes, and snippets.

@Ivanzar
Last active June 4, 2020 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ivanzar/3640e99cdd29a84a0c48a373f035bb51 to your computer and use it in GitHub Desktop.
Save Ivanzar/3640e99cdd29a84a0c48a373f035bb51 to your computer and use it in GitHub Desktop.
Get All Viz accounts fin info
viz.config.set('websocket',' https://rpc.viz.lexai.host');
var saveUrl;
async function look(){
console.log('Getting a list of all accounts. Wait...');
var count = await viz.api.getAccountCountAsync();
var allAccountsName = await getAll(count);
console.log('Scanning all accounts. Wait...');
var accounts = await viz.api.getAccountsAsync(allAccountsName);
var outArr = [['Account', 'VIZ', 'Clear SHARES', 'Effective SHARES']];
var table = '';
console.log('File generation for download. Wait...');
accounts.forEach(account => {
let {name, balance, vesting_shares, delegated_vesting_shares, received_vesting_shares} = account;
outArr.push([name,
parseFloat(balance).toString().replace('.', ','),
parseFloat(vesting_shares).toString().replace('.', ','),
(parseFloat(vesting_shares) + parseFloat(received_vesting_shares) - parseFloat(delegated_vesting_shares)).toString().replace('.', ',')]);
});
outArr.forEach(el => {
table += el.join(';') + '\n';
});
console.log(table)
var file = new Blob([table], {type : "text/csv"});
saveUrl = URL.createObjectURL(file);
console.log('enter save() to save file as viz-accounts.csv');
}
function getAll(count){
var arr = [];
async function get(str, offset)
{
console.log('get', offset)
var accounts = await viz.api.lookupAccountsAsync(str, 1000);
accounts.splice(0, offset);
arr = arr.concat(accounts);
//console.log(arr);
if (arr.length < count) {
return await get(arr[arr.length-1], 1);
}
//console.log(arr);
return arr;
}
return get('', 0);
}
function save(){
console.log(saveUrl);
var a = document.createElement('a');
document.body.appendChild(a);
a.style = "display: none";
a.href = saveUrl;
a.download = 'viz-accounts.csv'
a.click();
}
@Ivanzar
Copy link
Author

Ivanzar commented Mar 27, 2019

This code for debug js console of browser.

To run this code go to viz.world and past this code to developer console of browser.

Site must defined a variable is called viz

Enter look(); to start
And then eneter save(); to save file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment