Changeset View
Changeset View
Standalone View
Standalone View
apps/alias-server/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 cashaddr = require('ecashaddrjs'); | |||||
module.exports = { | module.exports = { | ||||
getAliasFromHex: function (aliasHex) { | getAliasFromHex: function (aliasHex) { | ||||
return Buffer.from(aliasHex, 'hex').toString('utf8'); | return Buffer.from(aliasHex, 'hex').toString('utf8'); | ||||
}, | }, | ||||
getHexFromAlias: function (alias) { | getHexFromAlias: function (alias) { | ||||
return Buffer.from(alias, 'utf8').toString('hex'); | return Buffer.from(alias, 'utf8').toString('hex'); | ||||
}, | }, | ||||
Show All 14 Lines | removeUnconfirmedTxsFromTxHistory: function (txHistory) { | ||||
for (let i = 0; i < txHistory.length; i += 1) { | for (let i = 0; i < txHistory.length; i += 1) { | ||||
const thisTx = txHistory[i]; | const thisTx = txHistory[i]; | ||||
if (typeof thisTx.block !== 'undefined') { | if (typeof thisTx.block !== 'undefined') { | ||||
confirmedTxHistory.push(thisTx); | confirmedTxHistory.push(thisTx); | ||||
} | } | ||||
} | } | ||||
return confirmedTxHistory; | return confirmedTxHistory; | ||||
}, | }, | ||||
getOutputScriptFromAddress: function (address) { | |||||
const { type, hash } = cashaddr.decode(address, true); | |||||
let registrationOutputScript; | |||||
if (type === 'p2pkh') { | |||||
registrationOutputScript = `76a914${hash}88ac`; | |||||
} else { | |||||
registrationOutputScript = `a914${hash}87`; | |||||
} | |||||
return registrationOutputScript; | |||||
}, | |||||
wait: async function (msecs) { | wait: async function (msecs) { | ||||
await new Promise(resolve => setTimeout(resolve, msecs)); | await new Promise(resolve => setTimeout(resolve, msecs)); | ||||
}, | }, | ||||
}; | }; |