@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,1781 @@
|
|
|
1
|
+
import { Bytes, BytesLike, bytesFrom } from "../bytes/index.js";
|
|
2
|
+
import type { ClientCollectableSearchKeyFilterLike } from "../client/clientTypes.advanced.js";
|
|
3
|
+
import type { CellDepInfoLike, Client, KnownScript } from "../client/index.js";
|
|
4
|
+
import {
|
|
5
|
+
Zero,
|
|
6
|
+
fixedPointFrom,
|
|
7
|
+
fixedPointToString,
|
|
8
|
+
} from "../fixedPoint/index.js";
|
|
9
|
+
import { Hasher, HasherCkb, hashCkb } from "../hasher/index.js";
|
|
10
|
+
import { Hex, HexLike, hexFrom } from "../hex/index.js";
|
|
11
|
+
import { mol } from "../molecule/index.js";
|
|
12
|
+
import {
|
|
13
|
+
Num,
|
|
14
|
+
NumLike,
|
|
15
|
+
numFrom,
|
|
16
|
+
numFromBytes,
|
|
17
|
+
numToBytes,
|
|
18
|
+
numToHex,
|
|
19
|
+
} from "../num/index.js";
|
|
20
|
+
import type { Signer } from "../signer/index.js";
|
|
21
|
+
import { apply, reduceAsync } from "../utils/index.js";
|
|
22
|
+
import { Script, ScriptLike, ScriptOpt } from "./script.js";
|
|
23
|
+
import { DEP_TYPE_TO_NUM, NUM_TO_DEP_TYPE } from "./transaction.advanced.js";
|
|
24
|
+
import type { LumosTransactionSkeletonType } from "./transactionLumos.js";
|
|
25
|
+
|
|
26
|
+
export const DepTypeCodec: mol.Codec<DepTypeLike, DepType> = mol.Codec.from({
|
|
27
|
+
byteLength: 1,
|
|
28
|
+
encode: depTypeToBytes,
|
|
29
|
+
decode: depTypeFromBytes,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export type DepTypeLike = string | number | bigint;
|
|
36
|
+
/**
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
export type DepType = "depGroup" | "code";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Converts a DepTypeLike value to a DepType.
|
|
43
|
+
* @public
|
|
44
|
+
*
|
|
45
|
+
* @param val - The value to convert, which can be a string, number, or bigint.
|
|
46
|
+
* @returns The corresponding DepType.
|
|
47
|
+
*
|
|
48
|
+
* @throws Will throw an error if the input value is not a valid dep type.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const depType = depTypeFrom(1); // Outputs "code"
|
|
53
|
+
* const depType = depTypeFrom("depGroup"); // Outputs "depGroup"
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
export function depTypeFrom(val: DepTypeLike): DepType {
|
|
58
|
+
const depType = (() => {
|
|
59
|
+
if (typeof val === "number") {
|
|
60
|
+
return NUM_TO_DEP_TYPE[val];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (typeof val === "bigint") {
|
|
64
|
+
return NUM_TO_DEP_TYPE[Number(val)];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return val as DepType;
|
|
68
|
+
})();
|
|
69
|
+
if (depType === undefined) {
|
|
70
|
+
throw new Error(`Invalid dep type ${val}`);
|
|
71
|
+
}
|
|
72
|
+
return depType;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Converts a DepTypeLike value to its corresponding byte representation.
|
|
77
|
+
* @public
|
|
78
|
+
*
|
|
79
|
+
* @param depType - The dep type value to convert.
|
|
80
|
+
* @returns A Uint8Array containing the byte representation of the dep type.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const depTypeBytes = depTypeToBytes("code"); // Outputs Uint8Array [1]
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
export function depTypeToBytes(depType: DepTypeLike): Bytes {
|
|
89
|
+
return bytesFrom([DEP_TYPE_TO_NUM[depTypeFrom(depType)]]);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Converts a byte-like value to a DepType.
|
|
94
|
+
* @public
|
|
95
|
+
*
|
|
96
|
+
* @param bytes - The byte-like value to convert.
|
|
97
|
+
* @returns The corresponding DepType.
|
|
98
|
+
*
|
|
99
|
+
* @throws Will throw an error if the input bytes do not correspond to a valid dep type.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* const depType = depTypeFromBytes(new Uint8Array([1])); // Outputs "code"
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
export function depTypeFromBytes(bytes: BytesLike): DepType {
|
|
108
|
+
return NUM_TO_DEP_TYPE[bytesFrom(bytes)[0]];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @public
|
|
113
|
+
*/
|
|
114
|
+
export type OutPointLike = {
|
|
115
|
+
txHash: HexLike;
|
|
116
|
+
index: NumLike;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* @public
|
|
120
|
+
*/
|
|
121
|
+
@mol.codec(
|
|
122
|
+
mol.struct({
|
|
123
|
+
txHash: mol.Byte32,
|
|
124
|
+
index: mol.Uint32,
|
|
125
|
+
}),
|
|
126
|
+
)
|
|
127
|
+
export class OutPoint extends mol.Entity.Base<OutPointLike, OutPoint>() {
|
|
128
|
+
/**
|
|
129
|
+
* Creates an instance of OutPoint.
|
|
130
|
+
*
|
|
131
|
+
* @param txHash - The transaction hash.
|
|
132
|
+
* @param index - The index of the output in the transaction.
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
constructor(
|
|
136
|
+
public txHash: Hex,
|
|
137
|
+
public index: Num,
|
|
138
|
+
) {
|
|
139
|
+
super();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Creates an OutPoint instance from an OutPointLike object.
|
|
144
|
+
*
|
|
145
|
+
* @param outPoint - An OutPointLike object or an instance of OutPoint.
|
|
146
|
+
* @returns An OutPoint instance.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const outPoint = OutPoint.from({ txHash: "0x...", index: 0 });
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
static from(outPoint: OutPointLike): OutPoint {
|
|
154
|
+
if (outPoint instanceof OutPoint) {
|
|
155
|
+
return outPoint;
|
|
156
|
+
}
|
|
157
|
+
return new OutPoint(hexFrom(outPoint.txHash), numFrom(outPoint.index));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @public
|
|
163
|
+
*/
|
|
164
|
+
export type CellOutputLike = {
|
|
165
|
+
capacity: NumLike;
|
|
166
|
+
lock: ScriptLike;
|
|
167
|
+
type?: ScriptLike | null;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* @public
|
|
171
|
+
*/
|
|
172
|
+
@mol.codec(
|
|
173
|
+
mol.table({
|
|
174
|
+
capacity: mol.Uint64,
|
|
175
|
+
lock: Script,
|
|
176
|
+
type: ScriptOpt,
|
|
177
|
+
}),
|
|
178
|
+
)
|
|
179
|
+
export class CellOutput extends mol.Entity.Base<CellOutputLike, CellOutput>() {
|
|
180
|
+
/**
|
|
181
|
+
* Creates an instance of CellOutput.
|
|
182
|
+
*
|
|
183
|
+
* @param capacity - The capacity of the cell.
|
|
184
|
+
* @param lock - The lock script of the cell.
|
|
185
|
+
* @param type - The optional type script of the cell.
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
constructor(
|
|
189
|
+
public capacity: Num,
|
|
190
|
+
public lock: Script,
|
|
191
|
+
public type?: Script,
|
|
192
|
+
) {
|
|
193
|
+
super();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
get occupiedSize(): number {
|
|
197
|
+
return 8 + this.lock.occupiedSize + (this.type?.occupiedSize ?? 0);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Creates a CellOutput instance from a CellOutputLike object.
|
|
202
|
+
*
|
|
203
|
+
* @param cellOutput - A CellOutputLike object or an instance of CellOutput.
|
|
204
|
+
* @returns A CellOutput instance.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* const cellOutput = CellOutput.from({
|
|
209
|
+
* capacity: 1000n,
|
|
210
|
+
* lock: { codeHash: "0x...", hashType: "type", args: "0x..." },
|
|
211
|
+
* type: { codeHash: "0x...", hashType: "type", args: "0x..." }
|
|
212
|
+
* });
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
static from(cellOutput: CellOutputLike): CellOutput {
|
|
216
|
+
if (cellOutput instanceof CellOutput) {
|
|
217
|
+
return cellOutput;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return new CellOutput(
|
|
221
|
+
numFrom(cellOutput.capacity),
|
|
222
|
+
Script.from(cellOutput.lock),
|
|
223
|
+
apply(Script.from, cellOutput.type),
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
export const CellOutputVec = mol.vector(CellOutput);
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @public
|
|
231
|
+
*/
|
|
232
|
+
export type CellLike = (
|
|
233
|
+
| {
|
|
234
|
+
outPoint: OutPointLike;
|
|
235
|
+
}
|
|
236
|
+
| { previousOutput: OutPointLike }
|
|
237
|
+
) & {
|
|
238
|
+
cellOutput: CellOutputLike;
|
|
239
|
+
outputData: HexLike;
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* @public
|
|
243
|
+
*/
|
|
244
|
+
export class Cell {
|
|
245
|
+
/**
|
|
246
|
+
* Creates an instance of Cell.
|
|
247
|
+
*
|
|
248
|
+
* @param outPoint - The output point of the cell.
|
|
249
|
+
* @param cellOutput - The cell output of the cell.
|
|
250
|
+
* @param outputData - The output data of the cell.
|
|
251
|
+
*/
|
|
252
|
+
|
|
253
|
+
constructor(
|
|
254
|
+
public outPoint: OutPoint,
|
|
255
|
+
public cellOutput: CellOutput,
|
|
256
|
+
public outputData: Hex,
|
|
257
|
+
) {}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Creates a Cell instance from a CellLike object.
|
|
261
|
+
*
|
|
262
|
+
* @param cell - A CellLike object or an instance of Cell.
|
|
263
|
+
* @returns A Cell instance.
|
|
264
|
+
*/
|
|
265
|
+
|
|
266
|
+
static from(cell: CellLike): Cell {
|
|
267
|
+
if (cell instanceof Cell) {
|
|
268
|
+
return cell;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return new Cell(
|
|
272
|
+
OutPoint.from("outPoint" in cell ? cell.outPoint : cell.previousOutput),
|
|
273
|
+
CellOutput.from(cell.cellOutput),
|
|
274
|
+
hexFrom(cell.outputData),
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Clone a Cell
|
|
280
|
+
*
|
|
281
|
+
* @returns A cloned Cell instance.
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```typescript
|
|
285
|
+
* const cell1 = cell0.clone();
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
clone(): Cell {
|
|
289
|
+
return new Cell(
|
|
290
|
+
this.outPoint.clone(),
|
|
291
|
+
this.cellOutput.clone(),
|
|
292
|
+
this.outputData,
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* @public
|
|
299
|
+
*/
|
|
300
|
+
export type EpochLike = [NumLike, NumLike, NumLike];
|
|
301
|
+
/**
|
|
302
|
+
* @public
|
|
303
|
+
*/
|
|
304
|
+
export type Epoch = [Num, Num, Num];
|
|
305
|
+
/**
|
|
306
|
+
* @public
|
|
307
|
+
*/
|
|
308
|
+
export function epochFrom(epochLike: EpochLike): Epoch {
|
|
309
|
+
return [numFrom(epochLike[0]), numFrom(epochLike[1]), numFrom(epochLike[2])];
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* @public
|
|
313
|
+
*/
|
|
314
|
+
export function epochFromHex(hex: HexLike): Epoch {
|
|
315
|
+
const num = numFrom(hexFrom(hex));
|
|
316
|
+
|
|
317
|
+
return [
|
|
318
|
+
num & numFrom("0xffffff"),
|
|
319
|
+
(num >> numFrom(24)) & numFrom("0xffff"),
|
|
320
|
+
(num >> numFrom(40)) & numFrom("0xffff"),
|
|
321
|
+
];
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* @public
|
|
325
|
+
*/
|
|
326
|
+
export function epochToHex(epochLike: EpochLike): Hex {
|
|
327
|
+
const epoch = epochFrom(epochLike);
|
|
328
|
+
|
|
329
|
+
return numToHex(
|
|
330
|
+
numFrom(epoch[0]) +
|
|
331
|
+
(numFrom(epoch[1]) << numFrom(24)) +
|
|
332
|
+
(numFrom(epoch[2]) << numFrom(40)),
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* @public
|
|
338
|
+
*/
|
|
339
|
+
export type SinceLike =
|
|
340
|
+
| {
|
|
341
|
+
relative: "absolute" | "relative";
|
|
342
|
+
metric: "blockNumber" | "epoch" | "timestamp";
|
|
343
|
+
value: NumLike;
|
|
344
|
+
}
|
|
345
|
+
| NumLike;
|
|
346
|
+
/**
|
|
347
|
+
* @public
|
|
348
|
+
*/
|
|
349
|
+
@mol.codec(
|
|
350
|
+
mol.Uint64.mapIn((encodable: SinceLike) => Since.from(encodable).toNum()),
|
|
351
|
+
)
|
|
352
|
+
export class Since extends mol.Entity.Base<SinceLike, Since>() {
|
|
353
|
+
/**
|
|
354
|
+
* Creates an instance of Since.
|
|
355
|
+
*
|
|
356
|
+
* @param relative - Absolute or relative
|
|
357
|
+
* @param metric - The metric of since
|
|
358
|
+
* @param value - The value of since
|
|
359
|
+
*/
|
|
360
|
+
|
|
361
|
+
constructor(
|
|
362
|
+
public relative: "absolute" | "relative",
|
|
363
|
+
public metric: "blockNumber" | "epoch" | "timestamp",
|
|
364
|
+
public value: Num,
|
|
365
|
+
) {
|
|
366
|
+
super();
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Clone a Since.
|
|
371
|
+
*
|
|
372
|
+
* @returns A cloned Since instance.
|
|
373
|
+
*
|
|
374
|
+
* @example
|
|
375
|
+
* ```typescript
|
|
376
|
+
* const since1 = since0.clone();
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
clone(): Since {
|
|
380
|
+
return new Since(this.relative, this.metric, this.value);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Creates a Since instance from a SinceLike object.
|
|
385
|
+
*
|
|
386
|
+
* @param since - A SinceLike object or an instance of Since.
|
|
387
|
+
* @returns A Since instance.
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```typescript
|
|
391
|
+
* const since = Since.from("0x1234567812345678");
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
static from(since: SinceLike): Since {
|
|
395
|
+
if (since instanceof Since) {
|
|
396
|
+
return since;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (typeof since === "object" && "relative" in since) {
|
|
400
|
+
return new Since(since.relative, since.metric, numFrom(since.value));
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return Since.fromNum(since);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Converts the Since instance to num.
|
|
408
|
+
*
|
|
409
|
+
* @returns A num
|
|
410
|
+
*
|
|
411
|
+
* @example
|
|
412
|
+
* ```typescript
|
|
413
|
+
* const num = since.toNum();
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
416
|
+
|
|
417
|
+
toNum(): Num {
|
|
418
|
+
return (
|
|
419
|
+
this.value |
|
|
420
|
+
(this.relative === "absolute" ? Zero : numFrom("0x8000000000000000")) |
|
|
421
|
+
{
|
|
422
|
+
blockNumber: numFrom("0x0000000000000000"),
|
|
423
|
+
epoch: numFrom("0x2000000000000000"),
|
|
424
|
+
timestamp: numFrom("0x4000000000000000"),
|
|
425
|
+
}[this.metric]
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Creates a Since instance from a num-like value.
|
|
431
|
+
*
|
|
432
|
+
* @param numLike - The num-like value to convert.
|
|
433
|
+
* @returns A Since instance.
|
|
434
|
+
*
|
|
435
|
+
* @example
|
|
436
|
+
* ```typescript
|
|
437
|
+
* const since = Since.fromNum("0x0");
|
|
438
|
+
* ```
|
|
439
|
+
*/
|
|
440
|
+
|
|
441
|
+
static fromNum(numLike: NumLike): Since {
|
|
442
|
+
const num = numFrom(numLike);
|
|
443
|
+
|
|
444
|
+
const relative = num >> numFrom(63) === Zero ? "absolute" : "relative";
|
|
445
|
+
const metric = (["blockNumber", "epoch", "timestamp"] as Since["metric"][])[
|
|
446
|
+
Number((num >> numFrom(61)) & numFrom(3))
|
|
447
|
+
];
|
|
448
|
+
const value = num & numFrom("0x00ffffffffffffff");
|
|
449
|
+
|
|
450
|
+
return new Since(relative, metric, value);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* @public
|
|
456
|
+
*/
|
|
457
|
+
export type CellInputLike = (
|
|
458
|
+
| {
|
|
459
|
+
previousOutput: OutPointLike;
|
|
460
|
+
}
|
|
461
|
+
| { outPoint: OutPointLike }
|
|
462
|
+
) & {
|
|
463
|
+
since?: SinceLike | NumLike | null;
|
|
464
|
+
cellOutput?: CellOutputLike | null;
|
|
465
|
+
outputData?: HexLike | null;
|
|
466
|
+
};
|
|
467
|
+
/**
|
|
468
|
+
* @public
|
|
469
|
+
*/
|
|
470
|
+
@mol.codec(
|
|
471
|
+
mol
|
|
472
|
+
.struct({
|
|
473
|
+
since: Since,
|
|
474
|
+
previousOutput: OutPoint,
|
|
475
|
+
})
|
|
476
|
+
.mapIn((encodable: CellInputLike) => CellInput.from(encodable)),
|
|
477
|
+
)
|
|
478
|
+
export class CellInput extends mol.Entity.Base<CellInputLike, CellInput>() {
|
|
479
|
+
/**
|
|
480
|
+
* Creates an instance of CellInput.
|
|
481
|
+
*
|
|
482
|
+
* @param previousOutput - The previous outpoint of the cell.
|
|
483
|
+
* @param since - The since value of the cell input.
|
|
484
|
+
* @param cellOutput - The optional cell output associated with the cell input.
|
|
485
|
+
* @param outputData - The optional output data associated with the cell input.
|
|
486
|
+
*/
|
|
487
|
+
|
|
488
|
+
constructor(
|
|
489
|
+
public previousOutput: OutPoint,
|
|
490
|
+
public since: Num,
|
|
491
|
+
public cellOutput?: CellOutput,
|
|
492
|
+
public outputData?: Hex,
|
|
493
|
+
) {
|
|
494
|
+
super();
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Creates a CellInput instance from a CellInputLike object.
|
|
499
|
+
*
|
|
500
|
+
* @param cellInput - A CellInputLike object or an instance of CellInput.
|
|
501
|
+
* @returns A CellInput instance.
|
|
502
|
+
*
|
|
503
|
+
* @example
|
|
504
|
+
* ```typescript
|
|
505
|
+
* const cellInput = CellInput.from({
|
|
506
|
+
* previousOutput: { txHash: "0x...", index: 0 },
|
|
507
|
+
* since: 0n
|
|
508
|
+
* });
|
|
509
|
+
* ```
|
|
510
|
+
*/
|
|
511
|
+
static from(cellInput: CellInputLike): CellInput {
|
|
512
|
+
if (cellInput instanceof CellInput) {
|
|
513
|
+
return cellInput;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
return new CellInput(
|
|
517
|
+
OutPoint.from(
|
|
518
|
+
"previousOutput" in cellInput
|
|
519
|
+
? cellInput.previousOutput
|
|
520
|
+
: cellInput.outPoint,
|
|
521
|
+
),
|
|
522
|
+
Since.from(cellInput.since ?? 0).toNum(),
|
|
523
|
+
apply(CellOutput.from, cellInput.cellOutput),
|
|
524
|
+
apply(hexFrom, cellInput.outputData),
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Complete extra infos in the input. Like the output of the out point.
|
|
530
|
+
* The instance will be modified.
|
|
531
|
+
*
|
|
532
|
+
* @returns true if succeed.
|
|
533
|
+
* @example
|
|
534
|
+
* ```typescript
|
|
535
|
+
* await cellInput.completeExtraInfos();
|
|
536
|
+
* ```
|
|
537
|
+
*/
|
|
538
|
+
async completeExtraInfos(client: Client): Promise<void> {
|
|
539
|
+
if (this.cellOutput && this.outputData) {
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
const cell = await client.getCell(this.previousOutput);
|
|
544
|
+
if (!cell) {
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
this.cellOutput = cell.cellOutput;
|
|
549
|
+
this.outputData = cell.outputData;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
clone(): CellInput {
|
|
553
|
+
const cloned = super.clone();
|
|
554
|
+
cloned.cellOutput = this.cellOutput;
|
|
555
|
+
cloned.outputData = this.outputData;
|
|
556
|
+
|
|
557
|
+
return cloned;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
export const CellInputVec = mol.vector(CellInput);
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* @public
|
|
564
|
+
*/
|
|
565
|
+
export type CellDepLike = {
|
|
566
|
+
outPoint: OutPointLike;
|
|
567
|
+
depType: DepTypeLike;
|
|
568
|
+
};
|
|
569
|
+
/**
|
|
570
|
+
* @public
|
|
571
|
+
*/
|
|
572
|
+
@mol.codec(
|
|
573
|
+
mol.struct({
|
|
574
|
+
outPoint: OutPoint,
|
|
575
|
+
depType: DepTypeCodec,
|
|
576
|
+
}),
|
|
577
|
+
)
|
|
578
|
+
export class CellDep extends mol.Entity.Base<CellDepLike, CellDep>() {
|
|
579
|
+
/**
|
|
580
|
+
* Creates an instance of CellDep.
|
|
581
|
+
*
|
|
582
|
+
* @param outPoint - The outpoint of the cell dependency.
|
|
583
|
+
* @param depType - The dependency type.
|
|
584
|
+
*/
|
|
585
|
+
|
|
586
|
+
constructor(
|
|
587
|
+
public outPoint: OutPoint,
|
|
588
|
+
public depType: DepType,
|
|
589
|
+
) {
|
|
590
|
+
super();
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Clone a CellDep.
|
|
595
|
+
*
|
|
596
|
+
* @returns A cloned CellDep instance.
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* ```typescript
|
|
600
|
+
* const cellDep1 = cellDep0.clone();
|
|
601
|
+
* ```
|
|
602
|
+
*/
|
|
603
|
+
|
|
604
|
+
clone(): CellDep {
|
|
605
|
+
return new CellDep(this.outPoint.clone(), this.depType);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Creates a CellDep instance from a CellDepLike object.
|
|
610
|
+
*
|
|
611
|
+
* @param cellDep - A CellDepLike object or an instance of CellDep.
|
|
612
|
+
* @returns A CellDep instance.
|
|
613
|
+
*
|
|
614
|
+
* @example
|
|
615
|
+
* ```typescript
|
|
616
|
+
* const cellDep = CellDep.from({
|
|
617
|
+
* outPoint: { txHash: "0x...", index: 0 },
|
|
618
|
+
* depType: "depGroup"
|
|
619
|
+
* });
|
|
620
|
+
* ```
|
|
621
|
+
*/
|
|
622
|
+
|
|
623
|
+
static from(cellDep: CellDepLike): CellDep {
|
|
624
|
+
if (cellDep instanceof CellDep) {
|
|
625
|
+
return cellDep;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
return new CellDep(
|
|
629
|
+
OutPoint.from(cellDep.outPoint),
|
|
630
|
+
depTypeFrom(cellDep.depType),
|
|
631
|
+
);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
export const CellDepVec = mol.vector(CellDep);
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* @public
|
|
638
|
+
*/
|
|
639
|
+
export type WitnessArgsLike = {
|
|
640
|
+
lock?: HexLike | null;
|
|
641
|
+
inputType?: HexLike | null;
|
|
642
|
+
outputType?: HexLike | null;
|
|
643
|
+
};
|
|
644
|
+
/**
|
|
645
|
+
* @public
|
|
646
|
+
*/
|
|
647
|
+
@mol.codec(
|
|
648
|
+
mol.table({
|
|
649
|
+
lock: mol.BytesOpt,
|
|
650
|
+
inputType: mol.BytesOpt,
|
|
651
|
+
outputType: mol.BytesOpt,
|
|
652
|
+
}),
|
|
653
|
+
)
|
|
654
|
+
export class WitnessArgs extends mol.Entity.Base<
|
|
655
|
+
WitnessArgsLike,
|
|
656
|
+
WitnessArgs
|
|
657
|
+
>() {
|
|
658
|
+
/**
|
|
659
|
+
* Creates an instance of WitnessArgs.
|
|
660
|
+
*
|
|
661
|
+
* @param lock - The optional lock field of the witness.
|
|
662
|
+
* @param inputType - The optional input type field of the witness.
|
|
663
|
+
* @param outputType - The optional output type field of the witness.
|
|
664
|
+
*/
|
|
665
|
+
|
|
666
|
+
constructor(
|
|
667
|
+
public lock?: Hex,
|
|
668
|
+
public inputType?: Hex,
|
|
669
|
+
public outputType?: Hex,
|
|
670
|
+
) {
|
|
671
|
+
super();
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Creates a WitnessArgs instance from a WitnessArgsLike object.
|
|
676
|
+
*
|
|
677
|
+
* @param witnessArgs - A WitnessArgsLike object or an instance of WitnessArgs.
|
|
678
|
+
* @returns A WitnessArgs instance.
|
|
679
|
+
*
|
|
680
|
+
* @example
|
|
681
|
+
* ```typescript
|
|
682
|
+
* const witnessArgs = WitnessArgs.from({
|
|
683
|
+
* lock: "0x...",
|
|
684
|
+
* inputType: "0x...",
|
|
685
|
+
* outputType: "0x..."
|
|
686
|
+
* });
|
|
687
|
+
* ```
|
|
688
|
+
*/
|
|
689
|
+
|
|
690
|
+
static from(witnessArgs: WitnessArgsLike): WitnessArgs {
|
|
691
|
+
if (witnessArgs instanceof WitnessArgs) {
|
|
692
|
+
return witnessArgs;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
return new WitnessArgs(
|
|
696
|
+
apply(hexFrom, witnessArgs.lock),
|
|
697
|
+
apply(hexFrom, witnessArgs.inputType),
|
|
698
|
+
apply(hexFrom, witnessArgs.outputType),
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* @public
|
|
705
|
+
*/
|
|
706
|
+
export function udtBalanceFrom(dataLike: BytesLike): Num {
|
|
707
|
+
const data = bytesFrom(dataLike).slice(0, 16);
|
|
708
|
+
return numFromBytes(data);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
export const RawTransaction = mol.table({
|
|
712
|
+
version: mol.Uint32,
|
|
713
|
+
cellDeps: CellDepVec,
|
|
714
|
+
headerDeps: mol.Byte32Vec,
|
|
715
|
+
inputs: CellInputVec,
|
|
716
|
+
outputs: CellOutputVec,
|
|
717
|
+
outputsData: mol.BytesVec,
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* @public
|
|
722
|
+
*/
|
|
723
|
+
export type TransactionLike = {
|
|
724
|
+
version?: NumLike | null;
|
|
725
|
+
cellDeps?: CellDepLike[] | null;
|
|
726
|
+
headerDeps?: HexLike[] | null;
|
|
727
|
+
inputs?: CellInputLike[] | null;
|
|
728
|
+
outputs?:
|
|
729
|
+
| (Omit<CellOutputLike, "capacity"> &
|
|
730
|
+
Partial<Pick<CellOutputLike, "capacity">>)[]
|
|
731
|
+
| null;
|
|
732
|
+
outputsData?: HexLike[] | null;
|
|
733
|
+
witnesses?: HexLike[] | null;
|
|
734
|
+
};
|
|
735
|
+
/**
|
|
736
|
+
* @public
|
|
737
|
+
*/
|
|
738
|
+
@mol.codec(
|
|
739
|
+
mol
|
|
740
|
+
.table({
|
|
741
|
+
raw: RawTransaction,
|
|
742
|
+
witnesses: mol.BytesVec,
|
|
743
|
+
})
|
|
744
|
+
.mapIn((txLike: TransactionLike) => {
|
|
745
|
+
const tx = Transaction.from(txLike);
|
|
746
|
+
return {
|
|
747
|
+
raw: tx,
|
|
748
|
+
witnesses: tx.witnesses,
|
|
749
|
+
};
|
|
750
|
+
})
|
|
751
|
+
.mapOut((tx) => Transaction.from({ ...tx.raw, witnesses: tx.witnesses })),
|
|
752
|
+
)
|
|
753
|
+
export class Transaction extends mol.Entity.Base<
|
|
754
|
+
TransactionLike,
|
|
755
|
+
Transaction
|
|
756
|
+
>() {
|
|
757
|
+
/**
|
|
758
|
+
* Creates an instance of Transaction.
|
|
759
|
+
*
|
|
760
|
+
* @param version - The version of the transaction.
|
|
761
|
+
* @param cellDeps - The cell dependencies of the transaction.
|
|
762
|
+
* @param headerDeps - The header dependencies of the transaction.
|
|
763
|
+
* @param inputs - The inputs of the transaction.
|
|
764
|
+
* @param outputs - The outputs of the transaction.
|
|
765
|
+
* @param outputsData - The data associated with the outputs.
|
|
766
|
+
* @param witnesses - The witnesses of the transaction.
|
|
767
|
+
*/
|
|
768
|
+
|
|
769
|
+
constructor(
|
|
770
|
+
public version: Num,
|
|
771
|
+
public cellDeps: CellDep[],
|
|
772
|
+
public headerDeps: Hex[],
|
|
773
|
+
public inputs: CellInput[],
|
|
774
|
+
public outputs: CellOutput[],
|
|
775
|
+
public outputsData: Hex[],
|
|
776
|
+
public witnesses: Hex[],
|
|
777
|
+
) {
|
|
778
|
+
super();
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Creates a default Transaction instance with empty fields.
|
|
783
|
+
*
|
|
784
|
+
* @returns A default Transaction instance.
|
|
785
|
+
*
|
|
786
|
+
* @example
|
|
787
|
+
* ```typescript
|
|
788
|
+
* const defaultTx = Transaction.default();
|
|
789
|
+
* ```
|
|
790
|
+
*/
|
|
791
|
+
static default(): Transaction {
|
|
792
|
+
return new Transaction(0n, [], [], [], [], [], []);
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* Copy every properties from another transaction.
|
|
797
|
+
*
|
|
798
|
+
* @example
|
|
799
|
+
* ```typescript
|
|
800
|
+
* this.copy(Transaction.default());
|
|
801
|
+
* ```
|
|
802
|
+
*/
|
|
803
|
+
copy(txLike: TransactionLike) {
|
|
804
|
+
const tx = Transaction.from(txLike);
|
|
805
|
+
this.version = tx.version;
|
|
806
|
+
this.cellDeps = tx.cellDeps;
|
|
807
|
+
this.headerDeps = tx.headerDeps;
|
|
808
|
+
this.inputs = tx.inputs;
|
|
809
|
+
this.outputs = tx.outputs;
|
|
810
|
+
this.outputsData = tx.outputsData;
|
|
811
|
+
this.witnesses = tx.witnesses;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* Creates a Transaction instance from a TransactionLike object.
|
|
816
|
+
*
|
|
817
|
+
* @param tx - A TransactionLike object or an instance of Transaction.
|
|
818
|
+
* @returns A Transaction instance.
|
|
819
|
+
*
|
|
820
|
+
* @example
|
|
821
|
+
* ```typescript
|
|
822
|
+
* const transaction = Transaction.from({
|
|
823
|
+
* version: 0,
|
|
824
|
+
* cellDeps: [],
|
|
825
|
+
* headerDeps: [],
|
|
826
|
+
* inputs: [],
|
|
827
|
+
* outputs: [],
|
|
828
|
+
* outputsData: [],
|
|
829
|
+
* witnesses: []
|
|
830
|
+
* });
|
|
831
|
+
* ```
|
|
832
|
+
*/
|
|
833
|
+
|
|
834
|
+
static from(tx: TransactionLike): Transaction {
|
|
835
|
+
if (tx instanceof Transaction) {
|
|
836
|
+
return tx;
|
|
837
|
+
}
|
|
838
|
+
const outputs =
|
|
839
|
+
tx.outputs?.map((output, i) => {
|
|
840
|
+
const o = CellOutput.from({
|
|
841
|
+
...output,
|
|
842
|
+
capacity: output.capacity ?? 0,
|
|
843
|
+
});
|
|
844
|
+
if (o.capacity === Zero) {
|
|
845
|
+
o.capacity = fixedPointFrom(
|
|
846
|
+
o.occupiedSize +
|
|
847
|
+
(apply(bytesFrom, tx.outputsData?.[i])?.length ?? 0),
|
|
848
|
+
);
|
|
849
|
+
}
|
|
850
|
+
return o;
|
|
851
|
+
}) ?? [];
|
|
852
|
+
const outputsData = outputs.map((_, i) =>
|
|
853
|
+
hexFrom(tx.outputsData?.[i] ?? "0x"),
|
|
854
|
+
);
|
|
855
|
+
if (tx.outputsData != null && outputsData.length < tx.outputsData.length) {
|
|
856
|
+
outputsData.push(
|
|
857
|
+
...tx.outputsData.slice(outputsData.length).map((d) => hexFrom(d)),
|
|
858
|
+
);
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
return new Transaction(
|
|
862
|
+
numFrom(tx.version ?? 0),
|
|
863
|
+
tx.cellDeps?.map((cellDep) => CellDep.from(cellDep)) ?? [],
|
|
864
|
+
tx.headerDeps?.map(hexFrom) ?? [],
|
|
865
|
+
tx.inputs?.map((input) => CellInput.from(input)) ?? [],
|
|
866
|
+
outputs,
|
|
867
|
+
outputsData,
|
|
868
|
+
tx.witnesses?.map(hexFrom) ?? [],
|
|
869
|
+
);
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* Creates a Transaction instance from a Lumos skeleton.
|
|
874
|
+
*
|
|
875
|
+
* @param skeleton - The Lumos transaction skeleton.
|
|
876
|
+
* @returns A Transaction instance.
|
|
877
|
+
*
|
|
878
|
+
* @throws Will throw an error if an input's outPoint is missing.
|
|
879
|
+
*
|
|
880
|
+
* @example
|
|
881
|
+
* ```typescript
|
|
882
|
+
* const transaction = Transaction.fromLumosSkeleton(skeleton);
|
|
883
|
+
* ```
|
|
884
|
+
*/
|
|
885
|
+
|
|
886
|
+
static fromLumosSkeleton(
|
|
887
|
+
skeleton: LumosTransactionSkeletonType,
|
|
888
|
+
): Transaction {
|
|
889
|
+
return Transaction.from({
|
|
890
|
+
version: 0n,
|
|
891
|
+
cellDeps: skeleton.cellDeps.toArray(),
|
|
892
|
+
headerDeps: skeleton.headerDeps.toArray(),
|
|
893
|
+
inputs: skeleton.inputs.toArray().map((input, i) => {
|
|
894
|
+
if (!input.outPoint) {
|
|
895
|
+
throw new Error("outPoint is required in input");
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
return CellInput.from({
|
|
899
|
+
previousOutput: input.outPoint,
|
|
900
|
+
since: skeleton.inputSinces.get(i, "0x0"),
|
|
901
|
+
cellOutput: input.cellOutput,
|
|
902
|
+
outputData: input.data,
|
|
903
|
+
});
|
|
904
|
+
}),
|
|
905
|
+
outputs: skeleton.outputs.toArray().map((output) => output.cellOutput),
|
|
906
|
+
outputsData: skeleton.outputs.toArray().map((output) => output.data),
|
|
907
|
+
witnesses: skeleton.witnesses.toArray(),
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
/**
|
|
912
|
+
* @deprecated
|
|
913
|
+
* Use ccc.stringify instead.
|
|
914
|
+
* stringify the tx to JSON string.
|
|
915
|
+
*/
|
|
916
|
+
stringify(): string {
|
|
917
|
+
return JSON.stringify(this, (_, value) => {
|
|
918
|
+
if (typeof value === "bigint") {
|
|
919
|
+
return numToHex(value);
|
|
920
|
+
}
|
|
921
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
922
|
+
return value;
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* Converts the raw transaction data to bytes.
|
|
928
|
+
*
|
|
929
|
+
* @returns A Uint8Array containing the raw transaction bytes.
|
|
930
|
+
*
|
|
931
|
+
* @example
|
|
932
|
+
* ```typescript
|
|
933
|
+
* const rawTxBytes = transaction.rawToBytes();
|
|
934
|
+
* ```
|
|
935
|
+
*/
|
|
936
|
+
rawToBytes(): Bytes {
|
|
937
|
+
return RawTransaction.encode(this);
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* Calculates the hash of the transaction without witnesses. This is the transaction hash in the usual sense.
|
|
942
|
+
* To calculate the hash of the whole transaction including the witnesses, use transaction.hashFull() instead.
|
|
943
|
+
*
|
|
944
|
+
* @returns The hash of the transaction.
|
|
945
|
+
*
|
|
946
|
+
* @example
|
|
947
|
+
* ```typescript
|
|
948
|
+
* const txHash = transaction.hash();
|
|
949
|
+
* ```
|
|
950
|
+
*/
|
|
951
|
+
hash(): Hex {
|
|
952
|
+
return hashCkb(this.rawToBytes());
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
/**
|
|
956
|
+
* Calculates the hash of the transaction with witnesses.
|
|
957
|
+
*
|
|
958
|
+
* @returns The hash of the transaction with witnesses.
|
|
959
|
+
*
|
|
960
|
+
* @example
|
|
961
|
+
* ```typescript
|
|
962
|
+
* const txFullHash = transaction.hashFull();
|
|
963
|
+
* ```
|
|
964
|
+
*/
|
|
965
|
+
hashFull(): Hex {
|
|
966
|
+
return hashCkb(this.toBytes());
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* Hashes a witness and updates the hasher.
|
|
971
|
+
*
|
|
972
|
+
* @param witness - The witness to hash.
|
|
973
|
+
* @param hasher - The hasher instance to update.
|
|
974
|
+
*
|
|
975
|
+
* @example
|
|
976
|
+
* ```typescript
|
|
977
|
+
* Transaction.hashWitnessToHasher("0x...", hasher);
|
|
978
|
+
* ```
|
|
979
|
+
*/
|
|
980
|
+
|
|
981
|
+
static hashWitnessToHasher(witness: HexLike, hasher: Hasher) {
|
|
982
|
+
const raw = bytesFrom(hexFrom(witness));
|
|
983
|
+
hasher.update(numToBytes(raw.length, 8));
|
|
984
|
+
hasher.update(raw);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
/**
|
|
988
|
+
* Computes the signing hash information for a given script.
|
|
989
|
+
*
|
|
990
|
+
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
991
|
+
* @param client - The client for complete extra infos in the transaction.
|
|
992
|
+
* @returns A promise that resolves to an object containing the signing message and the witness position,
|
|
993
|
+
* or undefined if no matching input is found.
|
|
994
|
+
*
|
|
995
|
+
* @example
|
|
996
|
+
* ```typescript
|
|
997
|
+
* const signHashInfo = await tx.getSignHashInfo(scriptLike, client);
|
|
998
|
+
* if (signHashInfo) {
|
|
999
|
+
* console.log(signHashInfo.message); // Outputs the signing message
|
|
1000
|
+
* console.log(signHashInfo.position); // Outputs the witness position
|
|
1001
|
+
* }
|
|
1002
|
+
* ```
|
|
1003
|
+
*/
|
|
1004
|
+
async getSignHashInfo(
|
|
1005
|
+
scriptLike: ScriptLike,
|
|
1006
|
+
client: Client,
|
|
1007
|
+
hasher: Hasher = new HasherCkb(),
|
|
1008
|
+
): Promise<{ message: Hex; position: number } | undefined> {
|
|
1009
|
+
const script = Script.from(scriptLike);
|
|
1010
|
+
let position = -1;
|
|
1011
|
+
hasher.update(this.hash());
|
|
1012
|
+
|
|
1013
|
+
for (let i = 0; i < this.witnesses.length; i += 1) {
|
|
1014
|
+
const input = this.inputs[i];
|
|
1015
|
+
if (input) {
|
|
1016
|
+
await input.completeExtraInfos(client);
|
|
1017
|
+
|
|
1018
|
+
if (!input.cellOutput) {
|
|
1019
|
+
throw new Error("Unable to complete input");
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
if (!script.eq(input.cellOutput.lock)) {
|
|
1023
|
+
continue;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
if (position === -1) {
|
|
1027
|
+
position = i;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
if (position === -1) {
|
|
1032
|
+
return undefined;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
Transaction.hashWitnessToHasher(this.witnesses[i], hasher);
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
if (position === -1) {
|
|
1039
|
+
return undefined;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
return {
|
|
1043
|
+
message: hasher.digest(),
|
|
1044
|
+
position,
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
/**
|
|
1049
|
+
* Find the first occurrence of a input with the specified lock id
|
|
1050
|
+
*
|
|
1051
|
+
* @param scriptIdLike - The script associated with the transaction, represented as a ScriptLike object without args.
|
|
1052
|
+
* @param client - The client for complete extra infos in the transaction.
|
|
1053
|
+
* @returns A promise that resolves to the found index
|
|
1054
|
+
*
|
|
1055
|
+
* @example
|
|
1056
|
+
* ```typescript
|
|
1057
|
+
* const index = await tx.findInputIndexByLockId(scriptIdLike, client);
|
|
1058
|
+
* ```
|
|
1059
|
+
*/
|
|
1060
|
+
async findInputIndexByLockId(
|
|
1061
|
+
scriptIdLike: Pick<ScriptLike, "codeHash" | "hashType">,
|
|
1062
|
+
client: Client,
|
|
1063
|
+
): Promise<number | undefined> {
|
|
1064
|
+
const script = Script.from({ ...scriptIdLike, args: "0x" });
|
|
1065
|
+
|
|
1066
|
+
for (let i = 0; i < this.inputs.length; i += 1) {
|
|
1067
|
+
const input = this.inputs[i];
|
|
1068
|
+
await input.completeExtraInfos(client);
|
|
1069
|
+
if (!input.cellOutput) {
|
|
1070
|
+
throw new Error("Unable to complete input");
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
if (
|
|
1074
|
+
script.codeHash === input.cellOutput.lock.codeHash &&
|
|
1075
|
+
script.hashType === input.cellOutput.lock.hashType
|
|
1076
|
+
) {
|
|
1077
|
+
return i;
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
/**
|
|
1083
|
+
* Find the first occurrence of a input with the specified lock
|
|
1084
|
+
*
|
|
1085
|
+
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
1086
|
+
* @param client - The client for complete extra infos in the transaction.
|
|
1087
|
+
* @returns A promise that resolves to the prepared transaction
|
|
1088
|
+
*
|
|
1089
|
+
* @example
|
|
1090
|
+
* ```typescript
|
|
1091
|
+
* const index = await tx.findInputIndexByLock(scriptLike, client);
|
|
1092
|
+
* ```
|
|
1093
|
+
*/
|
|
1094
|
+
async findInputIndexByLock(
|
|
1095
|
+
scriptLike: ScriptLike,
|
|
1096
|
+
client: Client,
|
|
1097
|
+
): Promise<number | undefined> {
|
|
1098
|
+
const script = Script.from(scriptLike);
|
|
1099
|
+
|
|
1100
|
+
for (let i = 0; i < this.inputs.length; i += 1) {
|
|
1101
|
+
const input = this.inputs[i];
|
|
1102
|
+
await input.completeExtraInfos(client);
|
|
1103
|
+
if (!input.cellOutput) {
|
|
1104
|
+
throw new Error("Unable to complete input");
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
if (script.eq(input.cellOutput.lock)) {
|
|
1108
|
+
return i;
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
/**
|
|
1114
|
+
* Find the last occurrence of a input with the specified lock
|
|
1115
|
+
*
|
|
1116
|
+
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
1117
|
+
* @param client - The client for complete extra infos in the transaction.
|
|
1118
|
+
* @returns A promise that resolves to the prepared transaction
|
|
1119
|
+
*
|
|
1120
|
+
* @example
|
|
1121
|
+
* ```typescript
|
|
1122
|
+
* const index = await tx.findLastInputIndexByLock(scriptLike, client);
|
|
1123
|
+
* ```
|
|
1124
|
+
*/
|
|
1125
|
+
async findLastInputIndexByLock(
|
|
1126
|
+
scriptLike: ScriptLike,
|
|
1127
|
+
client: Client,
|
|
1128
|
+
): Promise<number | undefined> {
|
|
1129
|
+
const script = Script.from(scriptLike);
|
|
1130
|
+
|
|
1131
|
+
for (let i = this.inputs.length - 1; i >= 0; i -= 1) {
|
|
1132
|
+
const input = this.inputs[i];
|
|
1133
|
+
await input.completeExtraInfos(client);
|
|
1134
|
+
if (!input.cellOutput) {
|
|
1135
|
+
throw new Error("Unable to complete input");
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
if (script.eq(input.cellOutput.lock)) {
|
|
1139
|
+
return i;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* Add cell deps if they are not existed
|
|
1146
|
+
*
|
|
1147
|
+
* @param cellDepLikes - The cell deps to add
|
|
1148
|
+
*
|
|
1149
|
+
* @example
|
|
1150
|
+
* ```typescript
|
|
1151
|
+
* tx.addCellDeps(cellDep);
|
|
1152
|
+
* ```
|
|
1153
|
+
*/
|
|
1154
|
+
addCellDeps(...cellDepLikes: (CellDepLike | CellDepLike[])[]): void {
|
|
1155
|
+
cellDepLikes.flat().forEach((cellDepLike) => {
|
|
1156
|
+
const cellDep = CellDep.from(cellDepLike);
|
|
1157
|
+
if (this.cellDeps.some((c) => c.eq(cellDep))) {
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
this.cellDeps.push(cellDep);
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
/**
|
|
1166
|
+
* Add cell deps at the start if they are not existed
|
|
1167
|
+
*
|
|
1168
|
+
* @param cellDepLikes - The cell deps to add
|
|
1169
|
+
*
|
|
1170
|
+
* @example
|
|
1171
|
+
* ```typescript
|
|
1172
|
+
* tx.addCellDepsAtBegin(cellDep);
|
|
1173
|
+
* ```
|
|
1174
|
+
*/
|
|
1175
|
+
addCellDepsAtStart(...cellDepLikes: (CellDepLike | CellDepLike[])[]): void {
|
|
1176
|
+
cellDepLikes.flat().forEach((cellDepLike) => {
|
|
1177
|
+
const cellDep = CellDep.from(cellDepLike);
|
|
1178
|
+
if (this.cellDeps.some((c) => c.eq(cellDep))) {
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
this.cellDeps.unshift(cellDep);
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
/**
|
|
1187
|
+
* Add cell dep from infos if they are not existed
|
|
1188
|
+
*
|
|
1189
|
+
* @param client - A client for searching cell deps
|
|
1190
|
+
* @param cellDepInfoLikes - The cell dep infos to add
|
|
1191
|
+
*
|
|
1192
|
+
* @example
|
|
1193
|
+
* ```typescript
|
|
1194
|
+
* tx.addCellDepInfos(client, cellDepInfos);
|
|
1195
|
+
* ```
|
|
1196
|
+
*/
|
|
1197
|
+
async addCellDepInfos(
|
|
1198
|
+
client: Client,
|
|
1199
|
+
...cellDepInfoLikes: (CellDepInfoLike | CellDepInfoLike[])[]
|
|
1200
|
+
): Promise<void> {
|
|
1201
|
+
this.addCellDeps(await client.getCellDeps(...cellDepInfoLikes));
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
/**
|
|
1205
|
+
* Add cell deps from known script
|
|
1206
|
+
*
|
|
1207
|
+
* @param client - The client for searching known script and cell deps
|
|
1208
|
+
* @param scripts - The known scripts to add
|
|
1209
|
+
*
|
|
1210
|
+
* @example
|
|
1211
|
+
* ```typescript
|
|
1212
|
+
* tx.addCellDepsOfKnownScripts(client, KnownScript.OmniLock);
|
|
1213
|
+
* ```
|
|
1214
|
+
*/
|
|
1215
|
+
async addCellDepsOfKnownScripts(
|
|
1216
|
+
client: Client,
|
|
1217
|
+
...scripts: (KnownScript | KnownScript[])[]
|
|
1218
|
+
): Promise<void> {
|
|
1219
|
+
await Promise.all(
|
|
1220
|
+
scripts
|
|
1221
|
+
.flat()
|
|
1222
|
+
.map(async (script) =>
|
|
1223
|
+
this.addCellDepInfos(
|
|
1224
|
+
client,
|
|
1225
|
+
(await client.getKnownScript(script)).cellDeps,
|
|
1226
|
+
),
|
|
1227
|
+
),
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
/**
|
|
1232
|
+
* Set output data at index.
|
|
1233
|
+
*
|
|
1234
|
+
* @param index - The index of the output data.
|
|
1235
|
+
* @param witness - The data to set.
|
|
1236
|
+
*
|
|
1237
|
+
* @example
|
|
1238
|
+
* ```typescript
|
|
1239
|
+
* await tx.setOutputDataAt(0, "0x00");
|
|
1240
|
+
* ```
|
|
1241
|
+
*/
|
|
1242
|
+
setOutputDataAt(index: number, witness: HexLike): void {
|
|
1243
|
+
if (this.outputsData.length < index) {
|
|
1244
|
+
this.outputsData.push(
|
|
1245
|
+
...Array.from(
|
|
1246
|
+
new Array(index - this.outputsData.length),
|
|
1247
|
+
(): Hex => "0x",
|
|
1248
|
+
),
|
|
1249
|
+
);
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
this.outputsData[index] = hexFrom(witness);
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
/**
|
|
1256
|
+
* get input
|
|
1257
|
+
*
|
|
1258
|
+
* @param index - The cell input index
|
|
1259
|
+
*
|
|
1260
|
+
* @example
|
|
1261
|
+
* ```typescript
|
|
1262
|
+
* await tx.getInput(0);
|
|
1263
|
+
* ```
|
|
1264
|
+
*/
|
|
1265
|
+
getInput(index: NumLike): CellInput | undefined {
|
|
1266
|
+
return this.inputs[Number(numFrom(index))];
|
|
1267
|
+
}
|
|
1268
|
+
/**
|
|
1269
|
+
* add input
|
|
1270
|
+
*
|
|
1271
|
+
* @param inputLike - The cell input.
|
|
1272
|
+
*
|
|
1273
|
+
* @example
|
|
1274
|
+
* ```typescript
|
|
1275
|
+
* await tx.addInput({ });
|
|
1276
|
+
* ```
|
|
1277
|
+
*/
|
|
1278
|
+
addInput(inputLike: CellInputLike): number {
|
|
1279
|
+
return this.inputs.push(CellInput.from(inputLike));
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
/**
|
|
1283
|
+
* get output
|
|
1284
|
+
*
|
|
1285
|
+
* @param index - The cell output index
|
|
1286
|
+
*
|
|
1287
|
+
* @example
|
|
1288
|
+
* ```typescript
|
|
1289
|
+
* await tx.getOutput(0);
|
|
1290
|
+
* ```
|
|
1291
|
+
*/
|
|
1292
|
+
getOutput(index: NumLike):
|
|
1293
|
+
| {
|
|
1294
|
+
cellOutput: CellOutput;
|
|
1295
|
+
outputData: Hex;
|
|
1296
|
+
}
|
|
1297
|
+
| undefined {
|
|
1298
|
+
const i = Number(numFrom(index));
|
|
1299
|
+
if (i >= this.outputs.length) {
|
|
1300
|
+
return;
|
|
1301
|
+
}
|
|
1302
|
+
return {
|
|
1303
|
+
cellOutput: this.outputs[i],
|
|
1304
|
+
outputData: this.outputsData[i] ?? "0x",
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Add output
|
|
1309
|
+
*
|
|
1310
|
+
* @param outputLike - The cell output to add
|
|
1311
|
+
* @param outputData - optional output data
|
|
1312
|
+
*
|
|
1313
|
+
* @example
|
|
1314
|
+
* ```typescript
|
|
1315
|
+
* await tx.addOutput(cellOutput, "0xabcd");
|
|
1316
|
+
* ```
|
|
1317
|
+
*/
|
|
1318
|
+
addOutput(
|
|
1319
|
+
outputLike: Omit<CellOutputLike, "capacity"> &
|
|
1320
|
+
Partial<Pick<CellOutputLike, "capacity">>,
|
|
1321
|
+
outputData: HexLike = "0x",
|
|
1322
|
+
): number {
|
|
1323
|
+
const output = CellOutput.from({
|
|
1324
|
+
...outputLike,
|
|
1325
|
+
capacity: outputLike.capacity ?? 0,
|
|
1326
|
+
});
|
|
1327
|
+
if (output.capacity === Zero) {
|
|
1328
|
+
output.capacity = fixedPointFrom(
|
|
1329
|
+
output.occupiedSize + bytesFrom(outputData).length,
|
|
1330
|
+
);
|
|
1331
|
+
}
|
|
1332
|
+
const len = this.outputs.push(output);
|
|
1333
|
+
this.setOutputDataAt(len - 1, outputData);
|
|
1334
|
+
|
|
1335
|
+
return len;
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
/**
|
|
1339
|
+
* Get witness at index as WitnessArgs
|
|
1340
|
+
*
|
|
1341
|
+
* @param index - The index of the witness.
|
|
1342
|
+
* @returns The witness parsed as WitnessArgs.
|
|
1343
|
+
*
|
|
1344
|
+
* @example
|
|
1345
|
+
* ```typescript
|
|
1346
|
+
* const witnessArgs = await tx.getWitnessArgsAt(0);
|
|
1347
|
+
* ```
|
|
1348
|
+
*/
|
|
1349
|
+
getWitnessArgsAt(index: number): WitnessArgs | undefined {
|
|
1350
|
+
const rawWitness = this.witnesses[index];
|
|
1351
|
+
return (rawWitness ?? "0x") !== "0x"
|
|
1352
|
+
? WitnessArgs.fromBytes(rawWitness)
|
|
1353
|
+
: undefined;
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
/**
|
|
1357
|
+
* Set witness at index by WitnessArgs
|
|
1358
|
+
*
|
|
1359
|
+
* @param index - The index of the witness.
|
|
1360
|
+
* @param witness - The WitnessArgs to set.
|
|
1361
|
+
*
|
|
1362
|
+
* @example
|
|
1363
|
+
* ```typescript
|
|
1364
|
+
* await tx.setWitnessArgsAt(0, witnessArgs);
|
|
1365
|
+
* ```
|
|
1366
|
+
*/
|
|
1367
|
+
setWitnessArgsAt(index: number, witness: WitnessArgs): void {
|
|
1368
|
+
if (this.witnesses.length < index) {
|
|
1369
|
+
this.witnesses.push(
|
|
1370
|
+
...Array.from(
|
|
1371
|
+
new Array(index - this.witnesses.length),
|
|
1372
|
+
(): Hex => "0x",
|
|
1373
|
+
),
|
|
1374
|
+
);
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
this.witnesses[index] = hexFrom(witness.toBytes());
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
/**
|
|
1381
|
+
* Prepare dummy witness for sighash all method
|
|
1382
|
+
*
|
|
1383
|
+
* @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
|
|
1384
|
+
* @param lockLen - The length of dummy lock bytes.
|
|
1385
|
+
* @param client - The client for complete extra infos in the transaction.
|
|
1386
|
+
* @returns A promise that resolves to the prepared transaction
|
|
1387
|
+
*
|
|
1388
|
+
* @example
|
|
1389
|
+
* ```typescript
|
|
1390
|
+
* await tx.prepareSighashAllWitness(scriptLike, 85, client);
|
|
1391
|
+
* ```
|
|
1392
|
+
*/
|
|
1393
|
+
async prepareSighashAllWitness(
|
|
1394
|
+
scriptLike: ScriptLike,
|
|
1395
|
+
lockLen: number,
|
|
1396
|
+
client: Client,
|
|
1397
|
+
): Promise<void> {
|
|
1398
|
+
const position = await this.findInputIndexByLock(scriptLike, client);
|
|
1399
|
+
if (position === undefined) {
|
|
1400
|
+
return;
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
const witness = this.getWitnessArgsAt(position) ?? WitnessArgs.from({});
|
|
1404
|
+
witness.lock = hexFrom(Array.from(new Array(lockLen), () => 0));
|
|
1405
|
+
this.setWitnessArgsAt(position, witness);
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
async getInputsCapacity(client: Client): Promise<Num> {
|
|
1409
|
+
return reduceAsync(
|
|
1410
|
+
this.inputs,
|
|
1411
|
+
async (acc, input) => {
|
|
1412
|
+
await input.completeExtraInfos(client);
|
|
1413
|
+
if (!input.cellOutput) {
|
|
1414
|
+
throw new Error("Unable to complete input");
|
|
1415
|
+
}
|
|
1416
|
+
return acc + input.cellOutput.capacity;
|
|
1417
|
+
},
|
|
1418
|
+
numFrom(0),
|
|
1419
|
+
);
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
getOutputsCapacity(): Num {
|
|
1423
|
+
return this.outputs.reduce(
|
|
1424
|
+
(acc, { capacity }) => acc + capacity,
|
|
1425
|
+
numFrom(0),
|
|
1426
|
+
);
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
async getInputsUdtBalance(client: Client, type: ScriptLike): Promise<Num> {
|
|
1430
|
+
return reduceAsync(
|
|
1431
|
+
this.inputs,
|
|
1432
|
+
async (acc, input) => {
|
|
1433
|
+
await input.completeExtraInfos(client);
|
|
1434
|
+
if (!input.cellOutput || !input.outputData) {
|
|
1435
|
+
throw new Error("Unable to complete input");
|
|
1436
|
+
}
|
|
1437
|
+
if (!input.cellOutput.type?.eq(type)) {
|
|
1438
|
+
return;
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
return acc + udtBalanceFrom(input.outputData);
|
|
1442
|
+
},
|
|
1443
|
+
numFrom(0),
|
|
1444
|
+
);
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
getOutputsUdtBalance(type: ScriptLike): Num {
|
|
1448
|
+
return this.outputs.reduce((acc, output, i) => {
|
|
1449
|
+
if (!output.type?.eq(type)) {
|
|
1450
|
+
return acc;
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
return acc + udtBalanceFrom(this.outputsData[i]);
|
|
1454
|
+
}, numFrom(0));
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
async completeInputs<T>(
|
|
1458
|
+
from: Signer,
|
|
1459
|
+
filter: ClientCollectableSearchKeyFilterLike,
|
|
1460
|
+
accumulator: (
|
|
1461
|
+
acc: T,
|
|
1462
|
+
v: Cell,
|
|
1463
|
+
i: number,
|
|
1464
|
+
array: Cell[],
|
|
1465
|
+
) => Promise<T | undefined> | T | undefined,
|
|
1466
|
+
init: T,
|
|
1467
|
+
): Promise<{
|
|
1468
|
+
addedCount: number;
|
|
1469
|
+
accumulated?: T;
|
|
1470
|
+
}> {
|
|
1471
|
+
const collectedCells = [];
|
|
1472
|
+
|
|
1473
|
+
let acc: T = init;
|
|
1474
|
+
let fulfilled = false;
|
|
1475
|
+
for await (const cell of from.findCells(filter, true)) {
|
|
1476
|
+
if (
|
|
1477
|
+
this.inputs.some(({ previousOutput }) =>
|
|
1478
|
+
previousOutput.eq(cell.outPoint),
|
|
1479
|
+
)
|
|
1480
|
+
) {
|
|
1481
|
+
continue;
|
|
1482
|
+
}
|
|
1483
|
+
const i = collectedCells.push(cell);
|
|
1484
|
+
const next = await Promise.resolve(
|
|
1485
|
+
accumulator(acc, cell, i - 1, collectedCells),
|
|
1486
|
+
);
|
|
1487
|
+
if (next === undefined) {
|
|
1488
|
+
fulfilled = true;
|
|
1489
|
+
break;
|
|
1490
|
+
}
|
|
1491
|
+
acc = next;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
collectedCells.forEach((cell) => this.addInput(cell));
|
|
1495
|
+
if (fulfilled) {
|
|
1496
|
+
return {
|
|
1497
|
+
addedCount: collectedCells.length,
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
return {
|
|
1502
|
+
addedCount: collectedCells.length,
|
|
1503
|
+
accumulated: acc,
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
async completeInputsByCapacity(
|
|
1508
|
+
from: Signer,
|
|
1509
|
+
capacityTweak?: NumLike,
|
|
1510
|
+
filter?: ClientCollectableSearchKeyFilterLike,
|
|
1511
|
+
): Promise<number> {
|
|
1512
|
+
const exceptedCapacity =
|
|
1513
|
+
this.getOutputsCapacity() + numFrom(capacityTweak ?? 0);
|
|
1514
|
+
const inputsCapacity = await this.getInputsCapacity(from.client);
|
|
1515
|
+
if (inputsCapacity >= exceptedCapacity) {
|
|
1516
|
+
return 0;
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
const { addedCount, accumulated } = await this.completeInputs(
|
|
1520
|
+
from,
|
|
1521
|
+
filter ?? {
|
|
1522
|
+
scriptLenRange: [0, 1],
|
|
1523
|
+
outputDataLenRange: [0, 1],
|
|
1524
|
+
},
|
|
1525
|
+
(acc, { cellOutput: { capacity } }) => {
|
|
1526
|
+
const sum = acc + capacity;
|
|
1527
|
+
return sum >= exceptedCapacity ? undefined : sum;
|
|
1528
|
+
},
|
|
1529
|
+
inputsCapacity,
|
|
1530
|
+
);
|
|
1531
|
+
|
|
1532
|
+
if (accumulated === undefined) {
|
|
1533
|
+
return addedCount;
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
throw new Error(
|
|
1537
|
+
`Insufficient CKB, need ${fixedPointToString(exceptedCapacity - accumulated)} extra CKB`,
|
|
1538
|
+
);
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
async completeInputsAll(
|
|
1542
|
+
from: Signer,
|
|
1543
|
+
filter?: ClientCollectableSearchKeyFilterLike,
|
|
1544
|
+
): Promise<number> {
|
|
1545
|
+
const { addedCount } = await this.completeInputs(
|
|
1546
|
+
from,
|
|
1547
|
+
filter ?? {
|
|
1548
|
+
scriptLenRange: [0, 1],
|
|
1549
|
+
outputDataLenRange: [0, 1],
|
|
1550
|
+
},
|
|
1551
|
+
(acc, { cellOutput: { capacity } }) => acc + capacity,
|
|
1552
|
+
Zero,
|
|
1553
|
+
);
|
|
1554
|
+
|
|
1555
|
+
return addedCount;
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
async completeInputsByUdt(
|
|
1559
|
+
from: Signer,
|
|
1560
|
+
type: ScriptLike,
|
|
1561
|
+
balanceTweak?: NumLike,
|
|
1562
|
+
): Promise<number> {
|
|
1563
|
+
const exceptedBalance =
|
|
1564
|
+
this.getOutputsUdtBalance(type) + numFrom(balanceTweak ?? 0);
|
|
1565
|
+
const inputsBalance = await this.getInputsUdtBalance(from.client, type);
|
|
1566
|
+
if (inputsBalance >= exceptedBalance) {
|
|
1567
|
+
return 0;
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
const { addedCount, accumulated } = await this.completeInputs(
|
|
1571
|
+
from,
|
|
1572
|
+
{
|
|
1573
|
+
script: type,
|
|
1574
|
+
outputDataLenRange: [16, numFrom("0xffffffff")],
|
|
1575
|
+
},
|
|
1576
|
+
(acc, { outputData }) => {
|
|
1577
|
+
const balance = udtBalanceFrom(outputData);
|
|
1578
|
+
const sum = acc + balance;
|
|
1579
|
+
return sum >= exceptedBalance ? undefined : sum;
|
|
1580
|
+
},
|
|
1581
|
+
inputsBalance,
|
|
1582
|
+
);
|
|
1583
|
+
|
|
1584
|
+
if (accumulated === undefined) {
|
|
1585
|
+
return addedCount;
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
throw new Error(
|
|
1589
|
+
`Insufficient coin, need ${exceptedBalance - accumulated} extra coin`,
|
|
1590
|
+
);
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
async completeInputsAddOne(
|
|
1594
|
+
from: Signer,
|
|
1595
|
+
filter?: ClientCollectableSearchKeyFilterLike,
|
|
1596
|
+
): Promise<number> {
|
|
1597
|
+
for await (const cell of from.findCells(
|
|
1598
|
+
filter ?? {
|
|
1599
|
+
scriptLenRange: [0, 1],
|
|
1600
|
+
outputDataLenRange: [0, 1],
|
|
1601
|
+
},
|
|
1602
|
+
true,
|
|
1603
|
+
undefined,
|
|
1604
|
+
1,
|
|
1605
|
+
)) {
|
|
1606
|
+
if (
|
|
1607
|
+
this.inputs.some(({ previousOutput }) =>
|
|
1608
|
+
previousOutput.eq(cell.outPoint),
|
|
1609
|
+
)
|
|
1610
|
+
) {
|
|
1611
|
+
continue;
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
this.addInput(cell);
|
|
1615
|
+
return 1;
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
throw new Error(`Insufficient CKB, need at least one new cell`);
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
async completeInputsAtLeastOne(
|
|
1622
|
+
from: Signer,
|
|
1623
|
+
filter?: ClientCollectableSearchKeyFilterLike,
|
|
1624
|
+
): Promise<number> {
|
|
1625
|
+
if (this.inputs.length > 0) {
|
|
1626
|
+
return 0;
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
return this.completeInputsAddOne(from, filter);
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
async fee(client: Client): Promise<Num> {
|
|
1633
|
+
return (await this.getInputsCapacity(client)) - this.getOutputsCapacity();
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
async feeRate(client: Client): Promise<Num> {
|
|
1637
|
+
return (
|
|
1638
|
+
((await this.fee(client)) * numFrom(1000)) /
|
|
1639
|
+
numFrom(this.toBytes().length + 4)
|
|
1640
|
+
);
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
estimateFee(feeRate: NumLike): Num {
|
|
1644
|
+
const txSize = this.toBytes().length + 4;
|
|
1645
|
+
// + 999 then / 1000 to ceil the calculated fee
|
|
1646
|
+
return (numFrom(txSize) * numFrom(feeRate) + numFrom(999)) / numFrom(1000);
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
async completeFee(
|
|
1650
|
+
from: Signer,
|
|
1651
|
+
change: (tx: Transaction, capacity: Num) => Promise<NumLike> | NumLike,
|
|
1652
|
+
expectedFeeRate?: NumLike,
|
|
1653
|
+
filter?: ClientCollectableSearchKeyFilterLike,
|
|
1654
|
+
options?: { feeRateBlockRange?: NumLike; maxFeeRate?: NumLike },
|
|
1655
|
+
): Promise<[number, boolean]> {
|
|
1656
|
+
const feeRate =
|
|
1657
|
+
expectedFeeRate ??
|
|
1658
|
+
(await from.client.getFeeRate(options?.feeRateBlockRange, options));
|
|
1659
|
+
|
|
1660
|
+
// Complete all inputs extra infos for cache
|
|
1661
|
+
await this.getInputsCapacity(from.client);
|
|
1662
|
+
|
|
1663
|
+
let leastFee = Zero;
|
|
1664
|
+
let leastExtraCapacity = Zero;
|
|
1665
|
+
|
|
1666
|
+
while (true) {
|
|
1667
|
+
const tx = this.clone();
|
|
1668
|
+
const collected = await (async () => {
|
|
1669
|
+
try {
|
|
1670
|
+
return await tx.completeInputsByCapacity(
|
|
1671
|
+
from,
|
|
1672
|
+
leastFee + leastExtraCapacity,
|
|
1673
|
+
filter,
|
|
1674
|
+
);
|
|
1675
|
+
} catch (err) {
|
|
1676
|
+
if (leastExtraCapacity !== Zero) {
|
|
1677
|
+
throw new Error("Not enough capacity for the change cell");
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
throw err;
|
|
1681
|
+
}
|
|
1682
|
+
})();
|
|
1683
|
+
|
|
1684
|
+
await from.prepareTransaction(tx);
|
|
1685
|
+
if (leastFee === Zero) {
|
|
1686
|
+
// The initial fee is calculated based on prepared transaction
|
|
1687
|
+
leastFee = tx.estimateFee(feeRate);
|
|
1688
|
+
}
|
|
1689
|
+
const fee = await tx.fee(from.client);
|
|
1690
|
+
// The extra capacity paid the fee without a change
|
|
1691
|
+
if (fee === leastFee) {
|
|
1692
|
+
this.copy(tx);
|
|
1693
|
+
return [collected, false];
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
const needed = numFrom(await Promise.resolve(change(tx, fee - leastFee)));
|
|
1697
|
+
// No enough extra capacity to create new cells for change
|
|
1698
|
+
if (needed > Zero) {
|
|
1699
|
+
leastExtraCapacity = needed;
|
|
1700
|
+
continue;
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
if ((await tx.fee(from.client)) !== leastFee) {
|
|
1704
|
+
throw new Error(
|
|
1705
|
+
"The change function doesn't use all available capacity",
|
|
1706
|
+
);
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
// New change cells created, update the fee
|
|
1710
|
+
await from.prepareTransaction(tx);
|
|
1711
|
+
const changedFee = tx.estimateFee(feeRate);
|
|
1712
|
+
if (leastFee > changedFee) {
|
|
1713
|
+
throw new Error("The change function removed existed transaction data");
|
|
1714
|
+
}
|
|
1715
|
+
// The fee has been paid
|
|
1716
|
+
if (leastFee === changedFee) {
|
|
1717
|
+
this.copy(tx);
|
|
1718
|
+
return [collected, true];
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
// The fee after changing is more than the original fee
|
|
1722
|
+
leastFee = changedFee;
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
completeFeeChangeToLock(
|
|
1727
|
+
from: Signer,
|
|
1728
|
+
change: ScriptLike,
|
|
1729
|
+
feeRate?: NumLike,
|
|
1730
|
+
filter?: ClientCollectableSearchKeyFilterLike,
|
|
1731
|
+
): Promise<[number, boolean]> {
|
|
1732
|
+
const script = Script.from(change);
|
|
1733
|
+
|
|
1734
|
+
return this.completeFee(
|
|
1735
|
+
from,
|
|
1736
|
+
(tx, capacity) => {
|
|
1737
|
+
const changeCell = CellOutput.from({ capacity: 0, lock: script });
|
|
1738
|
+
const occupiedCapacity = fixedPointFrom(changeCell.occupiedSize);
|
|
1739
|
+
if (capacity < occupiedCapacity) {
|
|
1740
|
+
return occupiedCapacity;
|
|
1741
|
+
}
|
|
1742
|
+
changeCell.capacity = capacity;
|
|
1743
|
+
tx.addOutput(changeCell);
|
|
1744
|
+
return 0;
|
|
1745
|
+
},
|
|
1746
|
+
feeRate,
|
|
1747
|
+
filter,
|
|
1748
|
+
);
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
async completeFeeBy(
|
|
1752
|
+
from: Signer,
|
|
1753
|
+
feeRate?: NumLike,
|
|
1754
|
+
filter?: ClientCollectableSearchKeyFilterLike,
|
|
1755
|
+
): Promise<[number, boolean]> {
|
|
1756
|
+
const { script } = await from.getRecommendedAddressObj();
|
|
1757
|
+
|
|
1758
|
+
return this.completeFeeChangeToLock(from, script, feeRate, filter);
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
completeFeeChangeToOutput(
|
|
1762
|
+
from: Signer,
|
|
1763
|
+
index: NumLike,
|
|
1764
|
+
feeRate?: NumLike,
|
|
1765
|
+
filter?: ClientCollectableSearchKeyFilterLike,
|
|
1766
|
+
): Promise<[number, boolean]> {
|
|
1767
|
+
const change = Number(numFrom(index));
|
|
1768
|
+
if (!this.outputs[change]) {
|
|
1769
|
+
throw new Error("Non-existed output to change");
|
|
1770
|
+
}
|
|
1771
|
+
return this.completeFee(
|
|
1772
|
+
from,
|
|
1773
|
+
(tx, capacity) => {
|
|
1774
|
+
tx.outputs[change].capacity += capacity;
|
|
1775
|
+
return 0;
|
|
1776
|
+
},
|
|
1777
|
+
feeRate,
|
|
1778
|
+
filter,
|
|
1779
|
+
);
|
|
1780
|
+
}
|
|
1781
|
+
}
|