Guest User

Untitled

a guest
Apr 23rd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. const create = async (blockchain, from, to, amount) => {
  2. try {
  3. const unused = await findUnusedTransactions(blockchain, from, amount)
  4. const sum = unused.sum
  5.  
  6. if (sum >= amount) {
  7. const trxn = new Transaction()
  8.  
  9. for (let key in unused.trxns) {
  10. const unusedTx = unused.trxns[key]
  11. trxn.addVin(key, unusedTx.idx, from)
  12. }
  13.  
  14. trxn.addVout(from, sum - amount) // Sender
  15. trxn.addVout(to, amount) // Receiver
  16. trxn.setID()
  17.  
  18. return Promise.resolve(trxn)
  19. } else {
  20. return Promise.reject("Insufficient amount")
  21. }
  22. } catch (error) {
  23. return Promise.reject(error)
  24. }
  25. }
Add Comment
Please, Sign In to add comment