Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. const fs = require('fs');
  2. const RippleAPI = require('ripple-lib').RippleAPI;
  3.  
  4. var transaction = '5FBCE5D6AAE920B0C4296B515CC65CD9E1BF5FA1934ED42B387FBFD9D49DE06F';
  5.  
  6. // Ripple Stuff
  7. const api = new RippleAPI({
  8. server: 'wss://s1.ripple.com'
  9. });
  10. api.on('error', (errorCode, errorMessage) => {
  11. console.log(errorCode + ': ' + errorMessage);
  12. });
  13. api.on('connected', () => {
  14. console.log('connected');
  15. });
  16. api.on('disconnected', (code) => {
  17. console.log('disconnected, code:', code);
  18. });
  19.  
  20.  
  21. // Main Logic
  22. async function download(transaction) {
  23. await api.connect();
  24. var data = await gettrans(transaction);
  25. await driller(data);
  26. }
  27.  
  28. // Get single transaction
  29. async function gettrans(transaction) {
  30. while (true) {
  31. var data = await api.getTransaction(transaction).then(info => {
  32. var data = info.specification.memos[0].data;
  33. return data;
  34. }).catch(error =>
  35. console.error(transaction,error.stack)
  36. );
  37. return data;
  38. }
  39. }
  40.  
  41. // Drill to data
  42. async function driller(data) {
  43. // Break into ordered 64 chunks
  44. var re = new RegExp('.{1,64}', 'g');
  45. var array = data.match(re);
  46. // Check the first chunk for non transaction data
  47. var re2 = new RegExp("([a-z])");
  48. if (! re2.test(array[0])) {
  49. var newdata = '';
  50. for(var i = 0; i < array.length; i++) {
  51. newdata += await gettrans(array[i], false).catch(error => console.error(error.stack));
  52. if(i== array.length-1) {
  53. driller(newdata);
  54. }
  55. }
  56. }
  57. // This is the data blob
  58. else{
  59. fs.writeFileSync("./output.webm", data,'base64');
  60. await api.disconnect();
  61. }
  62. }
  63.  
  64. // Run logic
  65. download(transaction).catch(error => console.error(error.stack));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement