Merge pull request #316 from passionofvc/master

add SLP Token Type https://github.com/simpleledger/slp-specifications…
This commit is contained in:
iancoleman
2019-04-17 08:07:28 +10:00
committed by GitHub
3 changed files with 66 additions and 12 deletions

View File

@@ -3416,11 +3416,11 @@ var ValidationError = validation.ValidationError;
*
* @private
*/
var VALID_PREFIXES = ['bitcoincash', 'bchtest', 'bchreg'];
var VALID_PREFIXES = ['bitcoincash', 'bchtest', 'bchreg', 'simpleledger', 'slptest'];
/**
* Checks whether a string is a valid prefix; ie., it has a single letter case
* and is one of 'bitcoincash', 'bchtest', or 'bchreg'.
* and is one of 'bitcoincash', 'bchtest', or 'bchreg', 'simpleledger' or 'slptest'.
*
* @private
* @param {string} prefix
@@ -9011,6 +9011,21 @@ function toCashAddress (address) {
return encodeAsCashaddr(decoded)
}
/**
* Translates the given address into SLP format.
* @static
* @param {string} address - A valid SLP address in any format.
* @return {string}
* @throws {InvalidAddressError}
*/
function toSlpAddress (address) {
var decoded = decodeAddress(address)
return encodeAsSlpaddr(decoded)
}
/**
* Version byte table for base58 formats.
* @private
@@ -9125,7 +9140,7 @@ function decodeCashAddress (address) {
} catch (error) {
}
} else {
var prefixes = ['bitcoincash', 'bchtest', 'regtest']
var prefixes = ['bitcoincash', 'bchtest', 'regtest', 'simpleledger', 'slptest']
for (var i = 0; i < prefixes.length; ++i) {
try {
var prefix = prefixes[i]
@@ -9151,6 +9166,7 @@ function decodeCashAddressWithPrefix (address) {
var type = decoded.type === 'P2PKH' ? Type.P2PKH : Type.P2SH
switch (decoded.prefix) {
case 'bitcoincash':
case 'simpleledger':
return {
hash: hash,
format: Format.Cashaddr,
@@ -9158,6 +9174,7 @@ function decodeCashAddressWithPrefix (address) {
type: type
}
case 'bchtest':
case 'slptest':
case 'regtest':
return {
hash: hash,
@@ -9212,6 +9229,19 @@ function encodeAsCashaddr (decoded) {
return cashaddr.encode(prefix, type, hash)
}
/**
* Encodes the given decoded address into slp addr format.
* @private
* @param {object} decoded
* @returns {string}
*/
function encodeAsSlpaddr (decoded) {
var prefix = decoded.network === Network.Mainnet ? 'simpleledger' : 'slptest'
var type = decoded.type === Type.P2PKH ? 'P2PKH' : 'P2SH'
var hash = Uint8Array.from(decoded.hash)
return cashaddr.encode(prefix, type, hash)
}
/**
* Returns a boolean indicating whether the address is in legacy format.
* @static
@@ -9313,6 +9343,7 @@ module.exports = {
toLegacyAddress: toLegacyAddress,
toBitpayAddress: toBitpayAddress,
toCashAddress: toCashAddress,
toSlpAddress: toSlpAddress,
isLegacyAddress: isLegacyAddress,
isBitpayAddress: isBitpayAddress,
isCashAddress: isCashAddress,

View File

@@ -952,6 +952,13 @@
address = bchaddr.toBitpayAddress(address);
}
}
// Bitcoin Cash address format may vary
if (networks[DOM.network.val()].name == "SLP - Simple Ledger Protocol") {
var bchAddrType = DOM.bitcoinCashAddressType.filter(":checked").val();
if (bchAddrType == "cashaddr") {
address = bchaddr.toSlpAddress(address);
}
}
// Segwit addresses are different
if (isSegwit) {
if (!segwitAvailable) {
@@ -2486,6 +2493,13 @@
setHdCoin(111);
},
},
{
name: "SLP - Simple Ledger Protocol",
onSelect: function() {
DOM.bitcoinCashAddressTypeContainer.removeClass("hidden");
setHdCoin(245);
},
},
{
name: "SLR - Solarcoin",
onSelect: function() {

View File

@@ -564,6 +564,15 @@ it('Allows selection of bitcoin cash', function(done) {
};
testNetwork(done, params);
});
it('Allows selection of simpleledger(SLP)', function(done) {
var params = {
selectText: "SLP - Simple Ledger Protocol",
firstAddress: "simpleledger:qrtffz6ajfsn74gpur7y3epjquz42pvww5acewqmre",
};
testNetwork(done, params);
});
it('Allows selection of myriadcoin', function(done) {
var params = {
selectText: "XMY - Myriadcoin",