Add error handling to fundall

This commit is contained in:
Snazzah 2021-06-10 21:08:01 -05:00
parent 63f864f48a
commit 751b1b2fbc
No known key found for this signature in database
GPG key ID: 5E71D54F3D86282E

View file

@ -35,18 +35,27 @@ module.exports = class FundAll extends Command {
header: `Are you sure you want to fund **all** accounts? *(${givenAmount} LBC)*` header: `Are you sure you want to fund **all** accounts? *(${givenAmount} LBC)*`
})) return; })) return;
// ID - TXID
await this.client.startTyping(message.channel); await this.client.startTyping(message.channel);
const resultLines = []; const resultLines = [];
let funded = 0,
errored = 0;
for (const pair of pairs) { for (const pair of pairs) {
const response = await this.client.lbry.fundAccount({ to: pair.lbryID, amount: givenAmount }); const response = await this.client.lbry.fundAccount({ to: pair.lbryID, amount: givenAmount });
const transaction = await response.json(); const transaction = await response.json();
console.info('Funded account', pair.lbryID, transaction.result.txid); if ('code' in transaction) {
resultLines.push(`${pair.discordID} - https://explorer.lbry.com/tx/${transaction.result.txid}`); console.info('Failed to fund account', pair.lbryID, transaction.code, transaction.message);
resultLines.push(`${pair.discordID} ! ${transaction.code} - ${transaction.message}`);
errored++;
} else {
console.info('Funded account', pair.lbryID, transaction.result.txid);
resultLines.push(`${pair.discordID} - https://explorer.lbry.com/tx/${transaction.result.txid}`);
funded++;
}
} }
this.client.stopTyping(message.channel); this.client.stopTyping(message.channel);
return message.channel.createMessage(`Successfully funded ${resultLines.length} account(s)!`, { return message.channel.createMessage(errored
? `Failed to fund ${errored} accounts! (${funded} funded)`
: `Successfully funded ${funded} account(s)!`, {
name: 'result.txt', name: 'result.txt',
file: Buffer.from(resultLines.join('\n'), 'utf8') file: Buffer.from(resultLines.join('\n'), 'utf8')
}); });