Created
May 26, 2020 17:52
-
-
Save tynes/8d0e5533f42832bec1044d9a4714b62f to your computer and use it in GitHub Desktop.
Scan the Handshake Blockchain for Outputs Related to an Auction
This file contains hidden or 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
const {NodeClient} = require('hs-client'); | |
const sha3 = require('bcrypto/lib/sha3'); | |
const TX = require('hsd/lib/primitives/tx'); | |
const client = new NodeClient({ | |
host: '127.0.0.1', | |
port: 12037 | |
}); | |
(async () => { | |
const name = 'music'; | |
const nameHash = sha3.digest(Buffer.from(name, 'ascii')); | |
const info = await client.getInfo(); | |
const height = info.chain.height; | |
const out = { | |
outputs: [], | |
txs: [] | |
}; | |
for (let i = 0; i <= height; i++) { | |
const block = await client.getBlock(i); | |
for (const txn of block.txs) { | |
let match = false; | |
const tx = TX.decode(Buffer.from(txn.hex, 'hex')); | |
for (const [i, output] of tx.outputs.entries()) { | |
const {covenant} = output; | |
if (covenant.isName()) { | |
const hash = covenant.getHash(0); | |
if (nameHash.equals(hash)) { | |
match = true; | |
out.outputs.push({ | |
outpoint: {hash: tx.txid(), index: i}, | |
output | |
}); | |
} | |
} | |
} | |
if (match) | |
out.txs.push(tx); | |
} | |
} | |
console.log(JSON.stringify(out, null, 2)); | |
})().catch(err => { | |
console.log(err); | |
process.exit(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment