@ton3/liteclient
Version:
TON Blockchain LiteClient
49 lines • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransactionCursor = void 0;
const ton3_core_1 = require("ton3-core");
const types_1 = require("@tonkite/types");
class TransactionCursor {
constructor(api, account, offset, take) {
this.api = api;
this.account = account;
this.offset = offset;
this.take = take;
}
async *[Symbol.asyncIterator]() {
let taken = 0;
let last = null;
let complete = false;
let result;
do {
result = await this.api.getTransactions({
account: {
workchain: this.account.workchain,
id: this.account.hash,
},
lt: last?.lt ?? this.offset.lt,
hash: last?.hash ?? this.offset.hash,
count: TransactionCursor.CHUNK_SIZE
});
const cells = ton3_core_1.BOC.from(result.transactions);
for (let cellIndex in cells) {
const block = result.ids[cellIndex];
const transaction = (0, types_1.loadTransaction)(ton3_core_1.Slice.parse(cells[cellIndex]));
yield {
block,
transaction,
};
last = transaction.id;
taken += 1;
if (transaction.previousTransaction.lt === 0n) {
complete = true;
break;
}
}
complete || (complete = taken >= this.take);
} while (!complete);
}
}
exports.TransactionCursor = TransactionCursor;
TransactionCursor.CHUNK_SIZE = 30;
//# sourceMappingURL=cursor.js.map