add ability to set the version

This commit is contained in:
Stephen Pair 2013-07-07 14:28:11 -04:00
parent 413bd1b1c5
commit 16ce63ca80
1 changed files with 9 additions and 2 deletions

View File

@ -9,13 +9,20 @@ function ClassSpec(b) {
}; };
// return the bitcoin address version (the first byte of the address) // return the bitcoin address version (the first byte of the address)
BitcoinAddress.prototype.version = function() { BitcoinAddress.prototype.version = function(num) {
if(num || (num === 0)) {
var oldEncoding = this.encoding();
this.encoding('binary');
this.data.writeUInt8(num, 0);
this.encoding(oldEncoding);
return num;
}
return this.as('binary').readUInt8(0); return this.as('binary').readUInt8(0);
}; };
// get or set the encoding used (transforms data) // get or set the encoding used (transforms data)
BitcoinAddress.prototype.encoding = function(encoding) { BitcoinAddress.prototype.encoding = function(encoding) {
if(encoding) { if(encoding && (encoding != this._encoding)) {
this.data = this.as(encoding); this.data = this.as(encoding);
this.__proto__ = encodings[encoding]; this.__proto__ = encodings[encoding];
} }