UNPKG

@danielyandev/qr-account

Version:
47 lines 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const qr_constants_1 = require("@danielyandev/qr-constants"); class Account { constructor(addresses) { this.addresses = addresses; this.balance = { [this.addresses[0]]: qr_constants_1.INITIAL_COINS, }; } initialize(address) { if (this.balance[address] === undefined) { this.balance[address] = 0; this.addresses.push(address); } } transfer(from, to, amount) { this.initialize(from); this.initialize(to); this.increment(to, amount); this.decrement(from, amount); } increment(to, amount) { this.balance[to] += amount; } decrement(from, amount) { this.balance[from] -= amount; } getBalance(address) { this.initialize(address); return this.balance[address]; } update(transaction) { const amount = transaction.output.amount; const from = transaction.input.sender; const to = transaction.output.recipient; this.transfer(from, to, amount); } transferFee(block, transaction) { const amount = transaction.fee; const from = transaction.input.sender; const to = block.validator; this.transfer(from, to, amount); } } exports.default = Account; //# sourceMappingURL=account.js.map