new address and copay address working in receive / send / scan

This commit is contained in:
Kadir Sekha 2018-01-09 18:04:52 +09:00
commit 205f70dd8c
7 changed files with 63 additions and 13 deletions

View file

@ -8,11 +8,11 @@ bitcoinCashJsModule.provider('bitcoinCashJsService', function() {
provider.$get = function() {
var service = {};
const Address = bchjs.Address;
const BitpayFormat = Address.BitpayFormat;
const CashAddrFormat = Address.CashAddrFormat;
service.translateAddresses = function(address) {
const Address = bchjs.Address;
const BitpayFormat = Address.BitpayFormat;
const CashAddrFormat = Address.CashAddrFormat;
var result = new Address(address);
return {
'legacy': result.toString(),
@ -21,6 +21,36 @@ bitcoinCashJsModule.provider('bitcoinCashJsService', function() {
};
}
service.readAddress = function(address) {
var a = address.replace('bitcoincash:', '');
var result = {};
if (a[0] == '1') {
result = Address.fromString(a, 'livenet', 'pubkeyhash');
} else if (a[0] == '3') {
result = Address.fromString(a, 'livenet', 'scripthash');
} else if (a[0] == 'C') {
result = Address.fromString(a, 'livenet', 'pubkeyhash', BitpayFormat);
} else if (a[0] == 'H') {
result = Address.fromString(a, 'livenet', 'scripthash', BitpayFormat);
} else if (a[0] == 'q') {
result = Address.fromString(address, 'livenet', 'pubkeyhash', CashAddrFormat);
} else if (a[0] == 'p') {
result = Address.fromString(address, 'livenet', 'scripthash', CashAddrFormat);
} else {
return null;
}
return {
'legacy': result.toString(),
'bitpay': result.toString(BitpayFormat),
'cashaddr': result.toString(CashAddrFormat).replace('bitcoincash:', '')
}
}
service.getBitcoinCashJs = function() {
return bchjs;
}
return service;
}