From 16ce63ca806b5145e81574c72b7cf26c12f16513 Mon Sep 17 00:00:00 2001 From: Stephen Pair Date: Sun, 7 Jul 2013 14:28:11 -0400 Subject: [PATCH] add ability to set the version --- BitcoinAddress.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/BitcoinAddress.js b/BitcoinAddress.js index 345256412..b01657024 100644 --- a/BitcoinAddress.js +++ b/BitcoinAddress.js @@ -9,13 +9,20 @@ function ClassSpec(b) { }; // 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); }; // get or set the encoding used (transforms data) BitcoinAddress.prototype.encoding = function(encoding) { - if(encoding) { + if(encoding && (encoding != this._encoding)) { this.data = this.as(encoding); this.__proto__ = encodings[encoding]; }