From d0cf4be2e679bd1ebd09a3f93c2016b9f6607e80 Mon Sep 17 00:00:00 2001 From: homura Date: Wed, 29 Nov 2023 19:34:12 +0800 Subject: [PATCH 1/6] chore: upgrade lumos to 0.21 --- packages/neuron-ui/package.json | 4 +- packages/neuron-wallet/package.json | 18 ++-- yarn.lock | 142 ++++++++++++++-------------- 3 files changed, 82 insertions(+), 82 deletions(-) diff --git a/packages/neuron-ui/package.json b/packages/neuron-ui/package.json index 344fbf9f61..b0a17fc778 100644 --- a/packages/neuron-ui/package.json +++ b/packages/neuron-ui/package.json @@ -50,8 +50,8 @@ "last 2 chrome versions" ], "dependencies": { - "@ckb-lumos/base": "0.21.0-next.2", - "@ckb-lumos/codec": "0.21.0-next.2", + "@ckb-lumos/base": "0.21.0", + "@ckb-lumos/codec": "0.21.0", "@nervosnetwork/ckb-sdk-core": "0.109.0", "@nervosnetwork/ckb-sdk-utils": "0.109.0", "canvg": "2.0.0", diff --git a/packages/neuron-wallet/package.json b/packages/neuron-wallet/package.json index f85c7e1d8a..3848706714 100644 --- a/packages/neuron-wallet/package.json +++ b/packages/neuron-wallet/package.json @@ -42,15 +42,15 @@ ] }, "dependencies": { - "@ckb-lumos/base": "0.21.0-next.2", - "@ckb-lumos/bi": "0.21.0-next.2", - "@ckb-lumos/ckb-indexer": "0.21.0-next.2", - "@ckb-lumos/codec": "0.21.0-next.2", - "@ckb-lumos/common-scripts": "0.21.0-next.2", - "@ckb-lumos/config-manager": "0.21.0-next.2", - "@ckb-lumos/hd": "0.21.0-next.2", - "@ckb-lumos/helpers": "0.21.0-next.2", - "@ckb-lumos/rpc": "0.21.0-next.2", + "@ckb-lumos/base": "0.21.0", + "@ckb-lumos/bi": "0.21.0", + "@ckb-lumos/ckb-indexer": "0.21.0", + "@ckb-lumos/codec": "0.21.0", + "@ckb-lumos/common-scripts": "0.21.0", + "@ckb-lumos/config-manager": "0.21.0", + "@ckb-lumos/hd": "0.21.0", + "@ckb-lumos/helpers": "0.21.0", + "@ckb-lumos/rpc": "0.21.0", "@iarna/toml": "2.2.5", "@ledgerhq/hw-transport-node-hid": "6.27.22", "@spore-sdk/core": "0.1.0-beta.9", diff --git a/yarn.lock b/yarn.lock index bfda35675f..4c02d095a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1757,14 +1757,14 @@ js-xxhash "^1.0.4" lodash.isequal "^4.5.0" -"@ckb-lumos/base@0.21.0-next.2": - version "0.21.0-next.2" - resolved "https://registry.yarnpkg.com/@ckb-lumos/base/-/base-0.21.0-next.2.tgz#8d7ba32aa98f63de64f0140ef2e530a16450a382" - integrity sha512-1QiuVR7BD6RV2oq3CpM1RBMoPQ0E+F4e4MLwtg1kWRkN0UQWLin8OIDewb7hXsifU/ZpoTdluoCOGGV0CY1DkQ== - dependencies: - "@ckb-lumos/bi" "0.21.0-next.2" - "@ckb-lumos/codec" "0.21.0-next.2" - "@ckb-lumos/toolkit" "0.21.0-next.2" +"@ckb-lumos/base@0.21.0": + version "0.21.0" + resolved "https://registry.yarnpkg.com/@ckb-lumos/base/-/base-0.21.0.tgz#fe0e69e24c01acfb3c9bbf8bcea623c6c9c35d58" + integrity sha512-1HcUJ6YXBUf+dgFRjg84fnFjAqjAksInoaAI+ku3LvjEvJ+Mh1bIVm04zHsrsPyPWvH5x6W59iOezorWFfa/9A== + dependencies: + "@ckb-lumos/bi" "0.21.0" + "@ckb-lumos/codec" "0.21.0" + "@ckb-lumos/toolkit" "0.21.0" "@types/blake2b" "^2.1.0" "@types/lodash.isequal" "^4.5.5" blake2b "^2.1.3" @@ -1778,10 +1778,10 @@ dependencies: jsbi "^4.1.0" -"@ckb-lumos/bi@0.21.0-next.2": - version "0.21.0-next.2" - resolved "https://registry.yarnpkg.com/@ckb-lumos/bi/-/bi-0.21.0-next.2.tgz#0797e8774c00d3f4e609833050529e0f6e022620" - integrity sha512-3c8jC94eO57vFFo30g9Rh6qrfk5EF+7OD58hX1GknXaHwykMs3EBQodmA7DUV517dswkHy5IzI5gt5ROn9asjQ== +"@ckb-lumos/bi@0.21.0": + version "0.21.0" + resolved "https://registry.yarnpkg.com/@ckb-lumos/bi/-/bi-0.21.0.tgz#06f486f3e872dd80095514584e6347b827e5a566" + integrity sha512-QrECcsW4j2ipIgFINms/Q5mP88zZnyo2Tf7NyBdqe3cxvCEOT2Y8FutMTA96J368vgJ4TJwTCtgPkjrVHZKj3g== dependencies: jsbi "^4.1.0" @@ -1797,16 +1797,16 @@ cross-fetch "^3.1.5" events "^3.3.0" -"@ckb-lumos/ckb-indexer@0.21.0-next.2": - version "0.21.0-next.2" - resolved "https://registry.yarnpkg.com/@ckb-lumos/ckb-indexer/-/ckb-indexer-0.21.0-next.2.tgz#b151ffaea0b53ca989b336d6e9b539017450a475" - integrity sha512-Niwx2LPU0jH9La7ItSA1IHpX8Z025+qZHcUs1hDLIDHhxtqV5OiPRDrBAPn6B8iJMf1WqyaGLuqHZ6S5R1sEWw== +"@ckb-lumos/ckb-indexer@0.21.0": + version "0.21.0" + resolved "https://registry.yarnpkg.com/@ckb-lumos/ckb-indexer/-/ckb-indexer-0.21.0.tgz#524b611ad8e1b4db0be21d9925a8d43c417e3e80" + integrity sha512-3nqG0tL1TNZfKdoMgMtNnZCPX2fCc4ryJE3vrOcB5Ysy+jwg4AzYuNbUBkv7fMW7AKJ+bzlG694fUe1ZXD4Smg== dependencies: - "@ckb-lumos/base" "0.21.0-next.2" - "@ckb-lumos/bi" "0.21.0-next.2" - "@ckb-lumos/codec" "0.21.0-next.2" - "@ckb-lumos/rpc" "0.21.0-next.2" - "@ckb-lumos/toolkit" "0.21.0-next.2" + "@ckb-lumos/base" "0.21.0" + "@ckb-lumos/bi" "0.21.0" + "@ckb-lumos/codec" "0.21.0" + "@ckb-lumos/rpc" "0.21.0" + "@ckb-lumos/toolkit" "0.21.0" cross-fetch "^3.1.5" events "^3.3.0" @@ -1817,12 +1817,12 @@ dependencies: "@ckb-lumos/bi" "0.20.0" -"@ckb-lumos/codec@0.21.0-next.2": - version "0.21.0-next.2" - resolved "https://registry.yarnpkg.com/@ckb-lumos/codec/-/codec-0.21.0-next.2.tgz#d29465fc22c2b98182b6079453be7deb7d3fd1ba" - integrity sha512-yTtWIG9LESLTU3tBb9fHREWo2mO0Ts7SSL1Jp3MSqYbnl90JZeYr/skvn+vaV9/2Cl/6qEgeKYa1AnHNSLchkw== +"@ckb-lumos/codec@0.21.0": + version "0.21.0" + resolved "https://registry.yarnpkg.com/@ckb-lumos/codec/-/codec-0.21.0.tgz#c9b6516a71ca07f3bcb562037568c385bbfa2946" + integrity sha512-1u0Esd3OzSoWhgay2LJF0+CEVvgUNihuaxEnS3yvBjsVZBfUZcPAE+/NAIrpEtK1RFkuu3YBlNnW3B5ZGI80sg== dependencies: - "@ckb-lumos/bi" "0.21.0-next.2" + "@ckb-lumos/bi" "0.21.0" "@ckb-lumos/common-scripts@0.20.0": version "0.20.0" @@ -1838,18 +1838,18 @@ "@ckb-lumos/toolkit" "0.20.0" immutable "^4.0.0-rc.12" -"@ckb-lumos/common-scripts@0.21.0-next.2": - version "0.21.0-next.2" - resolved "https://registry.yarnpkg.com/@ckb-lumos/common-scripts/-/common-scripts-0.21.0-next.2.tgz#222e58a96d92a4ddfa9e501fe2f0a5428c036e96" - integrity sha512-43r7DvXSccsi80NcXh0jaZT0MdQ+rhsElWBO2U3zRUt/55rV4HBaoo26Rj8h7esi0tVfDbiDrnc16ymN1V+B3w== - dependencies: - "@ckb-lumos/base" "0.21.0-next.2" - "@ckb-lumos/bi" "0.21.0-next.2" - "@ckb-lumos/codec" "0.21.0-next.2" - "@ckb-lumos/config-manager" "0.21.0-next.2" - "@ckb-lumos/helpers" "0.21.0-next.2" - "@ckb-lumos/rpc" "0.21.0-next.2" - "@ckb-lumos/toolkit" "0.21.0-next.2" +"@ckb-lumos/common-scripts@0.21.0": + version "0.21.0" + resolved "https://registry.yarnpkg.com/@ckb-lumos/common-scripts/-/common-scripts-0.21.0.tgz#535187c26bd919d4e7e9fdbeb9754ee574e0fe17" + integrity sha512-yKWra6QwKV3/n/XAInf9XwaA2Q9HNr8QZpKC3/vK7yZH0QATNvZEuF1+NjLKl8/6E5uo37wZI+IfNgFlv3vANg== + dependencies: + "@ckb-lumos/base" "0.21.0" + "@ckb-lumos/bi" "0.21.0" + "@ckb-lumos/codec" "0.21.0" + "@ckb-lumos/config-manager" "0.21.0" + "@ckb-lumos/helpers" "0.21.0" + "@ckb-lumos/rpc" "0.21.0" + "@ckb-lumos/toolkit" "0.21.0" immutable "^4.3.0" "@ckb-lumos/config-manager@0.20.0", "@ckb-lumos/config-manager@^0.20.0": @@ -1863,14 +1863,14 @@ "@types/deep-freeze-strict" "^1.1.0" deep-freeze-strict "^1.1.1" -"@ckb-lumos/config-manager@0.21.0-next.2": - version "0.21.0-next.2" - resolved "https://registry.yarnpkg.com/@ckb-lumos/config-manager/-/config-manager-0.21.0-next.2.tgz#ef08003193a49b248440fc73ce9207b1bb6a2a5f" - integrity sha512-dVyMcd5hbnTpN2nuukLOWv2J73hpuMf3ZRSO3asqAodKGZek74JhwOtZD9saCOItLYeOWdRRmzfXad34lDgHXg== +"@ckb-lumos/config-manager@0.21.0": + version "0.21.0" + resolved "https://registry.yarnpkg.com/@ckb-lumos/config-manager/-/config-manager-0.21.0.tgz#e7dc0f7991a0a337dac50094f54b094a28fb4d07" + integrity sha512-SQa8fbP9Yuka3IqFH5wz0iHMZ9d7gEwt+NxSVuuOJ3YTV+TcSlL3+U/1ndgUiMYVNX55aEACoI9djwei/+VM2Q== dependencies: - "@ckb-lumos/base" "0.21.0-next.2" - "@ckb-lumos/bi" "0.21.0-next.2" - "@ckb-lumos/codec" "0.21.0-next.2" + "@ckb-lumos/base" "0.21.0" + "@ckb-lumos/bi" "0.21.0" + "@ckb-lumos/codec" "0.21.0" "@types/deep-freeze-strict" "^1.1.0" deep-freeze-strict "^1.1.1" @@ -1887,13 +1887,13 @@ sha3 "^2.1.3" uuid "^8.3.0" -"@ckb-lumos/hd@0.21.0-next.2": - version "0.21.0-next.2" - resolved "https://registry.yarnpkg.com/@ckb-lumos/hd/-/hd-0.21.0-next.2.tgz#03239f9d31cd9daf70f224563e7733089194dbb6" - integrity sha512-wj6k0d39yJEKWlC1cjXezZ4Qjf0u6rG+R6zQdqRXZ2dUJ/n82+fX+hLSAcjOgm1mGNft/6c55IfCs5dag/xQVw== +"@ckb-lumos/hd@0.21.0": + version "0.21.0" + resolved "https://registry.yarnpkg.com/@ckb-lumos/hd/-/hd-0.21.0.tgz#bab3b051460ce5ebb4b342bdcc812d4bd6e13cf1" + integrity sha512-Z6i/lRcKPIlMH64Mmr4SG+y9jUmW5IguSw1MIxmtwSCogra3ibxwnkCpVaUNObIZzAFS/8G2z8KthOrRg13esw== dependencies: - "@ckb-lumos/base" "0.21.0-next.2" - "@ckb-lumos/bi" "0.21.0-next.2" + "@ckb-lumos/base" "0.21.0" + "@ckb-lumos/bi" "0.21.0" bn.js "^5.1.3" elliptic "^6.5.4" scrypt-js "^3.0.1" @@ -1912,16 +1912,16 @@ bech32 "^2.0.0" immutable "^4.0.0-rc.12" -"@ckb-lumos/helpers@0.21.0-next.2": - version "0.21.0-next.2" - resolved "https://registry.yarnpkg.com/@ckb-lumos/helpers/-/helpers-0.21.0-next.2.tgz#4a3ac9ff9e52f2063ce2c3670e2c72bb94acad45" - integrity sha512-pZkJwn4jV9uFICtS0Un0ftBnRvlC5BHAueeIBXwa7uclSFHxAejqr2lsM0KLavLBjK/kerOq182mejK9ejX/fQ== +"@ckb-lumos/helpers@0.21.0": + version "0.21.0" + resolved "https://registry.yarnpkg.com/@ckb-lumos/helpers/-/helpers-0.21.0.tgz#26dc2a18919aaa627cb6dd841402c2bdc494f7b0" + integrity sha512-kktkGj8QGM306n4gqRztZ5t92TRdjjnnafK1xfiHJWB38S3MFQcogIjtshEDVYM6PgIOaVSKYPMtnlGnSLW0cA== dependencies: - "@ckb-lumos/base" "0.21.0-next.2" - "@ckb-lumos/bi" "0.21.0-next.2" - "@ckb-lumos/codec" "0.21.0-next.2" - "@ckb-lumos/config-manager" "0.21.0-next.2" - "@ckb-lumos/toolkit" "0.21.0-next.2" + "@ckb-lumos/base" "0.21.0" + "@ckb-lumos/bi" "0.21.0" + "@ckb-lumos/codec" "0.21.0" + "@ckb-lumos/config-manager" "0.21.0" + "@ckb-lumos/toolkit" "0.21.0" bech32 "^2.0.0" immutable "^4.3.0" @@ -1951,13 +1951,13 @@ axios "0.27.2" tslib "2.3.1" -"@ckb-lumos/rpc@0.21.0-next.2": - version "0.21.0-next.2" - resolved "https://registry.yarnpkg.com/@ckb-lumos/rpc/-/rpc-0.21.0-next.2.tgz#a840f18535c419448e982807f49ede7012ac7daf" - integrity sha512-WWV1x+I2mS8/CFlstSC2POrQ64TIgr7H8YjdA0jMT7o8Pt7qo2KXO4bFwSuPMgtdo2DKPSxTUS9zFjiZsWmXRw== +"@ckb-lumos/rpc@0.21.0": + version "0.21.0" + resolved "https://registry.yarnpkg.com/@ckb-lumos/rpc/-/rpc-0.21.0.tgz#32e4cbf17492da391a48e7d214ec4d5ed508ee16" + integrity sha512-YuFb8XSHklo4bUPLR8DToiVAm/l72Yf7iyEOWmku5IEOoI0Jz7oua1A2REwJDQ1olykLi1L9AD9/PEJOasO28A== dependencies: - "@ckb-lumos/base" "0.21.0-next.2" - "@ckb-lumos/bi" "0.21.0-next.2" + "@ckb-lumos/base" "0.21.0" + "@ckb-lumos/bi" "0.21.0" abort-controller "^3.0.0" cross-fetch "^3.1.5" @@ -1966,12 +1966,12 @@ resolved "https://registry.yarnpkg.com/@ckb-lumos/toolkit/-/toolkit-0.20.0.tgz#8f71043324e50c8a3e94c65414325482d874cfca" integrity sha512-nLNXRPG20NqUdXwHAnKwr0T7nZyDrf4fGwIrsxo+7ffqWeg9wNEhZoqTBJLgxEpoe0I+WHRLwYLiwUbkkqR1SQ== -"@ckb-lumos/toolkit@0.21.0-next.2": - version "0.21.0-next.2" - resolved "https://registry.yarnpkg.com/@ckb-lumos/toolkit/-/toolkit-0.21.0-next.2.tgz#13a4b0c39cd8240dde24647ac50890f2f7ef1970" - integrity sha512-pTTXn6NwwNv3Ms3uj9ywzA4UtiI84IDBw5TEWCAlz4JVwh2dqlncci0O0YboaNA0gg1cVYCITQFLJBQvXQkDRw== +"@ckb-lumos/toolkit@0.21.0": + version "0.21.0" + resolved "https://registry.yarnpkg.com/@ckb-lumos/toolkit/-/toolkit-0.21.0.tgz#ecc5f946135bad73382c9c6bdd4343b60383da27" + integrity sha512-uqa4dQPevMqrDrdY3q8+UsX0qU/BTVFXs9kZ9Fk4iLtkkzSoJNfgN0FWF4ZDqPn5VVHpnR8uFM/XCm4t8y/How== dependencies: - "@ckb-lumos/bi" "0.21.0-next.2" + "@ckb-lumos/bi" "0.21.0" "@cnakazawa/watch@^1.0.3": version "1.0.4" From 0ca3b35581edf45322cccfa9bf1017536b8e5251 Mon Sep 17 00:00:00 2001 From: homura Date: Wed, 29 Nov 2023 21:47:17 +0800 Subject: [PATCH 2/6] refactor: fetch with keepalive to replace the http agent --- .../neuron-wallet/src/services/sdk-core.ts | 27 +----------- .../src/services/transaction-sender.ts | 4 +- packages/neuron-wallet/src/utils/ckb-rpc.ts | 42 +++++++------------ .../neuron-wallet/tests/utils/ckb-rpc.test.ts | 13 ++++-- 4 files changed, 29 insertions(+), 57 deletions(-) diff --git a/packages/neuron-wallet/src/services/sdk-core.ts b/packages/neuron-wallet/src/services/sdk-core.ts index a951c08ff6..36017e078c 100644 --- a/packages/neuron-wallet/src/services/sdk-core.ts +++ b/packages/neuron-wallet/src/services/sdk-core.ts @@ -1,32 +1,7 @@ import { CKBRPC } from '@ckb-lumos/rpc' -import https from 'https' -import http from 'http' - -let httpsAgent: https.Agent -let httpAgent: http.Agent - -const getHttpsAgent = () => { - if (!httpsAgent) { - httpsAgent = new https.Agent({ keepAlive: true }) - } - return httpsAgent -} - -const getHttpAgent = () => { - if (!httpAgent) { - httpAgent = new http.Agent({ keepAlive: true }) - } - return httpAgent -} export const generateCKB = (url: string): CKBRPC => { - const rpc = new CKBRPC(url) - if (url.startsWith('https')) { - rpc.setNode({ url, httpsAgent: getHttpsAgent() }) - } else { - rpc.setNode({ url, httpAgent: getHttpAgent() }) - } - return rpc + return new CKBRPC(url, { fetch: (request, init) => globalThis.fetch(request, { ...init, keepalive: true }) }) } export default { diff --git a/packages/neuron-wallet/src/services/transaction-sender.ts b/packages/neuron-wallet/src/services/transaction-sender.ts index 8955281951..208739a2d0 100644 --- a/packages/neuron-wallet/src/services/transaction-sender.ts +++ b/packages/neuron-wallet/src/services/transaction-sender.ts @@ -855,7 +855,9 @@ export default class TransactionSender { const rpc = generateRPC(currentNetwork.remote, currentNetwork.type) let tx = await rpc.getTransaction(depositOutPoint.txHash) - if (tx.txStatus.status !== 'committed') throw new Error('Transaction is not committed yet') + if (tx.txStatus.status !== 'committed' || !tx.txStatus.blockHash) { + throw new Error('Transaction is not committed yet') + } const depositBlockHash = tx.txStatus.blockHash const cellOutput = tx.transaction.outputs[+depositOutPoint.index] diff --git a/packages/neuron-wallet/src/utils/ckb-rpc.ts b/packages/neuron-wallet/src/utils/ckb-rpc.ts index 55fc0bb9f2..bfc73c8e94 100644 --- a/packages/neuron-wallet/src/utils/ckb-rpc.ts +++ b/packages/neuron-wallet/src/utils/ckb-rpc.ts @@ -2,7 +2,7 @@ import type { ParamsFormatter } from '@ckb-lumos/rpc' import type { Block } from '@ckb-lumos/base' import { HexString } from '@ckb-lumos/base' import { CKBRPC } from '@ckb-lumos/rpc' -import { Method } from '@ckb-lumos/rpc/lib/method' +import { Method as Method_ } from '@ckb-lumos/rpc/lib/method' import * as resultFormatter from '@ckb-lumos/rpc/lib/resultFormatter' import { formatter as paramsFormatter } from '@ckb-lumos/rpc/lib/paramsFormatter' import { Base } from '@ckb-lumos/rpc/lib/Base' @@ -11,11 +11,11 @@ import { PayloadInBatchException, IdNotMatchedInBatchException, } from '@ckb-lumos/rpc/lib/exceptions' -import https from 'https' -import http from 'http' import { request } from 'undici' import CommonUtils from './common' import { NetworkType } from '../models/network' +import { RPCConfig } from '@ckb-lumos/rpc/lib/types/common' +import { CKBComponents } from '@ckb-lumos/rpc/lib/types/api' export interface LightScriptFilter { script: CKBComponents.Script @@ -131,6 +131,12 @@ export class FullCKBRPC extends CKBRPC { } } +class Method extends Method_ { + constructor(node: CKBComponents.Node, options: CKBComponents.Method) { + super(node, options, rpcConfig) + } +} + export type FetchTransactionReturnType = { status: 'fetched' | 'fetching' | 'added' | 'not_found' txWithStatus?: CKBComponents.TransactionWithStatus @@ -192,14 +198,14 @@ export class LightRPC extends Base { this.getTransactionInLight = new Method(this.node, { name: 'getTransaction', ...this.rpcProperties['getTransaction'], - }).call + }).call as Base['getTransaction'] this.fetchTransaction = new Method(this.node, { name: 'fetchTransaction', ...lightRPCProperties['fetchTransaction'], }).call } - getTransaction = async (hash: string): Promise => { + getTransaction: Base['getTransaction'] = (async (hash: string) => { let tx = await this.getTransactionInLight(hash) if (!tx?.transaction) { tx = await CommonUtils.retry(3, 100, async () => { @@ -214,7 +220,7 @@ export class LightRPC extends Base { } } return tx - } + }) as Base['getTransaction'] getTipBlockNumber = async () => { const headerTip = await this.getTipHeader() @@ -359,21 +365,8 @@ export class LightRPC extends Base { } } -let httpsAgent: https.Agent -let httpAgent: http.Agent - -const getHttpsAgent = () => { - if (!httpsAgent) { - httpsAgent = new https.Agent({ keepAlive: true }) - } - return httpsAgent -} - -const getHttpAgent = () => { - if (!httpAgent) { - httpAgent = new http.Agent({ keepAlive: true }) - } - return httpAgent +const rpcConfig: Partial = { + fetch: (request, init) => globalThis.fetch(request, { ...init, keepalive: true }), } export const generateRPC = (url: string, type: NetworkType) => { @@ -381,12 +374,7 @@ export const generateRPC = (url: string, type: NetworkType) => { if (type === NetworkType.Light) { rpc = new LightRPC(url) } else { - rpc = new FullCKBRPC(url) - } - if (url?.startsWith('https')) { - rpc.setNode({ url, httpsAgent: getHttpsAgent() }) - } else { - rpc.setNode({ url, httpAgent: getHttpAgent() }) + rpc = new FullCKBRPC(url, rpcConfig) } return rpc } diff --git a/packages/neuron-wallet/tests/utils/ckb-rpc.test.ts b/packages/neuron-wallet/tests/utils/ckb-rpc.test.ts index ab04ab664a..8fc9e61e9d 100644 --- a/packages/neuron-wallet/tests/utils/ckb-rpc.test.ts +++ b/packages/neuron-wallet/tests/utils/ckb-rpc.test.ts @@ -12,9 +12,16 @@ describe('test ckb rpc file', () => { const result = generateRPC(BUNDLED_CKB_URL, NetworkType.Default) expect(result instanceof FullCKBRPC).toBeTruthy() }) - it('url is https', () => { - const result = generateRPC('https://localhost:8114', NetworkType.Default) - expect(result.node.httpsAgent).toBeDefined() + it('fetch should be keepalive', async () => { + const fetch = globalThis.fetch + globalThis.fetch = jest.fn() + + const rpc = generateRPC('https://localhost:8114', NetworkType.Default) + await rpc.getTipBlockNumber().catch(() => {}) + + expect((globalThis.fetch as unknown as jest.Mock).mock.calls[0][1]).toMatchObject({ keepalive: true }) + + globalThis.fetch = fetch }) }) }) From c0aef22486393afeb458a510199a4a848632fcf1 Mon Sep 17 00:00:00 2001 From: homura Date: Thu, 30 Nov 2023 17:25:32 +0800 Subject: [PATCH 3/6] refactor: rename variable for more clear --- packages/neuron-wallet/src/utils/ckb-rpc.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/neuron-wallet/src/utils/ckb-rpc.ts b/packages/neuron-wallet/src/utils/ckb-rpc.ts index bfc73c8e94..2d253a09e1 100644 --- a/packages/neuron-wallet/src/utils/ckb-rpc.ts +++ b/packages/neuron-wallet/src/utils/ckb-rpc.ts @@ -2,7 +2,7 @@ import type { ParamsFormatter } from '@ckb-lumos/rpc' import type { Block } from '@ckb-lumos/base' import { HexString } from '@ckb-lumos/base' import { CKBRPC } from '@ckb-lumos/rpc' -import { Method as Method_ } from '@ckb-lumos/rpc/lib/method' +import { Method as SdkRpcMethod } from '@ckb-lumos/rpc/lib/method' import * as resultFormatter from '@ckb-lumos/rpc/lib/resultFormatter' import { formatter as paramsFormatter } from '@ckb-lumos/rpc/lib/paramsFormatter' import { Base } from '@ckb-lumos/rpc/lib/Base' @@ -131,7 +131,7 @@ export class FullCKBRPC extends CKBRPC { } } -class Method extends Method_ { +class Method extends SdkRpcMethod { constructor(node: CKBComponents.Node, options: CKBComponents.Method) { super(node, options, rpcConfig) } From a22950eaaf30e2e005bc34d1ac4add658881166a Mon Sep 17 00:00:00 2001 From: homura Date: Tue, 12 Dec 2023 15:34:25 +0800 Subject: [PATCH 4/6] chore: upgrade lumos to 0.21.1 --- packages/neuron-ui/package.json | 4 +- packages/neuron-wallet/package.json | 18 ++-- yarn.lock | 142 ++++++++++++++-------------- 3 files changed, 82 insertions(+), 82 deletions(-) diff --git a/packages/neuron-ui/package.json b/packages/neuron-ui/package.json index b0a17fc778..1c1c8f12f6 100644 --- a/packages/neuron-ui/package.json +++ b/packages/neuron-ui/package.json @@ -50,8 +50,8 @@ "last 2 chrome versions" ], "dependencies": { - "@ckb-lumos/base": "0.21.0", - "@ckb-lumos/codec": "0.21.0", + "@ckb-lumos/base": "0.21.1", + "@ckb-lumos/codec": "0.21.1", "@nervosnetwork/ckb-sdk-core": "0.109.0", "@nervosnetwork/ckb-sdk-utils": "0.109.0", "canvg": "2.0.0", diff --git a/packages/neuron-wallet/package.json b/packages/neuron-wallet/package.json index 3848706714..b4f253a4ca 100644 --- a/packages/neuron-wallet/package.json +++ b/packages/neuron-wallet/package.json @@ -42,15 +42,15 @@ ] }, "dependencies": { - "@ckb-lumos/base": "0.21.0", - "@ckb-lumos/bi": "0.21.0", - "@ckb-lumos/ckb-indexer": "0.21.0", - "@ckb-lumos/codec": "0.21.0", - "@ckb-lumos/common-scripts": "0.21.0", - "@ckb-lumos/config-manager": "0.21.0", - "@ckb-lumos/hd": "0.21.0", - "@ckb-lumos/helpers": "0.21.0", - "@ckb-lumos/rpc": "0.21.0", + "@ckb-lumos/base": "0.21.1", + "@ckb-lumos/bi": "0.21.1", + "@ckb-lumos/ckb-indexer": "0.21.1", + "@ckb-lumos/codec": "0.21.1", + "@ckb-lumos/common-scripts": "0.21.1", + "@ckb-lumos/config-manager": "0.21.1", + "@ckb-lumos/hd": "0.21.1", + "@ckb-lumos/helpers": "0.21.1", + "@ckb-lumos/rpc": "0.21.1", "@iarna/toml": "2.2.5", "@ledgerhq/hw-transport-node-hid": "6.27.22", "@spore-sdk/core": "0.1.0-beta.9", diff --git a/yarn.lock b/yarn.lock index 4c02d095a3..a9c3e20a9b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1757,14 +1757,14 @@ js-xxhash "^1.0.4" lodash.isequal "^4.5.0" -"@ckb-lumos/base@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@ckb-lumos/base/-/base-0.21.0.tgz#fe0e69e24c01acfb3c9bbf8bcea623c6c9c35d58" - integrity sha512-1HcUJ6YXBUf+dgFRjg84fnFjAqjAksInoaAI+ku3LvjEvJ+Mh1bIVm04zHsrsPyPWvH5x6W59iOezorWFfa/9A== - dependencies: - "@ckb-lumos/bi" "0.21.0" - "@ckb-lumos/codec" "0.21.0" - "@ckb-lumos/toolkit" "0.21.0" +"@ckb-lumos/base@0.21.1": + version "0.21.1" + resolved "https://registry.yarnpkg.com/@ckb-lumos/base/-/base-0.21.1.tgz#1faf7909b5a68a124256d937cfb0fa03bb6b5457" + integrity sha512-7O+jBl7pqMsRbYTMNnbpamgaQzvaLZq+ftMtnKZ3A+Zbs6hZcGbz/6nfbRZnyJitPXQHRPT5KAQz6g+TiYqJGg== + dependencies: + "@ckb-lumos/bi" "0.21.1" + "@ckb-lumos/codec" "0.21.1" + "@ckb-lumos/toolkit" "0.21.1" "@types/blake2b" "^2.1.0" "@types/lodash.isequal" "^4.5.5" blake2b "^2.1.3" @@ -1778,10 +1778,10 @@ dependencies: jsbi "^4.1.0" -"@ckb-lumos/bi@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@ckb-lumos/bi/-/bi-0.21.0.tgz#06f486f3e872dd80095514584e6347b827e5a566" - integrity sha512-QrECcsW4j2ipIgFINms/Q5mP88zZnyo2Tf7NyBdqe3cxvCEOT2Y8FutMTA96J368vgJ4TJwTCtgPkjrVHZKj3g== +"@ckb-lumos/bi@0.21.1": + version "0.21.1" + resolved "https://registry.yarnpkg.com/@ckb-lumos/bi/-/bi-0.21.1.tgz#dfaa0968a9ffd990c1c4fcfc0711f20f09eb0485" + integrity sha512-6q8uesvu3DAM7GReei9H5seino4tnakTeg8uXtZBPDC6rboMohLCPQvEwhl1iHmsybXvBYVQt4Te1BPPZtuaRw== dependencies: jsbi "^4.1.0" @@ -1797,16 +1797,16 @@ cross-fetch "^3.1.5" events "^3.3.0" -"@ckb-lumos/ckb-indexer@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@ckb-lumos/ckb-indexer/-/ckb-indexer-0.21.0.tgz#524b611ad8e1b4db0be21d9925a8d43c417e3e80" - integrity sha512-3nqG0tL1TNZfKdoMgMtNnZCPX2fCc4ryJE3vrOcB5Ysy+jwg4AzYuNbUBkv7fMW7AKJ+bzlG694fUe1ZXD4Smg== +"@ckb-lumos/ckb-indexer@0.21.1": + version "0.21.1" + resolved "https://registry.yarnpkg.com/@ckb-lumos/ckb-indexer/-/ckb-indexer-0.21.1.tgz#a0e0ac3261c98181dc8c72e9e726030bb210779d" + integrity sha512-592pMVP3lwTXF7TmlOcayvGYKOhkYpjbLHUDo7By4yWbm7ZpdexaN5hn0X1sjJgMuee5prxGr9/fY684VTpJQw== dependencies: - "@ckb-lumos/base" "0.21.0" - "@ckb-lumos/bi" "0.21.0" - "@ckb-lumos/codec" "0.21.0" - "@ckb-lumos/rpc" "0.21.0" - "@ckb-lumos/toolkit" "0.21.0" + "@ckb-lumos/base" "0.21.1" + "@ckb-lumos/bi" "0.21.1" + "@ckb-lumos/codec" "0.21.1" + "@ckb-lumos/rpc" "0.21.1" + "@ckb-lumos/toolkit" "0.21.1" cross-fetch "^3.1.5" events "^3.3.0" @@ -1817,12 +1817,12 @@ dependencies: "@ckb-lumos/bi" "0.20.0" -"@ckb-lumos/codec@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@ckb-lumos/codec/-/codec-0.21.0.tgz#c9b6516a71ca07f3bcb562037568c385bbfa2946" - integrity sha512-1u0Esd3OzSoWhgay2LJF0+CEVvgUNihuaxEnS3yvBjsVZBfUZcPAE+/NAIrpEtK1RFkuu3YBlNnW3B5ZGI80sg== +"@ckb-lumos/codec@0.21.1": + version "0.21.1" + resolved "https://registry.yarnpkg.com/@ckb-lumos/codec/-/codec-0.21.1.tgz#160f21efa0cded6ea461eb6476f9af6010b682e0" + integrity sha512-z6IUUxVZrx663iC7VM9CmaQZL8jsdM3ybgz0UCS24JgBXTNec+Uz0/Zrl7yeH6fBpVls44C2wObcHKigKaNVAA== dependencies: - "@ckb-lumos/bi" "0.21.0" + "@ckb-lumos/bi" "0.21.1" "@ckb-lumos/common-scripts@0.20.0": version "0.20.0" @@ -1838,18 +1838,18 @@ "@ckb-lumos/toolkit" "0.20.0" immutable "^4.0.0-rc.12" -"@ckb-lumos/common-scripts@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@ckb-lumos/common-scripts/-/common-scripts-0.21.0.tgz#535187c26bd919d4e7e9fdbeb9754ee574e0fe17" - integrity sha512-yKWra6QwKV3/n/XAInf9XwaA2Q9HNr8QZpKC3/vK7yZH0QATNvZEuF1+NjLKl8/6E5uo37wZI+IfNgFlv3vANg== - dependencies: - "@ckb-lumos/base" "0.21.0" - "@ckb-lumos/bi" "0.21.0" - "@ckb-lumos/codec" "0.21.0" - "@ckb-lumos/config-manager" "0.21.0" - "@ckb-lumos/helpers" "0.21.0" - "@ckb-lumos/rpc" "0.21.0" - "@ckb-lumos/toolkit" "0.21.0" +"@ckb-lumos/common-scripts@0.21.1": + version "0.21.1" + resolved "https://registry.yarnpkg.com/@ckb-lumos/common-scripts/-/common-scripts-0.21.1.tgz#64776b5ce55d8c66898a3ab592c7f77fe13d865e" + integrity sha512-EfZQ9wdxPmEsxVVwtBjhpZVKbYCm1FJkMt59ABsIO1Ub7yi0qap7AQl0MMbuLwWIGKwS2w0U3wx/oJPm7z1RXg== + dependencies: + "@ckb-lumos/base" "0.21.1" + "@ckb-lumos/bi" "0.21.1" + "@ckb-lumos/codec" "0.21.1" + "@ckb-lumos/config-manager" "0.21.1" + "@ckb-lumos/helpers" "0.21.1" + "@ckb-lumos/rpc" "0.21.1" + "@ckb-lumos/toolkit" "0.21.1" immutable "^4.3.0" "@ckb-lumos/config-manager@0.20.0", "@ckb-lumos/config-manager@^0.20.0": @@ -1863,14 +1863,14 @@ "@types/deep-freeze-strict" "^1.1.0" deep-freeze-strict "^1.1.1" -"@ckb-lumos/config-manager@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@ckb-lumos/config-manager/-/config-manager-0.21.0.tgz#e7dc0f7991a0a337dac50094f54b094a28fb4d07" - integrity sha512-SQa8fbP9Yuka3IqFH5wz0iHMZ9d7gEwt+NxSVuuOJ3YTV+TcSlL3+U/1ndgUiMYVNX55aEACoI9djwei/+VM2Q== +"@ckb-lumos/config-manager@0.21.1": + version "0.21.1" + resolved "https://registry.yarnpkg.com/@ckb-lumos/config-manager/-/config-manager-0.21.1.tgz#857050ebf2ca38096d8fae26b6a8927164798ca3" + integrity sha512-BmrNqYyaksdCKHWagyC8+R8GUxhIO+sOM5S925jlkpjju2sUbH0Id2/zmdb7I9KxdKnbx3WsR+hqy7/bYqw1lA== dependencies: - "@ckb-lumos/base" "0.21.0" - "@ckb-lumos/bi" "0.21.0" - "@ckb-lumos/codec" "0.21.0" + "@ckb-lumos/base" "0.21.1" + "@ckb-lumos/bi" "0.21.1" + "@ckb-lumos/codec" "0.21.1" "@types/deep-freeze-strict" "^1.1.0" deep-freeze-strict "^1.1.1" @@ -1887,13 +1887,13 @@ sha3 "^2.1.3" uuid "^8.3.0" -"@ckb-lumos/hd@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@ckb-lumos/hd/-/hd-0.21.0.tgz#bab3b051460ce5ebb4b342bdcc812d4bd6e13cf1" - integrity sha512-Z6i/lRcKPIlMH64Mmr4SG+y9jUmW5IguSw1MIxmtwSCogra3ibxwnkCpVaUNObIZzAFS/8G2z8KthOrRg13esw== +"@ckb-lumos/hd@0.21.1": + version "0.21.1" + resolved "https://registry.yarnpkg.com/@ckb-lumos/hd/-/hd-0.21.1.tgz#406026ac2b570f72b4407149cb941d09bb8a0ab6" + integrity sha512-BnfpJf/sx/dJzL5BrOxPeKbKgv2x74KWd0xwjw1/gBQ2IMhu0S1mLwFsOT3Zu2nuhpQYvZGvr0cd3vD/SoMDow== dependencies: - "@ckb-lumos/base" "0.21.0" - "@ckb-lumos/bi" "0.21.0" + "@ckb-lumos/base" "0.21.1" + "@ckb-lumos/bi" "0.21.1" bn.js "^5.1.3" elliptic "^6.5.4" scrypt-js "^3.0.1" @@ -1912,16 +1912,16 @@ bech32 "^2.0.0" immutable "^4.0.0-rc.12" -"@ckb-lumos/helpers@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@ckb-lumos/helpers/-/helpers-0.21.0.tgz#26dc2a18919aaa627cb6dd841402c2bdc494f7b0" - integrity sha512-kktkGj8QGM306n4gqRztZ5t92TRdjjnnafK1xfiHJWB38S3MFQcogIjtshEDVYM6PgIOaVSKYPMtnlGnSLW0cA== +"@ckb-lumos/helpers@0.21.1": + version "0.21.1" + resolved "https://registry.yarnpkg.com/@ckb-lumos/helpers/-/helpers-0.21.1.tgz#fffd455071f51556b2cd2539a255b3759893da08" + integrity sha512-jFN6DtWzwVNEY4kmnzczRaQqtyRJQwzAEuHRUQ0LqTiIGM+SlfgjH/l/InAG4cIhDOurMudnUJ4ex68wmbkhVw== dependencies: - "@ckb-lumos/base" "0.21.0" - "@ckb-lumos/bi" "0.21.0" - "@ckb-lumos/codec" "0.21.0" - "@ckb-lumos/config-manager" "0.21.0" - "@ckb-lumos/toolkit" "0.21.0" + "@ckb-lumos/base" "0.21.1" + "@ckb-lumos/bi" "0.21.1" + "@ckb-lumos/codec" "0.21.1" + "@ckb-lumos/config-manager" "0.21.1" + "@ckb-lumos/toolkit" "0.21.1" bech32 "^2.0.0" immutable "^4.3.0" @@ -1951,13 +1951,13 @@ axios "0.27.2" tslib "2.3.1" -"@ckb-lumos/rpc@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@ckb-lumos/rpc/-/rpc-0.21.0.tgz#32e4cbf17492da391a48e7d214ec4d5ed508ee16" - integrity sha512-YuFb8XSHklo4bUPLR8DToiVAm/l72Yf7iyEOWmku5IEOoI0Jz7oua1A2REwJDQ1olykLi1L9AD9/PEJOasO28A== +"@ckb-lumos/rpc@0.21.1": + version "0.21.1" + resolved "https://registry.yarnpkg.com/@ckb-lumos/rpc/-/rpc-0.21.1.tgz#f6a6b3ed6d76adfb84c148e4b4acadb7fbaa7d7a" + integrity sha512-gZWXYCyQ98s84Pb+buOiYL3HOIxQPLHQdCyo96GFerNw9lB1XsbaGWzfHPYpZvOQqYtnJ1GUfTkQkADrQ7hmew== dependencies: - "@ckb-lumos/base" "0.21.0" - "@ckb-lumos/bi" "0.21.0" + "@ckb-lumos/base" "0.21.1" + "@ckb-lumos/bi" "0.21.1" abort-controller "^3.0.0" cross-fetch "^3.1.5" @@ -1966,12 +1966,12 @@ resolved "https://registry.yarnpkg.com/@ckb-lumos/toolkit/-/toolkit-0.20.0.tgz#8f71043324e50c8a3e94c65414325482d874cfca" integrity sha512-nLNXRPG20NqUdXwHAnKwr0T7nZyDrf4fGwIrsxo+7ffqWeg9wNEhZoqTBJLgxEpoe0I+WHRLwYLiwUbkkqR1SQ== -"@ckb-lumos/toolkit@0.21.0": - version "0.21.0" - resolved "https://registry.yarnpkg.com/@ckb-lumos/toolkit/-/toolkit-0.21.0.tgz#ecc5f946135bad73382c9c6bdd4343b60383da27" - integrity sha512-uqa4dQPevMqrDrdY3q8+UsX0qU/BTVFXs9kZ9Fk4iLtkkzSoJNfgN0FWF4ZDqPn5VVHpnR8uFM/XCm4t8y/How== +"@ckb-lumos/toolkit@0.21.1": + version "0.21.1" + resolved "https://registry.yarnpkg.com/@ckb-lumos/toolkit/-/toolkit-0.21.1.tgz#bcf4bf05615375087e3dd02fb087b797a8c67f37" + integrity sha512-awrFos7uQXEVGbqKSv/8Fc8B8XAfxdYoyYak4zFyAAmxxA0NiTTvk9V8TsOA7zVXpxct4Jal22+qUe+4Jg8T/g== dependencies: - "@ckb-lumos/bi" "0.21.0" + "@ckb-lumos/bi" "0.21.1" "@cnakazawa/watch@^1.0.3": version "1.0.4" From 07f6cf8437fe3d74ea7bcb3c35672dfcd10e223c Mon Sep 17 00:00:00 2001 From: homura Date: Tue, 12 Dec 2023 15:41:30 +0800 Subject: [PATCH 5/6] refactor: remove unnecessary http agent --- packages/neuron-wallet/src/types/ckbComponents.d.ts | 5 ----- packages/neuron-wallet/src/utils/ckb-rpc.ts | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/neuron-wallet/src/types/ckbComponents.d.ts b/packages/neuron-wallet/src/types/ckbComponents.d.ts index 56e2ff19b7..cd387b9df7 100644 --- a/packages/neuron-wallet/src/types/ckbComponents.d.ts +++ b/packages/neuron-wallet/src/types/ckbComponents.d.ts @@ -1,6 +1,3 @@ -import type { Agent as HttpsAgent } from 'node:https' -import type { Agent as HttpAgent } from 'node:http' - declare global { declare namespace CKBComponents { type DAO = string @@ -44,8 +41,6 @@ declare global { type Since = string interface Node { url: string - httpAgent?: HttpAgent - httpsAgent?: HttpsAgent } interface Method { name: string diff --git a/packages/neuron-wallet/src/utils/ckb-rpc.ts b/packages/neuron-wallet/src/utils/ckb-rpc.ts index 220ae1ec9d..0d4c69b4d2 100644 --- a/packages/neuron-wallet/src/utils/ckb-rpc.ts +++ b/packages/neuron-wallet/src/utils/ckb-rpc.ts @@ -15,8 +15,8 @@ import { import { request } from 'undici' import CommonUtils from './common' import { NetworkType } from '../models/network' -import { RPCConfig } from '@ckb-lumos/rpc/lib/types/common' -import { CKBComponents } from '@ckb-lumos/rpc/lib/types/api' +import type { RPCConfig } from '@ckb-lumos/rpc/lib/types/common' +import type { CKBComponents } from '@ckb-lumos/rpc/lib/types/api' export interface LightScriptFilter { script: Script From 2a6c07c4a944c1aac4add5a84f873f78b286a0a1 Mon Sep 17 00:00:00 2001 From: homura Date: Tue, 12 Dec 2023 23:31:32 +0800 Subject: [PATCH 6/6] refactor: remove unnecessary global declaration --- .../src/types/ckbComponents.d.ts | 537 +++++++++--------- 1 file changed, 267 insertions(+), 270 deletions(-) diff --git a/packages/neuron-wallet/src/types/ckbComponents.d.ts b/packages/neuron-wallet/src/types/ckbComponents.d.ts index cd387b9df7..0bd03bb762 100644 --- a/packages/neuron-wallet/src/types/ckbComponents.d.ts +++ b/packages/neuron-wallet/src/types/ckbComponents.d.ts @@ -1,275 +1,272 @@ -declare global { - declare namespace CKBComponents { - type DAO = string - type Hash = string - type Number = string - type Hash256 = string - type UInt32 = string - type UInt64 = string - type U256 = string - type Index = string - type Version = string - type Count = string - type Difficulty = string - type BlockNumber = string - type EpochInHeader = string - type Capacity = string - type ProposalShortId = string - type Timestamp = string - type Nonce = string - type Cycles = string - type Size = string - type OutputsValidator = 'default' | 'passthrough' | undefined - type RationalU256 = Record<'denom' | 'numer', string> - type ProposalWindow = Record<'closest' | 'farthest', BlockNumber> - type EpochNumberWithFraction = string - type EpochNumber = string - enum TransactionStatus { - Pending = 'pending', - Proposed = 'proposed', - Committed = 'committed', - } - type ScriptHashType = api.HashType - type DepType = 'code' | 'depGroup' - type JsonBytes = string - /** - * @typedef Bytes, keep consistent with CKB - * @description Bytes will be serialized to string - * @see https://github.com/nervosnetwork/ckb/blob/develop/util/jsonrpc-types/src/blockchain.rs#L19 - */ - type Bytes = string - type Since = string - interface Node { - url: string - } - interface Method { - name: string - method: string - paramsFormatters: function[] - resultFormatters?: function - } - /** - * RPC Units - */ - type Witness = Bytes - type Script = api.Script - type CellInput = api.Input - type CellOutput = api.Output - type Cell = CellOutput - type OutPoint = api.OutPoint - type CellDep = api.CellDep - type RawTransaction = api.RawTransaction & { - witnesses: Witness[] - } - type Transaction = Required - type TransactionWithStatus = api.TransactionWithStatus - type BlockHeader = api.Header - type Block = api.Block - type UncleBlock = api.UncleBlock - type LiveCell = api.LiveCell - type AlertMessage = api.AlertMessage - type BlockchainInfo = api.ChainInfo - type LocalNodeInfo = api.LocalNode - type RemoteNodeInfo = api.RemoteNode - type TxPoolInfo = api.TxPoolInfo - type Epoch = api.Epoch - type RunDryResult = api.DryRunResult - type BannedAddress = api.BannedAddr - type WitnessArgs = api.WitnessArgs - type BlockEconomicState = api.BlockEconomicState - type SyncState = api.SyncState - type TransactionProof = api.TransactionProof - type TxVerbosity = api.TxVerbosity - type TxPoolVerbosity = api.TxPoolVerbosity - type RawTxPool = api.RawTxPool - type Consensus = api.Consensus - type HardForks = api.HardForks - type HardForkFeature = api.HardforkFeature - type SoftForkStatus = api.SoftForkStatus - type SoftFork = api.SoftFork - type Buried = api.Buried - type Rfc0043 = api.Rfc0043 - type Ratio = api.Ratio - type Deployment = api.Deployment - type QueryOptions = api.QueryOptions - interface TransactionPoint { - blockNumber: BlockNumber - index: Index - txHash: Hash256 - } - interface TransactionByLockHash { - consumedBy: undefined | TransactionPoint - createdBy: TransactionPoint - } - type TransactionsByLockHash = TransactionByLockHash[] - interface FeeRate { - feeRate: string - } - interface CellIncludingOutPoint { - blockHash: Hash256 +declare namespace CKBComponents { + type DAO = string + type Hash = string + type Number = string + type Hash256 = string + type UInt32 = string + type UInt64 = string + type U256 = string + type Index = string + type Version = string + type Count = string + type Difficulty = string + type BlockNumber = string + type EpochInHeader = string + type Capacity = string + type ProposalShortId = string + type Timestamp = string + type Nonce = string + type Cycles = string + type Size = string + type OutputsValidator = 'default' | 'passthrough' | undefined + type RationalU256 = Record<'denom' | 'numer', string> + type ProposalWindow = Record<'closest' | 'farthest', BlockNumber> + type EpochNumberWithFraction = string + type EpochNumber = string + enum TransactionStatus { + Pending = 'pending', + Proposed = 'proposed', + Committed = 'committed', + } + type ScriptHashType = api.HashType + type DepType = 'code' | 'depGroup' + type JsonBytes = string + /** + * @typedef Bytes, keep consistent with CKB + * @description Bytes will be serialized to string + * @see https://github.com/nervosnetwork/ckb/blob/develop/util/jsonrpc-types/src/blockchain.rs#L19 + */ + type Bytes = string + type Since = string + interface Node { + url: string + } + interface Method { + name: string + method: string + paramsFormatters: function[] + resultFormatters?: function + } + /** + * RPC Units + */ + type Witness = Bytes + type Script = api.Script + type CellInput = api.Input + type CellOutput = api.Output + type Cell = CellOutput + type OutPoint = api.OutPoint + type CellDep = api.CellDep + type RawTransaction = api.RawTransaction & { + witnesses: Witness[] + } + type Transaction = Required + type TransactionWithStatus = api.TransactionWithStatus + type BlockHeader = api.Header + type Block = api.Block + type UncleBlock = api.UncleBlock + type LiveCell = api.LiveCell + type AlertMessage = api.AlertMessage + type BlockchainInfo = api.ChainInfo + type LocalNodeInfo = api.LocalNode + type RemoteNodeInfo = api.RemoteNode + type TxPoolInfo = api.TxPoolInfo + type Epoch = api.Epoch + type RunDryResult = api.DryRunResult + type BannedAddress = api.BannedAddr + type WitnessArgs = api.WitnessArgs + type BlockEconomicState = api.BlockEconomicState + type SyncState = api.SyncState + type TransactionProof = api.TransactionProof + type TxVerbosity = api.TxVerbosity + type TxPoolVerbosity = api.TxPoolVerbosity + type RawTxPool = api.RawTxPool + type Consensus = api.Consensus + type HardForks = api.HardForks + type HardForkFeature = api.HardforkFeature + type SoftForkStatus = api.SoftForkStatus + type SoftFork = api.SoftFork + type Buried = api.Buried + type Rfc0043 = api.Rfc0043 + type Ratio = api.Ratio + type Deployment = api.Deployment + type QueryOptions = api.QueryOptions + interface TransactionPoint { + blockNumber: BlockNumber + index: Index + txHash: Hash256 + } + interface TransactionByLockHash { + consumedBy: undefined | TransactionPoint + createdBy: TransactionPoint + } + type TransactionsByLockHash = TransactionByLockHash[] + interface FeeRate { + feeRate: string + } + interface CellIncludingOutPoint { + blockHash: Hash256 + capacity: Capacity + lock: Script + outPoint: OutPoint + cellbase: boolean + outputDataLen: string + } + type TransactionTrace = { + action: string + info: string + time: Timestamp + }[] + enum CellStatus { + Live = 'live', + Unknown = 'unknown', + } + interface LiveCellByLockHash { + cellOutput: CellOutput + createdBy: TransactionPoint + cellbase: boolean + outputDataLen: string + } + type LiveCellsByLockHash = LiveCellByLockHash[] + interface PeersState { + lastUpdated: string + blocksInFlight: string + peer: string + } + interface LockHashIndexState { + blockHash: Hash256 + blockNumber: BlockNumber + lockHash: Hash256 + } + type LockHashIndexStates = LockHashIndexState[] + type BannedAddresses = BannedAddress[] + interface CellbaseOutputCapacityDetails { + primary: string + proposalReward: string + secondary: string + total: string + txFee: string + } + interface RawTransactionToSign extends Omit { + witnesses: (WitnessArgs | Witness)[] + } + interface CapacityByLockHash { + blockNumber: BlockNumber + capacity: Capacity + cellsCount: string + } + type TxPoolIds = Record<'pending' | 'proposed', Array> + interface Tip { + blockNumber: BlockNumber + blockHash: Hash256 + } + type ScriptType = 'type' | 'lock' + type Order = 'asc' | 'desc' + type IOType = 'input' | 'output' | 'both' + type ScriptSearchMode = 'prefix' | 'exact' + interface IndexerCell { + blockNumber: BlockNumber + outPoint: OutPoint + output: { capacity: Capacity lock: Script - outPoint: OutPoint - cellbase: boolean - outputDataLen: string - } - type TransactionTrace = { - action: string - info: string - time: Timestamp - }[] - enum CellStatus { - Live = 'live', - Unknown = 'unknown', - } - interface LiveCellByLockHash { - cellOutput: CellOutput - createdBy: TransactionPoint - cellbase: boolean - outputDataLen: string - } - type LiveCellsByLockHash = LiveCellByLockHash[] - interface PeersState { - lastUpdated: string - blocksInFlight: string - peer: string - } - interface LockHashIndexState { - blockHash: Hash256 - blockNumber: BlockNumber - lockHash: Hash256 - } - type LockHashIndexStates = LockHashIndexState[] - type BannedAddresses = BannedAddress[] - interface CellbaseOutputCapacityDetails { - primary: string - proposalReward: string - secondary: string - total: string - txFee: string - } - interface RawTransactionToSign extends Omit { - witnesses: (WitnessArgs | Witness)[] - } - interface CapacityByLockHash { - blockNumber: BlockNumber - capacity: Capacity - cellsCount: string - } - type TxPoolIds = Record<'pending' | 'proposed', Array> - interface Tip { - blockNumber: BlockNumber - blockHash: Hash256 - } - type ScriptType = 'type' | 'lock' - type Order = 'asc' | 'desc' - type IOType = 'input' | 'output' | 'both' - type ScriptSearchMode = 'prefix' | 'exact' - interface IndexerCell { - blockNumber: BlockNumber - outPoint: OutPoint - output: { - capacity: Capacity - lock: Script - type?: Script - } - outputData: string - txIndex: string - } - interface IndexerCellWithoutData extends Omit { - outputData: null - } - interface GetCellsResult { - lastCursor: string - objects: WithData extends true ? IndexerCell[] : IndexerCellWithoutData[] + type?: Script } - type IndexerTransaction = Grouped extends true - ? GroupedIndexerTransaction - : UngroupedIndexerTransaction - type UngroupedIndexerTransaction = { - txHash: Hash256 - blockNumber: BlockNumber - ioIndex: number - ioType: IOType - txIndex: number - } - type GroupedIndexerTransaction = { - txHash: Hash256 - blockNumber: BlockNumber - txIndex: number - cells: Array<[IOType, number]> - } - interface GetTransactionsResult { - lastCursor: Hash256 - objects: IndexerTransaction[] - } - interface CKBIndexerQueryOptions extends QueryOptions { - outputDataLenRange?: HexadecimalRange - outputCapacityRange?: HexadecimalRange - scriptLenRange?: HexadecimalRange - bufferSize?: number - withData?: boolean - groupByTransaction?: boolean - } - type HexadecimalRange = [string, string] - interface SearchFilter { - script?: Script - scriptLenRange?: HexadecimalRange - outputDataLenRange?: HexadecimalRange - outputCapacityRange?: HexadecimalRange - blockRange?: HexadecimalRange - } - interface SearchKey { - script: Script - scriptType: ScriptType - filter?: SearchFilter - scriptSearchMode?: ScriptSearchMode - } - interface GetLiveCellsResult { - lastCursor: string - objects: WithData extends true ? IndexerCell[] : IndexerCellWithoutData[] - } - interface GetCellsSearchKey extends SearchKey { - withData?: WithData - } - interface GetTransactionsSearchKey extends SearchKey { - groupByTransaction?: Group - } - interface CellsCapacity { - capacity: Capacity - blockHash: Hash256 - blockNumber: BlockNumber - } - interface BlockFilter { - data: api.HexString - hash: api.Hash - } - interface TransactionAndWitnessProof { - blockHash: Hash256 - transactionsProof: api.MerkleProof - witnessesProof: api.MerkleProof - } - type TransactionView = api.Transaction & { - hash: api.Hash - } - interface BlockView { - header: BlockHeader - uncles: UncleBlock[] - transactions: TransactionView[] - proposals: ProposalShortId[] - } - type SerializedBlock = api.HexString - interface FeeRateStatistics { - mean: UInt64 - median: UInt64 - } - interface EstimateCycles { - cycles: UInt64 - } - type DeploymentPos = api.DeploymentPos - type DeploymentState = api.DeploymentState - type DeploymentInfo = api.DeploymentInfo - type DeploymentsInfo = api.DeploymentsInfo + outputData: string + txIndex: string + } + interface IndexerCellWithoutData extends Omit { + outputData: null + } + interface GetCellsResult { + lastCursor: string + objects: WithData extends true ? IndexerCell[] : IndexerCellWithoutData[] + } + type IndexerTransaction = Grouped extends true + ? GroupedIndexerTransaction + : UngroupedIndexerTransaction + type UngroupedIndexerTransaction = { + txHash: Hash256 + blockNumber: BlockNumber + ioIndex: number + ioType: IOType + txIndex: number + } + type GroupedIndexerTransaction = { + txHash: Hash256 + blockNumber: BlockNumber + txIndex: number + cells: Array<[IOType, number]> + } + interface GetTransactionsResult { + lastCursor: Hash256 + objects: IndexerTransaction[] + } + interface CKBIndexerQueryOptions extends QueryOptions { + outputDataLenRange?: HexadecimalRange + outputCapacityRange?: HexadecimalRange + scriptLenRange?: HexadecimalRange + bufferSize?: number + withData?: boolean + groupByTransaction?: boolean + } + type HexadecimalRange = [string, string] + interface SearchFilter { + script?: Script + scriptLenRange?: HexadecimalRange + outputDataLenRange?: HexadecimalRange + outputCapacityRange?: HexadecimalRange + blockRange?: HexadecimalRange + } + interface SearchKey { + script: Script + scriptType: ScriptType + filter?: SearchFilter + scriptSearchMode?: ScriptSearchMode + } + interface GetLiveCellsResult { + lastCursor: string + objects: WithData extends true ? IndexerCell[] : IndexerCellWithoutData[] + } + interface GetCellsSearchKey extends SearchKey { + withData?: WithData + } + interface GetTransactionsSearchKey extends SearchKey { + groupByTransaction?: Group + } + interface CellsCapacity { + capacity: Capacity + blockHash: Hash256 + blockNumber: BlockNumber + } + interface BlockFilter { + data: api.HexString + hash: api.Hash + } + interface TransactionAndWitnessProof { + blockHash: Hash256 + transactionsProof: api.MerkleProof + witnessesProof: api.MerkleProof + } + type TransactionView = api.Transaction & { + hash: api.Hash + } + interface BlockView { + header: BlockHeader + uncles: UncleBlock[] + transactions: TransactionView[] + proposals: ProposalShortId[] + } + type SerializedBlock = api.HexString + interface FeeRateStatistics { + mean: UInt64 + median: UInt64 + } + interface EstimateCycles { + cycles: UInt64 } - //# sourceMappingURL=api.d.ts.map + type DeploymentPos = api.DeploymentPos + type DeploymentState = api.DeploymentState + type DeploymentInfo = api.DeploymentInfo + type DeploymentsInfo = api.DeploymentsInfo }