flocore-node/lib/services/block/encoding.js
2018-05-08 13:48:43 -07:00

29 lines
661 B
JavaScript

'use strict';
var Block = require('fcoin').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.toRaw();
};
Encoding.prototype.decodeBlockValue = function(buffer) {
return Block.fromRaw(buffer);
};
module.exports = Encoding;