Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs');
- const RippleAPI = require('ripple-lib').RippleAPI;
- var transaction = '5FBCE5D6AAE920B0C4296B515CC65CD9E1BF5FA1934ED42B387FBFD9D49DE06F';
- // Ripple Stuff
- const api = new RippleAPI({
- server: 'wss://s1.ripple.com'
- });
- api.on('error', (errorCode, errorMessage) => {
- console.log(errorCode + ': ' + errorMessage);
- });
- api.on('connected', () => {
- console.log('connected');
- });
- api.on('disconnected', (code) => {
- console.log('disconnected, code:', code);
- });
- // Main Logic
- async function download(transaction) {
- await api.connect();
- var data = await gettrans(transaction);
- await driller(data);
- }
- // Get single transaction
- async function gettrans(transaction) {
- while (true) {
- var data = await api.getTransaction(transaction).then(info => {
- var data = info.specification.memos[0].data;
- return data;
- }).catch(error =>
- console.error(transaction,error.stack)
- );
- return data;
- }
- }
- // Drill to data
- async function driller(data) {
- // Break into ordered 64 chunks
- var re = new RegExp('.{1,64}', 'g');
- var array = data.match(re);
- // Check the first chunk for non transaction data
- var re2 = new RegExp("([a-z])");
- if (! re2.test(array[0])) {
- var newdata = '';
- for(var i = 0; i < array.length; i++) {
- newdata += await gettrans(array[i], false).catch(error => console.error(error.stack));
- if(i== array.length-1) {
- driller(newdata);
- }
- }
- }
- // This is the data blob
- else{
- fs.writeFileSync("./output.webm", data,'base64');
- await api.disconnect();
- }
- }
- // Run logic
- download(transaction).catch(error => console.error(error.stack));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement