flocore-node/lib/services/block/encoding.js
Chris Kleeschulte 6b45ef27cd wip
2017-07-19 18:58:18 -04:00

29 lines
673 B
JavaScript

'use strict';
var Block = require('bitcore-lib').Block;
// stores -- block header as key, block itself as value (optionally)
function Encoding(servicePrefix) {
this._servicePrefix = servicePrefix;
}
// ---- hash --> rawblock
Encoding.prototype.encodeBlockKey = function(hash) {
return Buffer.concat([ this._servicePrefix, new Buffer(hash, 'hex') ]);
};
Encoding.prototype.decodeBlockKey = function(buffer) {
return buffer.slice(2).toString('hex');
};
Encoding.prototype.encodeBlockValue = function(block) {
return block.toBuffer();
};
Encoding.prototype.decodeBlockValue = function(buffer) {
return Block.fromBuffer(buffer);
};
module.exports = Encoding;