mirror of
https://github.com/LBRYFoundation/curate.git
synced 2025-08-23 17:37:25 +00:00
Add error handling to fundall
This commit is contained in:
parent
63f864f48a
commit
751b1b2fbc
1 changed files with 14 additions and 5 deletions
|
@ -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')
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue