Changeset View
Changeset View
Standalone View
Standalone View
apps/ecash-herald/src/utils.js
// Copyright (c) 2023 The Bitcoin developers | // Copyright (c) 2023 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
'use strict'; | 'use strict'; | ||||
const axios = require('axios'); | const axios = require('axios'); | ||||
const config = require('../config'); | const config = require('../config'); | ||||
const BigNumber = require('bignumber.js'); | const BigNumber = require('bignumber.js'); | ||||
const cashaddr = require('ecashaddrjs'); | |||||
module.exports = { | module.exports = { | ||||
returnAddressPreview: function (cashAddress, sliceSize = 3) { | returnAddressPreview: function (cashAddress, sliceSize = 3) { | ||||
const addressParts = cashAddress.split(':'); | const addressParts = cashAddress.split(':'); | ||||
const unprefixedAddress = addressParts[addressParts.length - 1]; | const unprefixedAddress = addressParts[addressParts.length - 1]; | ||||
return `${unprefixedAddress.slice( | return `${unprefixedAddress.slice( | ||||
0, | 0, | ||||
sliceSize, | sliceSize, | ||||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | returnChronikTokenInfoPromise: function (chronik, tokenId, tokenInfoMap) { | ||||
resolve(true); | resolve(true); | ||||
}, | }, | ||||
err => { | err => { | ||||
reject(err); | reject(err); | ||||
}, | }, | ||||
); | ); | ||||
}); | }); | ||||
}, | }, | ||||
getOutputScriptFromAddress: function (address) { | |||||
Fabien: This is a copy paste of the same function in alias server.
What do you conclude ? | |||||
bytesofmanAuthorUnsubmitted Done Inline Actionsbytesofman: lol. forgot about this.
I did actually write it from the ground up here...again.
D13883 | |||||
/* | |||||
* Input params | |||||
* address - a valid p2pkh or p2sh cash address | |||||
* | |||||
* Output | |||||
* returns outputScript (string) - the outputScript for the given address | |||||
* returns false if input is invalid or of unsupported type | |||||
*/ | |||||
const { type, hash } = cashaddr.decode(address, true); | |||||
if (type === 'p2pkh') { | |||||
return `76a914${hash}88ac`; | |||||
} | |||||
if (type === 'p2sh') { | |||||
return `a914${hash}87`; | |||||
} | |||||
// If type is unsupported, return false | |||||
return false; | |||||
}, | |||||
}; | }; |
This is a copy paste of the same function in alias server.
What do you conclude ?