4

I see that there has been a utility created for the Java SDK to calculate the hash of the current block, but do not see this implementation in the Node SDK. I would really appreciate it if someone could give an example implementation in javascript.

I would like a javascript function that converts a decoded Block object to a Byte Array. This Byte Array is the parameter for the Channel.queryBlockByHash(block, target, useAdmin) method linked here.

So for example, if I have a decoded Block object -

let blockObj = { header:
   { number: '100',
     previous_hash: 
'99478ca59eb60cc968cec9dde401ce70b1e470aeab4a458ba870f4a717b2e24a',
     data_hash: 
'1bee34054bc4457f51e3c00bfa552878503deb3220f2d171b55d2a35299afdb0' },
  data: { data: [ [Array], [Array] ] },
  metadata: { metadata: [ [Array], [Array], [Array] ] } }

I want a function like so:

function blockObjToByteArray(blockObj) {
  // Do ASN1 conversion here

  // Return ByteArray that can be used as a parameter
  // for the queryBlockByHash() method 
  return byteArrayBlock;
}

Any help much appreciated!

Zach Gollwitzer
  • 2,114
  • 2
  • 16
  • 26
  • Check out this answer - https://stackoverflow.com/a/51674154/396949. You need to pass the `header` to the `calculateBlockHash` function. It will do the rest of the work. – tonymontana Nov 25 '18 at 13:48

0 Answers0