@bigmi/core 0.0.1
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 +11 -0
- package/LICENSE.md +21 -0
- package/README.md +137 -0
- package/dist/cjs/actions/getBalance.d.ts +7 -0
- package/dist/cjs/actions/getBalance.js +11 -0
- package/dist/cjs/actions/getBalance.js.map +1 -0
- package/dist/cjs/actions/getBlock.d.ts +12 -0
- package/dist/cjs/actions/getBlock.js +31 -0
- package/dist/cjs/actions/getBlock.js.map +1 -0
- package/dist/cjs/actions/getBlockCount.d.ts +4 -0
- package/dist/cjs/actions/getBlockCount.js +11 -0
- package/dist/cjs/actions/getBlockCount.js.map +1 -0
- package/dist/cjs/actions/getBlockStats.d.ts +14 -0
- package/dist/cjs/actions/getBlockStats.js +27 -0
- package/dist/cjs/actions/getBlockStats.js.map +1 -0
- package/dist/cjs/actions/getUTXOTransaction.d.ts +9 -0
- package/dist/cjs/actions/getUTXOTransaction.js +24 -0
- package/dist/cjs/actions/getUTXOTransaction.js.map +1 -0
- package/dist/cjs/actions/sendUTXOTransaction.d.ts +8 -0
- package/dist/cjs/actions/sendUTXOTransaction.js +15 -0
- package/dist/cjs/actions/sendUTXOTransaction.js.map +1 -0
- package/dist/cjs/actions/signPsbt.d.ts +3 -0
- package/dist/cjs/actions/signPsbt.js +11 -0
- package/dist/cjs/actions/signPsbt.js.map +1 -0
- package/dist/cjs/actions/waitForTransaction.d.ts +32 -0
- package/dist/cjs/actions/waitForTransaction.js +185 -0
- package/dist/cjs/actions/waitForTransaction.js.map +1 -0
- package/dist/cjs/actions/watchBlockNumber.d.ts +14 -0
- package/dist/cjs/actions/watchBlockNumber.js +45 -0
- package/dist/cjs/actions/watchBlockNumber.js.map +1 -0
- package/dist/cjs/chains/bitcoin.d.ts +36 -0
- package/dist/cjs/chains/bitcoin.js +21 -0
- package/dist/cjs/chains/bitcoin.js.map +1 -0
- package/dist/cjs/clients/types.d.ts +27 -0
- package/dist/cjs/clients/types.js +3 -0
- package/dist/cjs/clients/types.js.map +1 -0
- package/dist/cjs/decorators/UTXOAPIActions.d.ts +6 -0
- package/dist/cjs/decorators/UTXOAPIActions.js +10 -0
- package/dist/cjs/decorators/UTXOAPIActions.js.map +1 -0
- package/dist/cjs/decorators/UTXOActions.d.ts +10 -0
- package/dist/cjs/decorators/UTXOActions.js +14 -0
- package/dist/cjs/decorators/UTXOActions.js.map +1 -0
- package/dist/cjs/index.d.ts +38 -0
- package/dist/cjs/index.js +58 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/transports/ankr.d.ts +2 -0
- package/dist/cjs/transports/ankr.js +21 -0
- package/dist/cjs/transports/ankr.js.map +1 -0
- package/dist/cjs/transports/blockchair.d.ts +2 -0
- package/dist/cjs/transports/blockchair.js +24 -0
- package/dist/cjs/transports/blockchair.js.map +1 -0
- package/dist/cjs/transports/blockcypher.d.ts +2 -0
- package/dist/cjs/transports/blockcypher.js +21 -0
- package/dist/cjs/transports/blockcypher.js.map +1 -0
- package/dist/cjs/transports/getHttpRpcClient.d.ts +19 -0
- package/dist/cjs/transports/getHttpRpcClient.js +77 -0
- package/dist/cjs/transports/getHttpRpcClient.js.map +1 -0
- package/dist/cjs/transports/getRpcProviderMethods.d.ts +2 -0
- package/dist/cjs/transports/getRpcProviderMethods.js +22 -0
- package/dist/cjs/transports/getRpcProviderMethods.js.map +1 -0
- package/dist/cjs/transports/mempool.d.ts +2 -0
- package/dist/cjs/transports/mempool.js +17 -0
- package/dist/cjs/transports/mempool.js.map +1 -0
- package/dist/cjs/transports/types.d.ts +60 -0
- package/dist/cjs/transports/types.js +3 -0
- package/dist/cjs/transports/types.js.map +1 -0
- package/dist/cjs/transports/utxo.d.ts +6 -0
- package/dist/cjs/transports/utxo.js +56 -0
- package/dist/cjs/transports/utxo.js.map +1 -0
- package/dist/cjs/types/blockStats.d.ts +34 -0
- package/dist/cjs/types/blockStats.js +3 -0
- package/dist/cjs/types/blockStats.js.map +1 -0
- package/dist/cjs/types/transaction.d.ts +41 -0
- package/dist/cjs/types/transaction.js +3 -0
- package/dist/cjs/types/transaction.js.map +1 -0
- package/dist/cjs/utils/cancelTransaction.d.ts +2 -0
- package/dist/cjs/utils/cancelTransaction.js +51 -0
- package/dist/cjs/utils/cancelTransaction.js.map +1 -0
- package/dist/cjs/utils/getUTXOAddress.d.ts +19 -0
- package/dist/cjs/utils/getUTXOAddress.js +120 -0
- package/dist/cjs/utils/getUTXOAddress.js.map +1 -0
- package/dist/cjs/utils/isUTXOAddress.d.ts +2 -0
- package/dist/cjs/utils/isUTXOAddress.js +18 -0
- package/dist/cjs/utils/isUTXOAddress.js.map +1 -0
- package/dist/cjs/utils/modifyFee.d.ts +2 -0
- package/dist/cjs/utils/modifyFee.js +50 -0
- package/dist/cjs/utils/modifyFee.js.map +1 -0
- package/dist/cjs/utils/observe.d.ts +11 -0
- package/dist/cjs/utils/observe.js +48 -0
- package/dist/cjs/utils/observe.js.map +1 -0
- package/dist/cjs/utils/poll.d.ts +9 -0
- package/dist/cjs/utils/poll.js +30 -0
- package/dist/cjs/utils/poll.js.map +1 -0
- package/dist/cjs/utils/sleep.d.ts +1 -0
- package/dist/cjs/utils/sleep.js +9 -0
- package/dist/cjs/utils/sleep.js.map +1 -0
- package/dist/esm/actions/getBalance.d.ts +8 -0
- package/dist/esm/actions/getBalance.js +8 -0
- package/dist/esm/actions/getBalance.js.map +1 -0
- package/dist/esm/actions/getBlock.d.ts +12 -0
- package/dist/esm/actions/getBlock.js +28 -0
- package/dist/esm/actions/getBlock.js.map +1 -0
- package/dist/esm/actions/getBlockCount.d.ts +4 -0
- package/dist/esm/actions/getBlockCount.js +8 -0
- package/dist/esm/actions/getBlockCount.js.map +1 -0
- package/dist/esm/actions/getBlockStats.d.ts +14 -0
- package/dist/esm/actions/getBlockStats.js +24 -0
- package/dist/esm/actions/getBlockStats.js.map +1 -0
- package/dist/esm/actions/getUTXOTransaction.d.ts +11 -0
- package/dist/esm/actions/getUTXOTransaction.js +21 -0
- package/dist/esm/actions/getUTXOTransaction.js.map +1 -0
- package/dist/esm/actions/sendUTXOTransaction.d.ts +10 -0
- package/dist/esm/actions/sendUTXOTransaction.js +12 -0
- package/dist/esm/actions/sendUTXOTransaction.js.map +1 -0
- package/dist/esm/actions/signPsbt.d.ts +3 -0
- package/dist/esm/actions/signPsbt.js +8 -0
- package/dist/esm/actions/signPsbt.js.map +1 -0
- package/dist/esm/actions/waitForTransaction.d.ts +75 -0
- package/dist/esm/actions/waitForTransaction.js +230 -0
- package/dist/esm/actions/waitForTransaction.js.map +1 -0
- package/dist/esm/actions/watchBlockNumber.d.ts +25 -0
- package/dist/esm/actions/watchBlockNumber.js +58 -0
- package/dist/esm/actions/watchBlockNumber.js.map +1 -0
- package/dist/esm/chains/bitcoin.d.ts +36 -0
- package/dist/esm/chains/bitcoin.js +18 -0
- package/dist/esm/chains/bitcoin.js.map +1 -0
- package/dist/esm/clients/types.d.ts +43 -0
- package/dist/esm/clients/types.js +2 -0
- package/dist/esm/clients/types.js.map +1 -0
- package/dist/esm/decorators/UTXOAPIActions.d.ts +6 -0
- package/dist/esm/decorators/UTXOAPIActions.js +7 -0
- package/dist/esm/decorators/UTXOAPIActions.js.map +1 -0
- package/dist/esm/decorators/UTXOActions.d.ts +10 -0
- package/dist/esm/decorators/UTXOActions.js +11 -0
- package/dist/esm/decorators/UTXOActions.js.map +1 -0
- package/dist/esm/index.d.ts +38 -0
- package/dist/esm/index.js +31 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/transports/ankr.d.ts +2 -0
- package/dist/esm/transports/ankr.js +18 -0
- package/dist/esm/transports/ankr.js.map +1 -0
- package/dist/esm/transports/blockchair.d.ts +2 -0
- package/dist/esm/transports/blockchair.js +21 -0
- package/dist/esm/transports/blockchair.js.map +1 -0
- package/dist/esm/transports/blockcypher.d.ts +2 -0
- package/dist/esm/transports/blockcypher.js +18 -0
- package/dist/esm/transports/blockcypher.js.map +1 -0
- package/dist/esm/transports/getHttpRpcClient.d.ts +24 -0
- package/dist/esm/transports/getHttpRpcClient.js +74 -0
- package/dist/esm/transports/getHttpRpcClient.js.map +1 -0
- package/dist/esm/transports/getRpcProviderMethods.d.ts +2 -0
- package/dist/esm/transports/getRpcProviderMethods.js +19 -0
- package/dist/esm/transports/getRpcProviderMethods.js.map +1 -0
- package/dist/esm/transports/mempool.d.ts +2 -0
- package/dist/esm/transports/mempool.js +14 -0
- package/dist/esm/transports/mempool.js.map +1 -0
- package/dist/esm/transports/types.d.ts +60 -0
- package/dist/esm/transports/types.js +2 -0
- package/dist/esm/transports/types.js.map +1 -0
- package/dist/esm/transports/utxo.d.ts +6 -0
- package/dist/esm/transports/utxo.js +53 -0
- package/dist/esm/transports/utxo.js.map +1 -0
- package/dist/esm/types/blockStats.d.ts +34 -0
- package/dist/esm/types/blockStats.js +2 -0
- package/dist/esm/types/blockStats.js.map +1 -0
- package/dist/esm/types/transaction.d.ts +41 -0
- package/dist/esm/types/transaction.js +2 -0
- package/dist/esm/types/transaction.js.map +1 -0
- package/dist/esm/utils/cancelTransaction.d.ts +2 -0
- package/dist/esm/utils/cancelTransaction.js +55 -0
- package/dist/esm/utils/cancelTransaction.js.map +1 -0
- package/dist/esm/utils/getUTXOAddress.d.ts +19 -0
- package/dist/esm/utils/getUTXOAddress.js +116 -0
- package/dist/esm/utils/getUTXOAddress.js.map +1 -0
- package/dist/esm/utils/isUTXOAddress.d.ts +2 -0
- package/dist/esm/utils/isUTXOAddress.js +14 -0
- package/dist/esm/utils/isUTXOAddress.js.map +1 -0
- package/dist/esm/utils/modifyFee.d.ts +2 -0
- package/dist/esm/utils/modifyFee.js +53 -0
- package/dist/esm/utils/modifyFee.js.map +1 -0
- package/dist/esm/utils/observe.d.ts +18 -0
- package/dist/esm/utils/observe.js +51 -0
- package/dist/esm/utils/observe.js.map +1 -0
- package/dist/esm/utils/poll.d.ts +12 -0
- package/dist/esm/utils/poll.js +30 -0
- package/dist/esm/utils/poll.js.map +1 -0
- package/dist/esm/utils/sleep.d.ts +1 -0
- package/dist/esm/utils/sleep.js +6 -0
- package/dist/esm/utils/sleep.js.map +1 -0
- package/dist/types/actions/getBalance.d.ts +9 -0
- package/dist/types/actions/getBalance.d.ts.map +1 -0
- package/dist/types/actions/getBlock.d.ts +13 -0
- package/dist/types/actions/getBlock.d.ts.map +1 -0
- package/dist/types/actions/getBlockCount.d.ts +5 -0
- package/dist/types/actions/getBlockCount.d.ts.map +1 -0
- package/dist/types/actions/getBlockStats.d.ts +15 -0
- package/dist/types/actions/getBlockStats.d.ts.map +1 -0
- package/dist/types/actions/getUTXOTransaction.d.ts +12 -0
- package/dist/types/actions/getUTXOTransaction.d.ts.map +1 -0
- package/dist/types/actions/sendUTXOTransaction.d.ts +11 -0
- package/dist/types/actions/sendUTXOTransaction.d.ts.map +1 -0
- package/dist/types/actions/signPsbt.d.ts +4 -0
- package/dist/types/actions/signPsbt.d.ts.map +1 -0
- package/dist/types/actions/waitForTransaction.d.ts +76 -0
- package/dist/types/actions/waitForTransaction.d.ts.map +1 -0
- package/dist/types/actions/watchBlockNumber.d.ts +26 -0
- package/dist/types/actions/watchBlockNumber.d.ts.map +1 -0
- package/dist/types/chains/bitcoin.d.ts +37 -0
- package/dist/types/chains/bitcoin.d.ts.map +1 -0
- package/dist/types/clients/types.d.ts +44 -0
- package/dist/types/clients/types.d.ts.map +1 -0
- package/dist/types/decorators/UTXOAPIActions.d.ts +7 -0
- package/dist/types/decorators/UTXOAPIActions.d.ts.map +1 -0
- package/dist/types/decorators/UTXOActions.d.ts +11 -0
- package/dist/types/decorators/UTXOActions.d.ts.map +1 -0
- package/dist/types/index.d.ts +39 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/transports/ankr.d.ts +3 -0
- package/dist/types/transports/ankr.d.ts.map +1 -0
- package/dist/types/transports/blockchair.d.ts +3 -0
- package/dist/types/transports/blockchair.d.ts.map +1 -0
- package/dist/types/transports/blockcypher.d.ts +3 -0
- package/dist/types/transports/blockcypher.d.ts.map +1 -0
- package/dist/types/transports/getHttpRpcClient.d.ts +25 -0
- package/dist/types/transports/getHttpRpcClient.d.ts.map +1 -0
- package/dist/types/transports/getRpcProviderMethods.d.ts +3 -0
- package/dist/types/transports/getRpcProviderMethods.d.ts.map +1 -0
- package/dist/types/transports/mempool.d.ts +3 -0
- package/dist/types/transports/mempool.d.ts.map +1 -0
- package/dist/types/transports/types.d.ts +61 -0
- package/dist/types/transports/types.d.ts.map +1 -0
- package/dist/types/transports/utxo.d.ts +7 -0
- package/dist/types/transports/utxo.d.ts.map +1 -0
- package/dist/types/types/blockStats.d.ts +35 -0
- package/dist/types/types/blockStats.d.ts.map +1 -0
- package/dist/types/types/transaction.d.ts +42 -0
- package/dist/types/types/transaction.d.ts.map +1 -0
- package/dist/types/utils/cancelTransaction.d.ts +3 -0
- package/dist/types/utils/cancelTransaction.d.ts.map +1 -0
- package/dist/types/utils/getUTXOAddress.d.ts +20 -0
- package/dist/types/utils/getUTXOAddress.d.ts.map +1 -0
- package/dist/types/utils/isUTXOAddress.d.ts +3 -0
- package/dist/types/utils/isUTXOAddress.d.ts.map +1 -0
- package/dist/types/utils/modifyFee.d.ts +3 -0
- package/dist/types/utils/modifyFee.d.ts.map +1 -0
- package/dist/types/utils/observe.d.ts +19 -0
- package/dist/types/utils/observe.d.ts.map +1 -0
- package/dist/types/utils/poll.d.ts +13 -0
- package/dist/types/utils/poll.d.ts.map +1 -0
- package/dist/types/utils/sleep.d.ts +2 -0
- package/dist/types/utils/sleep.d.ts.map +1 -0
- package/package.json +50 -0
- package/src/actions/getBalance.ts +26 -0
- package/src/actions/getBlock.ts +58 -0
- package/src/actions/getBlockCount.ts +20 -0
- package/src/actions/getBlockStats.ts +55 -0
- package/src/actions/getUTXOTransaction.ts +43 -0
- package/src/actions/sendUTXOTransaction.ts +29 -0
- package/src/actions/signPsbt.ts +23 -0
- package/src/actions/waitForTransaction.ts +387 -0
- package/src/actions/watchBlockNumber.ts +105 -0
- package/src/chains/bitcoin.ts +18 -0
- package/src/clients/types.ts +48 -0
- package/src/decorators/UTXOAPIActions.ts +20 -0
- package/src/decorators/UTXOActions.ts +37 -0
- package/src/index.ts +97 -0
- package/src/transports/ankr.ts +30 -0
- package/src/transports/blockchair.ts +27 -0
- package/src/transports/blockcypher.ts +32 -0
- package/src/transports/getHttpRpcClient.ts +122 -0
- package/src/transports/getRpcProviderMethods.ts +22 -0
- package/src/transports/mempool.ts +34 -0
- package/src/transports/types.ts +71 -0
- package/src/transports/utxo.ts +84 -0
- package/src/types/blockStats.ts +35 -0
- package/src/types/transaction.ts +43 -0
- package/src/utils/cancelTransaction.ts +75 -0
- package/src/utils/getUTXOAddress.ts +148 -0
- package/src/utils/isUTXOAddress.ts +18 -0
- package/src/utils/modifyFee.ts +78 -0
- package/src/utils/observe.ts +81 -0
- package/src/utils/poll.ts +48 -0
- package/src/utils/sleep.ts +5 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poll.d.ts","sourceRoot":"","sources":["../../../src/utils/poll.ts"],"names":[],"mappings":"AAEA,KAAK,WAAW,CAAC,CAAC,IAAI;IAEpB,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAEjC,eAAe,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAA;IAExE,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,CAAC,EACpB,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,IAAI,CAAA;CAAE,KAAK,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,EAClE,EAAE,WAAW,EAAE,eAAe,EAAE,QAAQ,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC,cA+B3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../../../src/utils/sleep.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAI/C"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bigmi/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "TypeScript library for Bitcoin apps.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/esm/index.js",
|
|
7
|
+
"types": "./dist/esm/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"author": "Eugene Chybisov <eugene@li.finance>",
|
|
10
|
+
"homepage": "https://github.com/lifinance/bigmi",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/lifinance/bigmi.git",
|
|
14
|
+
"directory": "packages/core"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/lifinance/bigmi/issues"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"keywords": [
|
|
21
|
+
"bitcoin",
|
|
22
|
+
"bitcoinjs",
|
|
23
|
+
"btc",
|
|
24
|
+
"utxo",
|
|
25
|
+
"web3",
|
|
26
|
+
"dapp",
|
|
27
|
+
"typescript"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@noble/curves": "^1.6.0",
|
|
31
|
+
"@noble/hashes": "^1.5.0",
|
|
32
|
+
"bech32": "^2.0.0",
|
|
33
|
+
"bitcoinjs-lib": "^7.0.0-rc.0",
|
|
34
|
+
"bs58": "^6.0.0",
|
|
35
|
+
"viem": "^2.21.25"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"bitcoinjs-lib": "^7.0.0-rc.0",
|
|
39
|
+
"bs58": "^6.0.0",
|
|
40
|
+
"viem": "^2.21.0"
|
|
41
|
+
},
|
|
42
|
+
"exports": {
|
|
43
|
+
".": {
|
|
44
|
+
"types": "./dist/esm/index.d.ts",
|
|
45
|
+
"import": "./dist/esm/index.js",
|
|
46
|
+
"default": "./dist/cjs/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./package.json": "./package.json"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Account, Chain, Client, Transport } from 'viem'
|
|
2
|
+
import type { UTXOAPISchema } from '../transports/types.js'
|
|
3
|
+
|
|
4
|
+
export type GetBalanceParameters = {
|
|
5
|
+
/** The address of the account. */
|
|
6
|
+
address: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type GetBalanceReturnType = bigint
|
|
10
|
+
|
|
11
|
+
export async function getBalance<
|
|
12
|
+
C extends Chain | undefined,
|
|
13
|
+
A extends Account | undefined = Account | undefined,
|
|
14
|
+
>(
|
|
15
|
+
client: Client<Transport, C, A, UTXOAPISchema>,
|
|
16
|
+
params: GetBalanceParameters
|
|
17
|
+
): Promise<GetBalanceReturnType> {
|
|
18
|
+
const data = await client.request(
|
|
19
|
+
{
|
|
20
|
+
method: 'getBalance',
|
|
21
|
+
params,
|
|
22
|
+
},
|
|
23
|
+
{ dedupe: true }
|
|
24
|
+
)
|
|
25
|
+
return data
|
|
26
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Block } from 'bitcoinjs-lib'
|
|
2
|
+
import {
|
|
3
|
+
type Account,
|
|
4
|
+
BlockNotFoundError,
|
|
5
|
+
type Chain,
|
|
6
|
+
type Client,
|
|
7
|
+
type Transport,
|
|
8
|
+
} from 'viem'
|
|
9
|
+
import type { UTXOSchema } from '../transports/types.js'
|
|
10
|
+
|
|
11
|
+
export type GetBlockParameters =
|
|
12
|
+
| {
|
|
13
|
+
blockHash: string
|
|
14
|
+
blockNumber?: never
|
|
15
|
+
}
|
|
16
|
+
| {
|
|
17
|
+
blockHash?: never
|
|
18
|
+
blockNumber: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type GetBlockReturnType = Block
|
|
22
|
+
|
|
23
|
+
export async function getBlock<
|
|
24
|
+
C extends Chain | undefined,
|
|
25
|
+
A extends Account | undefined = Account | undefined,
|
|
26
|
+
>(
|
|
27
|
+
client: Client<Transport, C, A, UTXOSchema>,
|
|
28
|
+
{ blockHash, blockNumber }: GetBlockParameters
|
|
29
|
+
): Promise<GetBlockReturnType> {
|
|
30
|
+
let blockHex: string | undefined
|
|
31
|
+
try {
|
|
32
|
+
let _blockHash = blockHash
|
|
33
|
+
if (!_blockHash && blockNumber) {
|
|
34
|
+
_blockHash = await client.request(
|
|
35
|
+
{
|
|
36
|
+
method: 'getblockhash',
|
|
37
|
+
params: [blockNumber],
|
|
38
|
+
},
|
|
39
|
+
{ dedupe: true }
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
if (_blockHash) {
|
|
43
|
+
blockHex = await client.request(
|
|
44
|
+
{
|
|
45
|
+
method: 'getblock',
|
|
46
|
+
params: [_blockHash, 0],
|
|
47
|
+
},
|
|
48
|
+
{ dedupe: true }
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
} catch (_error) {
|
|
52
|
+
throw new BlockNotFoundError({ blockHash, blockNumber } as never)
|
|
53
|
+
}
|
|
54
|
+
if (!blockHex) {
|
|
55
|
+
throw new BlockNotFoundError({ blockHash, blockNumber } as never)
|
|
56
|
+
}
|
|
57
|
+
return Block.fromHex(blockHex)
|
|
58
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Account, Chain, Client, Transport } from 'viem'
|
|
2
|
+
import type { UTXOSchema } from '../transports/types.js'
|
|
3
|
+
|
|
4
|
+
export type GetBlockCountReturnType = number
|
|
5
|
+
|
|
6
|
+
export async function getBlockCount<
|
|
7
|
+
C extends Chain | undefined,
|
|
8
|
+
A extends Account | undefined = Account | undefined,
|
|
9
|
+
>(
|
|
10
|
+
client: Client<Transport, C, A, UTXOSchema>
|
|
11
|
+
): Promise<GetBlockCountReturnType> {
|
|
12
|
+
const data = await client.request(
|
|
13
|
+
{
|
|
14
|
+
method: 'getblockcount',
|
|
15
|
+
params: [],
|
|
16
|
+
},
|
|
17
|
+
{ dedupe: true }
|
|
18
|
+
)
|
|
19
|
+
return data
|
|
20
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Account,
|
|
3
|
+
BlockNotFoundError,
|
|
4
|
+
type Chain,
|
|
5
|
+
type Client,
|
|
6
|
+
type Transport,
|
|
7
|
+
} from 'viem'
|
|
8
|
+
import type { UTXOSchema } from '../transports/types.js'
|
|
9
|
+
import type { BlockStats, BlockStatsKeys } from '../types/blockStats.js'
|
|
10
|
+
|
|
11
|
+
export type GetBlockStatsParameters = (
|
|
12
|
+
| {
|
|
13
|
+
blockHash: string
|
|
14
|
+
blockNumber?: never
|
|
15
|
+
}
|
|
16
|
+
| {
|
|
17
|
+
blockHash?: never
|
|
18
|
+
blockNumber: number
|
|
19
|
+
}
|
|
20
|
+
) & {
|
|
21
|
+
stats?: Array<BlockStatsKeys>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type GetBlockStatsReturnType = BlockStats
|
|
25
|
+
|
|
26
|
+
export async function getBlockStats<
|
|
27
|
+
C extends Chain | undefined,
|
|
28
|
+
A extends Account | undefined = Account | undefined,
|
|
29
|
+
>(
|
|
30
|
+
client: Client<Transport, C, A, UTXOSchema>,
|
|
31
|
+
{ blockHash, blockNumber, stats }: GetBlockStatsParameters
|
|
32
|
+
): Promise<GetBlockStatsReturnType> {
|
|
33
|
+
const blockHashOrNumber = blockHash || blockNumber
|
|
34
|
+
if (!blockHashOrNumber) {
|
|
35
|
+
throw new BlockNotFoundError({ blockHash, blockNumber } as never)
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const params: [string | number, Array<BlockStatsKeys>?] = [
|
|
39
|
+
blockHashOrNumber,
|
|
40
|
+
]
|
|
41
|
+
if (stats) {
|
|
42
|
+
params.push(stats)
|
|
43
|
+
}
|
|
44
|
+
const data = await client.request(
|
|
45
|
+
{
|
|
46
|
+
method: 'getblockstats',
|
|
47
|
+
params: params,
|
|
48
|
+
},
|
|
49
|
+
{ dedupe: true }
|
|
50
|
+
)
|
|
51
|
+
return data
|
|
52
|
+
} catch (_error) {
|
|
53
|
+
throw new BlockNotFoundError({ blockHash, blockNumber } as never)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Account,
|
|
3
|
+
type Chain,
|
|
4
|
+
type Client,
|
|
5
|
+
TransactionNotFoundError,
|
|
6
|
+
type Transport,
|
|
7
|
+
} from 'viem'
|
|
8
|
+
import type { UTXOSchema } from '../transports/types.js'
|
|
9
|
+
import type { UTXOTransaction } from '../types/transaction.js'
|
|
10
|
+
|
|
11
|
+
export type GetUTXOTransactionParameters = {
|
|
12
|
+
/** The Id of the transaction */
|
|
13
|
+
txId: string
|
|
14
|
+
/** The block in which to look for the transaction */
|
|
15
|
+
blockHash?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type GetUTXOTransactionReturnType = UTXOTransaction
|
|
19
|
+
|
|
20
|
+
export async function getUTXOTransaction<
|
|
21
|
+
C extends Chain | undefined,
|
|
22
|
+
A extends Account | undefined = Account | undefined,
|
|
23
|
+
>(
|
|
24
|
+
client: Client<Transport, C, A, UTXOSchema>,
|
|
25
|
+
{ txId, blockHash }: GetUTXOTransactionParameters
|
|
26
|
+
): Promise<GetUTXOTransactionReturnType> {
|
|
27
|
+
try {
|
|
28
|
+
const params: [string, boolean, string?] = [txId, true]
|
|
29
|
+
if (blockHash) {
|
|
30
|
+
params.push(blockHash)
|
|
31
|
+
}
|
|
32
|
+
const data = await client.request({
|
|
33
|
+
method: 'getrawtransaction',
|
|
34
|
+
params: params,
|
|
35
|
+
})
|
|
36
|
+
return data
|
|
37
|
+
} catch (_error) {
|
|
38
|
+
throw new TransactionNotFoundError({
|
|
39
|
+
blockHash: blockHash as never,
|
|
40
|
+
hash: txId as never,
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Account, Chain, Client, Transport } from 'viem'
|
|
2
|
+
import type { UTXOSchema } from '../transports/types.js'
|
|
3
|
+
|
|
4
|
+
export type SendUTXOTransactionParameters = {
|
|
5
|
+
/** The hex string of the raw transaction. */
|
|
6
|
+
hex: string
|
|
7
|
+
/** Rejects transactions whose fee rate is higher than the specified value, expressed in BTC/kB. Set to 0 to accept any fee rate. Default = 0.10 */
|
|
8
|
+
maxFeeRate?: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type SendUTXOTransactionReturnType = string
|
|
12
|
+
|
|
13
|
+
export async function sendUTXOTransaction<
|
|
14
|
+
C extends Chain | undefined,
|
|
15
|
+
A extends Account | undefined = Account | undefined,
|
|
16
|
+
>(
|
|
17
|
+
client: Client<Transport, C, A, UTXOSchema>,
|
|
18
|
+
{ hex, maxFeeRate }: SendUTXOTransactionParameters
|
|
19
|
+
): Promise<SendUTXOTransactionReturnType> {
|
|
20
|
+
const params: [string, number?] = [hex]
|
|
21
|
+
if (maxFeeRate) {
|
|
22
|
+
params.push(maxFeeRate)
|
|
23
|
+
}
|
|
24
|
+
const data = await client.request({
|
|
25
|
+
method: 'sendrawtransaction',
|
|
26
|
+
params: params,
|
|
27
|
+
})
|
|
28
|
+
return data
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Account, Chain, Client, Transport } from 'viem'
|
|
2
|
+
import type {
|
|
3
|
+
SignPsbtParameters,
|
|
4
|
+
SignPsbtReturnType,
|
|
5
|
+
UTXOWalletSchema,
|
|
6
|
+
} from '../clients/types.js'
|
|
7
|
+
|
|
8
|
+
export async function signPsbt<
|
|
9
|
+
C extends Chain | undefined,
|
|
10
|
+
A extends Account | undefined = Account | undefined,
|
|
11
|
+
>(
|
|
12
|
+
client: Client<Transport, C, A, UTXOWalletSchema>,
|
|
13
|
+
params: SignPsbtParameters
|
|
14
|
+
): Promise<SignPsbtReturnType> {
|
|
15
|
+
const data = await client.request(
|
|
16
|
+
{
|
|
17
|
+
method: 'signPsbt',
|
|
18
|
+
params: params,
|
|
19
|
+
},
|
|
20
|
+
{ dedupe: true }
|
|
21
|
+
)
|
|
22
|
+
return data
|
|
23
|
+
}
|