bcb-stream-parser
Advanced tools
Comparing version 0.3.3 to 0.3.4
{ | ||
"name": "bcb-stream-parser", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "Parse BitCoin-Block via NodeJS.ReadableStream", | ||
@@ -13,3 +13,3 @@ "main": "index.cjs", | ||
"ver": "echo ${npm_package_name}@${npm_package_version}", | ||
"test": "jest --ci --coverage" | ||
"test": "jest --ci --coverage -c jest.config.json" | ||
}, | ||
@@ -22,4 +22,3 @@ "keywords": [ | ||
], | ||
"author": "Cotton Hou <himcotton@gmail.com>", | ||
"repository": "imcotton/bcb-stream-parser", | ||
"repository": "github:imcotton/bcb-stream-parser", | ||
"homepage": "https://github.com/imcotton/bcb-stream-parser#readme", | ||
@@ -31,22 +30,22 @@ "bugs": { | ||
"dependencies": { | ||
"async-readable": "~0.2.0", | ||
"bn.js": "^5.0.0", | ||
"buffer-pond": "~0.7.0", | ||
"proxy-bind": "^1.1.0", | ||
"ramda": "~0.26.1" | ||
"async-readable": "~0.4.2", | ||
"bn.js": "^5.1.3", | ||
"buffer-pond": "~0.8.2", | ||
"proxy-bind": "^1.2.2", | ||
"ramda": "~0.27.1" | ||
}, | ||
"devDependencies": { | ||
"@types/bn.js": "^4.11.5", | ||
"@types/jest": "^24.0.16", | ||
"@types/node": "^10.14.14", | ||
"@types/ramda": "~0.26.16", | ||
"bitcoinjs-lib": "^5.1.3", | ||
"jest": "^24.8.0", | ||
"jest-junit": "^8.0.0", | ||
"rollup": "^1.18.0", | ||
"ts-jest": "^24.0.2", | ||
"tslib": "^1.10.0", | ||
"typescript": "~3.5.3", | ||
"utility-types": "^3.7.0" | ||
"@types/bn.js": "^4.11.6", | ||
"@types/jest": "^26.0.14", | ||
"@types/node": "^10.17.34", | ||
"@types/ramda": "~0.27.17", | ||
"bitcoinjs-lib": "^5.2.0", | ||
"jest": "^26.4.2", | ||
"jest-junit": "^11.1.0", | ||
"rollup": "^2.27.0", | ||
"ts-jest": "^26.3.0", | ||
"tslib": "^2.0.1", | ||
"typescript": "~4.0.2", | ||
"utility-types": "^3.10.0" | ||
} | ||
} |
/// <reference types="node" /> | ||
/// <reference lib="es2018.asynciterable" /> | ||
import { Read, AsyncReadable } from 'async-readable'; | ||
import { PromiseType, Optional } from 'utility-types'; | ||
import { PromiseType } from 'utility-types'; | ||
declare type AII<T> = AsyncIterableIterator<T>; | ||
@@ -81,3 +81,3 @@ declare type PT<T extends Promise<any>> = PromiseType<T>; | ||
export declare type Parser = RT<typeof parser> extends AII<infer U> ? U : never; | ||
export declare function parser({ read, off }: Optional<AsyncReadable, 'off'>): AsyncIterableIterator<{ | ||
export declare function parser({ read }: AsyncReadable): AsyncGenerator<{ | ||
readonly type: "HEADER"; | ||
@@ -135,3 +135,3 @@ readonly version: number; | ||
readonly lockTime: string; | ||
}>; | ||
}, void, unknown>; | ||
export {}; |
@@ -5,5 +5,3 @@ 'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
const BN = _interopDefault(require('bn.js')); | ||
const BN = require('bn.js'); | ||
const proxyBind = require('proxy-bind'); | ||
@@ -15,18 +13,22 @@ const bufferPond = require('buffer-pond'); | ||
function thunkLooping(thunk) { | ||
return Object.freeze({ | ||
async array(size) { | ||
const list = []; | ||
while (size--) { | ||
list.push(await thunk()); | ||
} | ||
return list; | ||
}, | ||
async *generator(size) { | ||
while (size--) { | ||
yield thunk(); | ||
} | ||
}, | ||
}); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
const BN__default = /*#__PURE__*/_interopDefaultLegacy(BN); | ||
function loopArray(thunk) { | ||
return async function (size) { | ||
const list = []; | ||
while (size--) { | ||
list.push(await thunk()); | ||
} | ||
return list; | ||
}; | ||
} | ||
function loopGenerator(thunk) { | ||
return async function* (size) { | ||
while (size--) { | ||
yield thunk(); | ||
} | ||
}; | ||
} | ||
function mapIter(mapper) { | ||
@@ -58,7 +60,7 @@ return async function* (source) { | ||
function bufferCounter(read) { | ||
const chunks = []; | ||
const [chunks, { push }] = proxyBind.mirror([]); | ||
const marker = []; | ||
let flag = false; | ||
const notEmpty = ramda.complement(ramda.isEmpty); | ||
const mirror = ramda.tap(proxyBind.bond(chunks).push); | ||
const copy = ramda.tap(push); | ||
const concatChunks = () => Buffer.concat(chunks); | ||
@@ -72,3 +74,3 @@ const patchChunksBy = ramda.forEach(((x) => (i) => chunks[i] = x)(Buffer.alloc(0))); | ||
async read(size) { | ||
const chunk = mirror(await read(size)); | ||
const chunk = copy(await read(size)); | ||
if (flag === true) { | ||
@@ -114,3 +116,3 @@ markChunksFromBack(0); | ||
case 0xFE: return (await read(4)).readUInt32LE(0); | ||
case 0xFF: return new BN(await read(8), 'le').toNumber(); | ||
case 0xFF: return new BN__default['default'](await read(8), 'le').toNumber(); | ||
default: return size; | ||
@@ -149,3 +151,3 @@ } | ||
return async function () { | ||
const value = '0x' + new BN(await read(8), 'le').toString(16); | ||
const value = ramda.concat('0x', new BN__default['default'](await read(8), 'le').toString(16)); | ||
const script = await varStrThunk(); | ||
@@ -160,3 +162,3 @@ return { | ||
const compactSizeThunk = readCompactSize(read); | ||
const loopStr = thunkLooping(readVarHex(read)).array; | ||
const loopStr = loopArray(readVarHex(read)); | ||
return async function () { | ||
@@ -170,5 +172,5 @@ return loopStr(await compactSizeThunk()); | ||
const compactSizeThunk = readCompactSize(read); | ||
const loopInput = thunkLooping(readInput(read)).array; | ||
const loopOutput = thunkLooping(readOutput(read)).array; | ||
const loopWitness = thunkLooping(readWitness(read)).array; | ||
const loopInput = loopArray(readInput(read)); | ||
const loopOutput = loopArray(readOutput(read)); | ||
const loopWitness = loopArray(readWitness(read)); | ||
return async function () { | ||
@@ -229,6 +231,6 @@ const version = (await read(4)).readUInt32LE(0); | ||
const height = bytes < 1 ? 0 : scriptBuffer.readUIntLE(1, bytes); | ||
const value = '0x' + outputs | ||
.map(({ value }) => new BN(value.substr(2), 16)) | ||
const value = ramda.concat('0x', outputs | ||
.map(({ value }) => new BN__default['default'](value.substr(2), 16)) | ||
.reduce((a, b) => a.iadd(b)) | ||
.toString(16); | ||
.toString(16)); | ||
return { | ||
@@ -267,9 +269,8 @@ type: 'COINBASE', | ||
const reader = asyncReadable.toReadableStream(parser); | ||
async function* parser({ read, off = () => { } }) { | ||
async function* parser({ read }) { | ||
const header = await readHeader(read)(true); | ||
yield { ...header }; | ||
const { txCount } = header; | ||
const loopTx = thunkLooping(readTransaction(read)).generator; | ||
const indexed = mapIter((tx, i) => ({ i, tx })); | ||
for await (const { i, tx } of indexed(loopTx(txCount))) { | ||
const loop = ramda.o(mapIter((tx, i) => ({ i, tx })), loopGenerator(readTransaction(read))); | ||
for await (const { i, tx } of loop(txCount)) { | ||
if (i === 0) { | ||
@@ -283,3 +284,2 @@ const coinbase = parseCoinbase(tx); | ||
} | ||
off(); | ||
} | ||
@@ -286,0 +286,0 @@ |
/// <reference types="node" /> | ||
import { Read } from 'async-readable'; | ||
export declare function thunkLooping<T>(thunk: () => Promise<T>): Readonly<{ | ||
array(size: number): Promise<T[]>; | ||
generator(size: number): AsyncIterableIterator<T>; | ||
}>; | ||
export declare function mapIter<T, U>(mapper: (t: T, i: number) => U): (source: AsyncIterable<T>) => AsyncIterableIterator<U>; | ||
export declare function loopArray<T>(thunk: () => Promise<T>): (size: number) => Promise<T[]>; | ||
export declare function loopGenerator<T>(thunk: () => Promise<T>): (size: number) => AsyncGenerator<T, void, unknown>; | ||
export declare function mapIter<T, U>(mapper: (t: T, i: number) => U): (source: AsyncIterable<T>) => AsyncGenerator<U, void, unknown>; | ||
export declare function toHex(buffer: Buffer, prefix?: string): string; | ||
@@ -9,0 +7,0 @@ export declare function copy(buffer: Buffer): Buffer; |
38
utils.js
import { createHash } from 'crypto'; | ||
import { complement, forEach, isEmpty, tap, times } from 'ramda'; | ||
import { bond } from 'proxy-bind'; | ||
export function thunkLooping(thunk) { | ||
return Object.freeze({ | ||
async array(size) { | ||
const list = []; | ||
while (size--) { | ||
list.push(await thunk()); | ||
} | ||
return list; | ||
}, | ||
async *generator(size) { | ||
while (size--) { | ||
yield thunk(); | ||
} | ||
}, | ||
}); | ||
import { mirror } from 'proxy-bind'; | ||
export function loopArray(thunk) { | ||
return async function (size) { | ||
const list = []; | ||
while (size--) { | ||
list.push(await thunk()); | ||
} | ||
return list; | ||
}; | ||
} | ||
export function loopGenerator(thunk) { | ||
return async function* (size) { | ||
while (size--) { | ||
yield thunk(); | ||
} | ||
}; | ||
} | ||
export function mapIter(mapper) { | ||
@@ -46,7 +46,7 @@ return async function* (source) { | ||
export function bufferCounter(read) { | ||
const chunks = []; | ||
const [chunks, { push }] = mirror([]); | ||
const marker = []; | ||
let flag = false; | ||
const notEmpty = complement(isEmpty); | ||
const mirror = tap(bond(chunks).push); | ||
const copy = tap(push); | ||
const concatChunks = () => Buffer.concat(chunks); | ||
@@ -60,3 +60,3 @@ const patchChunksBy = forEach(((x) => (i) => chunks[i] = x)(Buffer.alloc(0))); | ||
async read(size) { | ||
const chunk = mirror(await read(size)); | ||
const chunk = copy(await read(size)); | ||
if (flag === true) { | ||
@@ -63,0 +63,0 @@ markChunksFromBack(0); |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
44922
13
1329
1
+ Addedasync-readable@0.4.2(transitive)
+ Addedbuffer-pond@0.8.3(transitive)
+ Addedramda@0.27.2(transitive)
- Removedasync-readable@0.2.3(transitive)
- Removedbuffer-pond@0.7.1(transitive)
- Removedramda@0.26.1(transitive)
Updatedasync-readable@~0.4.2
Updatedbn.js@^5.1.3
Updatedbuffer-pond@~0.8.2
Updatedproxy-bind@^1.2.2
Updatedramda@~0.27.1