flocore/util/VersionedData.js
Ryan X. Charles 7f348ca0bd Move BigNumber to internal
...no longer relies on Manuel's repo hostig a version of "bignum" that actually
contained bignumber.js. This moves bignumber.js internally and removes bignum
from the browser build process. Also adds a bitcore.Bignum that links to the
right thing. In node, browser.Bignum is require('bignum'). And in the browser,
bitcore.Bignum is is now Bignumber.js (same as before ... except bignumber.js
is now inside bitcore).
2014-04-28 18:00:59 -04:00

39 lines
1.1 KiB
JavaScript

var imports = require('soop').imports();
var base58 = imports.base58 || require('../lib/Base58').base58Check;
var parent = imports.parent || require('./EncodedData');
function VersionedData(version, payload) {
if(typeof version != 'number') {
VersionedData.super(this, arguments);
return;
};
this.data = new Buffer(payload.length + 1);
this.__proto__ = this.encodings['binary'];
this.version(version);
this.payload(payload);
};
VersionedData.parent = parent;
parent.applyEncodingsTo(VersionedData);
// get or set the version data (the first byte of the address)
VersionedData.prototype.version = function(num) {
if(num || (num === 0)) {
this.doAsBinary(function() {this.data.writeUInt8(num, 0);});
return num;
}
return this.as('binary').readUInt8(0);
};
// get or set the payload data (as a Buffer object)
VersionedData.prototype.payload = function(data) {
if(data) {
this.doAsBinary(function() {data.copy(this.data,1);});
return data;
}
return this.as('binary').slice(1);
};
module.exports = require('soop')(VersionedData);