Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. const crypto = require('crypto')
  2. const sha256 = require('crypto-js/sha256');
  3.  
  4. exports.createInput = (_amount) => {
  5. var input = {
  6. id : randomId(),
  7. type : "input",
  8. amount : _amount,
  9. }
  10. return input;
  11. }
  12.  
  13. exports.createOutput = (_amount) => {
  14.  
  15. var output = {
  16. id : randomId(),
  17. type : "output",
  18. amount : _amount
  19. }
  20. return output;
  21. }
  22.  
  23. function randomId(){
  24. a = Math.random();
  25. return myHash(a.toString());
  26. }
  27.  
  28. function myHash(_value){
  29. return Math.round(parseInt(sha256(_value),16)/Math.pow(10, 70))
  30. }
  31.  
  32. exports.createTx = (_input, _output) => {
  33. var transaction = {
  34. input: [],
  35. output: []
  36. }
  37. _input.forEach(e => {
  38. addInput(transaction, e)
  39. });
  40. _output.forEach(e => {
  41. addOutput(transaction, e)
  42. });
  43. return transaction;
  44. }
  45.  
  46. function addInput(_tx, _input){
  47. _tx.input.push(_input);
  48. }
  49.  
  50. function addOutput(_tx, _output){
  51. _tx.output.push(_output);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement