Guest User

Untitled

a guest
Apr 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. const start = async () => {
  2. ...
  3.  
  4. node.subscribe(channel.SYNC_BLOCK, async (buffer) => {
  5. const data = JSON.parse(buffer.data.toString())
  6. const currentNodeId = node.node.peerInfo.id.toB58String()
  7. if(data.nodeId == currentNodeId) {
  8. await bc.saveBlock(data.block)
  9. await bc.saveLatestHash(data.block.hash)
  10. await bc.clearSuccessTransactions(data.block.transactions)
  11.  
  12. setTimeout(() => {
  13. node.publish(channel.SYNC_REQUEST, JSON.stringify({
  14. nodeId: currentNodeId,
  15. latestHash: data.block.hash,
  16. }))
  17. }, 2000)
  18. }
  19. })
  20. }
Add Comment
Please, Sign In to add comment