@ethersphere/swarm-cli
Version:
CLI tool for Bee
48 lines (47 loc) • 1.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChequeCommand = void 0;
const bee_js_1 = require("@ethersphere/bee-js");
const utils_1 = require("../../utils");
const text_1 = require("../../utils/text");
const root_command_1 = require("../root-command");
class ChequeCommand extends root_command_1.RootCommand {
async getFilteredCheques(minimum) {
const cheques = await this.getCashableCheques();
return cheques.filter(({ amount }) => amount.toPLURBigInt() >= minimum);
}
async getCashableCheques() {
const { lastcheques } = await this.bee.getLastCheques();
const results = [];
for (const cheque of lastcheques) {
if (cheque.lastreceived === null) {
continue;
}
const uncashedAmount = await this.getUncashedAmount(cheque.peer);
results.push({
address: cheque.peer,
amount: uncashedAmount,
});
}
return results;
}
printCheque(cashable) {
this.console.divider('-');
this.console.log((0, text_1.createKeyValue)('Peer Address', cashable.address));
this.console.log((0, text_1.createKeyValue)('Cheque Value', cashable.amount.toDecimalString() + ' xBZZ'));
this.console.quiet(cashable.address + ' ' + cashable.amount);
}
async getUncashedAmount(address) {
try {
const lastCashout = await this.bee.getLastCashoutAction(address);
return lastCashout.uncashedAmount;
}
catch (error) {
if ((0, utils_1.getFieldOrNull)(error, 'message') === 'Not Found') {
return bee_js_1.BZZ.fromPLUR('0');
}
throw error;
}
}
}
exports.ChequeCommand = ChequeCommand;