Created
February 26, 2023 12:45
-
-
Save rithvikvibhu/e31e3ca615b16ff3e6a3cd185861104a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// node list-transferring-names.js | |
const { NodeClient, WalletClient } = require('hs-client'); | |
const { Network } = require('hsd'); | |
// Edit these: | |
const NETWORK = 'main'; | |
const API_KEY = 'api-key-here'; | |
const WALLET_NAME = 'walletname'; | |
/** @type {import('hsd/lib/protocol/network')} */ | |
const network = Network.get(NETWORK); | |
const nodeClient = new NodeClient({ | |
network: network.type, | |
port: network.rpcPort, | |
apiKey: API_KEY, | |
}); | |
const walletClient = new WalletClient({ | |
network: network.type, | |
port: network.walletPort, | |
apiKey: API_KEY, | |
}); | |
const wallet = walletClient.wallet(WALLET_NAME); | |
(async () => { | |
const result = []; | |
console.log('[*] Getting all names in wallet...') | |
await nodeClient.open(); | |
await walletClient.open(); | |
// Get all names in wallet | |
const allNames = await wallet.getNames(); | |
for (const ns of allNames) { | |
// We only care about own names | |
const { hash, index } = ns.owner; | |
const coin = await wallet.getCoin(hash, index); | |
if (!coin) continue; | |
// Only transferring names | |
if (ns.transfer === 0) continue; | |
const diff = ns.stats.blocksUntilValidFinalize; | |
const transferringName = { | |
name: ns.name, | |
canFinalize: diff > 0 ? `in ${diff} blocks` : `from ${-diff} blocks ago`, | |
}; | |
result.push(transferringName); | |
console.log(`transferring name #${result.length}:`, transferringName); | |
} | |
// Sort by blocks remaining | |
result.sort((a, b) => a.canFinalizeInBlocks - b.canFinalizeInBlocks) | |
console.log('\n Names in transfer state:'); | |
console.table(result) | |
await nodeClient.close(); | |
await walletClient.close(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment