@ckb-lumos/helpers
Advanced tools
Comparing version 0.17.0-rc7 to 0.17.0-rc8
import { HexString, Cell, Script, CellDep, Address, CellProvider, Hash, PackedSince, Transaction } from "@ckb-lumos/base"; | ||
import { List, Record, Map as ImmutableMap } from "immutable"; | ||
import { Config } from "@ckb-lumos/config-manager"; | ||
import { BI } from "@ckb-lumos/bi"; | ||
export interface Options { | ||
@@ -10,2 +11,5 @@ config?: Config; | ||
}): bigint; | ||
export declare function minimalCellCapacityCompatible(fullCell: Cell, { validate }?: { | ||
validate?: boolean; | ||
}): BI; | ||
export declare function locateCellDep(script: Script, { config }?: Options): CellDep | null; | ||
@@ -12,0 +16,0 @@ export declare function generateAddress(script: Script, { config }?: Options): Address; |
@@ -13,2 +13,3 @@ "use strict"; | ||
exports.minimalCellCapacity = minimalCellCapacity; | ||
exports.minimalCellCapacityCompatible = minimalCellCapacityCompatible; | ||
exports.objectToTransactionSkeleton = objectToTransactionSkeleton; | ||
@@ -24,3 +25,3 @@ exports.parseAddress = parseAddress; | ||
var _ckbJsToolkit = require("ckb-js-toolkit"); | ||
var _toolkit = require("@ckb-lumos/toolkit"); | ||
@@ -31,2 +32,4 @@ var _immutable = require("immutable"); | ||
var _bi = require("@ckb-lumos/bi"); | ||
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); } | ||
@@ -64,4 +67,13 @@ | ||
} = {}) { | ||
const result = minimalCellCapacityCompatible(fullCell, { | ||
validate | ||
}); | ||
return BigInt(result.toString()); | ||
} | ||
function minimalCellCapacityCompatible(fullCell, { | ||
validate = true | ||
} = {}) { | ||
if (validate) { | ||
_ckbJsToolkit.validators.ValidateCellOutput(fullCell.cell_output); | ||
_toolkit.validators.ValidateCellOutput(fullCell.cell_output); | ||
} // Capacity field itself | ||
@@ -71,4 +83,4 @@ | ||
let bytes = 8; | ||
bytes += new _ckbJsToolkit.Reader(fullCell.cell_output.lock.code_hash).length(); | ||
bytes += new _ckbJsToolkit.Reader(fullCell.cell_output.lock.args).length(); // hash_type field | ||
bytes += new _toolkit.Reader(fullCell.cell_output.lock.code_hash).length(); | ||
bytes += new _toolkit.Reader(fullCell.cell_output.lock.args).length(); // hash_type field | ||
@@ -78,4 +90,4 @@ bytes += 1; | ||
if (fullCell.cell_output.type) { | ||
bytes += new _ckbJsToolkit.Reader(fullCell.cell_output.type.code_hash).length(); | ||
bytes += new _ckbJsToolkit.Reader(fullCell.cell_output.type.args).length(); | ||
bytes += new _toolkit.Reader(fullCell.cell_output.type.code_hash).length(); | ||
bytes += new _toolkit.Reader(fullCell.cell_output.type.args).length(); | ||
bytes += 1; | ||
@@ -85,6 +97,6 @@ } | ||
if (fullCell.data) { | ||
bytes += new _ckbJsToolkit.Reader(fullCell.data).length(); | ||
bytes += new _toolkit.Reader(fullCell.data).length(); | ||
} | ||
return BigInt(bytes) * BigInt(100000000); | ||
return _bi.BI.from(bytes).mul(100000000); | ||
} | ||
@@ -258,3 +270,3 @@ | ||
if (validate) { | ||
_ckbJsToolkit.validators.ValidateTransaction(tx); | ||
_toolkit.validators.ValidateTransaction(tx); | ||
} | ||
@@ -276,3 +288,3 @@ | ||
const witness = tx.witnesses[e.index]; | ||
const witnessArgs = new _base.core.WitnessArgs(new _ckbJsToolkit.Reader(witness)); | ||
const witnessArgs = new _base.core.WitnessArgs(new _toolkit.Reader(witness)); | ||
const newWitnessArgs = { | ||
@@ -284,3 +296,3 @@ lock: sealingContents[i] | ||
if (inputType.hasValue()) { | ||
newWitnessArgs.input_type = new _ckbJsToolkit.Reader(inputType.value().raw()).serializeJson(); | ||
newWitnessArgs.input_type = new _toolkit.Reader(inputType.value().raw()).serializeJson(); | ||
} | ||
@@ -291,8 +303,8 @@ | ||
if (outputType.hasValue()) { | ||
newWitnessArgs.output_type = new _ckbJsToolkit.Reader(outputType.value().raw()).serializeJson(); | ||
newWitnessArgs.output_type = new _toolkit.Reader(outputType.value().raw()).serializeJson(); | ||
} | ||
_ckbJsToolkit.validators.ValidateWitnessArgs(newWitnessArgs); | ||
_toolkit.validators.ValidateWitnessArgs(newWitnessArgs); | ||
tx.witnesses[e.index] = new _ckbJsToolkit.Reader(_base.core.SerializeWitnessArgs(_ckbJsToolkit.normalizers.NormalizeWitnessArgs(newWitnessArgs))).serializeJson(); | ||
tx.witnesses[e.index] = new _toolkit.Reader(_base.core.SerializeWitnessArgs(_toolkit.normalizers.NormalizeWitnessArgs(newWitnessArgs))).serializeJson(); | ||
break; | ||
@@ -299,0 +311,0 @@ |
{ | ||
"name": "@ckb-lumos/helpers", | ||
"version": "0.17.0-rc7", | ||
"version": "0.17.0-rc8", | ||
"description": "Helper functions for working with CKB", | ||
@@ -33,3 +33,3 @@ "author": "Xuejie Xiao <xxuejie@gmail.com>", | ||
"lint": "eslint -c ../../.eslintrc.js \"{src,tests}/**/*.ts\"", | ||
"test": "ava tests/**/*.test.ts", | ||
"test": "ava tests/**/*.test.ts --timeout=2m", | ||
"build": "npm run build:types && npm run build:js", | ||
@@ -46,7 +46,7 @@ "build:types": "tsc --declaration --emitDeclarationOnly", | ||
"dependencies": { | ||
"@ckb-lumos/base": "^0.17.0-rc7", | ||
"@ckb-lumos/bi": "^0.17.0-rc7", | ||
"@ckb-lumos/config-manager": "^0.17.0-rc7", | ||
"@ckb-lumos/base": "^0.17.0-rc8", | ||
"@ckb-lumos/bi": "^0.17.0-rc8", | ||
"@ckb-lumos/config-manager": "^0.17.0-rc8", | ||
"@ckb-lumos/toolkit": "^0.17.0-rc8", | ||
"bech32": "^1.1.4", | ||
"ckb-js-toolkit": "^0.10.2", | ||
"immutable": "^4.0.0-rc.12" | ||
@@ -65,3 +65,3 @@ }, | ||
}, | ||
"gitHead": "38bf70632142311ae06f068b7d76ed4062fec5da" | ||
"gitHead": "2489e45e67fad85feb01e6a9793bcc150c30b8a3" | ||
} |
@@ -15,5 +15,6 @@ import { | ||
import * as bech32 from "bech32"; | ||
import { normalizers, validators, Reader } from "ckb-js-toolkit"; | ||
import { normalizers, validators, Reader } from "@ckb-lumos/toolkit"; | ||
import { List, Record, Map as ImmutableMap } from "immutable"; | ||
import { getConfig, Config } from "@ckb-lumos/config-manager"; | ||
import { BI } from "@ckb-lumos/bi"; | ||
@@ -49,2 +50,10 @@ export interface Options { | ||
): bigint { | ||
const result = minimalCellCapacityCompatible(fullCell, { validate }); | ||
return BigInt(result.toString()); | ||
} | ||
export function minimalCellCapacityCompatible( | ||
fullCell: Cell, | ||
{ validate = true }: { validate?: boolean } = {} | ||
): BI { | ||
if (validate) { | ||
@@ -67,3 +76,3 @@ validators.ValidateCellOutput(fullCell.cell_output); | ||
} | ||
return BigInt(bytes) * BigInt(100000000); | ||
return BI.from(bytes).mul(100000000); | ||
} | ||
@@ -70,0 +79,0 @@ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
50014
691
0
- Removedckb-js-toolkit@^0.10.2
- Removedckb-js-toolkit@0.10.2(transitive)
- Removedjsbi@3.2.5(transitive)
Updated@ckb-lumos/base@^0.17.0-rc8
Updated@ckb-lumos/bi@^0.17.0-rc8