Changeset View
Changeset View
Standalone View
Standalone View
apps/alias-server/src/alias.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'); | const cashaddr = require('ecashaddrjs'); | ||||
const config = require('../config'); | const config = require('../config'); | ||||
const { | const { getAliasFromHex, isValidAliasString } = require('./utils'); | ||||
getAliasFromHex, | |||||
isValidAliasString, | |||||
getOutputScriptFromAddress, | |||||
} = require('./utils'); | |||||
const { addOneAliasToDb } = require('./db'); | const { addOneAliasToDb } = require('./db'); | ||||
module.exports = { | module.exports = { | ||||
getAliasTxs: function (aliasTxHistory, aliasConstants) { | getAliasTxs: function (aliasTxHistory, aliasConstants) { | ||||
const aliasTxCount = aliasTxHistory.length; | const aliasTxCount = aliasTxHistory.length; | ||||
// Get expected output script match for parseAliasTx | // Get expected output script match for parseAliasTx | ||||
// Do it here and not in parseAliasTx so that you don't do it for every single tx | // Do it here and not in parseAliasTx so that you don't do it for every single tx | ||||
// Will all be the same for a given set of tx history | // Will all be the same for a given set of tx history | ||||
const registrationOutputScript = getOutputScriptFromAddress( | const registrationOutputScript = cashaddr.getOutputScriptFromAddress( | ||||
aliasConstants.registrationAddress, | aliasConstants.registrationAddress, | ||||
); | ); | ||||
// initialize array for all valid aliases | // initialize array for all valid aliases | ||||
const aliasTxs = []; | const aliasTxs = []; | ||||
// iterate over history to get all alias:address pairs | // iterate over history to get all alias:address pairs | ||||
for (let i = 0; i < aliasTxCount; i += 1) { | for (let i = 0; i < aliasTxCount; i += 1) { | ||||
const thisAliasTx = aliasTxHistory[i]; | const thisAliasTx = aliasTxHistory[i]; | ||||
▲ Show 20 Lines • Show All 167 Lines • Show Last 20 Lines |