@ckb-ccc/core 0.0.0-canary-20250214032000
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +375 -0
- package/README.md +41 -0
- package/dist/address/address.advanced.d.ts +65 -0
- package/dist/address/address.advanced.d.ts.map +1 -0
- package/dist/address/address.advanced.js +147 -0
- package/dist/address/advanced.d.ts +2 -0
- package/dist/address/advanced.d.ts.map +1 -0
- package/dist/address/advanced.js +1 -0
- package/dist/address/index.d.ts +58 -0
- package/dist/address/index.d.ts.map +1 -0
- package/dist/address/index.js +78 -0
- package/dist/advanced.d.ts +3 -0
- package/dist/advanced.d.ts.map +1 -0
- package/dist/advanced.js +2 -0
- package/dist/advancedBarrel.d.ts +7 -0
- package/dist/advancedBarrel.d.ts.map +1 -0
- package/dist/advancedBarrel.js +6 -0
- package/dist/barrel.d.ts +14 -0
- package/dist/barrel.d.ts.map +1 -0
- package/dist/barrel.js +13 -0
- package/dist/bytes/advanced.d.ts +6 -0
- package/dist/bytes/advanced.d.ts.map +1 -0
- package/dist/bytes/advanced.js +1 -0
- package/dist/bytes/index.d.ts +108 -0
- package/dist/bytes/index.d.ts.map +1 -0
- package/dist/bytes/index.js +151 -0
- package/dist/ckb/advanced.d.ts +3 -0
- package/dist/ckb/advanced.d.ts.map +1 -0
- package/dist/ckb/advanced.js +2 -0
- package/dist/ckb/index.d.ts +4 -0
- package/dist/ckb/index.d.ts.map +1 -0
- package/dist/ckb/index.js +3 -0
- package/dist/ckb/script.advanced.d.ts +5 -0
- package/dist/ckb/script.advanced.d.ts.map +1 -0
- package/dist/ckb/script.advanced.js +13 -0
- package/dist/ckb/script.d.ts +143 -0
- package/dist/ckb/script.d.ts.map +1 -0
- package/dist/ckb/script.js +167 -0
- package/dist/ckb/transaction.advanced.d.ts +5 -0
- package/dist/ckb/transaction.advanced.d.ts.map +1 -0
- package/dist/ckb/transaction.advanced.js +9 -0
- package/dist/ckb/transaction.d.ts +893 -0
- package/dist/ckb/transaction.d.ts.map +1 -0
- package/dist/ckb/transaction.js +1299 -0
- package/dist/ckb/transactionLumos.d.ts +30 -0
- package/dist/ckb/transactionLumos.d.ts.map +1 -0
- package/dist/ckb/transactionLumos.js +1 -0
- package/dist/client/advanced.d.ts +6 -0
- package/dist/client/advanced.d.ts.map +1 -0
- package/dist/client/advanced.js +5 -0
- package/dist/client/cache/advanced.d.ts +2 -0
- package/dist/client/cache/advanced.d.ts.map +1 -0
- package/dist/client/cache/advanced.js +1 -0
- package/dist/client/cache/cache.d.ts +91 -0
- package/dist/client/cache/cache.d.ts.map +1 -0
- package/dist/client/cache/cache.js +128 -0
- package/dist/client/cache/index.d.ts +3 -0
- package/dist/client/cache/index.d.ts.map +1 -0
- package/dist/client/cache/index.js +2 -0
- package/dist/client/cache/memory.advanced.d.ts +22 -0
- package/dist/client/cache/memory.advanced.d.ts.map +1 -0
- package/dist/client/cache/memory.advanced.js +118 -0
- package/dist/client/cache/memory.d.ts +44 -0
- package/dist/client/cache/memory.d.ts.map +1 -0
- package/dist/client/cache/memory.js +137 -0
- package/dist/client/client.d.ts +98 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +323 -0
- package/dist/client/clientPublicMainnet.advanced.d.ts +3 -0
- package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -0
- package/dist/client/clientPublicMainnet.advanced.js +326 -0
- package/dist/client/clientPublicMainnet.d.ts +16 -0
- package/dist/client/clientPublicMainnet.d.ts.map +1 -0
- package/dist/client/clientPublicMainnet.js +40 -0
- package/dist/client/clientPublicTestnet.advanced.d.ts +3 -0
- package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -0
- package/dist/client/clientPublicTestnet.advanced.js +336 -0
- package/dist/client/clientPublicTestnet.d.ts +16 -0
- package/dist/client/clientPublicTestnet.d.ts.map +1 -0
- package/dist/client/clientPublicTestnet.js +40 -0
- package/dist/client/clientTypes.advanced.d.ts +26 -0
- package/dist/client/clientTypes.advanced.d.ts.map +1 -0
- package/dist/client/clientTypes.advanced.js +7 -0
- package/dist/client/clientTypes.d.ts +360 -0
- package/dist/client/clientTypes.d.ts.map +1 -0
- package/dist/client/clientTypes.js +259 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +6 -0
- package/dist/client/jsonRpc/advanced.d.ts +3 -0
- package/dist/client/jsonRpc/advanced.d.ts.map +1 -0
- package/dist/client/jsonRpc/advanced.js +2 -0
- package/dist/client/jsonRpc/client.d.ts +160 -0
- package/dist/client/jsonRpc/client.d.ts.map +1 -0
- package/dist/client/jsonRpc/client.js +220 -0
- package/dist/client/jsonRpc/index.d.ts +2 -0
- package/dist/client/jsonRpc/index.d.ts.map +1 -0
- package/dist/client/jsonRpc/index.js +1 -0
- package/dist/client/jsonRpc/transformers.d.ts +51 -0
- package/dist/client/jsonRpc/transformers.d.ts.map +1 -0
- package/dist/client/jsonRpc/transformers.js +246 -0
- package/dist/client/jsonRpc/types.d.ts +101 -0
- package/dist/client/jsonRpc/types.d.ts.map +1 -0
- package/dist/client/jsonRpc/types.js +1 -0
- package/dist/fixedPoint/index.d.ts +55 -0
- package/dist/fixedPoint/index.d.ts.map +1 -0
- package/dist/fixedPoint/index.js +68 -0
- package/dist/hasher/advanced.d.ts +2 -0
- package/dist/hasher/advanced.d.ts.map +1 -0
- package/dist/hasher/advanced.js +1 -0
- package/dist/hasher/hasher.d.ts +35 -0
- package/dist/hasher/hasher.d.ts.map +1 -0
- package/dist/hasher/hasher.js +1 -0
- package/dist/hasher/hasherCkb.d.ts +73 -0
- package/dist/hasher/hasherCkb.d.ts.map +1 -0
- package/dist/hasher/hasherCkb.js +88 -0
- package/dist/hasher/hasherKeecak256.d.ts +41 -0
- package/dist/hasher/hasherKeecak256.d.ts.map +1 -0
- package/dist/hasher/hasherKeecak256.js +46 -0
- package/dist/hasher/index.d.ts +4 -0
- package/dist/hasher/index.d.ts.map +1 -0
- package/dist/hasher/index.js +3 -0
- package/dist/hex/index.d.ts +27 -0
- package/dist/hex/index.d.ts.map +1 -0
- package/dist/hex/index.js +17 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/jsonRpc/advanced.d.ts +2 -0
- package/dist/jsonRpc/advanced.d.ts.map +1 -0
- package/dist/jsonRpc/advanced.js +1 -0
- package/dist/jsonRpc/index.d.ts +2 -0
- package/dist/jsonRpc/index.d.ts.map +1 -0
- package/dist/jsonRpc/index.js +1 -0
- package/dist/jsonRpc/requestor.d.ts +49 -0
- package/dist/jsonRpc/requestor.d.ts.map +1 -0
- package/dist/jsonRpc/requestor.js +109 -0
- package/dist/jsonRpc/transports/advanced.d.ts +6 -0
- package/dist/jsonRpc/transports/advanced.d.ts.map +1 -0
- package/dist/jsonRpc/transports/advanced.js +5 -0
- package/dist/jsonRpc/transports/factory.d.ts +6 -0
- package/dist/jsonRpc/transports/factory.d.ts.map +1 -0
- package/dist/jsonRpc/transports/factory.js +8 -0
- package/dist/jsonRpc/transports/fallback.d.ts +8 -0
- package/dist/jsonRpc/transports/fallback.d.ts.map +1 -0
- package/dist/jsonRpc/transports/fallback.js +22 -0
- package/dist/jsonRpc/transports/http.d.ts +8 -0
- package/dist/jsonRpc/transports/http.d.ts.map +1 -0
- package/dist/jsonRpc/transports/http.js +22 -0
- package/dist/jsonRpc/transports/transport.d.ts +18 -0
- package/dist/jsonRpc/transports/transport.d.ts.map +1 -0
- package/dist/jsonRpc/transports/transport.js +1 -0
- package/dist/jsonRpc/transports/webSocket.d.ts +11 -0
- package/dist/jsonRpc/transports/webSocket.d.ts.map +1 -0
- package/dist/jsonRpc/transports/webSocket.js +87 -0
- package/dist/keystore/index.d.ts +31 -0
- package/dist/keystore/index.d.ts.map +1 -0
- package/dist/keystore/index.js +106 -0
- package/dist/molecule/barrel.d.ts +4 -0
- package/dist/molecule/barrel.d.ts.map +1 -0
- package/dist/molecule/barrel.js +3 -0
- package/dist/molecule/codec.d.ts +120 -0
- package/dist/molecule/codec.d.ts.map +1 -0
- package/dist/molecule/codec.js +468 -0
- package/dist/molecule/entity.d.ts +119 -0
- package/dist/molecule/entity.d.ts.map +1 -0
- package/dist/molecule/entity.js +134 -0
- package/dist/molecule/index.d.ts +2 -0
- package/dist/molecule/index.d.ts.map +1 -0
- package/dist/molecule/index.js +1 -0
- package/dist/molecule/predefined.d.ts +57 -0
- package/dist/molecule/predefined.d.ts.map +1 -0
- package/dist/molecule/predefined.js +83 -0
- package/dist/num/index.d.ts +148 -0
- package/dist/num/index.d.ts.map +1 -0
- package/dist/num/index.js +188 -0
- package/dist/package.json +3 -0
- package/dist/signer/btc/index.d.ts +4 -0
- package/dist/signer/btc/index.d.ts.map +1 -0
- package/dist/signer/btc/index.js +3 -0
- package/dist/signer/btc/signerBtc.d.ts +59 -0
- package/dist/signer/btc/signerBtc.d.ts.map +1 -0
- package/dist/signer/btc/signerBtc.js +83 -0
- package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts +55 -0
- package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -0
- package/dist/signer/btc/signerBtcPublicKeyReadonly.js +61 -0
- package/dist/signer/btc/verify.d.ts +19 -0
- package/dist/signer/btc/verify.d.ts.map +1 -0
- package/dist/signer/btc/verify.js +33 -0
- package/dist/signer/ckb/index.d.ts +6 -0
- package/dist/signer/ckb/index.d.ts.map +1 -0
- package/dist/signer/ckb/index.js +5 -0
- package/dist/signer/ckb/signerCkbPrivateKey.d.ts +16 -0
- package/dist/signer/ckb/signerCkbPrivateKey.d.ts.map +1 -0
- package/dist/signer/ckb/signerCkbPrivateKey.js +42 -0
- package/dist/signer/ckb/signerCkbPublicKey.d.ts +27 -0
- package/dist/signer/ckb/signerCkbPublicKey.d.ts.map +1 -0
- package/dist/signer/ckb/signerCkbPublicKey.js +105 -0
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +56 -0
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -0
- package/dist/signer/ckb/signerCkbScriptReadonly.js +66 -0
- package/dist/signer/ckb/verifyCkbSecp256k1.d.ts +11 -0
- package/dist/signer/ckb/verifyCkbSecp256k1.d.ts.map +1 -0
- package/dist/signer/ckb/verifyCkbSecp256k1.js +20 -0
- package/dist/signer/ckb/verifyJoyId.d.ts +6 -0
- package/dist/signer/ckb/verifyJoyId.d.ts.map +1 -0
- package/dist/signer/ckb/verifyJoyId.js +16 -0
- package/dist/signer/doge/index.d.ts +5 -0
- package/dist/signer/doge/index.d.ts.map +1 -0
- package/dist/signer/doge/index.js +4 -0
- package/dist/signer/doge/signerDoge.d.ts +52 -0
- package/dist/signer/doge/signerDoge.d.ts.map +1 -0
- package/dist/signer/doge/signerDoge.js +82 -0
- package/dist/signer/doge/signerDogeAddressReadonly.d.ts +41 -0
- package/dist/signer/doge/signerDogeAddressReadonly.d.ts.map +1 -0
- package/dist/signer/doge/signerDogeAddressReadonly.js +45 -0
- package/dist/signer/doge/signerDogePrivateKey.d.ts +52 -0
- package/dist/signer/doge/signerDogePrivateKey.d.ts.map +1 -0
- package/dist/signer/doge/signerDogePrivateKey.js +68 -0
- package/dist/signer/doge/verify.d.ts +6 -0
- package/dist/signer/doge/verify.d.ts.map +1 -0
- package/dist/signer/doge/verify.js +19 -0
- package/dist/signer/dummy/alwaysError.d.ts +12 -0
- package/dist/signer/dummy/alwaysError.d.ts.map +1 -0
- package/dist/signer/dummy/alwaysError.js +13 -0
- package/dist/signer/dummy/dummy.d.ts +15 -0
- package/dist/signer/dummy/dummy.d.ts.map +1 -0
- package/dist/signer/dummy/dummy.js +22 -0
- package/dist/signer/dummy/index.d.ts +4 -0
- package/dist/signer/dummy/index.d.ts.map +1 -0
- package/dist/signer/dummy/index.js +3 -0
- package/dist/signer/dummy/openLink.d.ts +12 -0
- package/dist/signer/dummy/openLink.d.ts.map +1 -0
- package/dist/signer/dummy/openLink.js +13 -0
- package/dist/signer/evm/index.d.ts +4 -0
- package/dist/signer/evm/index.d.ts.map +1 -0
- package/dist/signer/evm/index.js +3 -0
- package/dist/signer/evm/signerEvm.d.ts +59 -0
- package/dist/signer/evm/signerEvm.d.ts.map +1 -0
- package/dist/signer/evm/signerEvm.js +139 -0
- package/dist/signer/evm/signerEvmAddressReadonly.d.ts +47 -0
- package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -0
- package/dist/signer/evm/signerEvmAddressReadonly.js +51 -0
- package/dist/signer/evm/verify.d.ts +6 -0
- package/dist/signer/evm/verify.d.ts.map +1 -0
- package/dist/signer/evm/verify.js +9 -0
- package/dist/signer/index.d.ts +8 -0
- package/dist/signer/index.d.ts.map +1 -0
- package/dist/signer/index.js +7 -0
- package/dist/signer/nostr/index.d.ts +4 -0
- package/dist/signer/nostr/index.d.ts.map +1 -0
- package/dist/signer/nostr/index.js +3 -0
- package/dist/signer/nostr/signerNostr.d.ts +72 -0
- package/dist/signer/nostr/signerNostr.d.ts.map +1 -0
- package/dist/signer/nostr/signerNostr.js +88 -0
- package/dist/signer/nostr/signerNostrPrivateKey.d.ts +12 -0
- package/dist/signer/nostr/signerNostrPrivateKey.d.ts.map +1 -0
- package/dist/signer/nostr/signerNostrPrivateKey.js +28 -0
- package/dist/signer/nostr/verify.d.ts +9 -0
- package/dist/signer/nostr/verify.d.ts.map +1 -0
- package/dist/signer/nostr/verify.js +55 -0
- package/dist/signer/signer/index.d.ts +237 -0
- package/dist/signer/signer/index.d.ts.map +1 -0
- package/dist/signer/signer/index.js +274 -0
- package/dist/utils/index.d.ts +97 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +55 -0
- package/dist.commonjs/address/address.advanced.d.ts +65 -0
- package/dist.commonjs/address/address.advanced.d.ts.map +1 -0
- package/dist.commonjs/address/address.advanced.js +152 -0
- package/dist.commonjs/address/advanced.d.ts +2 -0
- package/dist.commonjs/address/advanced.d.ts.map +1 -0
- package/dist.commonjs/address/advanced.js +17 -0
- package/dist.commonjs/address/index.d.ts +58 -0
- package/dist.commonjs/address/index.d.ts.map +1 -0
- package/dist.commonjs/address/index.js +82 -0
- package/dist.commonjs/advanced.d.ts +3 -0
- package/dist.commonjs/advanced.d.ts.map +1 -0
- package/dist.commonjs/advanced.js +41 -0
- package/dist.commonjs/advancedBarrel.d.ts +7 -0
- package/dist.commonjs/advancedBarrel.d.ts.map +1 -0
- package/dist.commonjs/advancedBarrel.js +22 -0
- package/dist.commonjs/barrel.d.ts +14 -0
- package/dist.commonjs/barrel.d.ts.map +1 -0
- package/dist.commonjs/barrel.js +29 -0
- package/dist.commonjs/bytes/advanced.d.ts +6 -0
- package/dist.commonjs/bytes/advanced.d.ts.map +1 -0
- package/dist.commonjs/bytes/advanced.js +2 -0
- package/dist.commonjs/bytes/index.d.ts +108 -0
- package/dist.commonjs/bytes/index.d.ts.map +1 -0
- package/dist.commonjs/bytes/index.js +158 -0
- package/dist.commonjs/ckb/advanced.d.ts +3 -0
- package/dist.commonjs/ckb/advanced.d.ts.map +1 -0
- package/dist.commonjs/ckb/advanced.js +18 -0
- package/dist.commonjs/ckb/index.d.ts +4 -0
- package/dist.commonjs/ckb/index.d.ts.map +1 -0
- package/dist.commonjs/ckb/index.js +19 -0
- package/dist.commonjs/ckb/script.advanced.d.ts +5 -0
- package/dist.commonjs/ckb/script.advanced.d.ts.map +1 -0
- package/dist.commonjs/ckb/script.advanced.js +16 -0
- package/dist.commonjs/ckb/script.d.ts +143 -0
- package/dist.commonjs/ckb/script.d.ts.map +1 -0
- package/dist.commonjs/ckb/script.js +173 -0
- package/dist.commonjs/ckb/transaction.advanced.d.ts +5 -0
- package/dist.commonjs/ckb/transaction.advanced.d.ts.map +1 -0
- package/dist.commonjs/ckb/transaction.advanced.js +12 -0
- package/dist.commonjs/ckb/transaction.d.ts +893 -0
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -0
- package/dist.commonjs/ckb/transaction.js +1310 -0
- package/dist.commonjs/ckb/transactionLumos.d.ts +30 -0
- package/dist.commonjs/ckb/transactionLumos.d.ts.map +1 -0
- package/dist.commonjs/ckb/transactionLumos.js +2 -0
- package/dist.commonjs/client/advanced.d.ts +6 -0
- package/dist.commonjs/client/advanced.d.ts.map +1 -0
- package/dist.commonjs/client/advanced.js +21 -0
- package/dist.commonjs/client/cache/advanced.d.ts +2 -0
- package/dist.commonjs/client/cache/advanced.d.ts.map +1 -0
- package/dist.commonjs/client/cache/advanced.js +17 -0
- package/dist.commonjs/client/cache/cache.d.ts +91 -0
- package/dist.commonjs/client/cache/cache.d.ts.map +1 -0
- package/dist.commonjs/client/cache/cache.js +132 -0
- package/dist.commonjs/client/cache/index.d.ts +3 -0
- package/dist.commonjs/client/cache/index.d.ts.map +1 -0
- package/dist.commonjs/client/cache/index.js +18 -0
- package/dist.commonjs/client/cache/memory.advanced.d.ts +22 -0
- package/dist.commonjs/client/cache/memory.advanced.d.ts.map +1 -0
- package/dist.commonjs/client/cache/memory.advanced.js +127 -0
- package/dist.commonjs/client/cache/memory.d.ts +44 -0
- package/dist.commonjs/client/cache/memory.d.ts.map +1 -0
- package/dist.commonjs/client/cache/memory.js +141 -0
- package/dist.commonjs/client/client.d.ts +98 -0
- package/dist.commonjs/client/client.d.ts.map +1 -0
- package/dist.commonjs/client/client.js +327 -0
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +3 -0
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -0
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +329 -0
- package/dist.commonjs/client/clientPublicMainnet.d.ts +16 -0
- package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -0
- package/dist.commonjs/client/clientPublicMainnet.js +47 -0
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +3 -0
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -0
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +339 -0
- package/dist.commonjs/client/clientPublicTestnet.d.ts +16 -0
- package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -0
- package/dist.commonjs/client/clientPublicTestnet.js +47 -0
- package/dist.commonjs/client/clientTypes.advanced.d.ts +26 -0
- package/dist.commonjs/client/clientTypes.advanced.d.ts.map +1 -0
- package/dist.commonjs/client/clientTypes.advanced.js +11 -0
- package/dist.commonjs/client/clientTypes.d.ts +360 -0
- package/dist.commonjs/client/clientTypes.d.ts.map +1 -0
- package/dist.commonjs/client/clientTypes.js +278 -0
- package/dist.commonjs/client/index.d.ts +7 -0
- package/dist.commonjs/client/index.d.ts.map +1 -0
- package/dist.commonjs/client/index.js +22 -0
- package/dist.commonjs/client/jsonRpc/advanced.d.ts +3 -0
- package/dist.commonjs/client/jsonRpc/advanced.d.ts.map +1 -0
- package/dist.commonjs/client/jsonRpc/advanced.js +18 -0
- package/dist.commonjs/client/jsonRpc/client.d.ts +160 -0
- package/dist.commonjs/client/jsonRpc/client.d.ts.map +1 -0
- package/dist.commonjs/client/jsonRpc/client.js +224 -0
- package/dist.commonjs/client/jsonRpc/index.d.ts +2 -0
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -0
- package/dist.commonjs/client/jsonRpc/index.js +17 -0
- package/dist.commonjs/client/jsonRpc/transformers.d.ts +51 -0
- package/dist.commonjs/client/jsonRpc/transformers.d.ts.map +1 -0
- package/dist.commonjs/client/jsonRpc/transformers.js +250 -0
- package/dist.commonjs/client/jsonRpc/types.d.ts +101 -0
- package/dist.commonjs/client/jsonRpc/types.d.ts.map +1 -0
- package/dist.commonjs/client/jsonRpc/types.js +2 -0
- package/dist.commonjs/fixedPoint/index.d.ts +55 -0
- package/dist.commonjs/fixedPoint/index.d.ts.map +1 -0
- package/dist.commonjs/fixedPoint/index.js +73 -0
- package/dist.commonjs/hasher/advanced.d.ts +2 -0
- package/dist.commonjs/hasher/advanced.d.ts.map +1 -0
- package/dist.commonjs/hasher/advanced.js +4 -0
- package/dist.commonjs/hasher/hasher.d.ts +35 -0
- package/dist.commonjs/hasher/hasher.d.ts.map +1 -0
- package/dist.commonjs/hasher/hasher.js +2 -0
- package/dist.commonjs/hasher/hasherCkb.d.ts +73 -0
- package/dist.commonjs/hasher/hasherCkb.d.ts.map +1 -0
- package/dist.commonjs/hasher/hasherCkb.js +94 -0
- package/dist.commonjs/hasher/hasherKeecak256.d.ts +41 -0
- package/dist.commonjs/hasher/hasherKeecak256.d.ts.map +1 -0
- package/dist.commonjs/hasher/hasherKeecak256.js +50 -0
- package/dist.commonjs/hasher/index.d.ts +4 -0
- package/dist.commonjs/hasher/index.d.ts.map +1 -0
- package/dist.commonjs/hasher/index.js +19 -0
- package/dist.commonjs/hex/index.d.ts +27 -0
- package/dist.commonjs/hex/index.d.ts.map +1 -0
- package/dist.commonjs/hex/index.js +20 -0
- package/dist.commonjs/index.d.ts +3 -0
- package/dist.commonjs/index.d.ts.map +1 -0
- package/dist.commonjs/index.js +41 -0
- package/dist.commonjs/jsonRpc/advanced.d.ts +2 -0
- package/dist.commonjs/jsonRpc/advanced.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/advanced.js +17 -0
- package/dist.commonjs/jsonRpc/index.d.ts +2 -0
- package/dist.commonjs/jsonRpc/index.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/index.js +17 -0
- package/dist.commonjs/jsonRpc/requestor.d.ts +49 -0
- package/dist.commonjs/jsonRpc/requestor.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/requestor.js +113 -0
- package/dist.commonjs/jsonRpc/transports/advanced.d.ts +6 -0
- package/dist.commonjs/jsonRpc/transports/advanced.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/transports/advanced.js +21 -0
- package/dist.commonjs/jsonRpc/transports/factory.d.ts +6 -0
- package/dist.commonjs/jsonRpc/transports/factory.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/transports/factory.js +11 -0
- package/dist.commonjs/jsonRpc/transports/fallback.d.ts +8 -0
- package/dist.commonjs/jsonRpc/transports/fallback.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/transports/fallback.js +26 -0
- package/dist.commonjs/jsonRpc/transports/http.d.ts +8 -0
- package/dist.commonjs/jsonRpc/transports/http.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/transports/http.js +26 -0
- package/dist.commonjs/jsonRpc/transports/transport.d.ts +18 -0
- package/dist.commonjs/jsonRpc/transports/transport.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/transports/transport.js +2 -0
- package/dist.commonjs/jsonRpc/transports/webSocket.d.ts +11 -0
- package/dist.commonjs/jsonRpc/transports/webSocket.d.ts.map +1 -0
- package/dist.commonjs/jsonRpc/transports/webSocket.js +94 -0
- package/dist.commonjs/keystore/index.d.ts +31 -0
- package/dist.commonjs/keystore/index.d.ts.map +1 -0
- package/dist.commonjs/keystore/index.js +110 -0
- package/dist.commonjs/molecule/barrel.d.ts +4 -0
- package/dist.commonjs/molecule/barrel.d.ts.map +1 -0
- package/dist.commonjs/molecule/barrel.js +19 -0
- package/dist.commonjs/molecule/codec.d.ts +120 -0
- package/dist.commonjs/molecule/codec.d.ts.map +1 -0
- package/dist.commonjs/molecule/codec.js +483 -0
- package/dist.commonjs/molecule/entity.d.ts +119 -0
- package/dist.commonjs/molecule/entity.d.ts.map +1 -0
- package/dist.commonjs/molecule/entity.js +139 -0
- package/dist.commonjs/molecule/index.d.ts +2 -0
- package/dist.commonjs/molecule/index.d.ts.map +1 -0
- package/dist.commonjs/molecule/index.js +37 -0
- package/dist.commonjs/molecule/predefined.d.ts +57 -0
- package/dist.commonjs/molecule/predefined.d.ts.map +1 -0
- package/dist.commonjs/molecule/predefined.js +87 -0
- package/dist.commonjs/num/index.d.ts +148 -0
- package/dist.commonjs/num/index.d.ts.map +1 -0
- package/dist.commonjs/num/index.js +200 -0
- package/dist.commonjs/package.json +3 -0
- package/dist.commonjs/signer/btc/index.d.ts +4 -0
- package/dist.commonjs/signer/btc/index.d.ts.map +1 -0
- package/dist.commonjs/signer/btc/index.js +19 -0
- package/dist.commonjs/signer/btc/signerBtc.d.ts +59 -0
- package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -0
- package/dist.commonjs/signer/btc/signerBtc.js +87 -0
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +55 -0
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -0
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +65 -0
- package/dist.commonjs/signer/btc/verify.d.ts +19 -0
- package/dist.commonjs/signer/btc/verify.d.ts.map +1 -0
- package/dist.commonjs/signer/btc/verify.js +42 -0
- package/dist.commonjs/signer/ckb/index.d.ts +6 -0
- package/dist.commonjs/signer/ckb/index.d.ts.map +1 -0
- package/dist.commonjs/signer/ckb/index.js +21 -0
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.d.ts +16 -0
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.d.ts.map +1 -0
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +46 -0
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.d.ts +27 -0
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.d.ts.map +1 -0
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +109 -0
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +56 -0
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -0
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +70 -0
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.d.ts +11 -0
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.d.ts.map +1 -0
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +24 -0
- package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +6 -0
- package/dist.commonjs/signer/ckb/verifyJoyId.d.ts.map +1 -0
- package/dist.commonjs/signer/ckb/verifyJoyId.js +19 -0
- package/dist.commonjs/signer/doge/index.d.ts +5 -0
- package/dist.commonjs/signer/doge/index.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/index.js +20 -0
- package/dist.commonjs/signer/doge/signerDoge.d.ts +52 -0
- package/dist.commonjs/signer/doge/signerDoge.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/signerDoge.js +89 -0
- package/dist.commonjs/signer/doge/signerDogeAddressReadonly.d.ts +41 -0
- package/dist.commonjs/signer/doge/signerDogeAddressReadonly.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/signerDogeAddressReadonly.js +49 -0
- package/dist.commonjs/signer/doge/signerDogePrivateKey.d.ts +52 -0
- package/dist.commonjs/signer/doge/signerDogePrivateKey.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/signerDogePrivateKey.js +72 -0
- package/dist.commonjs/signer/doge/verify.d.ts +6 -0
- package/dist.commonjs/signer/doge/verify.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/verify.js +22 -0
- package/dist.commonjs/signer/dummy/alwaysError.d.ts +12 -0
- package/dist.commonjs/signer/dummy/alwaysError.d.ts.map +1 -0
- package/dist.commonjs/signer/dummy/alwaysError.js +17 -0
- package/dist.commonjs/signer/dummy/dummy.d.ts +15 -0
- package/dist.commonjs/signer/dummy/dummy.d.ts.map +1 -0
- package/dist.commonjs/signer/dummy/dummy.js +26 -0
- package/dist.commonjs/signer/dummy/index.d.ts +4 -0
- package/dist.commonjs/signer/dummy/index.d.ts.map +1 -0
- package/dist.commonjs/signer/dummy/index.js +19 -0
- package/dist.commonjs/signer/dummy/openLink.d.ts +12 -0
- package/dist.commonjs/signer/dummy/openLink.d.ts.map +1 -0
- package/dist.commonjs/signer/dummy/openLink.js +17 -0
- package/dist.commonjs/signer/evm/index.d.ts +4 -0
- package/dist.commonjs/signer/evm/index.d.ts.map +1 -0
- package/dist.commonjs/signer/evm/index.js +19 -0
- package/dist.commonjs/signer/evm/signerEvm.d.ts +59 -0
- package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -0
- package/dist.commonjs/signer/evm/signerEvm.js +143 -0
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +47 -0
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -0
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +55 -0
- package/dist.commonjs/signer/evm/verify.d.ts +6 -0
- package/dist.commonjs/signer/evm/verify.d.ts.map +1 -0
- package/dist.commonjs/signer/evm/verify.js +12 -0
- package/dist.commonjs/signer/index.d.ts +8 -0
- package/dist.commonjs/signer/index.d.ts.map +1 -0
- package/dist.commonjs/signer/index.js +23 -0
- package/dist.commonjs/signer/nostr/index.d.ts +4 -0
- package/dist.commonjs/signer/nostr/index.d.ts.map +1 -0
- package/dist.commonjs/signer/nostr/index.js +19 -0
- package/dist.commonjs/signer/nostr/signerNostr.d.ts +72 -0
- package/dist.commonjs/signer/nostr/signerNostr.d.ts.map +1 -0
- package/dist.commonjs/signer/nostr/signerNostr.js +92 -0
- package/dist.commonjs/signer/nostr/signerNostrPrivateKey.d.ts +12 -0
- package/dist.commonjs/signer/nostr/signerNostrPrivateKey.d.ts.map +1 -0
- package/dist.commonjs/signer/nostr/signerNostrPrivateKey.js +32 -0
- package/dist.commonjs/signer/nostr/verify.d.ts +9 -0
- package/dist.commonjs/signer/nostr/verify.d.ts.map +1 -0
- package/dist.commonjs/signer/nostr/verify.js +60 -0
- package/dist.commonjs/signer/signer/index.d.ts +237 -0
- package/dist.commonjs/signer/signer/index.d.ts.map +1 -0
- package/dist.commonjs/signer/signer/index.js +280 -0
- package/dist.commonjs/utils/index.d.ts +97 -0
- package/dist.commonjs/utils/index.d.ts.map +1 -0
- package/dist.commonjs/utils/index.js +62 -0
- package/jest.config.js +5 -0
- package/package.json +80 -0
- package/src/address/address.advanced.ts +182 -0
- package/src/address/advanced.ts +1 -0
- package/src/address/index.ts +127 -0
- package/src/advanced.ts +2 -0
- package/src/advancedBarrel.ts +6 -0
- package/src/barrel.ts +13 -0
- package/src/bytes/advanced.ts +14 -0
- package/src/bytes/index.ts +184 -0
- package/src/ckb/advanced.ts +2 -0
- package/src/ckb/index.ts +3 -0
- package/src/ckb/script.advanced.ts +15 -0
- package/src/ckb/script.ts +214 -0
- package/src/ckb/transaction.advanced.ts +11 -0
- package/src/ckb/transaction.ts +1781 -0
- package/src/ckb/transactionLumos.ts +27 -0
- package/src/client/advanced.ts +5 -0
- package/src/client/cache/advanced.ts +1 -0
- package/src/client/cache/cache.ts +188 -0
- package/src/client/cache/index.ts +2 -0
- package/src/client/cache/memory.advanced.ts +190 -0
- package/src/client/cache/memory.ts +219 -0
- package/src/client/client.ts +703 -0
- package/src/client/clientPublicMainnet.advanced.ts +372 -0
- package/src/client/clientPublicMainnet.ts +54 -0
- package/src/client/clientPublicTestnet.advanced.ts +384 -0
- package/src/client/clientPublicTestnet.ts +54 -0
- package/src/client/clientTypes.advanced.ts +30 -0
- package/src/client/clientTypes.ts +590 -0
- package/src/client/index.ts +6 -0
- package/src/client/jsonRpc/advanced.ts +2 -0
- package/src/client/jsonRpc/client.ts +397 -0
- package/src/client/jsonRpc/index.ts +1 -0
- package/src/client/jsonRpc/transformers.ts +358 -0
- package/src/client/jsonRpc/types.ts +115 -0
- package/src/fixedPoint/index.ts +92 -0
- package/src/hasher/advanced.ts +1 -0
- package/src/hasher/hasher.ts +38 -0
- package/src/hasher/hasherCkb.ts +107 -0
- package/src/hasher/hasherKeecak256.ts +55 -0
- package/src/hasher/index.ts +3 -0
- package/src/hex/index.ts +30 -0
- package/src/index.ts +2 -0
- package/src/jsonRpc/advanced.ts +1 -0
- package/src/jsonRpc/index.ts +1 -0
- package/src/jsonRpc/requestor.ts +166 -0
- package/src/jsonRpc/transports/advanced.ts +5 -0
- package/src/jsonRpc/transports/factory.ts +10 -0
- package/src/jsonRpc/transports/fallback.ts +27 -0
- package/src/jsonRpc/transports/http.ts +28 -0
- package/src/jsonRpc/transports/transport.ts +18 -0
- package/src/jsonRpc/transports/webSocket.ts +114 -0
- package/src/keystore/index.ts +162 -0
- package/src/molecule/barrel.ts +3 -0
- package/src/molecule/codec.ts +651 -0
- package/src/molecule/entity.ts +183 -0
- package/src/molecule/index.ts +1 -0
- package/src/molecule/predefined.ts +97 -0
- package/src/num/index.ts +217 -0
- package/src/signer/btc/index.ts +3 -0
- package/src/signer/btc/signerBtc.ts +126 -0
- package/src/signer/btc/signerBtcPublicKeyReadonly.ts +73 -0
- package/src/signer/btc/verify.ts +49 -0
- package/src/signer/ckb/index.ts +5 -0
- package/src/signer/ckb/signerCkbPrivateKey.ts +65 -0
- package/src/signer/ckb/signerCkbPublicKey.ts +151 -0
- package/src/signer/ckb/signerCkbScriptReadonly.ts +78 -0
- package/src/signer/ckb/verifyCkbSecp256k1.ts +33 -0
- package/src/signer/ckb/verifyJoyId.ts +27 -0
- package/src/signer/doge/index.ts +4 -0
- package/src/signer/doge/signerDoge.ts +116 -0
- package/src/signer/doge/signerDogeAddressReadonly.ts +52 -0
- package/src/signer/doge/signerDogePrivateKey.ts +97 -0
- package/src/signer/doge/verify.ts +40 -0
- package/src/signer/dummy/alwaysError.ts +20 -0
- package/src/signer/dummy/dummy.ts +31 -0
- package/src/signer/dummy/index.ts +3 -0
- package/src/signer/dummy/openLink.ts +20 -0
- package/src/signer/evm/index.ts +3 -0
- package/src/signer/evm/signerEvm.ts +259 -0
- package/src/signer/evm/signerEvmAddressReadonly.ts +60 -0
- package/src/signer/evm/verify.ts +19 -0
- package/src/signer/index.ts +7 -0
- package/src/signer/nostr/index.ts +3 -0
- package/src/signer/nostr/signerNostr.ts +141 -0
- package/src/signer/nostr/signerNostrPrivateKey.ts +37 -0
- package/src/signer/nostr/verify.ts +72 -0
- package/src/signer/signer/index.ts +468 -0
- package/src/utils/index.ts +198 -0
- package/typedoc.json +6 -0
|
@@ -0,0 +1,1299 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var OutPoint_1, CellOutput_1, Since_1, CellInput_1, CellDep_1, WitnessArgs_1, Transaction_1;
|
|
8
|
+
import { bytesFrom } from "../bytes/index.js";
|
|
9
|
+
import { Zero, fixedPointFrom, fixedPointToString, } from "../fixedPoint/index.js";
|
|
10
|
+
import { HasherCkb, hashCkb } from "../hasher/index.js";
|
|
11
|
+
import { hexFrom } from "../hex/index.js";
|
|
12
|
+
import { mol } from "../molecule/index.js";
|
|
13
|
+
import { numFrom, numFromBytes, numToBytes, numToHex, } from "../num/index.js";
|
|
14
|
+
import { apply, reduceAsync } from "../utils/index.js";
|
|
15
|
+
import { Script, ScriptOpt } from "./script.js";
|
|
16
|
+
import { DEP_TYPE_TO_NUM, NUM_TO_DEP_TYPE } from "./transaction.advanced.js";
|
|
17
|
+
export const DepTypeCodec = mol.Codec.from({
|
|
18
|
+
byteLength: 1,
|
|
19
|
+
encode: depTypeToBytes,
|
|
20
|
+
decode: depTypeFromBytes,
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Converts a DepTypeLike value to a DepType.
|
|
24
|
+
* @public
|
|
25
|
+
*
|
|
26
|
+
* @param val - The value to convert, which can be a string, number, or bigint.
|
|
27
|
+
* @returns The corresponding DepType.
|
|
28
|
+
*
|
|
29
|
+
* @throws Will throw an error if the input value is not a valid dep type.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const depType = depTypeFrom(1); // Outputs "code"
|
|
34
|
+
* const depType = depTypeFrom("depGroup"); // Outputs "depGroup"
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export function depTypeFrom(val) {
|
|
38
|
+
const depType = (() => {
|
|
39
|
+
if (typeof val === "number") {
|
|
40
|
+
return NUM_TO_DEP_TYPE[val];
|
|
41
|
+
}
|
|
42
|
+
if (typeof val === "bigint") {
|
|
43
|
+
return NUM_TO_DEP_TYPE[Number(val)];
|
|
44
|
+
}
|
|
45
|
+
return val;
|
|
46
|
+
})();
|
|
47
|
+
if (depType === undefined) {
|
|
48
|
+
throw new Error(`Invalid dep type ${val}`);
|
|
49
|
+
}
|
|
50
|
+
return depType;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Converts a DepTypeLike value to its corresponding byte representation.
|
|
54
|
+
* @public
|
|
55
|
+
*
|
|
56
|
+
* @param depType - The dep type value to convert.
|
|
57
|
+
* @returns A Uint8Array containing the byte representation of the dep type.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const depTypeBytes = depTypeToBytes("code"); // Outputs Uint8Array [1]
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export function depTypeToBytes(depType) {
|
|
65
|
+
return bytesFrom([DEP_TYPE_TO_NUM[depTypeFrom(depType)]]);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Converts a byte-like value to a DepType.
|
|
69
|
+
* @public
|
|
70
|
+
*
|
|
71
|
+
* @param bytes - The byte-like value to convert.
|
|
72
|
+
* @returns The corresponding DepType.
|
|
73
|
+
*
|
|
74
|
+
* @throws Will throw an error if the input bytes do not correspond to a valid dep type.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const depType = depTypeFromBytes(new Uint8Array([1])); // Outputs "code"
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export function depTypeFromBytes(bytes) {
|
|
82
|
+
return NUM_TO_DEP_TYPE[bytesFrom(bytes)[0]];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
87
|
+
let OutPoint = OutPoint_1 = class OutPoint extends mol.Entity.Base() {
|
|
88
|
+
/**
|
|
89
|
+
* Creates an instance of OutPoint.
|
|
90
|
+
*
|
|
91
|
+
* @param txHash - The transaction hash.
|
|
92
|
+
* @param index - The index of the output in the transaction.
|
|
93
|
+
*/
|
|
94
|
+
constructor(txHash, index) {
|
|
95
|
+
super();
|
|
96
|
+
this.txHash = txHash;
|
|
97
|
+
this.index = index;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Creates an OutPoint instance from an OutPointLike object.
|
|
101
|
+
*
|
|
102
|
+
* @param outPoint - An OutPointLike object or an instance of OutPoint.
|
|
103
|
+
* @returns An OutPoint instance.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const outPoint = OutPoint.from({ txHash: "0x...", index: 0 });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
static from(outPoint) {
|
|
111
|
+
if (outPoint instanceof OutPoint_1) {
|
|
112
|
+
return outPoint;
|
|
113
|
+
}
|
|
114
|
+
return new OutPoint_1(hexFrom(outPoint.txHash), numFrom(outPoint.index));
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
OutPoint = OutPoint_1 = __decorate([
|
|
118
|
+
mol.codec(mol.struct({
|
|
119
|
+
txHash: mol.Byte32,
|
|
120
|
+
index: mol.Uint32,
|
|
121
|
+
}))
|
|
122
|
+
], OutPoint);
|
|
123
|
+
export { OutPoint };
|
|
124
|
+
/**
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
let CellOutput = CellOutput_1 = class CellOutput extends mol.Entity.Base() {
|
|
128
|
+
/**
|
|
129
|
+
* Creates an instance of CellOutput.
|
|
130
|
+
*
|
|
131
|
+
* @param capacity - The capacity of the cell.
|
|
132
|
+
* @param lock - The lock script of the cell.
|
|
133
|
+
* @param type - The optional type script of the cell.
|
|
134
|
+
*/
|
|
135
|
+
constructor(capacity, lock, type) {
|
|
136
|
+
super();
|
|
137
|
+
this.capacity = capacity;
|
|
138
|
+
this.lock = lock;
|
|
139
|
+
this.type = type;
|
|
140
|
+
}
|
|
141
|
+
get occupiedSize() {
|
|
142
|
+
return 8 + this.lock.occupiedSize + (this.type?.occupiedSize ?? 0);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Creates a CellOutput instance from a CellOutputLike object.
|
|
146
|
+
*
|
|
147
|
+
* @param cellOutput - A CellOutputLike object or an instance of CellOutput.
|
|
148
|
+
* @returns A CellOutput instance.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const cellOutput = CellOutput.from({
|
|
153
|
+
* capacity: 1000n,
|
|
154
|
+
* lock: { codeHash: "0x...", hashType: "type", args: "0x..." },
|
|
155
|
+
* type: { codeHash: "0x...", hashType: "type", args: "0x..." }
|
|
156
|
+
* });
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
static from(cellOutput) {
|
|
160
|
+
if (cellOutput instanceof CellOutput_1) {
|
|
161
|
+
return cellOutput;
|
|
162
|
+
}
|
|
163
|
+
return new CellOutput_1(numFrom(cellOutput.capacity), Script.from(cellOutput.lock), apply(Script.from, cellOutput.type));
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
CellOutput = CellOutput_1 = __decorate([
|
|
167
|
+
mol.codec(mol.table({
|
|
168
|
+
capacity: mol.Uint64,
|
|
169
|
+
lock: Script,
|
|
170
|
+
type: ScriptOpt,
|
|
171
|
+
}))
|
|
172
|
+
], CellOutput);
|
|
173
|
+
export { CellOutput };
|
|
174
|
+
export const CellOutputVec = mol.vector(CellOutput);
|
|
175
|
+
/**
|
|
176
|
+
* @public
|
|
177
|
+
*/
|
|
178
|
+
export class Cell {
|
|
179
|
+
/**
|
|
180
|
+
* Creates an instance of Cell.
|
|
181
|
+
*
|
|
182
|
+
* @param outPoint - The output point of the cell.
|
|
183
|
+
* @param cellOutput - The cell output of the cell.
|
|
184
|
+
* @param outputData - The output data of the cell.
|
|
185
|
+
*/
|
|
186
|
+
constructor(outPoint, cellOutput, outputData) {
|
|
187
|
+
this.outPoint = outPoint;
|
|
188
|
+
this.cellOutput = cellOutput;
|
|
189
|
+
this.outputData = outputData;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Creates a Cell instance from a CellLike object.
|
|
193
|
+
*
|
|
194
|
+
* @param cell - A CellLike object or an instance of Cell.
|
|
195
|
+
* @returns A Cell instance.
|
|
196
|
+
*/
|
|
197
|
+
static from(cell) {
|
|
198
|
+
if (cell instanceof Cell) {
|
|
199
|
+
return cell;
|
|
200
|
+
}
|
|
201
|
+
return new Cell(OutPoint.from("outPoint" in cell ? cell.outPoint : cell.previousOutput), CellOutput.from(cell.cellOutput), hexFrom(cell.outputData));
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Clone a Cell
|
|
205
|
+
*
|
|
206
|
+
* @returns A cloned Cell instance.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* const cell1 = cell0.clone();
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
clone() {
|
|
214
|
+
return new Cell(this.outPoint.clone(), this.cellOutput.clone(), this.outputData);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* @public
|
|
219
|
+
*/
|
|
220
|
+
export function epochFrom(epochLike) {
|
|
221
|
+
return [numFrom(epochLike[0]), numFrom(epochLike[1]), numFrom(epochLike[2])];
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* @public
|
|
225
|
+
*/
|
|
226
|
+
export function epochFromHex(hex) {
|
|
227
|
+
const num = numFrom(hexFrom(hex));
|
|
228
|
+
return [
|
|
229
|
+
num & numFrom("0xffffff"),
|
|
230
|
+
(num >> numFrom(24)) & numFrom("0xffff"),
|
|
231
|
+
(num >> numFrom(40)) & numFrom("0xffff"),
|
|
232
|
+
];
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* @public
|
|
236
|
+
*/
|
|
237
|
+
export function epochToHex(epochLike) {
|
|
238
|
+
const epoch = epochFrom(epochLike);
|
|
239
|
+
return numToHex(numFrom(epoch[0]) +
|
|
240
|
+
(numFrom(epoch[1]) << numFrom(24)) +
|
|
241
|
+
(numFrom(epoch[2]) << numFrom(40)));
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* @public
|
|
245
|
+
*/
|
|
246
|
+
let Since = Since_1 = class Since extends mol.Entity.Base() {
|
|
247
|
+
/**
|
|
248
|
+
* Creates an instance of Since.
|
|
249
|
+
*
|
|
250
|
+
* @param relative - Absolute or relative
|
|
251
|
+
* @param metric - The metric of since
|
|
252
|
+
* @param value - The value of since
|
|
253
|
+
*/
|
|
254
|
+
constructor(relative, metric, value) {
|
|
255
|
+
super();
|
|
256
|
+
this.relative = relative;
|
|
257
|
+
this.metric = metric;
|
|
258
|
+
this.value = value;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Clone a Since.
|
|
262
|
+
*
|
|
263
|
+
* @returns A cloned Since instance.
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```typescript
|
|
267
|
+
* const since1 = since0.clone();
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
clone() {
|
|
271
|
+
return new Since_1(this.relative, this.metric, this.value);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Creates a Since instance from a SinceLike object.
|
|
275
|
+
*
|
|
276
|
+
* @param since - A SinceLike object or an instance of Since.
|
|
277
|
+
* @returns A Since instance.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```typescript
|
|
281
|
+
* const since = Since.from("0x1234567812345678");
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
static from(since) {
|
|
285
|
+
if (since instanceof Since_1) {
|
|
286
|
+
return since;
|
|
287
|
+
}
|
|
288
|
+
if (typeof since === "object" && "relative" in since) {
|
|
289
|
+
return new Since_1(since.relative, since.metric, numFrom(since.value));
|
|
290
|
+
}
|
|
291
|
+
return Since_1.fromNum(since);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Converts the Since instance to num.
|
|
295
|
+
*
|
|
296
|
+
* @returns A num
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```typescript
|
|
300
|
+
* const num = since.toNum();
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
toNum() {
|
|
304
|
+
return (this.value |
|
|
305
|
+
(this.relative === "absolute" ? Zero : numFrom("0x8000000000000000")) |
|
|
306
|
+
{
|
|
307
|
+
blockNumber: numFrom("0x0000000000000000"),
|
|
308
|
+
epoch: numFrom("0x2000000000000000"),
|
|
309
|
+
timestamp: numFrom("0x4000000000000000"),
|
|
310
|
+
}[this.metric]);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Creates a Since instance from a num-like value.
|
|
314
|
+
*
|
|
315
|
+
* @param numLike - The num-like value to convert.
|
|
316
|
+
* @returns A Since instance.
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```typescript
|
|
320
|
+
* const since = Since.fromNum("0x0");
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
static fromNum(numLike) {
|
|
324
|
+
const num = numFrom(numLike);
|
|
325
|
+
const relative = num >> numFrom(63) === Zero ? "absolute" : "relative";
|
|
326
|
+
const metric = ["blockNumber", "epoch", "timestamp"][Number((num >> numFrom(61)) & numFrom(3))];
|
|
327
|
+
const value = num & numFrom("0x00ffffffffffffff");
|
|
328
|
+
return new Since_1(relative, metric, value);
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
Since = Since_1 = __decorate([
|
|
332
|
+
mol.codec(mol.Uint64.mapIn((encodable) => Since.from(encodable).toNum()))
|
|
333
|
+
], Since);
|
|
334
|
+
export { Since };
|
|
335
|
+
/**
|
|
336
|
+
* @public
|
|
337
|
+
*/
|
|
338
|
+
let CellInput = CellInput_1 = class CellInput extends mol.Entity.Base() {
|
|
339
|
+
/**
|
|
340
|
+
* Creates an instance of CellInput.
|
|
341
|
+
*
|
|
342
|
+
* @param previousOutput - The previous outpoint of the cell.
|
|
343
|
+
* @param since - The since value of the cell input.
|
|
344
|
+
* @param cellOutput - The optional cell output associated with the cell input.
|
|
345
|
+
* @param outputData - The optional output data associated with the cell input.
|
|
346
|
+
*/
|
|
347
|
+
constructor(previousOutput, since, cellOutput, outputData) {
|
|
348
|
+
super();
|
|
349
|
+
this.previousOutput = previousOutput;
|
|
350
|
+
this.since = since;
|
|
351
|
+
this.cellOutput = cellOutput;
|
|
352
|
+
this.outputData = outputData;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Creates a CellInput instance from a CellInputLike object.
|
|
356
|
+
*
|
|
357
|
+
* @param cellInput - A CellInputLike object or an instance of CellInput.
|
|
358
|
+
* @returns A CellInput instance.
|
|
359
|
+
*
|
|
360
|
+
* @example
|
|
361
|
+
* ```typescript
|
|
362
|
+
* const cellInput = CellInput.from({
|
|
363
|
+
* previousOutput: { txHash: "0x...", index: 0 },
|
|
364
|
+
* since: 0n
|
|
365
|
+
* });
|
|
366
|
+
* ```
|
|
367
|
+
*/
|
|
368
|
+
static from(cellInput) {
|
|
369
|
+
if (cellInput instanceof CellInput_1) {
|
|
370
|
+
return cellInput;
|
|
371
|
+
}
|
|
372
|
+
return new CellInput_1(OutPoint.from("previousOutput" in cellInput
|
|
373
|
+
? cellInput.previousOutput
|
|
374
|
+
: cellInput.outPoint), Since.from(cellInput.since ?? 0).toNum(), apply(CellOutput.from, cellInput.cellOutput), apply(hexFrom, cellInput.outputData));
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Complete extra infos in the input. Like the output of the out point.
|
|
378
|
+
* The instance will be modified.
|
|
379
|
+
*
|
|
380
|
+
* @returns true if succeed.
|
|
381
|
+
* @example
|
|
382
|
+
* ```typescript
|
|
383
|
+
* await cellInput.completeExtraInfos();
|
|
384
|
+
* ```
|
|
385
|
+
*/
|
|
386
|
+
async completeExtraInfos(client) {
|
|
387
|
+
if (this.cellOutput && this.outputData) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
const cell = await client.getCell(this.previousOutput);
|
|
391
|
+
if (!cell) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
this.cellOutput = cell.cellOutput;
|
|
395
|
+
this.outputData = cell.outputData;
|
|
396
|
+
}
|
|
397
|
+
clone() {
|
|
398
|
+
const cloned = super.clone();
|
|
399
|
+
cloned.cellOutput = this.cellOutput;
|
|
400
|
+
cloned.outputData = this.outputData;
|
|
401
|
+
return cloned;
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
CellInput = CellInput_1 = __decorate([
|
|
405
|
+
mol.codec(mol
|
|
406
|
+
.struct({
|
|
407
|
+
since: Since,
|
|
408
|
+
previousOutput: OutPoint,
|
|
409
|
+
})
|
|
410
|
+
.mapIn((encodable) => CellInput.from(encodable)))
|
|
411
|
+
], CellInput);
|
|
412
|
+
export { CellInput };
|
|
413
|
+
export const CellInputVec = mol.vector(CellInput);
|
|
414
|
+
/**
|
|
415
|
+
* @public
|
|
416
|
+
*/
|
|
417
|
+
let CellDep = CellDep_1 = class CellDep extends mol.Entity.Base() {
|
|
418
|
+
/**
|
|
419
|
+
* Creates an instance of CellDep.
|
|
420
|
+
*
|
|
421
|
+
* @param outPoint - The outpoint of the cell dependency.
|
|
422
|
+
* @param depType - The dependency type.
|
|
423
|
+
*/
|
|
424
|
+
constructor(outPoint, depType) {
|
|
425
|
+
super();
|
|
426
|
+
this.outPoint = outPoint;
|
|
427
|
+
this.depType = depType;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Clone a CellDep.
|
|
431
|
+
*
|
|
432
|
+
* @returns A cloned CellDep instance.
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
* ```typescript
|
|
436
|
+
* const cellDep1 = cellDep0.clone();
|
|
437
|
+
* ```
|
|
438
|
+
*/
|
|
439
|
+
clone() {
|
|
440
|
+
return new CellDep_1(this.outPoint.clone(), this.depType);
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Creates a CellDep instance from a CellDepLike object.
|
|
444
|
+
*
|
|
445
|
+
* @param cellDep - A CellDepLike object or an instance of CellDep.
|
|
446
|
+
* @returns A CellDep instance.
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```typescript
|
|
450
|
+
* const cellDep = CellDep.from({
|
|
451
|
+
* outPoint: { txHash: "0x...", index: 0 },
|
|
452
|
+
* depType: "depGroup"
|
|
453
|
+
* });
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
static from(cellDep) {
|
|
457
|
+
if (cellDep instanceof CellDep_1) {
|
|
458
|
+
return cellDep;
|
|
459
|
+
}
|
|
460
|
+
return new CellDep_1(OutPoint.from(cellDep.outPoint), depTypeFrom(cellDep.depType));
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
CellDep = CellDep_1 = __decorate([
|
|
464
|
+
mol.codec(mol.struct({
|
|
465
|
+
outPoint: OutPoint,
|
|
466
|
+
depType: DepTypeCodec,
|
|
467
|
+
}))
|
|
468
|
+
], CellDep);
|
|
469
|
+
export { CellDep };
|
|
470
|
+
export const CellDepVec = mol.vector(CellDep);
|
|
471
|
+
/**
|
|
472
|
+
* @public
|
|
473
|
+
*/
|
|
474
|
+
let WitnessArgs = WitnessArgs_1 = class WitnessArgs extends mol.Entity.Base() {
|
|
475
|
+
/**
|
|
476
|
+
* Creates an instance of WitnessArgs.
|
|
477
|
+
*
|
|
478
|
+
* @param lock - The optional lock field of the witness.
|
|
479
|
+
* @param inputType - The optional input type field of the witness.
|
|
480
|
+
* @param outputType - The optional output type field of the witness.
|
|
481
|
+
*/
|
|
482
|
+
constructor(lock, inputType, outputType) {
|
|
483
|
+
super();
|
|
484
|
+
this.lock = lock;
|
|
485
|
+
this.inputType = inputType;
|
|
486
|
+
this.outputType = outputType;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Creates a WitnessArgs instance from a WitnessArgsLike object.
|
|
490
|
+
*
|
|
491
|
+
* @param witnessArgs - A WitnessArgsLike object or an instance of WitnessArgs.
|
|
492
|
+
* @returns A WitnessArgs instance.
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* ```typescript
|
|
496
|
+
* const witnessArgs = WitnessArgs.from({
|
|
497
|
+
* lock: "0x...",
|
|
498
|
+
* inputType: "0x...",
|
|
499
|
+
* outputType: "0x..."
|
|
500
|
+
* });
|
|
501
|
+
* ```
|
|
502
|
+
*/
|
|
503
|
+
static from(witnessArgs) {
|
|
504
|
+
if (witnessArgs instanceof WitnessArgs_1) {
|
|
505
|
+
return witnessArgs;
|
|
506
|
+
}
|
|
507
|
+
return new WitnessArgs_1(apply(hexFrom, witnessArgs.lock), apply(hexFrom, witnessArgs.inputType), apply(hexFrom, witnessArgs.outputType));
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
WitnessArgs = WitnessArgs_1 = __decorate([
|
|
511
|
+
mol.codec(mol.table({
|
|
512
|
+
lock: mol.BytesOpt,
|
|
513
|
+
inputType: mol.BytesOpt,
|
|
514
|
+
outputType: mol.BytesOpt,
|
|
515
|
+
}))
|
|
516
|
+
], WitnessArgs);
|
|
517
|
+
export { WitnessArgs };
|
|
518
|
+
/**
|
|
519
|
+
* @public
|
|
520
|
+
*/
|
|
521
|
+
export function udtBalanceFrom(dataLike) {
|
|
522
|
+
const data = bytesFrom(dataLike).slice(0, 16);
|
|
523
|
+
return numFromBytes(data);
|
|
524
|
+
}
|
|
525
|
+
export const RawTransaction = mol.table({
|
|
526
|
+
version: mol.Uint32,
|
|
527
|
+
cellDeps: CellDepVec,
|
|
528
|
+
headerDeps: mol.Byte32Vec,
|
|
529
|
+
inputs: CellInputVec,
|
|
530
|
+
outputs: CellOutputVec,
|
|
531
|
+
outputsData: mol.BytesVec,
|
|
532
|
+
});
|
|
533
|
+
/**
|
|
534
|
+
* @public
|
|
535
|
+
*/
|
|
536
|
+
let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
|
|
537
|
+
/**
|
|
538
|
+
* Creates an instance of Transaction.
|
|
539
|
+
*
|
|
540
|
+
* @param version - The version of the transaction.
|
|
541
|
+
* @param cellDeps - The cell dependencies of the transaction.
|
|
542
|
+
* @param headerDeps - The header dependencies of the transaction.
|
|
543
|
+
* @param inputs - The inputs of the transaction.
|
|
544
|
+
* @param outputs - The outputs of the transaction.
|
|
545
|
+
* @param outputsData - The data associated with the outputs.
|
|
546
|
+
* @param witnesses - The witnesses of the transaction.
|
|
547
|
+
*/
|
|
548
|
+
constructor(version, cellDeps, headerDeps, inputs, outputs, outputsData, witnesses) {
|
|
549
|
+
super();
|
|
550
|
+
this.version = version;
|
|
551
|
+
this.cellDeps = cellDeps;
|
|
552
|
+
this.headerDeps = headerDeps;
|
|
553
|
+
this.inputs = inputs;
|
|
554
|
+
this.outputs = outputs;
|
|
555
|
+
this.outputsData = outputsData;
|
|
556
|
+
this.witnesses = witnesses;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Creates a default Transaction instance with empty fields.
|
|
560
|
+
*
|
|
561
|
+
* @returns A default Transaction instance.
|
|
562
|
+
*
|
|
563
|
+
* @example
|
|
564
|
+
* ```typescript
|
|
565
|
+
* const defaultTx = Transaction.default();
|
|
566
|
+
* ```
|
|
567
|
+
*/
|
|
568
|
+
static default() {
|
|
569
|
+
return new Transaction_1(0n, [], [], [], [], [], []);
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Copy every properties from another transaction.
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* ```typescript
|
|
576
|
+
* this.copy(Transaction.default());
|
|
577
|
+
* ```
|
|
578
|
+
*/
|
|
579
|
+
copy(txLike) {
|
|
580
|
+
const tx = Transaction_1.from(txLike);
|
|
581
|
+
this.version = tx.version;
|
|
582
|
+
this.cellDeps = tx.cellDeps;
|
|
583
|
+
this.headerDeps = tx.headerDeps;
|
|
584
|
+
this.inputs = tx.inputs;
|
|
585
|
+
this.outputs = tx.outputs;
|
|
586
|
+
this.outputsData = tx.outputsData;
|
|
587
|
+
this.witnesses = tx.witnesses;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Creates a Transaction instance from a TransactionLike object.
|
|
591
|
+
*
|
|
592
|
+
* @param tx - A TransactionLike object or an instance of Transaction.
|
|
593
|
+
* @returns A Transaction instance.
|
|
594
|
+
*
|
|
595
|
+
* @example
|
|
596
|
+
* ```typescript
|
|
597
|
+
* const transaction = Transaction.from({
|
|
598
|
+
* version: 0,
|
|
599
|
+
* cellDeps: [],
|
|
600
|
+
* headerDeps: [],
|
|
601
|
+
* inputs: [],
|
|
602
|
+
* outputs: [],
|
|
603
|
+
* outputsData: [],
|
|
604
|
+
* witnesses: []
|
|
605
|
+
* });
|
|
606
|
+
* ```
|
|
607
|
+
*/
|
|
608
|
+
static from(tx) {
|
|
609
|
+
if (tx instanceof Transaction_1) {
|
|
610
|
+
return tx;
|
|
611
|
+
}
|
|
612
|
+
const outputs = tx.outputs?.map((output, i) => {
|
|
613
|
+
const o = CellOutput.from({
|
|
614
|
+
...output,
|
|
615
|
+
capacity: output.capacity ?? 0,
|
|
616
|
+
});
|
|
617
|
+
if (o.capacity === Zero) {
|
|
618
|
+
o.capacity = fixedPointFrom(o.occupiedSize +
|
|
619
|
+
(apply(bytesFrom, tx.outputsData?.[i])?.length ?? 0));
|
|
620
|
+
}
|
|
621
|
+
return o;
|
|
622
|
+
}) ?? [];
|
|
623
|
+
const outputsData = outputs.map((_, i) => hexFrom(tx.outputsData?.[i] ?? "0x"));
|
|
624
|
+
if (tx.outputsData != null && outputsData.length < tx.outputsData.length) {
|
|
625
|
+
outputsData.push(...tx.outputsData.slice(outputsData.length).map((d) => hexFrom(d)));
|
|
626
|
+
}
|
|
627
|
+
return new Transaction_1(numFrom(tx.version ?? 0), tx.cellDeps?.map((cellDep) => CellDep.from(cellDep)) ?? [], tx.headerDeps?.map(hexFrom) ?? [], tx.inputs?.map((input) => CellInput.from(input)) ?? [], outputs, outputsData, tx.witnesses?.map(hexFrom) ?? []);
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Creates a Transaction instance from a Lumos skeleton.
|
|
631
|
+
*
|
|
632
|
+
* @param skeleton - The Lumos transaction skeleton.
|
|
633
|
+
* @returns A Transaction instance.
|
|
634
|
+
*
|
|
635
|
+
* @throws Will throw an error if an input's outPoint is missing.
|
|
636
|
+
*
|
|
637
|
+
* @example
|
|
638
|
+
* ```typescript
|
|
639
|
+
* const transaction = Transaction.fromLumosSkeleton(skeleton);
|
|
640
|
+
* ```
|
|
641
|
+
*/
|
|
642
|
+
static fromLumosSkeleton(skeleton) {
|
|
643
|
+
return Transaction_1.from({
|
|
644
|
+
version: 0n,
|
|
645
|
+
cellDeps: skeleton.cellDeps.toArray(),
|
|
646
|
+
headerDeps: skeleton.headerDeps.toArray(),
|
|
647
|
+
inputs: skeleton.inputs.toArray().map((input, i) => {
|
|
648
|
+
if (!input.outPoint) {
|
|
649
|
+
throw new Error("outPoint is required in input");
|
|
650
|
+
}
|
|
651
|
+
return CellInput.from({
|
|
652
|
+
previousOutput: input.outPoint,
|
|
653
|
+
since: skeleton.inputSinces.get(i, "0x0"),
|
|
654
|
+
cellOutput: input.cellOutput,
|
|
655
|
+
outputData: input.data,
|
|
656
|
+
});
|
|
657
|
+
}),
|
|
658
|
+
outputs: skeleton.outputs.toArray().map((output) => output.cellOutput),
|
|
659
|
+
outputsData: skeleton.outputs.toArray().map((output) => output.data),
|
|
660
|
+
witnesses: skeleton.witnesses.toArray(),
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* @deprecated
|
|
665
|
+
* Use ccc.stringify instead.
|
|
666
|
+
* stringify the tx to JSON string.
|
|
667
|
+
*/
|
|
668
|
+
stringify() {
|
|
669
|
+
return JSON.stringify(this, (_, value) => {
|
|
670
|
+
if (typeof value === "bigint") {
|
|
671
|
+
return numToHex(value);
|
|
672
|
+
}
|
|
673
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
674
|
+
return value;
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Converts the raw transaction data to bytes.
|
|
679
|
+
*
|
|
680
|
+
* @returns A Uint8Array containing the raw transaction bytes.
|
|
681
|
+
*
|
|
682
|
+
* @example
|
|
683
|
+
* ```typescript
|
|
684
|
+
* const rawTxBytes = transaction.rawToBytes();
|
|
685
|
+
* ```
|
|
686
|
+
*/
|
|
687
|
+
rawToBytes() {
|
|
688
|
+
return RawTransaction.encode(this);
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Calculates the hash of the transaction without witnesses. This is the transaction hash in the usual sense.
|
|
692
|
+
* To calculate the hash of the whole transaction including the witnesses, use transaction.hashFull() instead.
|
|
693
|
+
*
|
|
694
|
+
* @returns The hash of the transaction.
|
|
695
|
+
*
|
|
696
|
+
* @example
|
|
697
|
+
* ```typescript
|
|
698
|
+
* const txHash = transaction.hash();
|
|
699
|
+
* ```
|
|
700
|
+
*/
|
|
701
|
+
hash() {
|
|
702
|
+
return hashCkb(this.rawToBytes());
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Calculates the hash of the transaction with witnesses.
|
|
706
|
+
*
|
|
707
|
+
* @returns The hash of the transaction with witnesses.
|
|
708
|
+
*
|
|
709
|
+
* @example
|
|
710
|
+
* ```typescript
|
|
711
|
+
* const txFullHash = transaction.hashFull();
|
|
712
|
+
* ```
|
|
713
|
+
*/
|
|
714
|
+
hashFull() {
|
|
715
|
+
return hashCkb(this.toBytes());
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Hashes a witness and updates the hasher.
|
|
719
|
+
*
|
|
720
|
+
* @param witness - The witness to hash.
|
|
721
|
+
* @param hasher - The hasher instance to update.
|
|
722
|
+
*
|
|
723
|
+
* @example
|
|
724
|
+
* ```typescript
|
|
725
|
+
* Transaction.hashWitnessToHasher("0x...", hasher);
|
|
726
|
+
* ```
|
|
727
|
+
*/
|
|
728
|
+
static hashWitnessToHasher(witness, hasher) {
|
|
729
|
+
const raw = bytesFrom(hexFrom(witness));
|
|
730
|
+
hasher.update(numToBytes(raw.length, 8));
|
|
731
|
+
hasher.update(raw);
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Computes the signing hash information for a given script.
|
|
735
|
+
*
|
|
736
|
+
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
737
|
+
* @param client - The client for complete extra infos in the transaction.
|
|
738
|
+
* @returns A promise that resolves to an object containing the signing message and the witness position,
|
|
739
|
+
* or undefined if no matching input is found.
|
|
740
|
+
*
|
|
741
|
+
* @example
|
|
742
|
+
* ```typescript
|
|
743
|
+
* const signHashInfo = await tx.getSignHashInfo(scriptLike, client);
|
|
744
|
+
* if (signHashInfo) {
|
|
745
|
+
* console.log(signHashInfo.message); // Outputs the signing message
|
|
746
|
+
* console.log(signHashInfo.position); // Outputs the witness position
|
|
747
|
+
* }
|
|
748
|
+
* ```
|
|
749
|
+
*/
|
|
750
|
+
async getSignHashInfo(scriptLike, client, hasher = new HasherCkb()) {
|
|
751
|
+
const script = Script.from(scriptLike);
|
|
752
|
+
let position = -1;
|
|
753
|
+
hasher.update(this.hash());
|
|
754
|
+
for (let i = 0; i < this.witnesses.length; i += 1) {
|
|
755
|
+
const input = this.inputs[i];
|
|
756
|
+
if (input) {
|
|
757
|
+
await input.completeExtraInfos(client);
|
|
758
|
+
if (!input.cellOutput) {
|
|
759
|
+
throw new Error("Unable to complete input");
|
|
760
|
+
}
|
|
761
|
+
if (!script.eq(input.cellOutput.lock)) {
|
|
762
|
+
continue;
|
|
763
|
+
}
|
|
764
|
+
if (position === -1) {
|
|
765
|
+
position = i;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
if (position === -1) {
|
|
769
|
+
return undefined;
|
|
770
|
+
}
|
|
771
|
+
Transaction_1.hashWitnessToHasher(this.witnesses[i], hasher);
|
|
772
|
+
}
|
|
773
|
+
if (position === -1) {
|
|
774
|
+
return undefined;
|
|
775
|
+
}
|
|
776
|
+
return {
|
|
777
|
+
message: hasher.digest(),
|
|
778
|
+
position,
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Find the first occurrence of a input with the specified lock id
|
|
783
|
+
*
|
|
784
|
+
* @param scriptIdLike - The script associated with the transaction, represented as a ScriptLike object without args.
|
|
785
|
+
* @param client - The client for complete extra infos in the transaction.
|
|
786
|
+
* @returns A promise that resolves to the found index
|
|
787
|
+
*
|
|
788
|
+
* @example
|
|
789
|
+
* ```typescript
|
|
790
|
+
* const index = await tx.findInputIndexByLockId(scriptIdLike, client);
|
|
791
|
+
* ```
|
|
792
|
+
*/
|
|
793
|
+
async findInputIndexByLockId(scriptIdLike, client) {
|
|
794
|
+
const script = Script.from({ ...scriptIdLike, args: "0x" });
|
|
795
|
+
for (let i = 0; i < this.inputs.length; i += 1) {
|
|
796
|
+
const input = this.inputs[i];
|
|
797
|
+
await input.completeExtraInfos(client);
|
|
798
|
+
if (!input.cellOutput) {
|
|
799
|
+
throw new Error("Unable to complete input");
|
|
800
|
+
}
|
|
801
|
+
if (script.codeHash === input.cellOutput.lock.codeHash &&
|
|
802
|
+
script.hashType === input.cellOutput.lock.hashType) {
|
|
803
|
+
return i;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Find the first occurrence of a input with the specified lock
|
|
809
|
+
*
|
|
810
|
+
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
811
|
+
* @param client - The client for complete extra infos in the transaction.
|
|
812
|
+
* @returns A promise that resolves to the prepared transaction
|
|
813
|
+
*
|
|
814
|
+
* @example
|
|
815
|
+
* ```typescript
|
|
816
|
+
* const index = await tx.findInputIndexByLock(scriptLike, client);
|
|
817
|
+
* ```
|
|
818
|
+
*/
|
|
819
|
+
async findInputIndexByLock(scriptLike, client) {
|
|
820
|
+
const script = Script.from(scriptLike);
|
|
821
|
+
for (let i = 0; i < this.inputs.length; i += 1) {
|
|
822
|
+
const input = this.inputs[i];
|
|
823
|
+
await input.completeExtraInfos(client);
|
|
824
|
+
if (!input.cellOutput) {
|
|
825
|
+
throw new Error("Unable to complete input");
|
|
826
|
+
}
|
|
827
|
+
if (script.eq(input.cellOutput.lock)) {
|
|
828
|
+
return i;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Find the last occurrence of a input with the specified lock
|
|
834
|
+
*
|
|
835
|
+
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
836
|
+
* @param client - The client for complete extra infos in the transaction.
|
|
837
|
+
* @returns A promise that resolves to the prepared transaction
|
|
838
|
+
*
|
|
839
|
+
* @example
|
|
840
|
+
* ```typescript
|
|
841
|
+
* const index = await tx.findLastInputIndexByLock(scriptLike, client);
|
|
842
|
+
* ```
|
|
843
|
+
*/
|
|
844
|
+
async findLastInputIndexByLock(scriptLike, client) {
|
|
845
|
+
const script = Script.from(scriptLike);
|
|
846
|
+
for (let i = this.inputs.length - 1; i >= 0; i -= 1) {
|
|
847
|
+
const input = this.inputs[i];
|
|
848
|
+
await input.completeExtraInfos(client);
|
|
849
|
+
if (!input.cellOutput) {
|
|
850
|
+
throw new Error("Unable to complete input");
|
|
851
|
+
}
|
|
852
|
+
if (script.eq(input.cellOutput.lock)) {
|
|
853
|
+
return i;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* Add cell deps if they are not existed
|
|
859
|
+
*
|
|
860
|
+
* @param cellDepLikes - The cell deps to add
|
|
861
|
+
*
|
|
862
|
+
* @example
|
|
863
|
+
* ```typescript
|
|
864
|
+
* tx.addCellDeps(cellDep);
|
|
865
|
+
* ```
|
|
866
|
+
*/
|
|
867
|
+
addCellDeps(...cellDepLikes) {
|
|
868
|
+
cellDepLikes.flat().forEach((cellDepLike) => {
|
|
869
|
+
const cellDep = CellDep.from(cellDepLike);
|
|
870
|
+
if (this.cellDeps.some((c) => c.eq(cellDep))) {
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
this.cellDeps.push(cellDep);
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* Add cell deps at the start if they are not existed
|
|
878
|
+
*
|
|
879
|
+
* @param cellDepLikes - The cell deps to add
|
|
880
|
+
*
|
|
881
|
+
* @example
|
|
882
|
+
* ```typescript
|
|
883
|
+
* tx.addCellDepsAtBegin(cellDep);
|
|
884
|
+
* ```
|
|
885
|
+
*/
|
|
886
|
+
addCellDepsAtStart(...cellDepLikes) {
|
|
887
|
+
cellDepLikes.flat().forEach((cellDepLike) => {
|
|
888
|
+
const cellDep = CellDep.from(cellDepLike);
|
|
889
|
+
if (this.cellDeps.some((c) => c.eq(cellDep))) {
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
this.cellDeps.unshift(cellDep);
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Add cell dep from infos if they are not existed
|
|
897
|
+
*
|
|
898
|
+
* @param client - A client for searching cell deps
|
|
899
|
+
* @param cellDepInfoLikes - The cell dep infos to add
|
|
900
|
+
*
|
|
901
|
+
* @example
|
|
902
|
+
* ```typescript
|
|
903
|
+
* tx.addCellDepInfos(client, cellDepInfos);
|
|
904
|
+
* ```
|
|
905
|
+
*/
|
|
906
|
+
async addCellDepInfos(client, ...cellDepInfoLikes) {
|
|
907
|
+
this.addCellDeps(await client.getCellDeps(...cellDepInfoLikes));
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* Add cell deps from known script
|
|
911
|
+
*
|
|
912
|
+
* @param client - The client for searching known script and cell deps
|
|
913
|
+
* @param scripts - The known scripts to add
|
|
914
|
+
*
|
|
915
|
+
* @example
|
|
916
|
+
* ```typescript
|
|
917
|
+
* tx.addCellDepsOfKnownScripts(client, KnownScript.OmniLock);
|
|
918
|
+
* ```
|
|
919
|
+
*/
|
|
920
|
+
async addCellDepsOfKnownScripts(client, ...scripts) {
|
|
921
|
+
await Promise.all(scripts
|
|
922
|
+
.flat()
|
|
923
|
+
.map(async (script) => this.addCellDepInfos(client, (await client.getKnownScript(script)).cellDeps)));
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* Set output data at index.
|
|
927
|
+
*
|
|
928
|
+
* @param index - The index of the output data.
|
|
929
|
+
* @param witness - The data to set.
|
|
930
|
+
*
|
|
931
|
+
* @example
|
|
932
|
+
* ```typescript
|
|
933
|
+
* await tx.setOutputDataAt(0, "0x00");
|
|
934
|
+
* ```
|
|
935
|
+
*/
|
|
936
|
+
setOutputDataAt(index, witness) {
|
|
937
|
+
if (this.outputsData.length < index) {
|
|
938
|
+
this.outputsData.push(...Array.from(new Array(index - this.outputsData.length), () => "0x"));
|
|
939
|
+
}
|
|
940
|
+
this.outputsData[index] = hexFrom(witness);
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
* get input
|
|
944
|
+
*
|
|
945
|
+
* @param index - The cell input index
|
|
946
|
+
*
|
|
947
|
+
* @example
|
|
948
|
+
* ```typescript
|
|
949
|
+
* await tx.getInput(0);
|
|
950
|
+
* ```
|
|
951
|
+
*/
|
|
952
|
+
getInput(index) {
|
|
953
|
+
return this.inputs[Number(numFrom(index))];
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* add input
|
|
957
|
+
*
|
|
958
|
+
* @param inputLike - The cell input.
|
|
959
|
+
*
|
|
960
|
+
* @example
|
|
961
|
+
* ```typescript
|
|
962
|
+
* await tx.addInput({ });
|
|
963
|
+
* ```
|
|
964
|
+
*/
|
|
965
|
+
addInput(inputLike) {
|
|
966
|
+
return this.inputs.push(CellInput.from(inputLike));
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* get output
|
|
970
|
+
*
|
|
971
|
+
* @param index - The cell output index
|
|
972
|
+
*
|
|
973
|
+
* @example
|
|
974
|
+
* ```typescript
|
|
975
|
+
* await tx.getOutput(0);
|
|
976
|
+
* ```
|
|
977
|
+
*/
|
|
978
|
+
getOutput(index) {
|
|
979
|
+
const i = Number(numFrom(index));
|
|
980
|
+
if (i >= this.outputs.length) {
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
return {
|
|
984
|
+
cellOutput: this.outputs[i],
|
|
985
|
+
outputData: this.outputsData[i] ?? "0x",
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Add output
|
|
990
|
+
*
|
|
991
|
+
* @param outputLike - The cell output to add
|
|
992
|
+
* @param outputData - optional output data
|
|
993
|
+
*
|
|
994
|
+
* @example
|
|
995
|
+
* ```typescript
|
|
996
|
+
* await tx.addOutput(cellOutput, "0xabcd");
|
|
997
|
+
* ```
|
|
998
|
+
*/
|
|
999
|
+
addOutput(outputLike, outputData = "0x") {
|
|
1000
|
+
const output = CellOutput.from({
|
|
1001
|
+
...outputLike,
|
|
1002
|
+
capacity: outputLike.capacity ?? 0,
|
|
1003
|
+
});
|
|
1004
|
+
if (output.capacity === Zero) {
|
|
1005
|
+
output.capacity = fixedPointFrom(output.occupiedSize + bytesFrom(outputData).length);
|
|
1006
|
+
}
|
|
1007
|
+
const len = this.outputs.push(output);
|
|
1008
|
+
this.setOutputDataAt(len - 1, outputData);
|
|
1009
|
+
return len;
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* Get witness at index as WitnessArgs
|
|
1013
|
+
*
|
|
1014
|
+
* @param index - The index of the witness.
|
|
1015
|
+
* @returns The witness parsed as WitnessArgs.
|
|
1016
|
+
*
|
|
1017
|
+
* @example
|
|
1018
|
+
* ```typescript
|
|
1019
|
+
* const witnessArgs = await tx.getWitnessArgsAt(0);
|
|
1020
|
+
* ```
|
|
1021
|
+
*/
|
|
1022
|
+
getWitnessArgsAt(index) {
|
|
1023
|
+
const rawWitness = this.witnesses[index];
|
|
1024
|
+
return (rawWitness ?? "0x") !== "0x"
|
|
1025
|
+
? WitnessArgs.fromBytes(rawWitness)
|
|
1026
|
+
: undefined;
|
|
1027
|
+
}
|
|
1028
|
+
/**
|
|
1029
|
+
* Set witness at index by WitnessArgs
|
|
1030
|
+
*
|
|
1031
|
+
* @param index - The index of the witness.
|
|
1032
|
+
* @param witness - The WitnessArgs to set.
|
|
1033
|
+
*
|
|
1034
|
+
* @example
|
|
1035
|
+
* ```typescript
|
|
1036
|
+
* await tx.setWitnessArgsAt(0, witnessArgs);
|
|
1037
|
+
* ```
|
|
1038
|
+
*/
|
|
1039
|
+
setWitnessArgsAt(index, witness) {
|
|
1040
|
+
if (this.witnesses.length < index) {
|
|
1041
|
+
this.witnesses.push(...Array.from(new Array(index - this.witnesses.length), () => "0x"));
|
|
1042
|
+
}
|
|
1043
|
+
this.witnesses[index] = hexFrom(witness.toBytes());
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Prepare dummy witness for sighash all method
|
|
1047
|
+
*
|
|
1048
|
+
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
1049
|
+
* @param lockLen - The length of dummy lock bytes.
|
|
1050
|
+
* @param client - The client for complete extra infos in the transaction.
|
|
1051
|
+
* @returns A promise that resolves to the prepared transaction
|
|
1052
|
+
*
|
|
1053
|
+
* @example
|
|
1054
|
+
* ```typescript
|
|
1055
|
+
* await tx.prepareSighashAllWitness(scriptLike, 85, client);
|
|
1056
|
+
* ```
|
|
1057
|
+
*/
|
|
1058
|
+
async prepareSighashAllWitness(scriptLike, lockLen, client) {
|
|
1059
|
+
const position = await this.findInputIndexByLock(scriptLike, client);
|
|
1060
|
+
if (position === undefined) {
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
const witness = this.getWitnessArgsAt(position) ?? WitnessArgs.from({});
|
|
1064
|
+
witness.lock = hexFrom(Array.from(new Array(lockLen), () => 0));
|
|
1065
|
+
this.setWitnessArgsAt(position, witness);
|
|
1066
|
+
}
|
|
1067
|
+
async getInputsCapacity(client) {
|
|
1068
|
+
return reduceAsync(this.inputs, async (acc, input) => {
|
|
1069
|
+
await input.completeExtraInfos(client);
|
|
1070
|
+
if (!input.cellOutput) {
|
|
1071
|
+
throw new Error("Unable to complete input");
|
|
1072
|
+
}
|
|
1073
|
+
return acc + input.cellOutput.capacity;
|
|
1074
|
+
}, numFrom(0));
|
|
1075
|
+
}
|
|
1076
|
+
getOutputsCapacity() {
|
|
1077
|
+
return this.outputs.reduce((acc, { capacity }) => acc + capacity, numFrom(0));
|
|
1078
|
+
}
|
|
1079
|
+
async getInputsUdtBalance(client, type) {
|
|
1080
|
+
return reduceAsync(this.inputs, async (acc, input) => {
|
|
1081
|
+
await input.completeExtraInfos(client);
|
|
1082
|
+
if (!input.cellOutput || !input.outputData) {
|
|
1083
|
+
throw new Error("Unable to complete input");
|
|
1084
|
+
}
|
|
1085
|
+
if (!input.cellOutput.type?.eq(type)) {
|
|
1086
|
+
return;
|
|
1087
|
+
}
|
|
1088
|
+
return acc + udtBalanceFrom(input.outputData);
|
|
1089
|
+
}, numFrom(0));
|
|
1090
|
+
}
|
|
1091
|
+
getOutputsUdtBalance(type) {
|
|
1092
|
+
return this.outputs.reduce((acc, output, i) => {
|
|
1093
|
+
if (!output.type?.eq(type)) {
|
|
1094
|
+
return acc;
|
|
1095
|
+
}
|
|
1096
|
+
return acc + udtBalanceFrom(this.outputsData[i]);
|
|
1097
|
+
}, numFrom(0));
|
|
1098
|
+
}
|
|
1099
|
+
async completeInputs(from, filter, accumulator, init) {
|
|
1100
|
+
const collectedCells = [];
|
|
1101
|
+
let acc = init;
|
|
1102
|
+
let fulfilled = false;
|
|
1103
|
+
for await (const cell of from.findCells(filter, true)) {
|
|
1104
|
+
if (this.inputs.some(({ previousOutput }) => previousOutput.eq(cell.outPoint))) {
|
|
1105
|
+
continue;
|
|
1106
|
+
}
|
|
1107
|
+
const i = collectedCells.push(cell);
|
|
1108
|
+
const next = await Promise.resolve(accumulator(acc, cell, i - 1, collectedCells));
|
|
1109
|
+
if (next === undefined) {
|
|
1110
|
+
fulfilled = true;
|
|
1111
|
+
break;
|
|
1112
|
+
}
|
|
1113
|
+
acc = next;
|
|
1114
|
+
}
|
|
1115
|
+
collectedCells.forEach((cell) => this.addInput(cell));
|
|
1116
|
+
if (fulfilled) {
|
|
1117
|
+
return {
|
|
1118
|
+
addedCount: collectedCells.length,
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
return {
|
|
1122
|
+
addedCount: collectedCells.length,
|
|
1123
|
+
accumulated: acc,
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
async completeInputsByCapacity(from, capacityTweak, filter) {
|
|
1127
|
+
const exceptedCapacity = this.getOutputsCapacity() + numFrom(capacityTweak ?? 0);
|
|
1128
|
+
const inputsCapacity = await this.getInputsCapacity(from.client);
|
|
1129
|
+
if (inputsCapacity >= exceptedCapacity) {
|
|
1130
|
+
return 0;
|
|
1131
|
+
}
|
|
1132
|
+
const { addedCount, accumulated } = await this.completeInputs(from, filter ?? {
|
|
1133
|
+
scriptLenRange: [0, 1],
|
|
1134
|
+
outputDataLenRange: [0, 1],
|
|
1135
|
+
}, (acc, { cellOutput: { capacity } }) => {
|
|
1136
|
+
const sum = acc + capacity;
|
|
1137
|
+
return sum >= exceptedCapacity ? undefined : sum;
|
|
1138
|
+
}, inputsCapacity);
|
|
1139
|
+
if (accumulated === undefined) {
|
|
1140
|
+
return addedCount;
|
|
1141
|
+
}
|
|
1142
|
+
throw new Error(`Insufficient CKB, need ${fixedPointToString(exceptedCapacity - accumulated)} extra CKB`);
|
|
1143
|
+
}
|
|
1144
|
+
async completeInputsAll(from, filter) {
|
|
1145
|
+
const { addedCount } = await this.completeInputs(from, filter ?? {
|
|
1146
|
+
scriptLenRange: [0, 1],
|
|
1147
|
+
outputDataLenRange: [0, 1],
|
|
1148
|
+
}, (acc, { cellOutput: { capacity } }) => acc + capacity, Zero);
|
|
1149
|
+
return addedCount;
|
|
1150
|
+
}
|
|
1151
|
+
async completeInputsByUdt(from, type, balanceTweak) {
|
|
1152
|
+
const exceptedBalance = this.getOutputsUdtBalance(type) + numFrom(balanceTweak ?? 0);
|
|
1153
|
+
const inputsBalance = await this.getInputsUdtBalance(from.client, type);
|
|
1154
|
+
if (inputsBalance >= exceptedBalance) {
|
|
1155
|
+
return 0;
|
|
1156
|
+
}
|
|
1157
|
+
const { addedCount, accumulated } = await this.completeInputs(from, {
|
|
1158
|
+
script: type,
|
|
1159
|
+
outputDataLenRange: [16, numFrom("0xffffffff")],
|
|
1160
|
+
}, (acc, { outputData }) => {
|
|
1161
|
+
const balance = udtBalanceFrom(outputData);
|
|
1162
|
+
const sum = acc + balance;
|
|
1163
|
+
return sum >= exceptedBalance ? undefined : sum;
|
|
1164
|
+
}, inputsBalance);
|
|
1165
|
+
if (accumulated === undefined) {
|
|
1166
|
+
return addedCount;
|
|
1167
|
+
}
|
|
1168
|
+
throw new Error(`Insufficient coin, need ${exceptedBalance - accumulated} extra coin`);
|
|
1169
|
+
}
|
|
1170
|
+
async completeInputsAddOne(from, filter) {
|
|
1171
|
+
for await (const cell of from.findCells(filter ?? {
|
|
1172
|
+
scriptLenRange: [0, 1],
|
|
1173
|
+
outputDataLenRange: [0, 1],
|
|
1174
|
+
}, true, undefined, 1)) {
|
|
1175
|
+
if (this.inputs.some(({ previousOutput }) => previousOutput.eq(cell.outPoint))) {
|
|
1176
|
+
continue;
|
|
1177
|
+
}
|
|
1178
|
+
this.addInput(cell);
|
|
1179
|
+
return 1;
|
|
1180
|
+
}
|
|
1181
|
+
throw new Error(`Insufficient CKB, need at least one new cell`);
|
|
1182
|
+
}
|
|
1183
|
+
async completeInputsAtLeastOne(from, filter) {
|
|
1184
|
+
if (this.inputs.length > 0) {
|
|
1185
|
+
return 0;
|
|
1186
|
+
}
|
|
1187
|
+
return this.completeInputsAddOne(from, filter);
|
|
1188
|
+
}
|
|
1189
|
+
async fee(client) {
|
|
1190
|
+
return (await this.getInputsCapacity(client)) - this.getOutputsCapacity();
|
|
1191
|
+
}
|
|
1192
|
+
async feeRate(client) {
|
|
1193
|
+
return (((await this.fee(client)) * numFrom(1000)) /
|
|
1194
|
+
numFrom(this.toBytes().length + 4));
|
|
1195
|
+
}
|
|
1196
|
+
estimateFee(feeRate) {
|
|
1197
|
+
const txSize = this.toBytes().length + 4;
|
|
1198
|
+
// + 999 then / 1000 to ceil the calculated fee
|
|
1199
|
+
return (numFrom(txSize) * numFrom(feeRate) + numFrom(999)) / numFrom(1000);
|
|
1200
|
+
}
|
|
1201
|
+
async completeFee(from, change, expectedFeeRate, filter, options) {
|
|
1202
|
+
const feeRate = expectedFeeRate ??
|
|
1203
|
+
(await from.client.getFeeRate(options?.feeRateBlockRange, options));
|
|
1204
|
+
// Complete all inputs extra infos for cache
|
|
1205
|
+
await this.getInputsCapacity(from.client);
|
|
1206
|
+
let leastFee = Zero;
|
|
1207
|
+
let leastExtraCapacity = Zero;
|
|
1208
|
+
while (true) {
|
|
1209
|
+
const tx = this.clone();
|
|
1210
|
+
const collected = await (async () => {
|
|
1211
|
+
try {
|
|
1212
|
+
return await tx.completeInputsByCapacity(from, leastFee + leastExtraCapacity, filter);
|
|
1213
|
+
}
|
|
1214
|
+
catch (err) {
|
|
1215
|
+
if (leastExtraCapacity !== Zero) {
|
|
1216
|
+
throw new Error("Not enough capacity for the change cell");
|
|
1217
|
+
}
|
|
1218
|
+
throw err;
|
|
1219
|
+
}
|
|
1220
|
+
})();
|
|
1221
|
+
await from.prepareTransaction(tx);
|
|
1222
|
+
if (leastFee === Zero) {
|
|
1223
|
+
// The initial fee is calculated based on prepared transaction
|
|
1224
|
+
leastFee = tx.estimateFee(feeRate);
|
|
1225
|
+
}
|
|
1226
|
+
const fee = await tx.fee(from.client);
|
|
1227
|
+
// The extra capacity paid the fee without a change
|
|
1228
|
+
if (fee === leastFee) {
|
|
1229
|
+
this.copy(tx);
|
|
1230
|
+
return [collected, false];
|
|
1231
|
+
}
|
|
1232
|
+
const needed = numFrom(await Promise.resolve(change(tx, fee - leastFee)));
|
|
1233
|
+
// No enough extra capacity to create new cells for change
|
|
1234
|
+
if (needed > Zero) {
|
|
1235
|
+
leastExtraCapacity = needed;
|
|
1236
|
+
continue;
|
|
1237
|
+
}
|
|
1238
|
+
if ((await tx.fee(from.client)) !== leastFee) {
|
|
1239
|
+
throw new Error("The change function doesn't use all available capacity");
|
|
1240
|
+
}
|
|
1241
|
+
// New change cells created, update the fee
|
|
1242
|
+
await from.prepareTransaction(tx);
|
|
1243
|
+
const changedFee = tx.estimateFee(feeRate);
|
|
1244
|
+
if (leastFee > changedFee) {
|
|
1245
|
+
throw new Error("The change function removed existed transaction data");
|
|
1246
|
+
}
|
|
1247
|
+
// The fee has been paid
|
|
1248
|
+
if (leastFee === changedFee) {
|
|
1249
|
+
this.copy(tx);
|
|
1250
|
+
return [collected, true];
|
|
1251
|
+
}
|
|
1252
|
+
// The fee after changing is more than the original fee
|
|
1253
|
+
leastFee = changedFee;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
completeFeeChangeToLock(from, change, feeRate, filter) {
|
|
1257
|
+
const script = Script.from(change);
|
|
1258
|
+
return this.completeFee(from, (tx, capacity) => {
|
|
1259
|
+
const changeCell = CellOutput.from({ capacity: 0, lock: script });
|
|
1260
|
+
const occupiedCapacity = fixedPointFrom(changeCell.occupiedSize);
|
|
1261
|
+
if (capacity < occupiedCapacity) {
|
|
1262
|
+
return occupiedCapacity;
|
|
1263
|
+
}
|
|
1264
|
+
changeCell.capacity = capacity;
|
|
1265
|
+
tx.addOutput(changeCell);
|
|
1266
|
+
return 0;
|
|
1267
|
+
}, feeRate, filter);
|
|
1268
|
+
}
|
|
1269
|
+
async completeFeeBy(from, feeRate, filter) {
|
|
1270
|
+
const { script } = await from.getRecommendedAddressObj();
|
|
1271
|
+
return this.completeFeeChangeToLock(from, script, feeRate, filter);
|
|
1272
|
+
}
|
|
1273
|
+
completeFeeChangeToOutput(from, index, feeRate, filter) {
|
|
1274
|
+
const change = Number(numFrom(index));
|
|
1275
|
+
if (!this.outputs[change]) {
|
|
1276
|
+
throw new Error("Non-existed output to change");
|
|
1277
|
+
}
|
|
1278
|
+
return this.completeFee(from, (tx, capacity) => {
|
|
1279
|
+
tx.outputs[change].capacity += capacity;
|
|
1280
|
+
return 0;
|
|
1281
|
+
}, feeRate, filter);
|
|
1282
|
+
}
|
|
1283
|
+
};
|
|
1284
|
+
Transaction = Transaction_1 = __decorate([
|
|
1285
|
+
mol.codec(mol
|
|
1286
|
+
.table({
|
|
1287
|
+
raw: RawTransaction,
|
|
1288
|
+
witnesses: mol.BytesVec,
|
|
1289
|
+
})
|
|
1290
|
+
.mapIn((txLike) => {
|
|
1291
|
+
const tx = Transaction.from(txLike);
|
|
1292
|
+
return {
|
|
1293
|
+
raw: tx,
|
|
1294
|
+
witnesses: tx.witnesses,
|
|
1295
|
+
};
|
|
1296
|
+
})
|
|
1297
|
+
.mapOut((tx) => Transaction.from({ ...tx.raw, witnesses: tx.witnesses })))
|
|
1298
|
+
], Transaction);
|
|
1299
|
+
export { Transaction };
|