modifies address translator to support Cashaddr

This commit is contained in:
Matias Alejo Garcia 2018-03-06 11:17:37 -05:00
parent d4ef5345f6
commit 771cf5d82c
No known key found for this signature in database
GPG Key ID: 02470DB551277AB3
4 changed files with 18 additions and 14 deletions

View File

@ -32,7 +32,11 @@ AddressTranslator.translate = function(addresses, coin, origCoin) {
origCoin = origCoin || AddressTranslator.getAddressCoin(addresses[0]); origCoin = origCoin || AddressTranslator.getAddressCoin(addresses[0]);
var ret = _.map(addresses, function(x) { var ret = _.map(addresses, function(x) {
var orig = new Bitcore_[origCoin].Address(x).toObject(); var orig = new Bitcore_[origCoin].Address(x).toObject();
return Bitcore_[coin].Address.fromObject(orig).toString(); if (coin == 'bch') {
return Bitcore_[coin].Address.fromObject(orig).toCashAddress(true);
} else {
return Bitcore_[coin].Address.fromObject(orig).toString();
}
}); });
if (wasArray) if (wasArray)

14
package-lock.json generated
View File

@ -247,9 +247,9 @@
} }
}, },
"bitcore-lib-cash": { "bitcore-lib-cash": {
"version": "0.16.1", "version": "0.17.0",
"resolved": "https://registry.npmjs.org/bitcore-lib-cash/-/bitcore-lib-cash-0.16.1.tgz", "resolved": "https://registry.npmjs.org/bitcore-lib-cash/-/bitcore-lib-cash-0.17.0.tgz",
"integrity": "sha512-RcOZCeyHBCTREHytQ7SwvmkSHJ3a/FZHQ6BIQwstQqpbMkEjGACHUfg8CAwvonLJ4soxcyuuRuensgtLI7MM8g==", "integrity": "sha512-uJVW6DPVR12p/uhxOCA0cIA/qrDXa5OYyQyZ9kFvJ/YjoXc8auljdo4cmAC89zF3lvikQebbjGqBYUY5Ej3tIg==",
"requires": { "requires": {
"bn.js": "4.11.8", "bn.js": "4.11.8",
"bs58": "4.0.1", "bs58": "4.0.1",
@ -2444,7 +2444,7 @@
"resolved": "https://registry.npmjs.org/phantomjs-prebuilt/-/phantomjs-prebuilt-2.1.16.tgz", "resolved": "https://registry.npmjs.org/phantomjs-prebuilt/-/phantomjs-prebuilt-2.1.16.tgz",
"integrity": "sha1-79ISpKOWbTZHaE6ouniFSb4q7+8=", "integrity": "sha1-79ISpKOWbTZHaE6ouniFSb4q7+8=",
"requires": { "requires": {
"es6-promise": "4.2.2", "es6-promise": "4.2.4",
"extract-zip": "1.6.6", "extract-zip": "1.6.6",
"fs-extra": "1.0.0", "fs-extra": "1.0.0",
"hasha": "2.2.0", "hasha": "2.2.0",
@ -2456,9 +2456,9 @@
}, },
"dependencies": { "dependencies": {
"es6-promise": { "es6-promise": {
"version": "4.2.2", "version": "4.2.4",
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.2.tgz", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.4.tgz",
"integrity": "sha512-LSas5vsuA6Q4nEdf9wokY5/AJYXry98i0IzXsv49rYsgDGDNDPbqAYR1Pe23iFxygfbGZNR/5VrHXBCh2BhvUQ==" "integrity": "sha512-/NdNZVJg+uZgtm9eS3O6lrOLYmQag2DjdEXuPaHlZ6RuVqgqaVZfgYCepEIKsLqwdQArOPtC3XzRLqGGfT8KQQ=="
} }
} }
}, },

View File

@ -22,7 +22,7 @@
"dependencies": { "dependencies": {
"async": "^0.9.2", "async": "^0.9.2",
"bitcore-lib": "^0.15.0", "bitcore-lib": "^0.15.0",
"bitcore-lib-cash": "^0.16.1", "bitcore-lib-cash": "^0.17.0",
"body-parser": "^1.11.0", "body-parser": "^1.11.0",
"compression": "^1.6.2", "compression": "^1.6.2",
"coveralls": "^2.11.2", "coveralls": "^2.11.2",

View File

@ -10,7 +10,7 @@ var AddressTranslator = require('../lib/addresstranslator');
describe('#AddressTranslator', function() { describe('#AddressTranslator', function() {
it('should translate address from btc to bch', function() { it('should translate address from btc to bch', function() {
var res = AddressTranslator.translate('1LqBGSKuX5yYUonjxT5qGfpUsXKYYWeabA', 'bch'); var res = AddressTranslator.translate('1LqBGSKuX5yYUonjxT5qGfpUsXKYYWeabA', 'bch');
assert( res == 'CcJ4qUfyQ8x5NwhAeCQkrBSWVeXxXghcNz'); assert( res == 'qrvcdmgpk73zyfd8pmdl9wnuld36zh9n4gms8s0u59');
}); });
it('should translate address from bch to btc', function() { it('should translate address from bch to btc', function() {
var res = AddressTranslator.translateInput('HBf8isgS8EXG1r3X6GP89FmooUmiJ42wHS'); var res = AddressTranslator.translateInput('HBf8isgS8EXG1r3X6GP89FmooUmiJ42wHS');
@ -19,7 +19,7 @@ describe('#AddressTranslator', function() {
it('should keep the address if there is nothing to do (bch)', function() { it('should keep the address if there is nothing to do (bch)', function() {
var res = AddressTranslator.translate('CcJ4qUfyQ8x5NwhAeCQkrBSWVeXxXghcNz', 'bch'); var res = AddressTranslator.translate('CcJ4qUfyQ8x5NwhAeCQkrBSWVeXxXghcNz', 'bch');
assert(res=='CcJ4qUfyQ8x5NwhAeCQkrBSWVeXxXghcNz'); assert(res=='qrvcdmgpk73zyfd8pmdl9wnuld36zh9n4gms8s0u59');
}); });
it('should keep the address if there is nothing to do (btc)', function() { it('should keep the address if there is nothing to do (btc)', function() {
var res = AddressTranslator.translate('1LqBGSKuX5yYUonjxT5qGfpUsXKYYWeabA', 'btc'); var res = AddressTranslator.translate('1LqBGSKuX5yYUonjxT5qGfpUsXKYYWeabA', 'btc');
@ -42,9 +42,9 @@ describe('#AddressTranslator', function() {
it('should work with arrays also', function() { it('should work with arrays also', function() {
var res = AddressTranslator.translateOutput(['1LqBGSKuX5yYUonjxT5qGfpUsXKYYWeabA', '37YHiaQnMjy73GS1UpiE8p2Ju6MyrrDw3J', '1DuPdCpGzVX73kBYaAbu5XDNDgE2Lza5Ed']); var res = AddressTranslator.translateOutput(['1LqBGSKuX5yYUonjxT5qGfpUsXKYYWeabA', '37YHiaQnMjy73GS1UpiE8p2Ju6MyrrDw3J', '1DuPdCpGzVX73kBYaAbu5XDNDgE2Lza5Ed']);
assert(res[0] == 'CcJ4qUfyQ8x5NwhAeCQkrBSWVeXxXghcNz'); assert(res[0] == 'qrvcdmgpk73zyfd8pmdl9wnuld36zh9n4gms8s0u59');
assert(res[1] == 'HCNQBNqsD4BmfSK3LWNP7CYqvkNznSrXS3'); assert(res[1] == 'ppqz5v08kssnuupe0ckqtw4ss3qt460fcqugqzq2me');
assert(res[2] == 'CVNHCFALsYVdwt5yFuvpf2qPqoSSGtvY7t'); assert(res[2] == 'qzxc5pnsfs8pmgfprhzc4l4vzf3zxz8p85nc6kfh8l');
}); });