Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: use Address for bulk tx and utxo reads #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions lib/node/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,27 @@ class HTTP extends Server {
});

// Bulk read UTXOs
// TODO(boymanjor): Deprecate this endpoint
// once the equivalent functionality is included
// in the wallet API.
this.post('/coin/address', async (req, res) => {
const valid = Validator.fromRequest(req);
const address = valid.array('addresses');
const addresses = valid.array('addresses');

enforce(address, 'Address is required.');
enforce(addresses, 'Addresses is required.');
enforce(!this.chain.options.spv, 'Cannot get coins in SPV mode.');

const coins = await this.node.getCoinsByAddress(address);
this.logger.warning('%s %s %s',
'Warning: endpoint being considered for deprecation.',
'Known to cause CPU exhaustion if too many addresses',
'are queried or too many results are found.');

const addrs = [];
for (const address of addresses) {
addrs.push(Address.fromString(address, this.network));
}

const coins = await this.node.getCoinsByAddress(addrs);
const result = [];

for (const coin of coins)
Expand Down Expand Up @@ -245,14 +258,27 @@ class HTTP extends Server {
});

// Bulk read TXs
// TODO(boymanjor): Deprecate this endpoint
// once the equivalent functionality is included
// in the wallet API.
this.post('/tx/address', async (req, res) => {
const valid = Validator.fromRequest(req);
const address = valid.array('addresses');
const addresses = valid.array('addresses');

enforce(address, 'Address is required.');
enforce(addresses, 'Addresses is required.');
enforce(!this.chain.options.spv, 'Cannot get TX in SPV mode.');

const metas = await this.node.getMetaByAddress(address);
this.logger.warning('%s %s %s',
'Warning: endpoint being considered for deprecation.',
'Known to cause CPU exhaustion if too many addresses',
'are queried or too many results are found.');

const addrs = [];
for (const address of addresses) {
addrs.push(Address.fromString(address, this.network));
}

const metas = await this.node.getMetaByAddress(addrs);
const result = [];

for (const meta of metas) {
Expand Down