New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ckb-lumos/ckb-indexer

Package Overview
Dependencies
Maintainers
3
Versions
154
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ckb-lumos/ckb-indexer - npm Package Compare versions

Comparing version 0.20.0 to 0.21.0-next.0

6

lib/ckbIndexerFilter.d.ts

@@ -10,8 +10,8 @@ import { Cell, DataWithSearchMode, Script, ScriptWrapper } from "@ckb-lumos/base";

*/
declare type LumosQueryOptions = Pick<CKBIndexerQueryOptions, "lock" | "type" | "data" | "argsLen" | "outputDataLenRange" | "outputCapacityRange" | "scriptLenRange">;
type LumosQueryOptions = Pick<CKBIndexerQueryOptions, "lock" | "type" | "data" | "argsLen" | "outputDataLenRange" | "outputCapacityRange" | "scriptLenRange">;
/**
* @description `blockRange` is not supported, because pending cells don't have block number
*/
declare type LumosSearchFilter = Pick<SearchFilter, "script" | "scriptLenRange" | "outputCapacityRange" | "outputDataLenRange">;
declare type LumosSearchKey = Pick<SearchKey, "script" | "scriptType" | "scriptSearchMode"> & {
type LumosSearchFilter = Pick<SearchFilter, "script" | "scriptLenRange" | "outputCapacityRange" | "outputDataLenRange">;
type LumosSearchKey = Pick<SearchKey, "script" | "scriptType" | "scriptSearchMode"> & {
filter?: LumosSearchFilter;

@@ -18,0 +18,0 @@ };

@@ -12,9 +12,17 @@ "use strict";

exports.unwrapScriptWrapper = exports.unwrapDataWrapper = void 0;
var _base = require("@ckb-lumos/base");
var _codec = require("@ckb-lumos/codec");
var _bi = require("@ckb-lumos/bi");
/**
* @description the following fields are not supported:
* 1. `fromBlock` pending cells don't have block number
* 2. `toBlock` pending cells don't have block number
* 3. `skip` not search key, shoule be implmented in cell collector
* 4. `order` not search key, shoule be implmented in cell collector
*/
/**
* @description `blockRange` is not supported, because pending cells don't have block number
*/
function convertQueryOptionToLumosSearchKey(queryOptions) {

@@ -26,3 +34,2 @@ let searchKeyLock;

const queryType = queryOptions.type;
if (queryLock) {

@@ -35,3 +42,2 @@ if (instanceOfScriptWrapper(queryLock)) {

}
if (queryType && queryType !== "empty") {

@@ -44,3 +50,2 @@ if (instanceOfScriptWrapper(queryType)) {

}
if (searchKeyLock) {

@@ -64,3 +69,2 @@ searchKey = {

}
const {

@@ -74,18 +78,13 @@ outputDataLenRange,

searchKey.filter.scriptLenRange = scriptLenRange;
if (queryType === "empty") {
searchKey.filter.scriptLenRange = ["0x0", "0x1"];
}
return searchKey;
}
function filterByLumosQueryOptions(cells, options) {
const searchKey = convertQueryOptionToLumosSearchKey(options);
let filteredCells = cells.filter(cell => filterByLumosSearchKey(cell, searchKey));
if (options.argsLen && options.argsLen !== "any" && options.argsLen !== -1) {
filteredCells = filteredCells.filter(cell => _codec.bytes.bytify(cell.cellOutput.lock.args).length === options.argsLen);
}
if (!!options.data && options.data !== "any") {

@@ -99,5 +98,3 @@ if (instanceOfDataWithSearchMode(options.data) && options.data.searchMode === "exact") {

const expectPrefix = _codec.bytes.bytify(dataSearch.data);
const actualPrefix = _codec.bytes.bytify(cell.data).slice(0, expectPrefix.length);
return _codec.bytes.equal(expectPrefix, actualPrefix);

@@ -108,5 +105,3 @@ });

const expectPrefix = _codec.bytes.bytify(options.data);
const actualPrefix = _codec.bytes.bytify(cell.data).slice(0, expectPrefix.length);
return _codec.bytes.equal(expectPrefix, actualPrefix);

@@ -116,10 +111,8 @@ });

}
return filteredCells;
}
/**
* @internal
*/
function filterByLumosSearchKey(cell, searchKey) {

@@ -134,4 +127,5 @@ const isExactMode = searchKey.scriptSearchMode === "exact";

filter
} = searchKey; // Search mode
} = searchKey;
// Search mode
if (isExactMode) {

@@ -146,4 +140,4 @@ if (scriptType === "lock") {

}
} // Prefix mode
}
// Prefix mode
} else {

@@ -159,9 +153,9 @@ if (scriptType === "lock") {

}
} // the "exact" mode works only on "SearchKey.script",
}
// the "exact" mode works only on "SearchKey.script",
// not on "SearchKey.filter.script"
// the "SearchKey.filter.script" is always in prefix mode
if (!filter) return true; // filter type script if scriptType is "lock"
if (!filter) return true;
// filter type script if scriptType is "lock"
if (scriptType === "lock") {

@@ -171,7 +165,6 @@ if (filter.script && !checkScriptWithPrefixMode(cellOutput.type, filter.script)) {

}
if (filter.scriptLenRange && !checkScriptLenRange(cellOutput.type, filter.scriptLenRange)) {
return false;
} // filter lock script if scriptType is "type"
}
// filter lock script if scriptType is "type"
} else {

@@ -181,3 +174,2 @@ if (filter.script && !checkScriptWithPrefixMode(cellOutput.lock, filter.script)) {

}
if (filter.scriptLenRange && !checkScriptLenRange(cellOutput.lock, filter.scriptLenRange)) {

@@ -187,3 +179,2 @@ return false;

}
const {

@@ -193,10 +184,6 @@ outputCapacityRange,

} = filter;
if (outputCapacityRange) {
const capacity = _bi.BI.from(cellOutput.capacity);
const fromCapacity = _bi.BI.from(outputCapacityRange[0]);
const toCapacity = _bi.BI.from(outputCapacityRange[1]);
if (capacity.lt(fromCapacity) || capacity.gte(toCapacity)) {

@@ -206,10 +193,6 @@ return false;

}
if (outputDataLenRange) {
const dataLen = _bi.BI.from(_codec.bytes.bytify(cell.data).length);
const fromDataLen = _bi.BI.from(outputDataLenRange[0]);
const toDataLen = _bi.BI.from(outputDataLenRange[1]);
if (dataLen.lt(fromDataLen) || dataLen.gte(toDataLen)) {

@@ -219,55 +202,38 @@ return false;

}
return true;
}
function checkScriptWithPrefixMode(script, filterScript) {
if (!script) {
return false;
} // codeHash should always be 32 bytes, so it only supports exact match mode
}
// codeHash should always be 32 bytes, so it only supports exact match mode
if (!_codec.bytes.equal(filterScript.codeHash, script.codeHash)) {
return false;
}
const expectArgsPrefix = _codec.bytes.bytify(filterScript.args);
const actualArgsPrefix = _codec.bytes.bytify(script.args).slice(0, expectArgsPrefix.length);
if (!_codec.bytes.equal(expectArgsPrefix, actualArgsPrefix)) {
return false;
}
if (script.hashType !== filterScript.hashType) {
return false;
}
return true;
}
function checkScriptLenRange(script, scriptLenRange) {
const scriptLen = script ? _bi.BI.from(_codec.bytes.concat(script.codeHash, script.args).length + 1
/* hashType length is 1 */
) : _bi.BI.from(0);
const scriptLen = script ? _bi.BI.from(_codec.bytes.concat(script.codeHash, script.args).length + 1 /* hashType length is 1 */) : _bi.BI.from(0);
const fromScriptLen = _bi.BI.from(scriptLenRange[0]);
const toScriptLen = _bi.BI.from(scriptLenRange[1]);
if (scriptLen.lt(fromScriptLen) || scriptLen.gte(toScriptLen)) {
return false;
}
return true;
}
function instanceOfScriptWrapper(object) {
return typeof object === "object" && object != null && "script" in object;
}
function instanceOfDataWithSearchMode(object) {
return typeof object === "object" && object != null && "data" in object;
}
const unwrapScriptWrapper = inputScript => {

@@ -277,8 +243,5 @@ if (instanceOfScriptWrapper(inputScript)) {

}
return inputScript;
};
exports.unwrapScriptWrapper = unwrapScriptWrapper;
const unwrapDataWrapper = input => {

@@ -288,7 +251,5 @@ if (instanceOfDataWithSearchMode(input)) {

}
return input;
};
exports.unwrapDataWrapper = unwrapDataWrapper;
//# sourceMappingURL=ckbIndexerFilter.js.map

@@ -7,15 +7,8 @@ "use strict";

exports.CKBCellCollector = void 0;
var _base = require("@ckb-lumos/base");
var _toolkit = require("@ckb-lumos/toolkit");
var _services = require("./services");
var _crossFetch = _interopRequireDefault(require("cross-fetch"));
var _ckbIndexerFilter = require("./ckbIndexerFilter");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/** CellCollector will not get cell with blockHash by default, please use OtherQueryOptions.withBlockHash and OtherQueryOptions.CKBRpcUrl to get blockHash if you need. */

@@ -39,3 +32,4 @@ class CKBCellCollector {

};
this.queries = (Array.isArray(queries) ? queries : [queries]).map(query => ({ ...defaultQuery,
this.queries = (Array.isArray(queries) ? queries : [queries]).map(query => ({
...defaultQuery,
...query

@@ -48,3 +42,2 @@ }));

}
validateQueryOption(queries) {

@@ -54,3 +47,2 @@ if (!queries.lock && (!queries.type || queries.type === "empty")) {

}
if (queries.lock) {

@@ -63,3 +55,2 @@ if (!(0, _ckbIndexerFilter.instanceOfScriptWrapper)(queries.lock)) {

}
if (queries.type && queries.type !== "empty") {

@@ -72,36 +63,25 @@ if (typeof queries.type === "object" && !(0, _ckbIndexerFilter.instanceOfScriptWrapper)(queries.type)) {

}
if (queries.fromBlock) {
_base.utils.assertHexadecimal("fromBlock", queries.fromBlock);
}
if (queries.toBlock) {
_base.utils.assertHexadecimal("toBlock", queries.toBlock);
}
if (queries.order !== "asc" && queries.order !== "desc") {
throw new Error("Order must be either asc or desc!");
}
if (queries.outputCapacityRange) {
_base.utils.assertHexadecimal("outputCapacityRange[0]", queries.outputCapacityRange[0]);
_base.utils.assertHexadecimal("outputCapacityRange[1]", queries.outputCapacityRange[1]);
}
if (queries.outputDataLenRange) {
_base.utils.assertHexadecimal("outputDataLenRange[0]", queries.outputDataLenRange[0]);
_base.utils.assertHexadecimal("outputDataLenRange[1]", queries.outputDataLenRange[1]);
}
if (queries.scriptLenRange) {
_base.utils.assertHexadecimal("scriptLenRange[0]", queries.scriptLenRange[0]);
_base.utils.assertHexadecimal("scriptLenRange[1]", queries.scriptLenRange[1]);
}
if (queries.outputDataLenRange && queries.data && queries.data !== "any") {
const dataLen = (0, _services.getHexStringBytes)((0, _ckbIndexerFilter.unwrapDataWrapper)(queries.data));
if (dataLen < Number(queries.outputDataLenRange[0]) || dataLen >= Number(queries.outputDataLenRange[1])) {

@@ -111,7 +91,5 @@ throw new Error("data length not match outputDataLenRange");

}
if (queries.skip && typeof queries.skip !== "number") {
throw new Error("skip must be a number!");
}
if (queries.bufferSize && typeof queries.bufferSize !== "number") {

@@ -121,24 +99,20 @@ throw new Error("bufferSize must be a number!");

}
convertQueryOptionToSearchKey() {
this.queries.forEach(query => {
const queryLock = query.lock; // unWrap `ScriptWrapper` into `Script`.
const queryLock = query.lock;
// unWrap `ScriptWrapper` into `Script`.
if (queryLock) {
if ((0, _ckbIndexerFilter.instanceOfScriptWrapper)(queryLock)) {
_toolkit.validators.ValidateScript(queryLock.script);
query.lock = queryLock.script;
}
} // unWrap `ScriptWrapper` into `Script`.
}
// unWrap `ScriptWrapper` into `Script`.
if (query.type && query.type !== "empty") {
if (typeof query.type === "object" && (0, _ckbIndexerFilter.instanceOfScriptWrapper)(query.type)) {
_toolkit.validators.ValidateScript(query.type.script);
query.type = query.type.script;
}
}
if (!query.outputDataLenRange) {

@@ -150,3 +124,2 @@ if (query.data && query.data !== "any") {

}
if (!query.scriptLenRange && query.type === "empty") {

@@ -157,3 +130,2 @@ query.scriptLenRange = ["0x0", "0x1"];

}
async getLiveCell(query, lastCursor) {

@@ -168,14 +140,11 @@ const searchKeyFilter = {

}
async count() {
let counter = 0;
for await (const _cell of this.collect()) {
counter++;
}
return counter;
} // eslint-disable-next-line
}
// eslint-disable-next-line
async request(rpcUrl, data) {

@@ -189,16 +158,11 @@ const res = await (0, _crossFetch.default)(rpcUrl, {

});
if (res.status !== 200) {
throw new Error(`indexer request failed with HTTP code ${res.status}`);
}
const result = await res.json();
if (result.error !== undefined) {
throw new Error(`indexer request rpc failed with error: ${JSON.stringify(result.error)}`);
}
return result;
}
async getLiveCellWithBlockHash(query, lastCursor) {

@@ -208,9 +172,6 @@ if (!this.otherQueryOptions) {

}
const result = await this.getLiveCell(query, lastCursor);
if (result.objects.length === 0) {
return result;
}
const requestData = result.objects.map((cell, index) => {

@@ -228,3 +189,4 @@ return {

const blockHash = rpcResponse && rpcResponse.result;
return { ...item,
return {
...item,
blockHash

@@ -235,2 +197,3 @@ };

}
/**

@@ -240,13 +203,8 @@ * collect cells without blockHash by default.if you need blockHash, please add OtherQueryOptions.withBlockHash and OtherQueryOptions.ckbRpcUrl when constructor CellCollect.

*/
async *collect() {
const visitedCellKey = new Set();
for (const query of this.queries) {
for await (const cell of this.collectBySingleQuery(query)) {
var _cell$outPoint, _cell$outPoint2;
const key = `${(_cell$outPoint = cell.outPoint) === null || _cell$outPoint === void 0 ? void 0 : _cell$outPoint.txHash}-${(_cell$outPoint2 = cell.outPoint) === null || _cell$outPoint2 === void 0 ? void 0 : _cell$outPoint2.index}`;
if (visitedCellKey.has(key)) {

@@ -261,3 +219,2 @@ continue;

}
async *collectBySingleQuery(query) {

@@ -267,3 +224,2 @@ //TODO: fix return type

let lastCursor = undefined;
const getCellWithCursor = async () => {

@@ -274,15 +230,11 @@ const result = await (withBlockHash ? this.getLiveCellWithBlockHash(query, lastCursor) : this.getLiveCell(query, lastCursor));

};
let cells = await getCellWithCursor(); // filter cells by lumos query options
let cells = await getCellWithCursor();
// filter cells by lumos query options
cells = (0, _ckbIndexerFilter.filterByLumosQueryOptions)(cells, query);
if (cells.length === 0) {
return;
}
let buffer = getCellWithCursor();
let index = 0;
let skippedCount = 0;
while (true) {

@@ -294,13 +246,11 @@ if (query.skip && skippedCount < query.skip) {

}
index++; //reset index and exchange `cells` and `buffer` after yield last cell
index++;
//reset index and exchange `cells` and `buffer` after yield last cell
if (index === cells.length) {
index = 0;
cells = await buffer; // break if can not get more cells
cells = await buffer;
// break if can not get more cells
if (cells.length === 0) {
break;
}
buffer = getCellWithCursor();

@@ -310,6 +260,4 @@ }

}
}
exports.CKBCellCollector = CKBCellCollector;
//# sourceMappingURL=collector.js.map

@@ -36,10 +36,6 @@ "use strict";

});
var _collector = require("./collector");
var _indexer = require("./indexer");
var _transaction_collector = require("./transaction_collector");
var _rpc = require("./rpc");
//# sourceMappingURL=index.js.map

@@ -7,23 +7,15 @@ "use strict";

exports.TerminableCellAdapter = exports.CkbIndexer = void 0;
var _base = require("@ckb-lumos/base");
var _services = require("./services");
var _collector = require("./collector");
var _events = require("events");
var _type = require("./type");
var _bi = require("@ckb-lumos/bi");
var _rpc = require("./rpc");
var _rpc2 = require("@ckb-lumos/rpc");
var _toolkit = require("@ckb-lumos/toolkit");
var _ckbIndexerFilter = require("./ckbIndexerFilter");
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
const DefaultTerminator = () => {

@@ -35,16 +27,12 @@ return {

};
function defaultLogger(level, message) {
console.log(`[${level}] ${message}`);
}
/** CkbIndexer.collector will not get cell with blockHash by default, please use OtherQueryOptions.withBlockHash and OtherQueryOptions.CKBRpcUrl to get blockHash if you need. */
class CkbIndexer {
static version = "0.4.1";
medianTimeEmitters = [];
emitters = [];
isSubscribeRunning = false;
constructor(ckbIndexerUrl, ckbRpcUrl) {
_defineProperty(this, "medianTimeEmitters", []);
_defineProperty(this, "emitters", []);
_defineProperty(this, "isSubscribeRunning", false);
this.ckbIndexerUrl = ckbIndexerUrl;

@@ -55,54 +43,43 @@ this.ckbRpcUrl = ckbRpcUrl;

}
getCkbRpc() {
return new _rpc2.CKBRPC(this.uri);
}
/* c8 ignore next 12 */
getIndexerRpc() {
if (this.uri === this.ckbIndexerUri) {
const rpc = this.getCkbRpc();
return { ...rpc,
return {
...rpc,
getTip: rpc.getIndexerTip
};
}
return new _rpc.RPC(this.ckbIndexerUri);
}
async tip() {
return await this.getIndexerRpc().getTip();
}
asyncSleep(timeout) {
return new Promise(resolve => setTimeout(resolve, timeout));
}
async waitForSync(blockDifference = 0) {
const rpcTipNumber = parseInt((await this.getCkbRpc().getTipHeader()).number, 16);
while (true) {
const indexerTipNumber = parseInt((await this.tip()).blockNumber, 16);
if (indexerTipNumber + blockDifference >= rpcTipNumber) {
return;
}
await this.asyncSleep(1000);
}
}
/** collector cells without blockHash by default.if you need blockHash, please add OtherQueryOptions.withBlockHash and OtherQueryOptions.ckbRpcUrl.
* don't use OtherQueryOption if you don't need blockHash,cause it will slowly your collect.
*/
collector(queries, otherQueryOptions) {
return new _collector.CKBCellCollector(this, queries, otherQueryOptions);
}
async getCells(searchKey, terminator = DefaultTerminator, searchKeyFilter = {}) {
return new TerminableCellAdapter(this.getIndexerRpc()).getCells(searchKey, terminator, searchKeyFilter);
}
async getTransactions(searchKey, searchKeyFilter = {}) {

@@ -113,3 +90,2 @@ let infos = [];

const order = searchKeyFilter.order || "asc";
while (true) {

@@ -120,3 +96,2 @@ const res = await this.getIndexerRpc().getTransactions(searchKey, order, `0x${sizeLimit.toString(16)}`, cursor);

infos = infos.concat(txs);
if (txs.length <= sizeLimit) {

@@ -126,3 +101,2 @@ break;

}
return {

@@ -133,48 +107,35 @@ objects: infos,

}
running() {
return true;
}
start() {
defaultLogger("warn", "deprecated: no need to start the ckb-indexer manually");
}
startForever() {
defaultLogger("warn", "deprecated: no need to startForever the ckb-indexer manually");
}
stop() {
defaultLogger("warn", "deprecated: no need to stop the ckb-indexer manually");
}
subscribe(queries) {
this.isSubscribeRunning = true;
this.scheduleLoop();
if (queries.lock && queries.type) {
throw new Error("The notification machanism only supports you subscribing for one script once so far!");
}
if (queries.toBlock !== null || queries.skip !== null) {
defaultLogger("warn", "The passing fields such as toBlock and skip are ignored in subscribe() method.");
}
const emitter = new _type.IndexerEmitter();
emitter.argsLen = queries.argsLen;
emitter.outputData = queries.data && (0, _ckbIndexerFilter.unwrapDataWrapper)(queries.data);
if (queries.fromBlock) {
_base.utils.assertHexadecimal("fromBlock", queries.fromBlock);
}
emitter.fromBlock = !queries.fromBlock ? _bi.BI.from(0) : _bi.BI.from(queries.fromBlock);
if (queries.lock) {
_toolkit.validators.ValidateScript(queries.lock);
emitter.lock = queries.lock;
} else if (queries.type && queries.type !== "empty") {
_toolkit.validators.ValidateScript(queries.type);
emitter.type = queries.type;

@@ -184,7 +145,5 @@ } else {

}
this.emitters.push(emitter);
return emitter;
}
loop() {

@@ -194,3 +153,2 @@ if (!this.isSubscribeRunning) {

}
this.poll().then(timeout => {

@@ -203,3 +161,2 @@ this.scheduleLoop(timeout);

}
scheduleLoop(timeout = 1) {

@@ -210,3 +167,2 @@ setTimeout(() => {

}
async poll() {

@@ -219,3 +175,2 @@ let timeout = 1;

} = tip;
if (blockNumber === "0x0") {

@@ -225,7 +180,4 @@ const block = await this.getCkbRpc().getBlockByNumber(blockNumber);

}
const nextBlockNumber = _bi.BI.from(blockNumber).add(1);
const block = await this.getCkbRpc().getBlockByNumber(`0x${nextBlockNumber.toString(16)}`);
if (block) {

@@ -243,13 +195,12 @@ if (block.header.parentHash === blockHash) {

}
return timeout;
}
async publishAppendBlockEvents(block) {
for (const [txIndex, tx] of block.transactions.entries()) {
const blockNumber = block.header.number; // publish changed events if subscribed script exists in previous output cells , skip the cellbase.
const blockNumber = block.header.number;
// publish changed events if subscribed script exists in previous output cells , skip the cellbase.
if (txIndex > 0) {
const inputTxHashes = tx.inputs.map(input => input.previousOutput.txHash); // batch request by block
const inputTxHashes = tx.inputs.map(input => input.previousOutput.txHash);
// batch request by block
const transactionResponse = await (0, _services.requestBatchTransactionWithStatus)(this.uri, inputTxHashes).then(response => {

@@ -272,5 +223,4 @@ return response.map((txWithStatus, index) => {

});
} // publish changed events if subscribed script exists in output cells.
}
// publish changed events if subscribed script exists in output cells.
for (const [outputIndex, output] of tx.outputs.entries()) {

@@ -281,6 +231,4 @@ const outputData = tx.outputsData[outputIndex];

}
await this.emitMedianTimeEvents();
}
filterEvents(output, blockNumber, outputData) {

@@ -292,3 +240,2 @@ for (const emitter of this.emitters) {

}
if (output.type !== null) {

@@ -302,3 +249,2 @@ for (const emitter of this.emitters) {

}
checkFilterOptions(emitter, blockNumber, outputData, emitterScript, script) {

@@ -310,3 +256,2 @@ const checkBlockNumber = emitter.fromBlock ? _bi.BI.from(emitter.fromBlock).lte(blockNumber) : true;

}
checkArgs(argsLen, emitterArgs, args) {

@@ -323,3 +268,2 @@ if (argsLen === -1 || !argsLen && argsLen !== 0) {

}
async emitMedianTimeEvents() {

@@ -329,6 +273,4 @@ if (this.medianTimeEmitters.length === 0) {

}
const info = await this.getCkbRpc().getBlockchainInfo();
const medianTime = info.medianTime;
for (const medianTimeEmitter of this.medianTimeEmitters) {

@@ -338,3 +280,2 @@ medianTimeEmitter.emit("changed", medianTime);

}
subscribeMedianTime() {

@@ -347,7 +288,5 @@ this.isSubscribeRunning = true;

}
}
exports.CkbIndexer = CkbIndexer;
_defineProperty(CkbIndexer, "version", "0.4.1");
class TerminableCellAdapter {

@@ -357,3 +296,2 @@ constructor(getCellsableRpc) {

}
async getCells(searchKey, terminator = DefaultTerminator, searchKeyFilter = {}) {

@@ -365,3 +303,2 @@ const infos = [];

const index = 0;
while (true) {

@@ -371,3 +308,2 @@ const res = await this.getCellsableRpc.getCells(searchKey, order, `0x${sizeLimit.toString(16)}`, cursor);

cursor = res.lastCursor;
for (const liveCell of liveCells) {

@@ -384,7 +320,5 @@ const cell = {

} = terminator(index, cell);
if (push) {
infos.push(cell);
}
if (stop) {

@@ -397,3 +331,2 @@ return {

}
if (liveCells.length <= sizeLimit) {

@@ -403,3 +336,2 @@ break;

}
return {

@@ -410,6 +342,4 @@ objects: infos,

}
}
exports.TerminableCellAdapter = TerminableCellAdapter;
//# sourceMappingURL=indexer.js.map
import { HexString, HexNumber, Script } from "@ckb-lumos/base";
export declare type Tip = {
export type Tip = {
blockHash: HexNumber;
blockNumber: HexString;
};
export declare type CellOutput = {
export type CellOutput = {
capacity: HexNumber;

@@ -8,0 +8,0 @@ lock: Script;

@@ -7,3 +7,2 @@ "use strict";

exports.toSearchKey = exports.toSearchFilter = exports.toScript = exports.toGetTransactionsSearchKey = exports.toGetCellsSearchKey = void 0;
const toScript = data => ({

@@ -14,5 +13,3 @@ code_hash: data.codeHash,

});
exports.toScript = toScript;
const toSearchFilter = data => {

@@ -27,5 +24,3 @@ return {

};
exports.toSearchFilter = toSearchFilter;
const toSearchKey = data => ({

@@ -37,16 +32,13 @@ script: toScript(data.script),

});
exports.toSearchKey = toSearchKey;
const toGetCellsSearchKey = data => ({ ...toSearchKey(data),
const toGetCellsSearchKey = data => ({
...toSearchKey(data),
with_data: data.withData
});
exports.toGetCellsSearchKey = toGetCellsSearchKey;
const toGetTransactionsSearchKey = data => ({ ...toSearchKey(data),
const toGetTransactionsSearchKey = data => ({
...toSearchKey(data),
group_by_transaction: data.groupByTransaction
});
exports.toGetTransactionsSearchKey = toGetTransactionsSearchKey;
//# sourceMappingURL=paramsFormatter.js.map

@@ -7,3 +7,2 @@ "use strict";

exports.toTip = exports.toSearchKey = exports.toSearchFilter = exports.toScript = exports.toOutPoint = exports.toCellOutPut = void 0;
const toTip = tip => ({

@@ -13,5 +12,3 @@ blockHash: tip.block_hash,

});
exports.toTip = toTip;
const toScript = data => ({

@@ -22,5 +19,3 @@ codeHash: data.code_hash,

});
exports.toScript = toScript;
const toOutPoint = data => ({

@@ -30,12 +25,9 @@ txHash: data.tx_hash,

});
exports.toOutPoint = toOutPoint;
const toCellOutPut = data => ({ ...data,
const toCellOutPut = data => ({
...data,
lock: toScript(data.lock),
type: data.type ? toScript(data.type) : undefined
});
exports.toCellOutPut = toCellOutPut;
const toSearchFilter = data => {

@@ -50,5 +42,3 @@ return {

};
exports.toSearchFilter = toSearchFilter;
const toSearchKey = data => ({

@@ -60,4 +50,3 @@ script: toScript(data.script),

});
exports.toSearchKey = toSearchKey;
//# sourceMappingURL=resultFormatter.js.map

@@ -7,11 +7,6 @@ "use strict";

exports.RPC = void 0;
var _base = require("@ckb-lumos/base");
var _crossFetch = _interopRequireDefault(require("cross-fetch"));
var _paramsFormatter = require("./paramsFormatter");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class RPC {

@@ -25,7 +20,5 @@ /**

}
async getTip() {
return _base.utils.deepCamel(await request(this.uri, "get_tip"));
}
async getCells(searchKey, order, limit, cursor) {

@@ -35,3 +28,2 @@ const params = [(0, _paramsFormatter.toGetCellsSearchKey)(searchKey), order, limit, cursor];

}
async getTransactions(searchKey, order, limit, cursor) {

@@ -41,13 +33,9 @@ const params = [(0, _paramsFormatter.toGetTransactionsSearchKey)(searchKey), order, limit, cursor];

}
async getIndexerInfo() {
return _base.utils.deepCamel(await request(this.uri, "get_indexer_info"));
}
}
}
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types */
exports.RPC = RPC;
const request = async (ckbIndexerUrl, method, params) => {

@@ -66,13 +54,9 @@ const res = await (0, _crossFetch.default)(ckbIndexerUrl, {

});
if (res.status !== 200) {
throw new Error(`indexer request failed with HTTP code ${res.status}`);
}
const data = await res.json();
if (data.error !== undefined) {
throw new Error(`indexer request rpc failed with error: ${JSON.stringify(data.error)}`);
}
return data.result;

@@ -79,0 +63,0 @@ };

import { HexString, HexNumber, Hash, Hexadecimal } from "@ckb-lumos/base";
export declare type Tip = {
export type Tip = {
block_hash: HexNumber;
block_number: HexString;
};
export declare type Script = {
export type Script = {
code_hash: HexString;

@@ -15,3 +15,3 @@ hash_type: "type" | "data" | "data1";

}
export declare type CellOutput = {
export type CellOutput = {
capacity: HexNumber;

@@ -21,5 +21,5 @@ lock: Script;

};
export declare type HexadecimalRange = [Hexadecimal, Hexadecimal];
export declare type ScriptType = "type" | "lock";
export declare type ScriptSearchMode = "prefix" | "exact";
export type HexadecimalRange = [Hexadecimal, Hexadecimal];
export type ScriptType = "type" | "lock";
export type ScriptSearchMode = "prefix" | "exact";
export interface SearchFilter {

@@ -26,0 +26,0 @@ script?: Script;

@@ -9,19 +9,10 @@ "use strict";

exports.requestBatchTransactionWithStatus = requestBatchTransactionWithStatus;
var _base = require("@ckb-lumos/base");
var _crossFetch = _interopRequireDefault(require("cross-fetch"));
var _bi = require("@ckb-lumos/bi");
var _paramsFormatter = require("./paramsFormatter");
var _resultFormatter = require("./resultFormatter");
var _ckbIndexerFilter = require("./ckbIndexerFilter");
var _rpc = require("@ckb-lumos/rpc");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const generateSearchKey = queries => {

@@ -32,3 +23,2 @@ let script = undefined;

let script_search_mode = "prefix";
if (queries.lock) {

@@ -38,3 +28,2 @@ const lock = (0, _ckbIndexerFilter.unwrapScriptWrapper)(queries.lock);

script_type = "lock";
if (queries.type && typeof queries.type !== "string") {

@@ -49,5 +38,3 @@ const type = (0, _ckbIndexerFilter.unwrapScriptWrapper)(queries.type);

}
let block_range = null;
if (queries.fromBlock && queries.toBlock) {

@@ -57,31 +44,23 @@ //toBlock+1 cause toBlock need to be included

}
if (block_range) {
filter.block_range = block_range;
}
if (queries.outputDataLenRange) {
filter.output_data_len_range = queries.outputDataLenRange;
}
if (queries.outputCapacityRange) {
filter.output_capacity_range = queries.outputCapacityRange;
}
if (queries.scriptLenRange) {
filter.script_len_range = queries.scriptLenRange;
}
if (queries.scriptSearchMode) {
script_search_mode = queries.scriptSearchMode;
}
if (!script) {
throw new Error("Either lock or type script must be provided!");
}
if (!script_type) {
throw new Error("script_type must be provided");
}
return (0, _resultFormatter.toSearchKey)({

@@ -94,18 +73,14 @@ script,

};
exports.generateSearchKey = generateSearchKey;
const getHexStringBytes = hexString => {
_base.utils.assertHexString("", hexString);
return Math.ceil(hexString.substr(2).length / 2);
};
exports.getHexStringBytes = getHexStringBytes;
let id = 0; // will be tested in e2e
let id = 0;
// will be tested in e2e
/* c8 ignore next 25 */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async function requestBatch(rpcUrl, // eslint-disable-next-line
async function requestBatch(rpcUrl,
// eslint-disable-next-line
data) {

@@ -115,3 +90,2 @@ if (!data.length) {

}
const res = await (0, _crossFetch.default)(rpcUrl, {

@@ -127,18 +101,13 @@ method: "POST",

});
if (res.status !== 200) {
throw new Error(`Indexer request failed with HTTP code ${res.status}`);
}
const result = await res.json();
if (result.error !== undefined) {
throw new Error(`indexer request rpc failed with error: ${JSON.stringify(result.error)}`);
}
return result;
}
/* c8 ignore next 23 */
async function requestBatchTransactionWithStatus(rpcUrl, txHashes) {

@@ -148,3 +117,2 @@ if (txHashes.length === 0) {

}
const requestBody = txHashes.map((txHash, index) => {

@@ -151,0 +119,0 @@ return {

@@ -7,18 +7,76 @@ "use strict";

exports.CKBIndexerTransactionCollector = void 0;
var _base = require("@ckb-lumos/base");
var _ckbIndexerFilter = require("./ckbIndexerFilter");
var services = _interopRequireWildcard(require("./services"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
class CKBIndexerTransactionCollector extends _base.indexer.TransactionCollector {
constructor(indexer, queries, CKBRpcUrl, options) {
super(indexer, queries, options);
constructor(indexer, _queries, CKBRpcUrl, options) {
super(indexer, _queries, options);
_defineProperty(this, "getTransactionListFromRpc", async indexerTransactionList => {
const getDetailRequestData = indexerTransactionList.objects.map(hashItem => {
return hashItem.txHash;
});
const transactionList = await services.requestBatchTransactionWithStatus(this.CKBRpcUrl, getDetailRequestData).then(response => {
return response.map((item, index) => {
if (!this.filterOptions.skipMissing && !item.transaction) {
throw new Error(`Transaction ${indexerTransactionList.objects[index].txHash} is missing!`);
}
return item;
});
});
return transactionList;
});
_defineProperty(this, "isLockArgsLenMatched", (args, argsLen) => {
if (!argsLen) return true;
if (argsLen === "any") return true;
if (argsLen === -1) return true;
return services.getHexStringBytes(args) === argsLen;
});
// only valid after pass flow three validate
_defineProperty(this, "isCellScriptArgsValid", targetCell => {
if (this.queries.lock) {
const lockArgsLen = (0, _ckbIndexerFilter.instanceOfScriptWrapper)(this.queries.lock) ? this.queries.lock.argsLen : this.queries.argsLen;
if (!this.isLockArgsLenMatched(targetCell.lock.args, lockArgsLen)) {
return false;
}
}
if (this.queries.type && this.queries.type !== "empty") {
var _targetCell$type;
const typeArgsLen = (0, _ckbIndexerFilter.instanceOfScriptWrapper)(this.queries.type) ? this.queries.type.argsLen : this.queries.argsLen;
if (!this.isLockArgsLenMatched((_targetCell$type = targetCell.type) === null || _targetCell$type === void 0 ? void 0 : _targetCell$type.args, typeArgsLen)) {
return false;
}
}
if (this.queries.type && this.queries.type === "empty") {
if (targetCell.type) {
return false;
}
}
return true;
});
_defineProperty(this, "filterByIoType", (inputResult, ioType) => {
if (ioType === "both") {
return inputResult;
}
if (ioType === "input" || ioType === "output") {
return inputResult.filter(item => item.ioType === ioType || item.ioType === "both");
}
return inputResult;
});
_defineProperty(this, "filterByTypeIoTypeAndLockIoType", (inputResult, queries) => {
let result = inputResult;
if ((0, _ckbIndexerFilter.instanceOfScriptWrapper)(queries.lock) && queries.lock.ioType) {
result = this.filterByIoType(result, queries.lock.ioType);
}
if ((0, _ckbIndexerFilter.instanceOfScriptWrapper)(queries.type) && queries.type.ioType) {
result = this.filterByIoType(result, queries.type.ioType);
}
return result;
});
this.indexer = indexer;
this.queries = queries;
this.queries = _queries;
this.CKBRpcUrl = CKBRpcUrl;

@@ -30,6 +88,8 @@ this.options = options;

};
this.filterOptions = { ...defaultOptions,
this.filterOptions = {
...defaultOptions,
...this.options
};
}
/**

@@ -39,4 +99,2 @@ * @deprecated

*/
static asBaseTransactionCollector(CKBRpcUrl) {

@@ -48,6 +106,4 @@ return class extends _base.indexer.TransactionCollector {

}
};
}
async fetchIndexerTransaction(queries, lastCursor) {

@@ -58,7 +114,5 @@ const searchKeyFilter = {

};
if (lastCursor) {
searchKeyFilter.lastCursor = lastCursor;
}
let indexerTransactionList = {

@@ -73,4 +127,4 @@ objects: [],

*/
//if both lock and type, search search them in independent and then get intersection, GetTransactionsResults.lastCursor change to `${lockLastCursor}-${typeLastCursor}`
if ((0, _ckbIndexerFilter.instanceOfScriptWrapper)(queries.lock) && (0, _ckbIndexerFilter.instanceOfScriptWrapper)(queries.type)) {

@@ -83,9 +137,7 @@ indexerTransactionList = await this.getTransactionByLockAndTypeIndependent(searchKeyFilter);

lastCursor = indexerTransactionList.lastCursor;
} // filter by ScriptWrapper.io_type
}
// filter by ScriptWrapper.io_type
indexerTransactionList.objects = this.filterByTypeIoTypeAndLockIoType(indexerTransactionList.objects, queries);
return indexerTransactionList;
}
getResolvedTransactionRequestPayload(unresolvedTransactionList, indexerTransactionList) {

@@ -95,3 +147,2 @@ const requestPayload = [];

const indexerTransaction = indexerTransactionList.objects[index];
if (indexerTransaction.ioType === "input") {

@@ -104,3 +155,2 @@ const unresolvedOutPoint = unresolvedTransaction.transaction.inputs[Number(indexerTransaction.ioIndex)].previousOutput;

}
getResolvedCell(unresolvedTransaction, resolvedTransactionList, indexerTransaction) {

@@ -114,13 +164,11 @@ if (indexerTransaction.ioType !== "input") {

});
if (!resolvedTransaction) {
throw new Error(`Impossible: can NOT find resolved transaction!`);
}
const resolvedCell = resolvedTransaction.transaction.outputs[Number(unresolvedOutPoint.index)];
return resolvedCell;
}
} //filter by ScriptWrapper.argsLen
}
//filter by ScriptWrapper.argsLen
filterTransaction(unresolvedTransactionList, resolvedTransactionList, indexerTransactionList) {

@@ -137,2 +185,3 @@ const filteredTransactionList = unresolvedTransactionList.filter((unresolvedTransaction, index) => {

}
/*

@@ -148,8 +197,7 @@ *lock?: ScriptWrapper.script query by ckb-indexer,ScriptWrapper.ioType filter after get transaction from indexer, ScriptWrapper.argsLen filter after get transaction from rpc;

*/
async getTransactions(lastCursor) {
const indexerTransactionList = await this.fetchIndexerTransaction(this.queries, lastCursor);
lastCursor = indexerTransactionList.lastCursor; // return if transaction hash list if empty
lastCursor = indexerTransactionList.lastCursor;
// return if transaction hash list if empty
if (indexerTransactionList.objects.length === 0) {

@@ -161,3 +209,2 @@ return {

}
const unresolvedTransactionList = await this.getTransactionListFromRpc(indexerTransactionList);

@@ -172,9 +219,9 @@ const requestPayload = this.getResolvedTransactionRequestPayload(unresolvedTransactionList, indexerTransactionList);

}
async getTransactionByLockAndTypeIndependent(searchKeyFilter) {
const queryWithTypeAdditionOptions = { ...searchKeyFilter
const queryWithTypeAdditionOptions = {
...searchKeyFilter
};
const queryWithLockAdditionOptions = { ...searchKeyFilter
const queryWithLockAdditionOptions = {
...searchKeyFilter
};
if (searchKeyFilter.lastCursor) {

@@ -185,12 +232,12 @@ const [lockLastCursor, typeLastCursor] = searchKeyFilter.lastCursor.split("-");

}
const queriesWithoutType = { ...this.queries,
const queriesWithoutType = {
...this.queries,
type: undefined
};
const transactionByLock = await this.indexer.getTransactions(services.generateSearchKey(queriesWithoutType), queryWithTypeAdditionOptions);
const queriesWithoutLock = { ...this.queries,
const queriesWithoutLock = {
...this.queries,
lock: undefined
};
const transactionByType = await this.indexer.getTransactions(services.generateSearchKey(queriesWithoutLock), queryWithLockAdditionOptions);
const intersection = (transactionList1, transactionList2) => {

@@ -200,8 +247,8 @@ const result = [];

const tx2 = transactionList2.find(item => item.txHash === tx1.txHash);
if (tx2) {
// put the output io_type to intersection result, cause output have cells
const targetTx = tx1.ioType === "output" ? tx1 : tx2; // change io_type to both cause targetTx exist both input and output
result.push({ ...targetTx,
const targetTx = tx1.ioType === "output" ? tx1 : tx2;
// change io_type to both cause targetTx exist both input and output
result.push({
...targetTx,
ioType: "both"

@@ -213,3 +260,2 @@ });

};
const hashList = intersection(transactionByType.objects, transactionByLock.objects);

@@ -223,80 +269,4 @@ const lastCursor = transactionByLock.lastCursor + "-" + transactionByType.lastCursor;

}
getTransactionListFromRpc = async indexerTransactionList => {
const getDetailRequestData = indexerTransactionList.objects.map(hashItem => {
return hashItem.txHash;
});
const transactionList = await services.requestBatchTransactionWithStatus(this.CKBRpcUrl, getDetailRequestData).then(response => {
return response.map((item, index) => {
if (!this.filterOptions.skipMissing && !item.transaction) {
throw new Error(`Transaction ${indexerTransactionList.objects[index].txHash} is missing!`);
}
return item;
});
});
return transactionList;
};
isLockArgsLenMatched = (args, argsLen) => {
if (!argsLen) return true;
if (argsLen === "any") return true;
if (argsLen === -1) return true;
return services.getHexStringBytes(args) === argsLen;
}; // only valid after pass flow three validate
isCellScriptArgsValid = targetCell => {
if (this.queries.lock) {
const lockArgsLen = (0, _ckbIndexerFilter.instanceOfScriptWrapper)(this.queries.lock) ? this.queries.lock.argsLen : this.queries.argsLen;
if (!this.isLockArgsLenMatched(targetCell.lock.args, lockArgsLen)) {
return false;
}
}
if (this.queries.type && this.queries.type !== "empty") {
var _targetCell$type;
const typeArgsLen = (0, _ckbIndexerFilter.instanceOfScriptWrapper)(this.queries.type) ? this.queries.type.argsLen : this.queries.argsLen;
if (!this.isLockArgsLenMatched((_targetCell$type = targetCell.type) === null || _targetCell$type === void 0 ? void 0 : _targetCell$type.args, typeArgsLen)) {
return false;
}
}
if (this.queries.type && this.queries.type === "empty") {
if (targetCell.type) {
return false;
}
}
return true;
};
filterByIoType = (inputResult, ioType) => {
if (ioType === "both") {
return inputResult;
}
if (ioType === "input" || ioType === "output") {
return inputResult.filter(item => item.ioType === ioType || item.ioType === "both");
}
return inputResult;
};
filterByTypeIoTypeAndLockIoType = (inputResult, queries) => {
let result = inputResult;
if ((0, _ckbIndexerFilter.instanceOfScriptWrapper)(queries.lock) && queries.lock.ioType) {
result = this.filterByIoType(result, queries.lock.ioType);
}
if ((0, _ckbIndexerFilter.instanceOfScriptWrapper)(queries.type) && queries.type.ioType) {
result = this.filterByIoType(result, queries.type.ioType);
}
return result;
};
async count() {
let lastCursor = undefined;
const getTxWithCursor = async () => {

@@ -307,14 +277,10 @@ const result = await this.getTransactions(lastCursor);

};
let counter = 0;
let txs = await getTxWithCursor();
if (txs.length === 0) {
return 0;
}
let buffer = getTxWithCursor();
let index = 0;
let skippedCount = 0;
while (true) {

@@ -326,23 +292,18 @@ if (this.queries.skip && skippedCount < this.queries.skip) {

}
index++; //reset index and exchange `txs` and `buffer` after count last tx
index++;
//reset index and exchange `txs` and `buffer` after count last tx
if (index === txs.length) {
index = 0;
txs = await buffer; // break if can not get more txs
txs = await buffer;
// break if can not get more txs
if (txs.length === 0) {
break;
}
buffer = getTxWithCursor();
}
}
return counter;
}
async getTransactionHashes() {
let lastCursor = undefined;
const getTxWithCursor = async () => {

@@ -353,15 +314,11 @@ const result = await this.getTransactions(lastCursor);

};
const transactionHashes = []; //skip query result in first query
const transactionHashes = [];
//skip query result in first query
let txs = await getTxWithCursor();
if (txs.length === 0) {
return [];
}
let buffer = getTxWithCursor();
let index = 0;
let skippedCount = 0;
while (true) {

@@ -375,23 +332,18 @@ if (this.queries.skip && skippedCount < this.queries.skip) {

}
index++; //reset index and exchange `txs` and `buffer` after count last tx
index++;
//reset index and exchange `txs` and `buffer` after count last tx
if (index === txs.length) {
index = 0;
txs = await buffer; // break if can not get more txs
txs = await buffer;
// break if can not get more txs
if (txs.length === 0) {
break;
}
buffer = getTxWithCursor();
}
}
return transactionHashes;
}
async *collect() {
let lastCursor = undefined;
const getTxWithCursor = async () => {

@@ -401,15 +353,11 @@ const result = await this.getTransactions(lastCursor);

return result.objects;
}; //skip query result in first query
};
//skip query result in first query
let txs = await getTxWithCursor();
if (txs.length === 0) {
return undefined;
}
let buffer = getTxWithCursor();
let index = 0;
let skippedCount = 0;
while (true) {

@@ -425,13 +373,11 @@ if (this.queries.skip && skippedCount < this.queries.skip) {

}
index++; //reset index and exchange `txs` and `buffer` after count last tx
index++;
//reset index and exchange `txs` and `buffer` after count last tx
if (index === txs.length) {
index = 0;
txs = await buffer; // break if can not get more txs
txs = await buffer;
// break if can not get more txs
if (txs.length === 0) {
break;
}
buffer = getTxWithCursor();

@@ -441,6 +387,4 @@ }

}
}
exports.CKBIndexerTransactionCollector = CKBIndexerTransactionCollector;
//# sourceMappingURL=transaction_collector.js.map

@@ -5,5 +5,5 @@ /// <reference types="node" />

import { BIish } from "@ckb-lumos/bi";
export declare type ScriptType = "type" | "lock";
export declare type Order = "asc" | "desc";
export declare type ScriptSearchMode = "prefix" | "exact";
export type ScriptType = "type" | "lock";
export type Order = "asc" | "desc";
export type ScriptSearchMode = "prefix" | "exact";
export interface CKBIndexerQueryOptions extends QueryOptions {

@@ -18,3 +18,3 @@ outputDataLenRange?: HexadecimalRange;

}
export declare type HexadecimalRange = [Hexadecimal, Hexadecimal];
export type HexadecimalRange = [Hexadecimal, Hexadecimal];
export interface SearchFilter {

@@ -74,7 +74,7 @@ script?: Script;

}
export declare type HexNum = string;
export declare type IOType = "input" | "output" | "both";
export declare type Bytes32 = string;
export declare type IndexerTransaction<Goruped extends boolean = false> = Goruped extends true ? GroupedIndexerTransaction : UngroupedIndexerTransaction;
export declare type UngroupedIndexerTransaction = {
export type HexNum = string;
export type IOType = "input" | "output" | "both";
export type Bytes32 = string;
export type IndexerTransaction<Goruped extends boolean = false> = Goruped extends true ? GroupedIndexerTransaction : UngroupedIndexerTransaction;
export type UngroupedIndexerTransaction = {
blockNumber: HexNum;

@@ -86,3 +86,3 @@ ioIndex: HexNum;

};
export declare type GroupedIndexerTransaction = {
export type GroupedIndexerTransaction = {
txHash: Bytes32;

@@ -89,0 +89,0 @@ blockNumber: HexNum;

@@ -7,8 +7,5 @@ "use strict";

exports.IndexerEmitter = void 0;
var _events = require("events");
class IndexerEmitter extends _events.EventEmitter {}
exports.IndexerEmitter = IndexerEmitter;
//# sourceMappingURL=type.js.map
{
"name": "@ckb-lumos/ckb-indexer",
"version": "0.20.0",
"version": "0.21.0-next.0",
"description": "CKB Indexer",

@@ -22,6 +22,7 @@ "author": "Xuejie Xiao <xxuejie@gmail.com>",

"dependencies": {
"@ckb-lumos/base": "0.20.0",
"@ckb-lumos/bi": "0.20.0",
"@ckb-lumos/rpc": "0.20.0",
"@ckb-lumos/toolkit": "0.20.0",
"@ckb-lumos/base": "0.21.0-next.0",
"@ckb-lumos/bi": "0.21.0-next.0",
"@ckb-lumos/codec": "0.21.0-next.0",
"@ckb-lumos/rpc": "0.21.0-next.0",
"@ckb-lumos/toolkit": "0.21.0-next.0",
"cross-fetch": "^3.1.5",

@@ -31,3 +32,3 @@ "events": "^3.3.0"

"devDependencies": {
"@ckb-lumos/testkit": "0.20.0",
"@ckb-lumos/testkit": "0.21.0-next.0",
"@types/lodash.uniqby": "^4.7.7",

@@ -39,19 +40,4 @@ "@types/request": "^2.48.8",

"request": "^2.88.2",
"sinon": "^12.0.1",
"ts-node": "^10.4.0"
"sinon": "^15.0.4"
},
"scripts": {
"fmt": "prettier --write \"{src,tests,examples}/**/*.ts\" package.json",
"lint": "eslint -c ../../.eslintrc.js \"{src,tests,examples}/**/*.ts\"",
"posttest:e2e": "ts-node tests/close-mock-server-and-ckb-indexer.ts",
"pretest:e2e": "(nohup ts-node tests/start_mock_rpc.ts &) ; (sleep 5) ; (nohup ts-node tests/start_ckb_indexer.ts &) ; (sleep 10)",
"test:e2e": "ava **/*.e2e.test.ts --timeout=2m",
"test": "ava **/*.unit.test.ts --timeout=2m",
"build": "npm run build:types && npm run build:js",
"build:types": "tsc --declaration --emitDeclarationOnly",
"build:js": "babel --root-mode upward src --out-dir lib --extensions .ts -s",
"clean": "rm -rf lib",
"prepublishOnly": "yarn run clean && yarn run build",
"release": "npm publish"
},
"bugs": {

@@ -71,3 +57,12 @@ "url": "https://github.com/ckb-js/lumos/issues"

},
"gitHead": "28756be37c312eca132cac0c00b40510803030e0"
}
"scripts": {
"fmt": "prettier --write \"{src,tests,examples}/**/*.ts\" package.json",
"lint": "eslint -c ../../.eslintrc.js \"{src,tests,examples}/**/*.ts\"",
"test:e2e": "ts-node scripts/e2e-test.ts",
"test": "ava **/*.unit.test.ts --timeout=2m",
"build": "pnpm run build:types && pnpm run build:js",
"build:types": "tsc --declaration --emitDeclarationOnly",
"build:js": "babel --root-mode upward src --out-dir lib --extensions .ts -s",
"clean": "rm -rf lib"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc