Skip to content

Instantly share code, notes, and snippets.

@pinheadmz
Created August 12, 2020 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinheadmz/8103e1de606d2a530eccdb32cfcc66c6 to your computer and use it in GitHub Desktop.
Save pinheadmz/8103e1de606d2a530eccdb32cfcc66c6 to your computer and use it in GitHub Desktop.
'use strict';
const {NodeClient, WalletClient} = require('hs-client');
const {Network} = require('hsd');
const network = Network.get('regtest');
const nodeOptions = {
network: network.type,
port: network.rpcPort
};
const walletOptions = {
network: network.type,
port: network.walletPort
};
const nodeClient = new NodeClient(nodeOptions);
const walletClient = new WalletClient(walletOptions);
(async () => {
await nodeClient.open();
await walletClient.open();
console.log('funding wallet...');
const addr = await walletClient.execute('getnewaddress', []);
await nodeClient.execute('generatetoaddress', [200, addr]);
for (let j = 0; j < 20; j++) {
console.log(`Iteration: ${j}`);
console.log('opening...');
for (let i = 0; i < 50; i ++) {
await walletClient.execute('sendopen', [`test-${j}-${i}`]);
}
await nodeClient.execute('generatetoaddress', [7, addr]);
console.log('bidding...');
for (let i = 0; i < 50; i ++) {
await walletClient.execute(
'sendbid',
[`test-${j}-${i}`, 0.010000, 0.010000]
);
}
await nodeClient.execute('generatetoaddress', [7, addr]);
console.log('revealing...');
// only reveal half the names. wallet can not own un-revealed bids
for (let i = 0; i < 25; i ++) {
await walletClient.execute('sendreveal', [`test-${j}-${i}`]);
}
await nodeClient.execute('generatetoaddress', [10, addr]);
}
console.time('ALLNAMES');
const allNames = await walletClient.execute('getnames', [false]);
console.timeEnd('ALLNAMES');
console.time('OWNEDNAMES');
const ownedNames = await walletClient.execute('getnames', [true]);
console.timeEnd('OWNEDNAMES');
console.log(`All: ${allNames.length} \nOwned: ${ownedNames.length}`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment