Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Commit 53fc8ee

Browse files
committed
refactor: bypass named importing from @nervosnetwork/ckb-sdk-utils directly
1 parent 6096395 commit 53fc8ee

File tree

16 files changed

+54
-55
lines changed

16 files changed

+54
-55
lines changed

packages/ckb/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export { serializeScript } from '@nervosnetwork/ckb-sdk-utils';
1+
import * as ckbUtils from '@nervosnetwork/ckb-sdk-utils';
2+
export const serializeScript = ckbUtils.serializeScript;
23

34
export * from './schemas/generated/blockchain';
45
export * from './schemas/generated/rgbpp';

packages/ckb/src/paymaster/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { AddressPrefix, addressToScript, getTransactionSize, privateKeyToAddress } from '@nervosnetwork/ckb-sdk-utils';
1+
import * as ckbUtils from '@nervosnetwork/ckb-sdk-utils';
22
import { ConstructPaymasterParams } from '../types/rgbpp';
33
import { NoLiveCellError } from '../error';
44
import { CKB_UNIT, MAX_FEE, SECP256K1_WITNESS_LOCK_SIZE, getSecp256k1CellDep } from '../constants';
55
import { append0x, calculateTransactionFee } from '../utils';
66

7+
const { AddressPrefix, addressToScript, getTransactionSize, privateKeyToAddress } = ckbUtils;
8+
79
const SECP256K1_MIN_CAPACITY = BigInt(61) * CKB_UNIT;
810

911
export const splitMultiCellsWithSecp256k1 = async ({

packages/ckb/src/rgbpp/btc-jump-ckb.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ import {
2525
} from '../utils/rgbpp';
2626
import { Hex, IndexerCell } from '../types';
2727
import { RGBPP_WITNESS_PLACEHOLDER, getSecp256k1CellDep } from '../constants';
28-
import { addressToScript, getTransactionSize } from '@nervosnetwork/ckb-sdk-utils';
28+
import * as ckbUtils from '@nervosnetwork/ckb-sdk-utils';
29+
30+
const { addressToScript, getTransactionSize } = ckbUtils;
2931

3032
/**
3133
* Generate the virtual ckb transaction for the jumping tx from BTC to CKB

packages/ckb/src/rgbpp/btc-time.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import {
2-
addressToScript,
3-
bytesToHex,
4-
getTransactionSize,
5-
rawTransactionToHash,
6-
scriptToHash,
7-
serializeOutPoint,
8-
serializeWitnessArgs,
9-
} from '@nervosnetwork/ckb-sdk-utils';
1+
import * as ckbUtils from '@nervosnetwork/ckb-sdk-utils';
102
import {
113
BTC_JUMP_CONFIRMATION_BLOCKS,
124
SECP256K1_WITNESS_LOCK_SIZE,
@@ -29,6 +21,16 @@ import { buildSpvClientCellDep } from '../utils';
2921
import { blockchain } from '@ckb-lumos/base';
3022
import signWitnesses from '@nervosnetwork/ckb-sdk-core/lib/signWitnesses.js';
3123

24+
const {
25+
addressToScript,
26+
bytesToHex,
27+
getTransactionSize,
28+
rawTransactionToHash,
29+
scriptToHash,
30+
serializeOutPoint,
31+
serializeWitnessArgs,
32+
} = ckbUtils;
33+
3234
export const buildBtcTimeUnlockWitness = (btcTxProof: Hex): Hex => {
3335
const btcTimeUnlock = BTCTimeUnlock.pack({ btcTxProof: blockchain.Bytes.pack(btcTxProof) });
3436
return append0x(bytesToHex(btcTimeUnlock));

packages/ckb/src/rgbpp/btc-transfer.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,11 @@ import {
3737
getRgbppLockScript,
3838
getSecp256k1CellDep,
3939
} from '../constants';
40-
import {
41-
addressToScript,
42-
getTransactionSize,
43-
rawTransactionToHash,
44-
scriptToHash,
45-
serializeWitnessArgs,
46-
} from '@nervosnetwork/ckb-sdk-utils';
40+
import * as ckbUtils from '@nervosnetwork/ckb-sdk-utils';
4741
import signWitnesses from '@nervosnetwork/ckb-sdk-core/lib/signWitnesses.js';
4842

43+
const { addressToScript, getTransactionSize, rawTransactionToHash, scriptToHash, serializeWitnessArgs } = ckbUtils;
44+
4945
/**
5046
* Generate the virtual ckb transaction for the btc transfer tx
5147
* @param collector The collector that collects CKB live cells and transactions

packages/ckb/src/rgbpp/ckb-builder.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
bytesToHex,
3-
getTransactionSize,
4-
rawTransactionToHash,
5-
scriptToHash,
6-
serializeWitnessArgs,
7-
} from '@nervosnetwork/ckb-sdk-utils';
1+
import * as ckbUtils from '@nervosnetwork/ckb-sdk-utils';
82
import {
93
UpdateCkbTxWithRealBtcTxIdParams,
104
AppendPaymasterCellAndSignTxParams,
@@ -27,6 +21,8 @@ import { buildSpvClientCellDep } from '../utils';
2721
import { RGBPPUnlock, Uint16 } from '../schemas/generated/rgbpp';
2822
import { Bytes } from '@ckb-lumos/base/lib/blockchain.js';
2923

24+
const { bytesToHex, getTransactionSize, rawTransactionToHash, scriptToHash, serializeWitnessArgs } = ckbUtils;
25+
3026
export const buildRgbppUnlockWitness = (
3127
btcTxBytes: Hex,
3228
btcTxProof: Hex,

packages/ckb/src/rgbpp/ckb-jump-btc.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import {
1212
} from '../utils';
1313
import { genRgbppLockScript } from '../utils/rgbpp';
1414
import { MAX_FEE, MIN_CAPACITY, RGBPP_TX_WITNESS_MAX_SIZE } from '../constants';
15-
import { addressToScript, getTransactionSize } from '@nervosnetwork/ckb-sdk-utils';
15+
import * as ckbUtils from '@nervosnetwork/ckb-sdk-utils';
16+
17+
const { addressToScript, getTransactionSize } = ckbUtils;
1618

1719
/**
1820
* Generate the virtual ckb transaction for the jumping tx from CKB to BTC

packages/ckb/src/rgbpp/launch.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import {
2424
getUniqueTypeScript,
2525
UNLOCKABLE_LOCK_SCRIPT,
2626
} from '../constants';
27-
import { getTransactionSize, scriptToHash } from '@nervosnetwork/ckb-sdk-utils';
27+
import * as ckbUtils from '@nervosnetwork/ckb-sdk-utils';
28+
29+
const { getTransactionSize, scriptToHash } = ckbUtils;
2830

2931
/**
3032
* Generate the virtual ckb transaction for the btc transfer tx

packages/ckb/src/spore/cluster.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import {
1111
} from '../constants';
1212
import { generateClusterCreateCoBuild, generateClusterId } from '../utils/spore';
1313
import { NoRgbppLiveCellError } from '../error';
14-
import { bytesToHex, getTransactionSize } from '@nervosnetwork/ckb-sdk-utils';
14+
import * as ckbUtils from '@nervosnetwork/ckb-sdk-utils';
15+
16+
const { bytesToHex, getTransactionSize } = ckbUtils;
1517

1618
/**
1719
* Generate the virtual ckb transaction for creating cluster

packages/ckb/src/spore/leap.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,12 @@ import {
2424
} from '../constants';
2525
import { generateSporeTransferCoBuild, throwErrorWhenSporeCellsInvalid } from '../utils/spore';
2626
import { NoRgbppLiveCellError } from '../error';
27-
import {
28-
addressToScript,
29-
getTransactionSize,
30-
serializeOutPoint,
31-
serializeWitnessArgs,
32-
} from '@nervosnetwork/ckb-sdk-utils';
27+
import * as ckbUtils from '@nervosnetwork/ckb-sdk-utils';
3328
import { blockchain } from '@ckb-lumos/base';
3429
import { buildBtcTimeUnlockWitness } from '../rgbpp';
3530

31+
const { addressToScript, getTransactionSize, serializeOutPoint, serializeWitnessArgs } = ckbUtils;
32+
3633
/**
3734
* Generate the virtual ckb transaction for leaping spore from BTC to CKB
3835
* @param collector The collector that collects CKB live cells and transactions

packages/ckb/src/spore/spore.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,12 @@ import {
4141
RgbppUtxoBindMultiTypeAssetsError,
4242
TypeAssetNotSupportedError,
4343
} from '../error';
44-
import {
45-
addressToScript,
46-
bytesToHex,
47-
getTransactionSize,
48-
rawTransactionToHash,
49-
scriptToHash,
50-
serializeWitnessArgs,
51-
} from '@nervosnetwork/ckb-sdk-utils';
44+
import * as ckbUtils from '@nervosnetwork/ckb-sdk-utils';
5245
import signWitnesses from '@nervosnetwork/ckb-sdk-core/lib/signWitnesses.js';
5346

47+
const { addressToScript, bytesToHex, getTransactionSize, rawTransactionToHash, scriptToHash, serializeWitnessArgs } =
48+
ckbUtils;
49+
5450
/**
5551
* Generate the virtual ckb transaction for creating spores
5652
* @param collector The collector that collects CKB live cells and transactions

packages/ckb/src/utils/ckb-tx.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import {
99
getXudtTypeScript,
1010
} from '../constants';
1111
import { Hex, RgbppTokenInfo } from '../types';
12-
import { PERSONAL, blake2b, hexToBytes, serializeInput, serializeScript } from '@nervosnetwork/ckb-sdk-utils';
12+
import * as ckbUtils from '@nervosnetwork/ckb-sdk-utils';
1313
import { encodeRgbppTokenInfo, genBtcTimeLockScript } from './rgbpp';
1414
import { Collector } from '../collector';
1515
import { NoLiveCellError } from '../error';
1616

17+
const { PERSONAL, blake2b, hexToBytes, serializeInput, serializeScript } = ckbUtils;
18+
1719
export const calculateTransactionFee = (txSize: number, feeRate?: bigint): bigint => {
1820
const rate = feeRate ?? BigInt(1100);
1921
const fee = calculateTxFee(BigInt(txSize), rate);

packages/ckb/src/utils/hex.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { hexToBytes, bytesToHex } from '@nervosnetwork/ckb-sdk-utils';
1+
import * as ckbUtils from '@nervosnetwork/ckb-sdk-utils';
22
import { Hex } from '../types';
33

4+
const { hexToBytes, bytesToHex } = ckbUtils;
5+
46
export const remove0x = (hex: string): string => {
57
if (hex.startsWith('0x')) {
68
return hex.substring(2);

packages/ckb/src/utils/rgbpp.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ import {
1010
getBtcTimeLockScript,
1111
getRgbppLockScript,
1212
} from '../constants';
13-
import {
14-
bytesToHex,
15-
hexToBytes,
16-
serializeOutPoint,
17-
serializeOutput,
18-
serializeScript,
19-
} from '@nervosnetwork/ckb-sdk-utils';
13+
import * as ckbUtils from '@nervosnetwork/ckb-sdk-utils';
2014
import { BTCTimeLock } from '../schemas/generated/rgbpp';
2115
import { Script } from '../schemas/generated/blockchain';
2216
import { blockchain } from '@ckb-lumos/base';
@@ -31,6 +25,8 @@ import {
3125
} from '../error';
3226
import { calculateRgbppCellCapacity, isScriptEqual, isUDTTypeSupported } from './ckb-tx';
3327

28+
const { bytesToHex, hexToBytes, serializeOutPoint, serializeOutput, serializeScript } = ckbUtils;
29+
3430
export const genRgbppLockScript = (rgbppLockArgs: Hex, isMainnet: boolean, btcTestnetType?: BTCTestnetType) => {
3531
return {
3632
...getRgbppLockScript(isMainnet, btcTestnetType),

packages/ckb/src/utils/spore.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PERSONAL, blake2b, hexToBytes, serializeInput } from '@nervosnetwork/ckb-sdk-utils';
1+
import * as ckbUtils from '@nervosnetwork/ckb-sdk-utils';
22
import { Cell as LumosCell } from '@ckb-lumos/base';
33
import { UnpackResult } from '@ckb-lumos/codec';
44
import {
@@ -14,6 +14,8 @@ import { Hex, IndexerCell, SporesCreateCobuildParams } from '../types';
1414
import { NoRgbppLiveCellError, RgbppSporeTypeMismatchError, RgbppUtxoBindMultiTypeAssetsError } from '../error';
1515
import { isScriptEqual, isSporeTypeSupported } from './ckb-tx';
1616

17+
const { PERSONAL, blake2b, hexToBytes, serializeInput } = ckbUtils;
18+
1719
// Generate type id for cluster id
1820
export const generateClusterId = (firstInput: CKBComponents.CellInput, firstOutputIndex: number) => {
1921
const input = hexToBytes(serializeInput(firstInput));

packages/rgbpp/src/rgbpp/xudt.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { genBtcTransferCkbVirtualTx, getXudtTypeScript } from '@rgbpp-sdk/ckb';
2-
import { serializeScript } from '@nervosnetwork/ckb-sdk-utils';
1+
import { genBtcTransferCkbVirtualTx, getXudtTypeScript, serializeScript } from '@rgbpp-sdk/ckb';
32
import { sendRgbppUtxos } from '@rgbpp-sdk/btc';
43
import { RgbppTransferTxParams, RgbppTransferTxResult } from './types';
54

0 commit comments

Comments
 (0)