UNPKG

swtc-lib

Version:

websocket access for jingtum blockchain

40 lines 1.4 kB
import { EventEmitter } from "events"; import { utils } from "@swtc/utils"; class Account extends EventEmitter { constructor(remote) { super(); this.setMaxListeners(0); this._remote = remote; this._accounts = {}; this._token = remote._token || "swt"; this.on("newListener", function (account, listener) { if (account === "removeListener") return; if (!utils.isValidAddress(account)) { this.account = new Error("invalid account"); return this; } this._accounts[account] = listener; }); this.on("removeListener", function (account) { if (!utils.isValidAddress(account)) { this.account = new Error("invalid account"); return this; } delete this._accounts[account]; }); this._remote.on("transactions", this.__infoAffectedAccounts.bind(this)); } __infoAffectedAccounts(data) { const accounts = utils.affectedAccounts(data); for (const account of accounts) { const callback = this._accounts[accounts[account]]; const _tx = utils.processTx(data, accounts[account]); if (callback) { callback(_tx); } } } } export { Account }; //# sourceMappingURL=account.js.map