@gnolang/tm2-js-client 2.0.3 → 2.0.5
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 +424 -0
- package/CONTRIBUTING.md +83 -0
- package/dist/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/defineProperty.cjs +12 -0
- package/dist/_virtual/{_@oxc-project_runtime@0.122.0/helpers → _@oxc-project_runtime@0.143.0/helpers/esm}/defineProperty.mjs +3 -3
- package/dist/_virtual/{_@oxc-project_runtime@0.122.0/helpers → _@oxc-project_runtime@0.143.0/helpers/esm}/toPrimitive.cjs +4 -4
- package/dist/_virtual/{_@oxc-project_runtime@0.122.0/helpers → _@oxc-project_runtime@0.143.0/helpers/esm}/toPrimitive.mjs +3 -3
- package/dist/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/toPropertyKey.cjs +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/toPropertyKey.mjs +9 -0
- package/dist/_virtual/{_@oxc-project_runtime@0.122.0/helpers → _@oxc-project_runtime@0.143.0/helpers/esm}/typeof.cjs +2 -2
- package/dist/_virtual/{_@oxc-project_runtime@0.122.0/helpers → _@oxc-project_runtime@0.143.0/helpers/esm}/typeof.mjs +2 -2
- package/dist/_virtual/_rolldown/runtime.cjs +1 -1
- package/dist/index.cjs +9 -2
- package/dist/index.d.cts +8 -1
- package/dist/index.d.mts +8 -1
- package/dist/index.mjs +3 -1
- package/dist/proto/google/protobuf/any.cjs +3 -4
- package/dist/proto/google/protobuf/any.cjs.map +1 -1
- package/dist/proto/google/protobuf/any.d.cts +3 -4
- package/dist/proto/google/protobuf/any.d.cts.map +1 -1
- package/dist/proto/google/protobuf/any.d.mts +3 -4
- package/dist/proto/google/protobuf/any.d.mts.map +1 -1
- package/dist/proto/google/protobuf/any.mjs +3 -3
- package/dist/proto/google/protobuf/any.mjs.map +1 -1
- package/dist/proto/index.cjs +15 -2
- package/dist/proto/index.d.cts +4 -1
- package/dist/proto/index.d.mts +4 -1
- package/dist/proto/index.mjs +5 -3
- package/dist/proto/tm2/abci.cjs +4 -4
- package/dist/proto/tm2/abci.cjs.map +1 -1
- package/dist/proto/tm2/abci.d.cts +3 -4
- package/dist/proto/tm2/abci.d.cts.map +1 -1
- package/dist/proto/tm2/abci.d.mts +3 -4
- package/dist/proto/tm2/abci.d.mts.map +1 -1
- package/dist/proto/tm2/abci.mjs +4 -4
- package/dist/proto/tm2/abci.mjs.map +1 -1
- package/dist/proto/tm2/multisig.cjs +198 -0
- package/dist/proto/tm2/multisig.cjs.map +1 -0
- package/dist/proto/tm2/multisig.d.cts +3 -4
- package/dist/proto/tm2/multisig.d.cts.map +1 -1
- package/dist/proto/tm2/multisig.d.mts +3 -4
- package/dist/proto/tm2/multisig.d.mts.map +1 -1
- package/dist/proto/tm2/multisig.mjs +196 -0
- package/dist/proto/tm2/multisig.mjs.map +1 -0
- package/dist/proto/tm2/tx.cjs +6 -7
- package/dist/proto/tm2/tx.cjs.map +1 -1
- package/dist/proto/tm2/tx.d.cts +2 -3
- package/dist/proto/tm2/tx.d.cts.map +1 -1
- package/dist/proto/tm2/tx.d.mts +2 -3
- package/dist/proto/tm2/tx.d.mts.map +1 -1
- package/dist/proto/tm2/tx.mjs +6 -6
- package/dist/proto/tm2/tx.mjs.map +1 -1
- package/dist/provider/endpoints.cjs.map +1 -1
- package/dist/provider/endpoints.d.cts.map +1 -1
- package/dist/provider/endpoints.d.mts.map +1 -1
- package/dist/provider/endpoints.mjs.map +1 -1
- package/dist/provider/errors/errors.cjs +2 -2
- package/dist/provider/errors/errors.cjs.map +1 -1
- package/dist/provider/errors/errors.d.cts.map +1 -1
- package/dist/provider/errors/errors.d.mts.map +1 -1
- package/dist/provider/errors/errors.mjs +1 -1
- package/dist/provider/errors/errors.mjs.map +1 -1
- package/dist/provider/errors/index.cjs +20 -1
- package/dist/provider/errors/index.d.cts +2 -1
- package/dist/provider/errors/index.d.mts +2 -1
- package/dist/provider/errors/index.mjs +2 -2
- package/dist/provider/index.cjs +61 -9
- package/dist/provider/index.d.cts +7 -1
- package/dist/provider/index.d.mts +7 -1
- package/dist/provider/index.mjs +10 -10
- package/dist/provider/jsonrpc/index.cjs +2 -1
- package/dist/provider/jsonrpc/index.d.cts +2 -1
- package/dist/provider/jsonrpc/index.d.mts +2 -1
- package/dist/provider/jsonrpc/index.mjs +2 -2
- package/dist/provider/jsonrpc/jsonrpc.cjs +2 -2
- package/dist/provider/jsonrpc/jsonrpc.cjs.map +1 -1
- package/dist/provider/jsonrpc/jsonrpc.d.cts +0 -1
- package/dist/provider/jsonrpc/jsonrpc.d.cts.map +1 -1
- package/dist/provider/jsonrpc/jsonrpc.d.mts +0 -1
- package/dist/provider/jsonrpc/jsonrpc.d.mts.map +1 -1
- package/dist/provider/jsonrpc/jsonrpc.mjs +2 -1
- package/dist/provider/jsonrpc/jsonrpc.mjs.map +1 -1
- package/dist/provider/provider.cjs +8 -9
- package/dist/provider/provider.cjs.map +1 -1
- package/dist/provider/provider.d.cts +2 -1
- package/dist/provider/provider.d.cts.map +1 -1
- package/dist/provider/provider.d.mts +2 -1
- package/dist/provider/provider.d.mts.map +1 -1
- package/dist/provider/provider.mjs +43 -26
- package/dist/provider/provider.mjs.map +1 -1
- package/dist/provider/types/abci.d.cts.map +1 -1
- package/dist/provider/types/abci.d.mts.map +1 -1
- package/dist/provider/types/common.d.cts +1 -2
- package/dist/provider/types/common.d.cts.map +1 -1
- package/dist/provider/types/common.d.mts +1 -2
- package/dist/provider/types/common.d.mts.map +1 -1
- package/dist/provider/types/index.cjs +2 -1
- package/dist/provider/types/index.d.cts +2 -1
- package/dist/provider/types/index.d.mts +2 -1
- package/dist/provider/types/index.mjs +2 -2
- package/dist/provider/types/jsonrpc.d.cts.map +1 -1
- package/dist/provider/types/jsonrpc.d.mts.map +1 -1
- package/dist/provider/utility/adapters.cjs +1 -1
- package/dist/provider/utility/adapters.cjs.map +1 -1
- package/dist/provider/utility/adapters.d.cts +1 -1
- package/dist/provider/utility/adapters.d.cts.map +1 -1
- package/dist/provider/utility/adapters.d.mts +1 -1
- package/dist/provider/utility/adapters.d.mts.map +1 -1
- package/dist/provider/utility/adapters.mjs +1 -1
- package/dist/provider/utility/adapters.mjs.map +1 -1
- package/dist/provider/utility/errors.utility.cjs.map +1 -1
- package/dist/provider/utility/errors.utility.mjs.map +1 -1
- package/dist/provider/utility/index.cjs +27 -3
- package/dist/provider/utility/index.d.cts +2 -1
- package/dist/provider/utility/index.d.mts +2 -1
- package/dist/provider/utility/index.mjs +4 -4
- package/dist/provider/utility/provider.utility.cjs +4 -5
- package/dist/provider/utility/provider.utility.cjs.map +1 -1
- package/dist/provider/utility/provider.utility.d.cts +3 -2
- package/dist/provider/utility/provider.utility.d.cts.map +1 -1
- package/dist/provider/utility/provider.utility.d.mts +3 -2
- package/dist/provider/utility/provider.utility.d.mts.map +1 -1
- package/dist/provider/utility/provider.utility.mjs +3 -2
- package/dist/provider/utility/provider.utility.mjs.map +1 -1
- package/dist/provider/utility/requests.utility.cjs +0 -1
- package/dist/provider/utility/requests.utility.cjs.map +1 -1
- package/dist/provider/utility/requests.utility.d.cts +1 -1
- package/dist/provider/utility/requests.utility.d.cts.map +1 -1
- package/dist/provider/utility/requests.utility.d.mts +1 -1
- package/dist/provider/utility/requests.utility.d.mts.map +1 -1
- package/dist/provider/utility/requests.utility.mjs.map +1 -1
- package/dist/provider/websocket/index.cjs +2 -1
- package/dist/provider/websocket/index.d.cts +2 -1
- package/dist/provider/websocket/index.d.mts +2 -1
- package/dist/provider/websocket/index.mjs +2 -2
- package/dist/provider/websocket/ws.cjs +2 -2
- package/dist/provider/websocket/ws.cjs.map +1 -1
- package/dist/provider/websocket/ws.d.cts +0 -1
- package/dist/provider/websocket/ws.d.cts.map +1 -1
- package/dist/provider/websocket/ws.d.mts +0 -1
- package/dist/provider/websocket/ws.d.mts.map +1 -1
- package/dist/provider/websocket/ws.mjs +2 -1
- package/dist/provider/websocket/ws.mjs.map +1 -1
- package/dist/services/index.cjs +2 -1
- package/dist/services/index.d.cts +2 -1
- package/dist/services/index.d.mts +2 -1
- package/dist/services/index.mjs +2 -2
- package/dist/services/rest/restService.cjs +1 -1
- package/dist/services/rest/restService.cjs.map +1 -1
- package/dist/services/rest/restService.d.cts +0 -1
- package/dist/services/rest/restService.d.cts.map +1 -1
- package/dist/services/rest/restService.d.mts +0 -1
- package/dist/services/rest/restService.d.mts.map +1 -1
- package/dist/services/rest/restService.mjs.map +1 -1
- package/dist/services/rest/restService.types.d.cts +1 -1
- package/dist/services/rest/restService.types.d.cts.map +1 -1
- package/dist/services/rest/restService.types.d.mts +1 -1
- package/dist/services/rest/restService.types.d.mts.map +1 -1
- package/dist/utility/compact-bit-array.cjs +1 -1
- package/dist/utility/compact-bit-array.cjs.map +1 -1
- package/dist/utility/compact-bit-array.d.cts +0 -1
- package/dist/utility/compact-bit-array.d.cts.map +1 -1
- package/dist/utility/compact-bit-array.d.mts +0 -1
- package/dist/utility/compact-bit-array.d.mts.map +1 -1
- package/dist/utility/compact-bit-array.mjs +1 -1
- package/dist/utility/compact-bit-array.mjs.map +1 -1
- package/dist/utility/index.cjs +3 -1
- package/dist/utility/index.d.cts +2 -1
- package/dist/utility/index.d.mts +2 -1
- package/dist/utility/index.mjs +2 -2
- package/dist/wallet/index.cjs +16 -5
- package/dist/wallet/index.d.cts +6 -1
- package/dist/wallet/index.d.mts +6 -1
- package/dist/wallet/index.mjs +6 -6
- package/dist/wallet/key/index.cjs +2 -1
- package/dist/wallet/key/index.d.cts +2 -1
- package/dist/wallet/key/index.d.mts +2 -1
- package/dist/wallet/key/index.mjs +2 -2
- package/dist/wallet/key/key.cjs +9 -10
- package/dist/wallet/key/key.cjs.map +1 -1
- package/dist/wallet/key/key.d.cts +0 -1
- package/dist/wallet/key/key.d.cts.map +1 -1
- package/dist/wallet/key/key.d.mts +0 -1
- package/dist/wallet/key/key.d.mts.map +1 -1
- package/dist/wallet/key/key.mjs +1 -1
- package/dist/wallet/key/key.mjs.map +1 -1
- package/dist/wallet/ledger/index.cjs +2 -1
- package/dist/wallet/ledger/index.d.cts +2 -1
- package/dist/wallet/ledger/index.d.mts +2 -1
- package/dist/wallet/ledger/index.mjs +2 -2
- package/dist/wallet/ledger/ledger.cjs +9 -10
- package/dist/wallet/ledger/ledger.cjs.map +1 -1
- package/dist/wallet/ledger/ledger.d.cts +0 -1
- package/dist/wallet/ledger/ledger.d.cts.map +1 -1
- package/dist/wallet/ledger/ledger.d.mts +0 -1
- package/dist/wallet/ledger/ledger.d.mts.map +1 -1
- package/dist/wallet/ledger/ledger.mjs +3 -2
- package/dist/wallet/ledger/ledger.mjs.map +1 -1
- package/dist/wallet/signer.d.cts.map +1 -1
- package/dist/wallet/signer.d.mts.map +1 -1
- package/dist/wallet/types/index.cjs +2 -1
- package/dist/wallet/types/index.d.cts +2 -1
- package/dist/wallet/types/index.d.mts +2 -1
- package/dist/wallet/types/index.mjs +2 -2
- package/dist/wallet/types/sign.d.cts.map +1 -1
- package/dist/wallet/types/sign.d.mts.map +1 -1
- package/dist/wallet/types/wallet.d.cts.map +1 -1
- package/dist/wallet/types/wallet.d.mts.map +1 -1
- package/dist/wallet/utility/index.cjs +8 -1
- package/dist/wallet/utility/index.d.cts +2 -1
- package/dist/wallet/utility/index.d.mts +2 -1
- package/dist/wallet/utility/index.mjs +2 -2
- package/dist/wallet/utility/utility.cjs +1 -1
- package/dist/wallet/utility/utility.cjs.map +1 -1
- package/dist/wallet/utility/utility.d.cts +0 -1
- package/dist/wallet/utility/utility.d.cts.map +1 -1
- package/dist/wallet/utility/utility.d.mts +0 -1
- package/dist/wallet/utility/utility.d.mts.map +1 -1
- package/dist/wallet/utility/utility.mjs.map +1 -1
- package/dist/wallet/wallet.cjs +16 -17
- package/dist/wallet/wallet.cjs.map +1 -1
- package/dist/wallet/wallet.d.cts +3 -1
- package/dist/wallet/wallet.d.cts.map +1 -1
- package/dist/wallet/wallet.d.mts +3 -1
- package/dist/wallet/wallet.d.mts.map +1 -1
- package/dist/wallet/wallet.mjs +4 -3
- package/dist/wallet/wallet.mjs.map +1 -1
- package/package.json +38 -36
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.cjs +0 -12
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.cjs +0 -9
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.mjs +0 -9
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.utility.cjs","names":["parseABCI","constructRequestError","ABCIErrorKey","parseProto","ResponseDeliverTx","base64ToUint8Array","uint8ArrayToBase64","Tx"],"sources":["../../../src/provider/utility/provider.utility.ts"],"sourcesContent":["import {\n sha256,\n} from \"@cosmjs/crypto\";\n\nimport {\n Tx,\n} from \"../../proto/index.js\";\nimport {\n ResponseDeliverTx,\n} from \"../../proto/tm2/abci.js\";\nimport {\n Provider,\n} from \"../provider.js\";\nimport {\n ABCIAccount, ABCIErrorKey, ABCIResponse, BlockInfo,\n} from \"../types/index.js\";\nimport {\n constructRequestError,\n} from \"./errors.utility.js\";\nimport {\n base64ToUint8Array,\n parseABCI,\n parseProto,\n uint8ArrayToBase64,\n} from \"./requests.utility.js\";\n\n/**\n * Extracts the specific balance denomination from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n * @param {string} denomination the required denomination\n */\nexport const extractBalanceFromResponse = (\n abciData: string | null,\n denomination: string,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n return 0;\n }\n\n // Extract the balances\n const balancesRaw = Buffer.from(abciData, \"base64\")\n .toString()\n .replace(/\"/gi, \"\");\n\n // Find the correct balance denomination\n const balances: string[] = balancesRaw.split(\",\");\n if (balances.length < 1) {\n return 0;\n }\n\n // Find the correct denomination\n const pattern = new RegExp(`^(\\\\d+)${denomination}$`);\n for (const balance of balances) {\n const match = balance.match(pattern);\n if (match) {\n return parseInt(match[1], 10);\n }\n }\n\n return 0;\n};\n\n/**\n * Extracts the account sequence from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractSequenceFromResponse = (\n abciData: string | null,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n return 0;\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return parseInt(account.BaseAccount.sequence, 10);\n }\n catch (_e) {\n // unused case\n }\n\n // Account not initialized,\n // return default value (0)\n return 0;\n};\n\n/**\n * Extracts the account number from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractAccountNumberFromResponse = (\n abciData: string | null,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n throw new Error(\"account is not initialized\");\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return parseInt(account.BaseAccount.account_number, 10);\n }\n catch (e) {\n throw new Error(\"account is not initialized\", {\n cause: e,\n });\n }\n};\n\n/**\n * Extracts the account from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractAccountFromResponse = (\n abciData: string | null,\n): ABCIAccount => {\n // Make sure the response is initialized\n if (!abciData) {\n throw new Error(\"account is not initialized\");\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return account;\n }\n catch (e) {\n throw new Error(\"account is not initialized\", {\n cause: e,\n });\n }\n};\n\n/**\n * Extracts the simulate transaction response from the ABCI response value\n * @param {string | null} abciData the base64-encoded ResponseDeliverTx proto message\n */\nexport const extractSimulateFromResponse = (\n abciResponse: ABCIResponse | null,\n): ResponseDeliverTx => {\n // Make sure the response is initialized\n if (!abciResponse) {\n throw new Error(\"abci data is not initialized\");\n }\n\n const error = abciResponse.response?.ResponseBase?.Error;\n if (error && error[ABCIErrorKey]) {\n throw constructRequestError(error[ABCIErrorKey]);\n }\n\n const value = abciResponse.response.Value;\n if (!value) {\n throw new Error(\"abci data is not initialized\");\n }\n\n try {\n return parseProto(value, ResponseDeliverTx.decode);\n }\n catch (e) {\n throw new Error(\"unable to parse simulate response\", {\n cause: e,\n });\n }\n};\n\n/**\n * Waits for the transaction to be committed to a block in the chain\n * of the specified provider. This helper does a search for incoming blocks\n * and checks if a transaction\n * @param {Provider} provider the provider instance\n * @param {string} hash the base64-encoded hash of the transaction\n * @param {number} [fromHeight=latest] the starting height for the search. If omitted, it is the latest block in the chain\n * @param {number} [timeout=15000] the timeout in MS for the search\n */\nexport const waitForTransaction = async (\n provider: Provider,\n hash: string,\n fromHeight?: number,\n timeout?: number,\n): Promise<Tx> => {\n // Fetch the starting point\n let currentHeight = fromHeight\n ? fromHeight\n : await provider.getBlockNumber();\n\n return new Promise((resolve, reject) => {\n const exitTimeout = timeout ? timeout : 15000;\n\n const fetchInterval = setInterval(async () => {\n // Fetch the latest block height\n const latestHeight = await provider.getBlockNumber();\n\n if (latestHeight < currentHeight) {\n // No need to parse older blocks\n return;\n }\n\n for (let blockNum = currentHeight; blockNum <= latestHeight; blockNum++) {\n // Fetch the block from the chain\n const block: BlockInfo = await provider.getBlock(blockNum);\n\n // Check if there are any transactions at all in the block\n if (!block.block.data.txs || block.block.data.txs.length == 0) {\n continue;\n }\n\n // Find the transaction among the block transactions\n for (const tx of block.block.data.txs) {\n // Decode the base-64 transaction\n const txRaw = base64ToUint8Array(tx);\n\n // Calculate the transaction hash\n const txHash = sha256(txRaw);\n\n if (uint8ArrayToBase64(txHash) == hash) {\n // Clear the interval\n clearInterval(fetchInterval);\n\n // Decode the transaction from amino\n resolve(Tx.decode(txRaw));\n }\n }\n }\n\n currentHeight = latestHeight + 1;\n }, 1000);\n\n setTimeout(() => {\n // Clear the fetch interval\n clearInterval(fetchInterval);\n\n reject(\"transaction fetch timeout\");\n }, exitTimeout);\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider.utility.cjs","names":["parseABCI","constructRequestError","ABCIErrorKey","parseProto","ResponseDeliverTx","base64ToUint8Array","sha256","uint8ArrayToBase64","Tx"],"sources":["../../../src/provider/utility/provider.utility.ts"],"sourcesContent":["import {\n sha256,\n} from \"@cosmjs/crypto\";\n\nimport {\n Tx,\n} from \"../../proto/index.js\";\nimport {\n ResponseDeliverTx,\n} from \"../../proto/tm2/abci.js\";\nimport {\n Provider,\n} from \"../provider.js\";\nimport {\n ABCIAccount, ABCIErrorKey, ABCIResponse, BlockInfo,\n} from \"../types/index.js\";\nimport {\n constructRequestError,\n} from \"./errors.utility.js\";\nimport {\n base64ToUint8Array,\n parseABCI,\n parseProto,\n uint8ArrayToBase64,\n} from \"./requests.utility.js\";\n\n/**\n * Extracts the specific balance denomination from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n * @param {string} denomination the required denomination\n */\nexport const extractBalanceFromResponse = (\n abciData: string | null,\n denomination: string,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n return 0;\n }\n\n // Extract the balances\n const balancesRaw = Buffer.from(abciData, \"base64\")\n .toString()\n .replace(/\"/gi, \"\");\n\n // Find the correct balance denomination\n const balances: string[] = balancesRaw.split(\",\");\n if (balances.length < 1) {\n return 0;\n }\n\n // Find the correct denomination\n const pattern = new RegExp(`^(\\\\d+)${denomination}$`);\n for (const balance of balances) {\n const match = balance.match(pattern);\n if (match) {\n return parseInt(match[1], 10);\n }\n }\n\n return 0;\n};\n\n/**\n * Extracts the account sequence from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractSequenceFromResponse = (\n abciData: string | null,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n return 0;\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return parseInt(account.BaseAccount.sequence, 10);\n }\n catch (_e) {\n // unused case\n }\n\n // Account not initialized,\n // return default value (0)\n return 0;\n};\n\n/**\n * Extracts the account number from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractAccountNumberFromResponse = (\n abciData: string | null,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n throw new Error(\"account is not initialized\");\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return parseInt(account.BaseAccount.account_number, 10);\n }\n catch (e) {\n throw new Error(\"account is not initialized\", {\n cause: e,\n });\n }\n};\n\n/**\n * Extracts the account from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractAccountFromResponse = (\n abciData: string | null,\n): ABCIAccount => {\n // Make sure the response is initialized\n if (!abciData) {\n throw new Error(\"account is not initialized\");\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return account;\n }\n catch (e) {\n throw new Error(\"account is not initialized\", {\n cause: e,\n });\n }\n};\n\n/**\n * Extracts the simulate transaction response from the ABCI response value\n * @param {string | null} abciData the base64-encoded ResponseDeliverTx proto message\n */\nexport const extractSimulateFromResponse = (\n abciResponse: ABCIResponse | null,\n): ResponseDeliverTx => {\n // Make sure the response is initialized\n if (!abciResponse) {\n throw new Error(\"abci data is not initialized\");\n }\n\n const error = abciResponse.response?.ResponseBase?.Error;\n if (error && error[ABCIErrorKey]) {\n throw constructRequestError(error[ABCIErrorKey]);\n }\n\n const value = abciResponse.response.Value;\n if (!value) {\n throw new Error(\"abci data is not initialized\");\n }\n\n try {\n return parseProto(value, ResponseDeliverTx.decode);\n }\n catch (e) {\n throw new Error(\"unable to parse simulate response\", {\n cause: e,\n });\n }\n};\n\n/**\n * Waits for the transaction to be committed to a block in the chain\n * of the specified provider. This helper does a search for incoming blocks\n * and checks if a transaction\n * @param {Provider} provider the provider instance\n * @param {string} hash the base64-encoded hash of the transaction\n * @param {number} [fromHeight=latest] the starting height for the search. If omitted, it is the latest block in the chain\n * @param {number} [timeout=15000] the timeout in MS for the search\n */\nexport const waitForTransaction = async (\n provider: Provider,\n hash: string,\n fromHeight?: number,\n timeout?: number,\n): Promise<Tx> => {\n // Fetch the starting point\n let currentHeight = fromHeight\n ? fromHeight\n : await provider.getBlockNumber();\n\n return new Promise((resolve, reject) => {\n const exitTimeout = timeout ? timeout : 15000;\n\n const fetchInterval = setInterval(async () => {\n // Fetch the latest block height\n const latestHeight = await provider.getBlockNumber();\n\n if (latestHeight < currentHeight) {\n // No need to parse older blocks\n return;\n }\n\n for (let blockNum = currentHeight; blockNum <= latestHeight; blockNum++) {\n // Fetch the block from the chain\n const block: BlockInfo = await provider.getBlock(blockNum);\n\n // Check if there are any transactions at all in the block\n if (!block.block.data.txs || block.block.data.txs.length == 0) {\n continue;\n }\n\n // Find the transaction among the block transactions\n for (const tx of block.block.data.txs) {\n // Decode the base-64 transaction\n const txRaw = base64ToUint8Array(tx);\n\n // Calculate the transaction hash\n const txHash = sha256(txRaw);\n\n if (uint8ArrayToBase64(txHash) == hash) {\n // Clear the interval\n clearInterval(fetchInterval);\n\n // Decode the transaction from amino\n resolve(Tx.decode(txRaw));\n }\n }\n }\n\n currentHeight = latestHeight + 1;\n }, 1000);\n\n setTimeout(() => {\n // Clear the fetch interval\n clearInterval(fetchInterval);\n\n reject(\"transaction fetch timeout\");\n }, exitTimeout);\n });\n};\n"],"mappings":";;;;;;;;;;;;;;AA+BA,MAAa,8BACX,UACA,iBACW;CAEX,IAAI,CAAC,UACH,OAAO;CAST,MAAM,WALc,OAAO,KAAK,UAAU,QAAQ,CAAC,CAChD,SAAS,CAAC,CACV,QAAQ,OAAO,EAGS,CAAA,CAAY,MAAM,GAAG;CAChD,IAAI,SAAS,SAAS,GACpB,OAAO;CAIT,MAAM,UAAU,IAAI,OAAO,UAAU,aAAa,EAAE;CACpD,KAAK,MAAM,WAAW,UAAU;EAC9B,MAAM,QAAQ,QAAQ,MAAM,OAAO;EACnC,IAAI,OACF,OAAO,SAAS,MAAM,IAAI,EAAE;CAEhC;CAEA,OAAO;AACT;;;;;AAMA,MAAa,+BACX,aACW;CAEX,IAAI,CAAC,UACH,OAAO;CAGT,IAAI;EAEF,MAAM,UAAuBA,yBAAAA,UAAuB,QAAQ;EAE5D,OAAO,SAAS,QAAQ,YAAY,UAAU,EAAE;CAClD,SACO,IAAI,CAEX;CAIA,OAAO;AACT;;;;;AAMA,MAAa,oCACX,aACW;CAEX,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,4BAA4B;CAG9C,IAAI;EAEF,MAAM,UAAuBA,yBAAAA,UAAuB,QAAQ;EAE5D,OAAO,SAAS,QAAQ,YAAY,gBAAgB,EAAE;CACxD,SACO,GAAG;EACR,MAAM,IAAI,MAAM,8BAA8B,EAC5C,OAAO,EACT,CAAC;CACH;AACF;;;;;AAMA,MAAa,8BACX,aACgB;CAEhB,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,4BAA4B;CAG9C,IAAI;EAIF,OAF6BA,yBAAAA,UAAuB,QAE7C;CACT,SACO,GAAG;EACR,MAAM,IAAI,MAAM,8BAA8B,EAC5C,OAAO,EACT,CAAC;CACH;AACF;;;;;AAMA,MAAa,+BACX,iBACsB;CAEtB,IAAI,CAAC,cACH,MAAM,IAAI,MAAM,8BAA8B;CAGhD,MAAM,QAAQ,aAAa,UAAU,cAAc;CACnD,IAAI,SAAS,MAAA,UACX,MAAMC,uBAAAA,sBAAsB,MAAMC,eAAAA,aAAa;CAGjD,MAAM,QAAQ,aAAa,SAAS;CACpC,IAAI,CAAC,OACH,MAAM,IAAI,MAAM,8BAA8B;CAGhD,IAAI;EACF,OAAOC,yBAAAA,WAAW,OAAOC,aAAAA,kBAAkB,MAAM;CACnD,SACO,GAAG;EACR,MAAM,IAAI,MAAM,qCAAqC,EACnD,OAAO,EACT,CAAC;CACH;AACF;;;;;;;;;;AAWA,MAAa,qBAAqB,OAChC,UACA,MACA,YACA,YACgB;CAEhB,IAAI,gBAAgB,aAChB,aACA,MAAM,SAAS,eAAe;CAElC,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,cAAc,UAAU,UAAU;EAExC,MAAM,gBAAgB,YAAY,YAAY;GAE5C,MAAM,eAAe,MAAM,SAAS,eAAe;GAEnD,IAAI,eAAe,eAEjB;GAGF,KAAK,IAAI,WAAW,eAAe,YAAY,cAAc,YAAY;IAEvE,MAAM,QAAmB,MAAM,SAAS,SAAS,QAAQ;IAGzD,IAAI,CAAC,MAAM,MAAM,KAAK,OAAO,MAAM,MAAM,KAAK,IAAI,UAAU,GAC1D;IAIF,KAAK,MAAM,MAAM,MAAM,MAAM,KAAK,KAAK;KAErC,MAAM,QAAQC,yBAAAA,mBAAmB,EAAE;KAGnC,MAAM,UAAA,GAASC,eAAAA,OAAAA,CAAO,KAAK;KAE3B,IAAIC,yBAAAA,mBAAmB,MAAM,KAAK,MAAM;MAEtC,cAAc,aAAa;MAG3B,QAAQC,WAAAA,GAAG,OAAO,KAAK,CAAC;KAC1B;IACF;GACF;GAEA,gBAAgB,eAAe;EACjC,GAAG,GAAI;EAEP,iBAAiB;GAEf,cAAc,aAAa;GAE3B,OAAO,2BAA2B;EACpC,GAAG,WAAW;CAChB,CAAC;AACH"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { ResponseDeliverTx } from "../../proto/tm2/abci.cjs";
|
|
1
2
|
import { Tx } from "../../proto/tm2/tx.cjs";
|
|
3
|
+
import "../../proto/index.cjs";
|
|
2
4
|
import { ABCIAccount, ABCIResponse } from "../types/abci.cjs";
|
|
5
|
+
import "../types/index.cjs";
|
|
3
6
|
import { Provider } from "../provider.cjs";
|
|
4
|
-
import { ResponseDeliverTx } from "../../proto/tm2/abci.cjs";
|
|
5
|
-
|
|
6
7
|
//#region src/provider/utility/provider.utility.d.ts
|
|
7
8
|
/**
|
|
8
9
|
* Extracts the specific balance denomination from the ABCI response
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.utility.d.cts","names":[],"sources":["../../../src/provider/utility/provider.utility.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider.utility.d.cts","names":[],"sources":["../../../src/provider/utility/provider.utility.ts"],"mappings":";;;;;;;;;;;;cA+Ba,6BACX,yBACA;;;;;cAkCW,8BACX;;;;;cA0BW,mCACX;;;;;cAwBW,6BACX,4BACC;;;;;cAuBU,8BACX,cAAc,wBACb;;;;;;;;;;cAmCU,qBACX,UAAU,UACV,cACA,qBACA,qBACC,QAAQ"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { ResponseDeliverTx } from "../../proto/tm2/abci.mjs";
|
|
1
2
|
import { Tx } from "../../proto/tm2/tx.mjs";
|
|
3
|
+
import "../../proto/index.mjs";
|
|
2
4
|
import { ABCIAccount, ABCIResponse } from "../types/abci.mjs";
|
|
5
|
+
import "../types/index.mjs";
|
|
3
6
|
import { Provider } from "../provider.mjs";
|
|
4
|
-
import { ResponseDeliverTx } from "../../proto/tm2/abci.mjs";
|
|
5
|
-
|
|
6
7
|
//#region src/provider/utility/provider.utility.d.ts
|
|
7
8
|
/**
|
|
8
9
|
* Extracts the specific balance denomination from the ABCI response
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.utility.d.mts","names":[],"sources":["../../../src/provider/utility/provider.utility.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider.utility.d.mts","names":[],"sources":["../../../src/provider/utility/provider.utility.ts"],"mappings":";;;;;;;;;;;;cA+Ba,6BACX,yBACA;;;;;cAkCW,8BACX;;;;;cA0BW,mCACX;;;;;cAwBW,6BACX,4BACC;;;;;cAuBU,8BACX,cAAc,wBACb;;;;;;;;;;cAmCU,qBACX,UAAU,UACV,cACA,qBACA,qBACC,QAAQ"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { ResponseDeliverTx } from "../../proto/tm2/abci.mjs";
|
|
1
2
|
import { Tx } from "../../proto/tm2/tx.mjs";
|
|
2
3
|
import "../../proto/index.mjs";
|
|
3
4
|
import { ABCIErrorKey } from "../types/abci.mjs";
|
|
4
5
|
import "../types/index.mjs";
|
|
5
6
|
import { constructRequestError } from "./errors.utility.mjs";
|
|
6
|
-
import { ResponseDeliverTx } from "../../proto/tm2/abci.mjs";
|
|
7
7
|
import { base64ToUint8Array, parseABCI, parseProto, uint8ArrayToBase64 } from "./requests.utility.mjs";
|
|
8
8
|
import { sha256 } from "@cosmjs/crypto";
|
|
9
9
|
//#region src/provider/utility/provider.utility.ts
|
|
@@ -97,7 +97,8 @@ const waitForTransaction = async (provider, hash, fromHeight, timeout) => {
|
|
|
97
97
|
if (!block.block.data.txs || block.block.data.txs.length == 0) continue;
|
|
98
98
|
for (const tx of block.block.data.txs) {
|
|
99
99
|
const txRaw = base64ToUint8Array(tx);
|
|
100
|
-
|
|
100
|
+
const txHash = sha256(txRaw);
|
|
101
|
+
if (uint8ArrayToBase64(txHash) == hash) {
|
|
101
102
|
clearInterval(fetchInterval);
|
|
102
103
|
resolve(Tx.decode(txRaw));
|
|
103
104
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.utility.mjs","names":[],"sources":["../../../src/provider/utility/provider.utility.ts"],"sourcesContent":["import {\n sha256,\n} from \"@cosmjs/crypto\";\n\nimport {\n Tx,\n} from \"../../proto/index.js\";\nimport {\n ResponseDeliverTx,\n} from \"../../proto/tm2/abci.js\";\nimport {\n Provider,\n} from \"../provider.js\";\nimport {\n ABCIAccount, ABCIErrorKey, ABCIResponse, BlockInfo,\n} from \"../types/index.js\";\nimport {\n constructRequestError,\n} from \"./errors.utility.js\";\nimport {\n base64ToUint8Array,\n parseABCI,\n parseProto,\n uint8ArrayToBase64,\n} from \"./requests.utility.js\";\n\n/**\n * Extracts the specific balance denomination from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n * @param {string} denomination the required denomination\n */\nexport const extractBalanceFromResponse = (\n abciData: string | null,\n denomination: string,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n return 0;\n }\n\n // Extract the balances\n const balancesRaw = Buffer.from(abciData, \"base64\")\n .toString()\n .replace(/\"/gi, \"\");\n\n // Find the correct balance denomination\n const balances: string[] = balancesRaw.split(\",\");\n if (balances.length < 1) {\n return 0;\n }\n\n // Find the correct denomination\n const pattern = new RegExp(`^(\\\\d+)${denomination}$`);\n for (const balance of balances) {\n const match = balance.match(pattern);\n if (match) {\n return parseInt(match[1], 10);\n }\n }\n\n return 0;\n};\n\n/**\n * Extracts the account sequence from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractSequenceFromResponse = (\n abciData: string | null,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n return 0;\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return parseInt(account.BaseAccount.sequence, 10);\n }\n catch (_e) {\n // unused case\n }\n\n // Account not initialized,\n // return default value (0)\n return 0;\n};\n\n/**\n * Extracts the account number from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractAccountNumberFromResponse = (\n abciData: string | null,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n throw new Error(\"account is not initialized\");\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return parseInt(account.BaseAccount.account_number, 10);\n }\n catch (e) {\n throw new Error(\"account is not initialized\", {\n cause: e,\n });\n }\n};\n\n/**\n * Extracts the account from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractAccountFromResponse = (\n abciData: string | null,\n): ABCIAccount => {\n // Make sure the response is initialized\n if (!abciData) {\n throw new Error(\"account is not initialized\");\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return account;\n }\n catch (e) {\n throw new Error(\"account is not initialized\", {\n cause: e,\n });\n }\n};\n\n/**\n * Extracts the simulate transaction response from the ABCI response value\n * @param {string | null} abciData the base64-encoded ResponseDeliverTx proto message\n */\nexport const extractSimulateFromResponse = (\n abciResponse: ABCIResponse | null,\n): ResponseDeliverTx => {\n // Make sure the response is initialized\n if (!abciResponse) {\n throw new Error(\"abci data is not initialized\");\n }\n\n const error = abciResponse.response?.ResponseBase?.Error;\n if (error && error[ABCIErrorKey]) {\n throw constructRequestError(error[ABCIErrorKey]);\n }\n\n const value = abciResponse.response.Value;\n if (!value) {\n throw new Error(\"abci data is not initialized\");\n }\n\n try {\n return parseProto(value, ResponseDeliverTx.decode);\n }\n catch (e) {\n throw new Error(\"unable to parse simulate response\", {\n cause: e,\n });\n }\n};\n\n/**\n * Waits for the transaction to be committed to a block in the chain\n * of the specified provider. This helper does a search for incoming blocks\n * and checks if a transaction\n * @param {Provider} provider the provider instance\n * @param {string} hash the base64-encoded hash of the transaction\n * @param {number} [fromHeight=latest] the starting height for the search. If omitted, it is the latest block in the chain\n * @param {number} [timeout=15000] the timeout in MS for the search\n */\nexport const waitForTransaction = async (\n provider: Provider,\n hash: string,\n fromHeight?: number,\n timeout?: number,\n): Promise<Tx> => {\n // Fetch the starting point\n let currentHeight = fromHeight\n ? fromHeight\n : await provider.getBlockNumber();\n\n return new Promise((resolve, reject) => {\n const exitTimeout = timeout ? timeout : 15000;\n\n const fetchInterval = setInterval(async () => {\n // Fetch the latest block height\n const latestHeight = await provider.getBlockNumber();\n\n if (latestHeight < currentHeight) {\n // No need to parse older blocks\n return;\n }\n\n for (let blockNum = currentHeight; blockNum <= latestHeight; blockNum++) {\n // Fetch the block from the chain\n const block: BlockInfo = await provider.getBlock(blockNum);\n\n // Check if there are any transactions at all in the block\n if (!block.block.data.txs || block.block.data.txs.length == 0) {\n continue;\n }\n\n // Find the transaction among the block transactions\n for (const tx of block.block.data.txs) {\n // Decode the base-64 transaction\n const txRaw = base64ToUint8Array(tx);\n\n // Calculate the transaction hash\n const txHash = sha256(txRaw);\n\n if (uint8ArrayToBase64(txHash) == hash) {\n // Clear the interval\n clearInterval(fetchInterval);\n\n // Decode the transaction from amino\n resolve(Tx.decode(txRaw));\n }\n }\n }\n\n currentHeight = latestHeight + 1;\n }, 1000);\n\n setTimeout(() => {\n // Clear the fetch interval\n clearInterval(fetchInterval);\n\n reject(\"transaction fetch timeout\");\n }, exitTimeout);\n });\n};\n"],"mappings":";;;;;;;;;;;;;;AA+BA,MAAa,8BACX,UACA,iBACW;
|
|
1
|
+
{"version":3,"file":"provider.utility.mjs","names":[],"sources":["../../../src/provider/utility/provider.utility.ts"],"sourcesContent":["import {\n sha256,\n} from \"@cosmjs/crypto\";\n\nimport {\n Tx,\n} from \"../../proto/index.js\";\nimport {\n ResponseDeliverTx,\n} from \"../../proto/tm2/abci.js\";\nimport {\n Provider,\n} from \"../provider.js\";\nimport {\n ABCIAccount, ABCIErrorKey, ABCIResponse, BlockInfo,\n} from \"../types/index.js\";\nimport {\n constructRequestError,\n} from \"./errors.utility.js\";\nimport {\n base64ToUint8Array,\n parseABCI,\n parseProto,\n uint8ArrayToBase64,\n} from \"./requests.utility.js\";\n\n/**\n * Extracts the specific balance denomination from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n * @param {string} denomination the required denomination\n */\nexport const extractBalanceFromResponse = (\n abciData: string | null,\n denomination: string,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n return 0;\n }\n\n // Extract the balances\n const balancesRaw = Buffer.from(abciData, \"base64\")\n .toString()\n .replace(/\"/gi, \"\");\n\n // Find the correct balance denomination\n const balances: string[] = balancesRaw.split(\",\");\n if (balances.length < 1) {\n return 0;\n }\n\n // Find the correct denomination\n const pattern = new RegExp(`^(\\\\d+)${denomination}$`);\n for (const balance of balances) {\n const match = balance.match(pattern);\n if (match) {\n return parseInt(match[1], 10);\n }\n }\n\n return 0;\n};\n\n/**\n * Extracts the account sequence from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractSequenceFromResponse = (\n abciData: string | null,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n return 0;\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return parseInt(account.BaseAccount.sequence, 10);\n }\n catch (_e) {\n // unused case\n }\n\n // Account not initialized,\n // return default value (0)\n return 0;\n};\n\n/**\n * Extracts the account number from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractAccountNumberFromResponse = (\n abciData: string | null,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n throw new Error(\"account is not initialized\");\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return parseInt(account.BaseAccount.account_number, 10);\n }\n catch (e) {\n throw new Error(\"account is not initialized\", {\n cause: e,\n });\n }\n};\n\n/**\n * Extracts the account from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractAccountFromResponse = (\n abciData: string | null,\n): ABCIAccount => {\n // Make sure the response is initialized\n if (!abciData) {\n throw new Error(\"account is not initialized\");\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return account;\n }\n catch (e) {\n throw new Error(\"account is not initialized\", {\n cause: e,\n });\n }\n};\n\n/**\n * Extracts the simulate transaction response from the ABCI response value\n * @param {string | null} abciData the base64-encoded ResponseDeliverTx proto message\n */\nexport const extractSimulateFromResponse = (\n abciResponse: ABCIResponse | null,\n): ResponseDeliverTx => {\n // Make sure the response is initialized\n if (!abciResponse) {\n throw new Error(\"abci data is not initialized\");\n }\n\n const error = abciResponse.response?.ResponseBase?.Error;\n if (error && error[ABCIErrorKey]) {\n throw constructRequestError(error[ABCIErrorKey]);\n }\n\n const value = abciResponse.response.Value;\n if (!value) {\n throw new Error(\"abci data is not initialized\");\n }\n\n try {\n return parseProto(value, ResponseDeliverTx.decode);\n }\n catch (e) {\n throw new Error(\"unable to parse simulate response\", {\n cause: e,\n });\n }\n};\n\n/**\n * Waits for the transaction to be committed to a block in the chain\n * of the specified provider. This helper does a search for incoming blocks\n * and checks if a transaction\n * @param {Provider} provider the provider instance\n * @param {string} hash the base64-encoded hash of the transaction\n * @param {number} [fromHeight=latest] the starting height for the search. If omitted, it is the latest block in the chain\n * @param {number} [timeout=15000] the timeout in MS for the search\n */\nexport const waitForTransaction = async (\n provider: Provider,\n hash: string,\n fromHeight?: number,\n timeout?: number,\n): Promise<Tx> => {\n // Fetch the starting point\n let currentHeight = fromHeight\n ? fromHeight\n : await provider.getBlockNumber();\n\n return new Promise((resolve, reject) => {\n const exitTimeout = timeout ? timeout : 15000;\n\n const fetchInterval = setInterval(async () => {\n // Fetch the latest block height\n const latestHeight = await provider.getBlockNumber();\n\n if (latestHeight < currentHeight) {\n // No need to parse older blocks\n return;\n }\n\n for (let blockNum = currentHeight; blockNum <= latestHeight; blockNum++) {\n // Fetch the block from the chain\n const block: BlockInfo = await provider.getBlock(blockNum);\n\n // Check if there are any transactions at all in the block\n if (!block.block.data.txs || block.block.data.txs.length == 0) {\n continue;\n }\n\n // Find the transaction among the block transactions\n for (const tx of block.block.data.txs) {\n // Decode the base-64 transaction\n const txRaw = base64ToUint8Array(tx);\n\n // Calculate the transaction hash\n const txHash = sha256(txRaw);\n\n if (uint8ArrayToBase64(txHash) == hash) {\n // Clear the interval\n clearInterval(fetchInterval);\n\n // Decode the transaction from amino\n resolve(Tx.decode(txRaw));\n }\n }\n }\n\n currentHeight = latestHeight + 1;\n }, 1000);\n\n setTimeout(() => {\n // Clear the fetch interval\n clearInterval(fetchInterval);\n\n reject(\"transaction fetch timeout\");\n }, exitTimeout);\n });\n};\n"],"mappings":";;;;;;;;;;;;;;AA+BA,MAAa,8BACX,UACA,iBACW;CAEX,IAAI,CAAC,UACH,OAAO;CAST,MAAM,WALc,OAAO,KAAK,UAAU,QAAQ,CAAC,CAChD,SAAS,CAAC,CACV,QAAQ,OAAO,EAGS,CAAA,CAAY,MAAM,GAAG;CAChD,IAAI,SAAS,SAAS,GACpB,OAAO;CAIT,MAAM,UAAU,IAAI,OAAO,UAAU,aAAa,EAAE;CACpD,KAAK,MAAM,WAAW,UAAU;EAC9B,MAAM,QAAQ,QAAQ,MAAM,OAAO;EACnC,IAAI,OACF,OAAO,SAAS,MAAM,IAAI,EAAE;CAEhC;CAEA,OAAO;AACT;;;;;AAMA,MAAa,+BACX,aACW;CAEX,IAAI,CAAC,UACH,OAAO;CAGT,IAAI;EAEF,MAAM,UAAuB,UAAuB,QAAQ;EAE5D,OAAO,SAAS,QAAQ,YAAY,UAAU,EAAE;CAClD,SACO,IAAI,CAEX;CAIA,OAAO;AACT;;;;;AAMA,MAAa,oCACX,aACW;CAEX,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,4BAA4B;CAG9C,IAAI;EAEF,MAAM,UAAuB,UAAuB,QAAQ;EAE5D,OAAO,SAAS,QAAQ,YAAY,gBAAgB,EAAE;CACxD,SACO,GAAG;EACR,MAAM,IAAI,MAAM,8BAA8B,EAC5C,OAAO,EACT,CAAC;CACH;AACF;;;;;AAMA,MAAa,8BACX,aACgB;CAEhB,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,4BAA4B;CAG9C,IAAI;EAIF,OAF6B,UAAuB,QAE7C;CACT,SACO,GAAG;EACR,MAAM,IAAI,MAAM,8BAA8B,EAC5C,OAAO,EACT,CAAC;CACH;AACF;;;;;AAMA,MAAa,+BACX,iBACsB;CAEtB,IAAI,CAAC,cACH,MAAM,IAAI,MAAM,8BAA8B;CAGhD,MAAM,QAAQ,aAAa,UAAU,cAAc;CACnD,IAAI,SAAS,MAAA,UACX,MAAM,sBAAsB,MAAM,aAAa;CAGjD,MAAM,QAAQ,aAAa,SAAS;CACpC,IAAI,CAAC,OACH,MAAM,IAAI,MAAM,8BAA8B;CAGhD,IAAI;EACF,OAAO,WAAW,OAAO,kBAAkB,MAAM;CACnD,SACO,GAAG;EACR,MAAM,IAAI,MAAM,qCAAqC,EACnD,OAAO,EACT,CAAC;CACH;AACF;;;;;;;;;;AAWA,MAAa,qBAAqB,OAChC,UACA,MACA,YACA,YACgB;CAEhB,IAAI,gBAAgB,aAChB,aACA,MAAM,SAAS,eAAe;CAElC,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,cAAc,UAAU,UAAU;EAExC,MAAM,gBAAgB,YAAY,YAAY;GAE5C,MAAM,eAAe,MAAM,SAAS,eAAe;GAEnD,IAAI,eAAe,eAEjB;GAGF,KAAK,IAAI,WAAW,eAAe,YAAY,cAAc,YAAY;IAEvE,MAAM,QAAmB,MAAM,SAAS,SAAS,QAAQ;IAGzD,IAAI,CAAC,MAAM,MAAM,KAAK,OAAO,MAAM,MAAM,KAAK,IAAI,UAAU,GAC1D;IAIF,KAAK,MAAM,MAAM,MAAM,MAAM,KAAK,KAAK;KAErC,MAAM,QAAQ,mBAAmB,EAAE;KAGnC,MAAM,SAAS,OAAO,KAAK;KAE3B,IAAI,mBAAmB,MAAM,KAAK,MAAM;MAEtC,cAAc,aAAa;MAG3B,QAAQ,GAAG,OAAO,KAAK,CAAC;KAC1B;IACF;GACF;GAEA,gBAAgB,eAAe;EACjC,GAAG,GAAI;EAEP,iBAAiB;GAEf,cAAc,aAAa;GAE3B,OAAO,2BAA2B;EACpC,GAAG,WAAW;CAChB,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requests.utility.cjs","names":[],"sources":["../../../src/provider/utility/requests.utility.ts"],"sourcesContent":["import {\n BinaryReader,\n} from \"@bufbuild/protobuf/wire\";\nimport {\n v4 as uuidv4,\n} from \"uuid\";\n\nimport {\n RPCError, RPCRequest, RPCResponse,\n} from \"../types/index.js\";\n\n// The version of the supported JSON-RPC protocol\nconst standardVersion = \"2.0\";\n\n/**\n * Creates a new JSON-RPC 2.0 request\n * @param {string} method the requested method\n * @param {unknown[]} [params] the requested params, if any\n */\nexport const newRequest = (method: string, params?: unknown[]): RPCRequest => {\n return {\n // the ID of the request is not that relevant for this helper method;\n // for finer ID control, instantiate the request object directly\n id: uuidv4(),\n jsonrpc: standardVersion,\n method: method,\n params: params,\n };\n};\n\n/**\n * Creates a new JSON-RPC 2.0 response\n * @param {Result} result the response result, if any\n * @param {RPCError} error the response error, if any\n */\nexport const newResponse = <Result>(\n result?: Result,\n error?: RPCError,\n): RPCResponse<Result> => {\n return {\n id: uuidv4(),\n jsonrpc: standardVersion,\n result: result,\n error: error,\n };\n};\n\n/**\n * Parses the base64 encoded ABCI JSON into a concrete type\n * @param {string} data the base64-encoded JSON\n */\nexport const parseABCI = <Result>(data: string): Result => {\n const jsonData: string = Buffer.from(data, \"base64\").toString();\n const parsedData: Result | null = JSON.parse(jsonData);\n\n if (!parsedData) {\n throw new Error(\"unable to parse JSON response\");\n }\n\n return parsedData;\n};\n\nexport const parseProto = <T>(\n data: string,\n decodeFn: (input: BinaryReader | Uint8Array, length?: number) => T,\n) => {\n const protoData = decodeFn(Buffer.from(data, \"base64\"));\n\n return protoData;\n};\n\n/**\n * Converts a string into base64 representation\n * @param {string} str the raw string\n */\nexport const stringToBase64 = (str: string): string => {\n const buffer = Buffer.from(str, \"utf-8\");\n\n return buffer.toString(\"base64\");\n};\n\n/**\n * Converts a base64 string into a Uint8Array representation\n * @param {string} str the base64-encoded string\n */\nexport const base64ToUint8Array = (str: string): Uint8Array => {\n const buffer = Buffer.from(str, \"base64\");\n\n return new Uint8Array(buffer);\n};\n\n/**\n * Converts a Uint8Array into base64 representation\n * @param {Uint8Array} data the Uint8Array to be encoded\n */\nexport const uint8ArrayToBase64 = (data: Uint8Array): string => {\n return Buffer.from(data).toString(\"base64\");\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"requests.utility.cjs","names":["uuidv4"],"sources":["../../../src/provider/utility/requests.utility.ts"],"sourcesContent":["import {\n BinaryReader,\n} from \"@bufbuild/protobuf/wire\";\nimport {\n v4 as uuidv4,\n} from \"uuid\";\n\nimport {\n RPCError, RPCRequest, RPCResponse,\n} from \"../types/index.js\";\n\n// The version of the supported JSON-RPC protocol\nconst standardVersion = \"2.0\";\n\n/**\n * Creates a new JSON-RPC 2.0 request\n * @param {string} method the requested method\n * @param {unknown[]} [params] the requested params, if any\n */\nexport const newRequest = (method: string, params?: unknown[]): RPCRequest => {\n return {\n // the ID of the request is not that relevant for this helper method;\n // for finer ID control, instantiate the request object directly\n id: uuidv4(),\n jsonrpc: standardVersion,\n method: method,\n params: params,\n };\n};\n\n/**\n * Creates a new JSON-RPC 2.0 response\n * @param {Result} result the response result, if any\n * @param {RPCError} error the response error, if any\n */\nexport const newResponse = <Result>(\n result?: Result,\n error?: RPCError,\n): RPCResponse<Result> => {\n return {\n id: uuidv4(),\n jsonrpc: standardVersion,\n result: result,\n error: error,\n };\n};\n\n/**\n * Parses the base64 encoded ABCI JSON into a concrete type\n * @param {string} data the base64-encoded JSON\n */\nexport const parseABCI = <Result>(data: string): Result => {\n const jsonData: string = Buffer.from(data, \"base64\").toString();\n const parsedData: Result | null = JSON.parse(jsonData);\n\n if (!parsedData) {\n throw new Error(\"unable to parse JSON response\");\n }\n\n return parsedData;\n};\n\nexport const parseProto = <T>(\n data: string,\n decodeFn: (input: BinaryReader | Uint8Array, length?: number) => T,\n) => {\n const protoData = decodeFn(Buffer.from(data, \"base64\"));\n\n return protoData;\n};\n\n/**\n * Converts a string into base64 representation\n * @param {string} str the raw string\n */\nexport const stringToBase64 = (str: string): string => {\n const buffer = Buffer.from(str, \"utf-8\");\n\n return buffer.toString(\"base64\");\n};\n\n/**\n * Converts a base64 string into a Uint8Array representation\n * @param {string} str the base64-encoded string\n */\nexport const base64ToUint8Array = (str: string): Uint8Array => {\n const buffer = Buffer.from(str, \"base64\");\n\n return new Uint8Array(buffer);\n};\n\n/**\n * Converts a Uint8Array into base64 representation\n * @param {Uint8Array} data the Uint8Array to be encoded\n */\nexport const uint8ArrayToBase64 = (data: Uint8Array): string => {\n return Buffer.from(data).toString(\"base64\");\n};\n"],"mappings":";;AAYA,MAAM,kBAAkB;;;;;;AAOxB,MAAa,cAAc,QAAgB,WAAmC;CAC5E,OAAO;EAGL,KAAA,GAAIA,KAAAA,GAAAA,CAAO;EACX,SAAS;EACD;EACA;CACV;AACF;;;;;;AAOA,MAAa,eACX,QACA,UACwB;CACxB,OAAO;EACL,KAAA,GAAIA,KAAAA,GAAAA,CAAO;EACX,SAAS;EACD;EACD;CACT;AACF;;;;;AAMA,MAAa,aAAqB,SAAyB;CACzD,MAAM,WAAmB,OAAO,KAAK,MAAM,QAAQ,CAAC,CAAC,SAAS;CAC9D,MAAM,aAA4B,KAAK,MAAM,QAAQ;CAErD,IAAI,CAAC,YACH,MAAM,IAAI,MAAM,+BAA+B;CAGjD,OAAO;AACT;AAEA,MAAa,cACX,MACA,aACG;CAGH,OAFkB,SAAS,OAAO,KAAK,MAAM,QAAQ,CAE9C;AACT;;;;;AAMA,MAAa,kBAAkB,QAAwB;CAGrD,OAFe,OAAO,KAAK,KAAK,OAEzB,CAAA,CAAO,SAAS,QAAQ;AACjC;;;;;AAMA,MAAa,sBAAsB,QAA4B;CAC7D,MAAM,SAAS,OAAO,KAAK,KAAK,QAAQ;CAExC,OAAO,IAAI,WAAW,MAAM;AAC9B;;;;;AAMA,MAAa,sBAAsB,SAA6B;CAC9D,OAAO,OAAO,KAAK,IAAI,CAAC,CAAC,SAAS,QAAQ;AAC5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requests.utility.d.cts","names":[],"sources":["../../../src/provider/utility/requests.utility.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"requests.utility.d.cts","names":[],"sources":["../../../src/provider/utility/requests.utility.ts"],"mappings":";;;;;;;;;cAmBa,aAAc,gBAAgB,uBAAqB;;;;;;cAgBnD,cAAe,QAC1B,SAAS,QACT,QAAQ,aACP,YAAY;;;;;cAaF,YAAa,QAAQ,iBAAe;cAWpC,aAAc,GACzB,cACA,WAAW,OAAO,eAAe,YAAY,oBAAoB,MAAC;;;;;cAWvD,iBAAkB;;;;;cAUlB,qBAAsB,gBAAc;;;;;cAUpC,qBAAsB,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requests.utility.d.mts","names":[],"sources":["../../../src/provider/utility/requests.utility.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"requests.utility.d.mts","names":[],"sources":["../../../src/provider/utility/requests.utility.ts"],"mappings":";;;;;;;;;cAmBa,aAAc,gBAAgB,uBAAqB;;;;;;cAgBnD,cAAe,QAC1B,SAAS,QACT,QAAQ,aACP,YAAY;;;;;cAaF,YAAa,QAAQ,iBAAe;cAWpC,aAAc,GACzB,cACA,WAAW,OAAO,eAAe,YAAY,oBAAoB,MAAC;;;;;cAWvD,iBAAkB;;;;;cAUlB,qBAAsB,gBAAc;;;;;cAUpC,qBAAsB,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requests.utility.mjs","names":["uuidv4"],"sources":["../../../src/provider/utility/requests.utility.ts"],"sourcesContent":["import {\n BinaryReader,\n} from \"@bufbuild/protobuf/wire\";\nimport {\n v4 as uuidv4,\n} from \"uuid\";\n\nimport {\n RPCError, RPCRequest, RPCResponse,\n} from \"../types/index.js\";\n\n// The version of the supported JSON-RPC protocol\nconst standardVersion = \"2.0\";\n\n/**\n * Creates a new JSON-RPC 2.0 request\n * @param {string} method the requested method\n * @param {unknown[]} [params] the requested params, if any\n */\nexport const newRequest = (method: string, params?: unknown[]): RPCRequest => {\n return {\n // the ID of the request is not that relevant for this helper method;\n // for finer ID control, instantiate the request object directly\n id: uuidv4(),\n jsonrpc: standardVersion,\n method: method,\n params: params,\n };\n};\n\n/**\n * Creates a new JSON-RPC 2.0 response\n * @param {Result} result the response result, if any\n * @param {RPCError} error the response error, if any\n */\nexport const newResponse = <Result>(\n result?: Result,\n error?: RPCError,\n): RPCResponse<Result> => {\n return {\n id: uuidv4(),\n jsonrpc: standardVersion,\n result: result,\n error: error,\n };\n};\n\n/**\n * Parses the base64 encoded ABCI JSON into a concrete type\n * @param {string} data the base64-encoded JSON\n */\nexport const parseABCI = <Result>(data: string): Result => {\n const jsonData: string = Buffer.from(data, \"base64\").toString();\n const parsedData: Result | null = JSON.parse(jsonData);\n\n if (!parsedData) {\n throw new Error(\"unable to parse JSON response\");\n }\n\n return parsedData;\n};\n\nexport const parseProto = <T>(\n data: string,\n decodeFn: (input: BinaryReader | Uint8Array, length?: number) => T,\n) => {\n const protoData = decodeFn(Buffer.from(data, \"base64\"));\n\n return protoData;\n};\n\n/**\n * Converts a string into base64 representation\n * @param {string} str the raw string\n */\nexport const stringToBase64 = (str: string): string => {\n const buffer = Buffer.from(str, \"utf-8\");\n\n return buffer.toString(\"base64\");\n};\n\n/**\n * Converts a base64 string into a Uint8Array representation\n * @param {string} str the base64-encoded string\n */\nexport const base64ToUint8Array = (str: string): Uint8Array => {\n const buffer = Buffer.from(str, \"base64\");\n\n return new Uint8Array(buffer);\n};\n\n/**\n * Converts a Uint8Array into base64 representation\n * @param {Uint8Array} data the Uint8Array to be encoded\n */\nexport const uint8ArrayToBase64 = (data: Uint8Array): string => {\n return Buffer.from(data).toString(\"base64\");\n};\n"],"mappings":";;AAYA,MAAM,kBAAkB;;;;;;AAOxB,MAAa,cAAc,QAAgB,WAAmC;
|
|
1
|
+
{"version":3,"file":"requests.utility.mjs","names":["uuidv4"],"sources":["../../../src/provider/utility/requests.utility.ts"],"sourcesContent":["import {\n BinaryReader,\n} from \"@bufbuild/protobuf/wire\";\nimport {\n v4 as uuidv4,\n} from \"uuid\";\n\nimport {\n RPCError, RPCRequest, RPCResponse,\n} from \"../types/index.js\";\n\n// The version of the supported JSON-RPC protocol\nconst standardVersion = \"2.0\";\n\n/**\n * Creates a new JSON-RPC 2.0 request\n * @param {string} method the requested method\n * @param {unknown[]} [params] the requested params, if any\n */\nexport const newRequest = (method: string, params?: unknown[]): RPCRequest => {\n return {\n // the ID of the request is not that relevant for this helper method;\n // for finer ID control, instantiate the request object directly\n id: uuidv4(),\n jsonrpc: standardVersion,\n method: method,\n params: params,\n };\n};\n\n/**\n * Creates a new JSON-RPC 2.0 response\n * @param {Result} result the response result, if any\n * @param {RPCError} error the response error, if any\n */\nexport const newResponse = <Result>(\n result?: Result,\n error?: RPCError,\n): RPCResponse<Result> => {\n return {\n id: uuidv4(),\n jsonrpc: standardVersion,\n result: result,\n error: error,\n };\n};\n\n/**\n * Parses the base64 encoded ABCI JSON into a concrete type\n * @param {string} data the base64-encoded JSON\n */\nexport const parseABCI = <Result>(data: string): Result => {\n const jsonData: string = Buffer.from(data, \"base64\").toString();\n const parsedData: Result | null = JSON.parse(jsonData);\n\n if (!parsedData) {\n throw new Error(\"unable to parse JSON response\");\n }\n\n return parsedData;\n};\n\nexport const parseProto = <T>(\n data: string,\n decodeFn: (input: BinaryReader | Uint8Array, length?: number) => T,\n) => {\n const protoData = decodeFn(Buffer.from(data, \"base64\"));\n\n return protoData;\n};\n\n/**\n * Converts a string into base64 representation\n * @param {string} str the raw string\n */\nexport const stringToBase64 = (str: string): string => {\n const buffer = Buffer.from(str, \"utf-8\");\n\n return buffer.toString(\"base64\");\n};\n\n/**\n * Converts a base64 string into a Uint8Array representation\n * @param {string} str the base64-encoded string\n */\nexport const base64ToUint8Array = (str: string): Uint8Array => {\n const buffer = Buffer.from(str, \"base64\");\n\n return new Uint8Array(buffer);\n};\n\n/**\n * Converts a Uint8Array into base64 representation\n * @param {Uint8Array} data the Uint8Array to be encoded\n */\nexport const uint8ArrayToBase64 = (data: Uint8Array): string => {\n return Buffer.from(data).toString(\"base64\");\n};\n"],"mappings":";;AAYA,MAAM,kBAAkB;;;;;;AAOxB,MAAa,cAAc,QAAgB,WAAmC;CAC5E,OAAO;EAGL,IAAIA,GAAO;EACX,SAAS;EACD;EACA;CACV;AACF;;;;;;AAOA,MAAa,eACX,QACA,UACwB;CACxB,OAAO;EACL,IAAIA,GAAO;EACX,SAAS;EACD;EACD;CACT;AACF;;;;;AAMA,MAAa,aAAqB,SAAyB;CACzD,MAAM,WAAmB,OAAO,KAAK,MAAM,QAAQ,CAAC,CAAC,SAAS;CAC9D,MAAM,aAA4B,KAAK,MAAM,QAAQ;CAErD,IAAI,CAAC,YACH,MAAM,IAAI,MAAM,+BAA+B;CAGjD,OAAO;AACT;AAEA,MAAa,cACX,MACA,aACG;CAGH,OAFkB,SAAS,OAAO,KAAK,MAAM,QAAQ,CAE9C;AACT;;;;;AAMA,MAAa,kBAAkB,QAAwB;CAGrD,OAFe,OAAO,KAAK,KAAK,OAEzB,CAAA,CAAO,SAAS,QAAQ;AACjC;;;;;AAMA,MAAa,sBAAsB,QAA4B;CAC7D,MAAM,SAAS,OAAO,KAAK,KAAK,QAAQ;CAExC,OAAO,IAAI,WAAW,MAAM;AAC9B;;;;;AAMA,MAAa,sBAAsB,SAA6B;CAC9D,OAAO,OAAO,KAAK,IAAI,CAAC,CAAC,SAAS,QAAQ;AAC5C"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
require("./ws.cjs");
|
|
1
|
+
const require_ws = require("./ws.cjs");
|
|
2
|
+
exports.WSProvider = require_ws.WSProvider;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import { WSProvider } from "./ws.cjs";
|
|
1
|
+
import { WSProvider } from "./ws.cjs";
|
|
2
|
+
export { WSProvider };
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import { WSProvider } from "./ws.mjs";
|
|
1
|
+
import { WSProvider } from "./ws.mjs";
|
|
2
|
+
export { WSProvider };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import "./ws.mjs";
|
|
2
|
-
export {};
|
|
1
|
+
import { WSProvider } from "./ws.mjs";
|
|
2
|
+
export { WSProvider };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
1
|
const require_provider = require("../provider.cjs");
|
|
3
2
|
let _gnolang_tm2_rpc = require("@gnolang/tm2-rpc");
|
|
4
3
|
//#region src/provider/websocket/ws.ts
|
|
@@ -11,7 +10,8 @@ var WSProvider = class WSProvider extends require_provider.BaseTm2Provider {
|
|
|
11
10
|
* @param {string} baseURL the WS URL of the node
|
|
12
11
|
*/
|
|
13
12
|
static async create(baseURL) {
|
|
14
|
-
|
|
13
|
+
const client = await _gnolang_tm2_rpc.Tm2Client.connect(baseURL);
|
|
14
|
+
return new WSProvider(client);
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Closes the WS connection. Required when done working
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws.cjs","names":["BaseTm2Provider","Tm2Client"],"sources":["../../../src/provider/websocket/ws.ts"],"sourcesContent":["import {\n Tm2Client,\n} from \"@gnolang/tm2-rpc\";\n\nimport {\n BaseTm2Provider,\n} from \"../provider.js\";\n\n/**\n * Provider based on WS JSON-RPC requests\n */\nexport class WSProvider extends BaseTm2Provider {\n /**\n * Creates a new instance of the {@link WSProvider}\n * @param {string} baseURL the WS URL of the node\n */\n static async create(baseURL: string): Promise<WSProvider> {\n const client = await Tm2Client.connect(baseURL);\n return new WSProvider(client);\n }\n\n /**\n * Closes the WS connection. Required when done working\n * with the WS provider\n */\n closeConnection() {\n this.client.disconnect();\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ws.cjs","names":["BaseTm2Provider","Tm2Client"],"sources":["../../../src/provider/websocket/ws.ts"],"sourcesContent":["import {\n Tm2Client,\n} from \"@gnolang/tm2-rpc\";\n\nimport {\n BaseTm2Provider,\n} from \"../provider.js\";\n\n/**\n * Provider based on WS JSON-RPC requests\n */\nexport class WSProvider extends BaseTm2Provider {\n /**\n * Creates a new instance of the {@link WSProvider}\n * @param {string} baseURL the WS URL of the node\n */\n static async create(baseURL: string): Promise<WSProvider> {\n const client = await Tm2Client.connect(baseURL);\n return new WSProvider(client);\n }\n\n /**\n * Closes the WS connection. Required when done working\n * with the WS provider\n */\n closeConnection() {\n this.client.disconnect();\n }\n}\n"],"mappings":";;;;;;AAWA,IAAa,aAAb,MAAa,mBAAmBA,iBAAAA,gBAAgB;;;;;CAK9C,aAAa,OAAO,SAAsC;EACxD,MAAM,SAAS,MAAMC,iBAAAA,UAAU,QAAQ,OAAO;EAC9C,OAAO,IAAI,WAAW,MAAM;CAC9B;;;;;CAMA,kBAAkB;EAChB,KAAK,OAAO,WAAW;CACzB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws.d.cts","names":[],"sources":["../../../src/provider/websocket/ws.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"ws.d.cts","names":[],"sources":["../../../src/provider/websocket/ws.ts"],"mappings":";;;;;cAWa,mBAAmB;;;;;SAKjB,OAAO,kBAAkB,QAAQ;;;;;EAS9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws.d.mts","names":[],"sources":["../../../src/provider/websocket/ws.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"ws.d.mts","names":[],"sources":["../../../src/provider/websocket/ws.ts"],"mappings":";;;;;cAWa,mBAAmB;;;;;SAKjB,OAAO,kBAAkB,QAAQ;;;;;EAS9C"}
|
|
@@ -10,7 +10,8 @@ var WSProvider = class WSProvider extends BaseTm2Provider {
|
|
|
10
10
|
* @param {string} baseURL the WS URL of the node
|
|
11
11
|
*/
|
|
12
12
|
static async create(baseURL) {
|
|
13
|
-
|
|
13
|
+
const client = await Tm2Client.connect(baseURL);
|
|
14
|
+
return new WSProvider(client);
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* Closes the WS connection. Required when done working
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws.mjs","names":[],"sources":["../../../src/provider/websocket/ws.ts"],"sourcesContent":["import {\n Tm2Client,\n} from \"@gnolang/tm2-rpc\";\n\nimport {\n BaseTm2Provider,\n} from \"../provider.js\";\n\n/**\n * Provider based on WS JSON-RPC requests\n */\nexport class WSProvider extends BaseTm2Provider {\n /**\n * Creates a new instance of the {@link WSProvider}\n * @param {string} baseURL the WS URL of the node\n */\n static async create(baseURL: string): Promise<WSProvider> {\n const client = await Tm2Client.connect(baseURL);\n return new WSProvider(client);\n }\n\n /**\n * Closes the WS connection. Required when done working\n * with the WS provider\n */\n closeConnection() {\n this.client.disconnect();\n }\n}\n"],"mappings":";;;;;;AAWA,IAAa,aAAb,MAAa,mBAAmB,gBAAgB;;;;;CAK9C,aAAa,OAAO,SAAsC;
|
|
1
|
+
{"version":3,"file":"ws.mjs","names":[],"sources":["../../../src/provider/websocket/ws.ts"],"sourcesContent":["import {\n Tm2Client,\n} from \"@gnolang/tm2-rpc\";\n\nimport {\n BaseTm2Provider,\n} from \"../provider.js\";\n\n/**\n * Provider based on WS JSON-RPC requests\n */\nexport class WSProvider extends BaseTm2Provider {\n /**\n * Creates a new instance of the {@link WSProvider}\n * @param {string} baseURL the WS URL of the node\n */\n static async create(baseURL: string): Promise<WSProvider> {\n const client = await Tm2Client.connect(baseURL);\n return new WSProvider(client);\n }\n\n /**\n * Closes the WS connection. Required when done working\n * with the WS provider\n */\n closeConnection() {\n this.client.disconnect();\n }\n}\n"],"mappings":";;;;;;AAWA,IAAa,aAAb,MAAa,mBAAmB,gBAAgB;;;;;CAK9C,aAAa,OAAO,SAAsC;EACxD,MAAM,SAAS,MAAM,UAAU,QAAQ,OAAO;EAC9C,OAAO,IAAI,WAAW,MAAM;CAC9B;;;;;CAMA,kBAAkB;EAChB,KAAK,OAAO,WAAW;CACzB;AACF"}
|
package/dist/services/index.cjs
CHANGED
package/dist/services/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./rest/restService.mjs";
|
|
1
|
+
import { RestService } from "./rest/restService.mjs";
|
|
2
2
|
import "./rest/restService.types.mjs";
|
|
3
|
-
export {};
|
|
3
|
+
export { RestService };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
let axios = require("axios");
|
|
3
|
-
axios = require_runtime.__toESM(axios);
|
|
3
|
+
axios = require_runtime.__toESM(axios, 1);
|
|
4
4
|
//#region src/services/rest/restService.ts
|
|
5
5
|
var RestService = class {
|
|
6
6
|
static async post(baseURL, params) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restService.cjs","names":[],"sources":["../../../src/services/rest/restService.ts"],"sourcesContent":["import axios from \"axios\";\n\nimport {\n RPCResponse,\n} from \"../../provider/index.js\";\nimport {\n RequestParams,\n} from \"./restService.types.js\";\n\nexport class RestService {\n static async post<TResult>(\n baseURL: string,\n params: RequestParams,\n ): Promise<TResult> {\n const axiosResponse = await axios.post<RPCResponse<TResult>>(\n baseURL,\n params.request,\n params.config,\n );\n\n const {\n result, error,\n } = axiosResponse.data;\n\n // Check for errors\n if (error) {\n // Error encountered during the POST request\n throw new Error(`${error.message}: ${error.data}`);\n }\n\n // Check for the correct result format\n if (!result) {\n throw new Error(\"invalid result returned\");\n }\n\n return result;\n }\n}\n"],"mappings":";;;;AASA,IAAa,cAAb,MAAyB;CACvB,aAAa,KACX,SACA,QACkB;EAOlB,MAAM,EACJ,QAAQ,
|
|
1
|
+
{"version":3,"file":"restService.cjs","names":[],"sources":["../../../src/services/rest/restService.ts"],"sourcesContent":["import axios from \"axios\";\n\nimport {\n RPCResponse,\n} from \"../../provider/index.js\";\nimport {\n RequestParams,\n} from \"./restService.types.js\";\n\nexport class RestService {\n static async post<TResult>(\n baseURL: string,\n params: RequestParams,\n ): Promise<TResult> {\n const axiosResponse = await axios.post<RPCResponse<TResult>>(\n baseURL,\n params.request,\n params.config,\n );\n\n const {\n result, error,\n } = axiosResponse.data;\n\n // Check for errors\n if (error) {\n // Error encountered during the POST request\n throw new Error(`${error.message}: ${error.data}`);\n }\n\n // Check for the correct result format\n if (!result) {\n throw new Error(\"invalid result returned\");\n }\n\n return result;\n }\n}\n"],"mappings":";;;;AASA,IAAa,cAAb,MAAyB;CACvB,aAAa,KACX,SACA,QACkB;EAOlB,MAAM,EACJ,QAAQ,WACN,MARwB,MAAA,QAAM,KAChC,SACA,OAAO,SACP,OAAO,MACT,EAII,CAAc;EAGlB,IAAI,OAEF,MAAM,IAAI,MAAM,GAAG,MAAM,QAAQ,IAAI,MAAM,MAAM;EAInD,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,yBAAyB;EAG3C,OAAO;CACT;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restService.d.cts","names":[],"sources":["../../../src/services/rest/restService.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"restService.d.cts","names":[],"sources":["../../../src/services/rest/restService.ts"],"mappings":";;cASa;SACE,KAAK,SAChB,iBACA,QAAQ,gBACP,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restService.d.mts","names":[],"sources":["../../../src/services/rest/restService.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"restService.d.mts","names":[],"sources":["../../../src/services/rest/restService.ts"],"mappings":";;cASa;SACE,KAAK,SAChB,iBACA,QAAQ,gBACP,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restService.mjs","names":[],"sources":["../../../src/services/rest/restService.ts"],"sourcesContent":["import axios from \"axios\";\n\nimport {\n RPCResponse,\n} from \"../../provider/index.js\";\nimport {\n RequestParams,\n} from \"./restService.types.js\";\n\nexport class RestService {\n static async post<TResult>(\n baseURL: string,\n params: RequestParams,\n ): Promise<TResult> {\n const axiosResponse = await axios.post<RPCResponse<TResult>>(\n baseURL,\n params.request,\n params.config,\n );\n\n const {\n result, error,\n } = axiosResponse.data;\n\n // Check for errors\n if (error) {\n // Error encountered during the POST request\n throw new Error(`${error.message}: ${error.data}`);\n }\n\n // Check for the correct result format\n if (!result) {\n throw new Error(\"invalid result returned\");\n }\n\n return result;\n }\n}\n"],"mappings":";;AASA,IAAa,cAAb,MAAyB;CACvB,aAAa,KACX,SACA,QACkB;EAOlB,MAAM,EACJ,QAAQ,
|
|
1
|
+
{"version":3,"file":"restService.mjs","names":[],"sources":["../../../src/services/rest/restService.ts"],"sourcesContent":["import axios from \"axios\";\n\nimport {\n RPCResponse,\n} from \"../../provider/index.js\";\nimport {\n RequestParams,\n} from \"./restService.types.js\";\n\nexport class RestService {\n static async post<TResult>(\n baseURL: string,\n params: RequestParams,\n ): Promise<TResult> {\n const axiosResponse = await axios.post<RPCResponse<TResult>>(\n baseURL,\n params.request,\n params.config,\n );\n\n const {\n result, error,\n } = axiosResponse.data;\n\n // Check for errors\n if (error) {\n // Error encountered during the POST request\n throw new Error(`${error.message}: ${error.data}`);\n }\n\n // Check for the correct result format\n if (!result) {\n throw new Error(\"invalid result returned\");\n }\n\n return result;\n }\n}\n"],"mappings":";;AASA,IAAa,cAAb,MAAyB;CACvB,aAAa,KACX,SACA,QACkB;EAOlB,MAAM,EACJ,QAAQ,WACN,MARwB,MAAM,KAChC,SACA,OAAO,SACP,OAAO,MACT,EAII,CAAc;EAGlB,IAAI,OAEF,MAAM,IAAI,MAAM,GAAG,MAAM,QAAQ,IAAI,MAAM,MAAM;EAInD,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,yBAAyB;EAG3C,OAAO;CACT;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restService.types.d.cts","names":[],"sources":["../../../src/services/rest/restService.types.ts"],"mappings":";;;;UAQiB
|
|
1
|
+
{"version":3,"file":"restService.types.d.cts","names":[],"sources":["../../../src/services/rest/restService.types.ts"],"mappings":";;;;UAQiB;EACf,SAAS;EACT,SAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restService.types.d.mts","names":[],"sources":["../../../src/services/rest/restService.types.ts"],"mappings":";;;;UAQiB
|
|
1
|
+
{"version":3,"file":"restService.types.d.mts","names":[],"sources":["../../../src/services/rest/restService.types.ts"],"mappings":";;;;UAQiB;EACf,SAAS;EACT,SAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compact-bit-array.cjs","names":[],"sources":["../../src/utility/compact-bit-array.ts"],"sourcesContent":["import type {\n CompactBitArray,\n} from \"../proto/tm2/multisig.js\";\n\n/**\n * Converts an amino-encoded compact bit array string to a CompactBitArray.\n * In the amino format, 'x' represents a set bit (1) and '_' represents\n * an unset bit (0). A null input produces an empty CompactBitArray.\n *\n * @example\n * compactBitArrayFromAmino(\"xx___\") // { extra_bits_stored: 5, elems: Uint8Array([0xC0]) }\n * compactBitArrayFromAmino(null) // { extra_bits_stored: 0, elems: Uint8Array([]) }\n */\nexport function compactBitArrayFromAmino(\n amino: string | null,\n): CompactBitArray {\n if (amino === null) {\n return {\n extra_bits_stored: 0,\n elems: new Uint8Array(0),\n };\n }\n\n const count = amino.length;\n const extraBits = count % 8;\n const numBytes = Math.ceil(count / 8);\n const elems = new Uint8Array(numBytes);\n\n for (let i = 0; i < count; i++) {\n if (amino[i] === \"x\") {\n const byteIndex = Math.floor(i / 8);\n const bitIndex = 7 - (i % 8);\n elems[byteIndex] |= 1 << bitIndex;\n }\n }\n\n return {\n extra_bits_stored: extraBits,\n elems,\n };\n}\n\n/**\n * Converts a CompactBitArray to its amino string representation.\n * Set bits (1) become 'x' and unset bits (0) become '_'.\n * Returns null for empty bit arrays (zero length).\n *\n * @example\n * compactBitArrayToAmino({ extra_bits_stored: 5, elems: Uint8Array([0xC0]) }) // \"xx___\"\n * compactBitArrayToAmino({ extra_bits_stored: 0, elems: Uint8Array([]) }) // null\n */\nexport function compactBitArrayToAmino(\n cba: CompactBitArray,\n): string | null {\n if (cba.elems.length === 0) {\n return null;\n }\n\n const fullBytes = cba.extra_bits_stored === 0\n ? cba.elems.length\n : cba.elems.length - 1;\n const totalBits = fullBytes * 8 + cba.extra_bits_stored;\n\n let result = \"\";\n for (let i = 0; i < totalBits; i++) {\n const byteIndex = Math.floor(i / 8);\n const bitIndex = 7 - (i % 8);\n const isSet = (cba.elems[byteIndex] & (1 << bitIndex)) !== 0;\n result += isSet ? \"x\" : \"_\";\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,yBACd,OACiB;
|
|
1
|
+
{"version":3,"file":"compact-bit-array.cjs","names":[],"sources":["../../src/utility/compact-bit-array.ts"],"sourcesContent":["import type {\n CompactBitArray,\n} from \"../proto/tm2/multisig.js\";\n\n/**\n * Converts an amino-encoded compact bit array string to a CompactBitArray.\n * In the amino format, 'x' represents a set bit (1) and '_' represents\n * an unset bit (0). A null input produces an empty CompactBitArray.\n *\n * @example\n * compactBitArrayFromAmino(\"xx___\") // { extra_bits_stored: 5, elems: Uint8Array([0xC0]) }\n * compactBitArrayFromAmino(null) // { extra_bits_stored: 0, elems: Uint8Array([]) }\n */\nexport function compactBitArrayFromAmino(\n amino: string | null,\n): CompactBitArray {\n if (amino === null) {\n return {\n extra_bits_stored: 0,\n elems: new Uint8Array(0),\n };\n }\n\n const count = amino.length;\n const extraBits = count % 8;\n const numBytes = Math.ceil(count / 8);\n const elems = new Uint8Array(numBytes);\n\n for (let i = 0; i < count; i++) {\n if (amino[i] === \"x\") {\n const byteIndex = Math.floor(i / 8);\n const bitIndex = 7 - (i % 8);\n elems[byteIndex] |= 1 << bitIndex;\n }\n }\n\n return {\n extra_bits_stored: extraBits,\n elems,\n };\n}\n\n/**\n * Converts a CompactBitArray to its amino string representation.\n * Set bits (1) become 'x' and unset bits (0) become '_'.\n * Returns null for empty bit arrays (zero length).\n *\n * @example\n * compactBitArrayToAmino({ extra_bits_stored: 5, elems: Uint8Array([0xC0]) }) // \"xx___\"\n * compactBitArrayToAmino({ extra_bits_stored: 0, elems: Uint8Array([]) }) // null\n */\nexport function compactBitArrayToAmino(\n cba: CompactBitArray,\n): string | null {\n if (cba.elems.length === 0) {\n return null;\n }\n\n const fullBytes = cba.extra_bits_stored === 0\n ? cba.elems.length\n : cba.elems.length - 1;\n const totalBits = fullBytes * 8 + cba.extra_bits_stored;\n\n let result = \"\";\n for (let i = 0; i < totalBits; i++) {\n const byteIndex = Math.floor(i / 8);\n const bitIndex = 7 - (i % 8);\n const isSet = (cba.elems[byteIndex] & (1 << bitIndex)) !== 0;\n result += isSet ? \"x\" : \"_\";\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,yBACd,OACiB;CACjB,IAAI,UAAU,MACZ,OAAO;EACL,mBAAmB;EACnB,uBAAO,IAAI,WAAW,CAAC;CACzB;CAGF,MAAM,QAAQ,MAAM;CACpB,MAAM,YAAY,QAAQ;CAC1B,MAAM,WAAW,KAAK,KAAK,QAAQ,CAAC;CACpC,MAAM,QAAQ,IAAI,WAAW,QAAQ;CAErC,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KACzB,IAAI,MAAM,OAAO,KAAK;EACpB,MAAM,YAAY,KAAK,MAAM,IAAI,CAAC;EAClC,MAAM,WAAW,IAAK,IAAI;EAC1B,MAAM,cAAc,KAAK;CAC3B;CAGF,OAAO;EACL,mBAAmB;EACnB;CACF;AACF;;;;;;;;;;AAWA,SAAgB,uBACd,KACe;CACf,IAAI,IAAI,MAAM,WAAW,GACvB,OAAO;CAMT,MAAM,aAHY,IAAI,sBAAsB,IACxC,IAAI,MAAM,SACV,IAAI,MAAM,SAAS,KACO,IAAI,IAAI;CAEtC,IAAI,SAAS;CACb,KAAK,IAAI,IAAI,GAAG,IAAI,WAAW,KAAK;EAClC,MAAM,YAAY,KAAK,MAAM,IAAI,CAAC;EAClC,MAAM,WAAW,IAAK,IAAI;EAC1B,MAAM,SAAS,IAAI,MAAM,aAAc,KAAK,cAAe;EAC3D,UAAU,QAAQ,MAAM;CAC1B;CAEA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compact-bit-array.d.cts","names":[],"sources":["../../src/utility/compact-bit-array.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"compact-bit-array.d.cts","names":[],"sources":["../../src/utility/compact-bit-array.ts"],"mappings":";;;;;;;;;;;iBAagB,yBACd,uBACC;;;;;;;;;;iBAoCa,uBACd,KAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compact-bit-array.d.mts","names":[],"sources":["../../src/utility/compact-bit-array.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"compact-bit-array.d.mts","names":[],"sources":["../../src/utility/compact-bit-array.ts"],"mappings":";;;;;;;;;;;iBAagB,yBACd,uBACC;;;;;;;;;;iBAoCa,uBACd,KAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compact-bit-array.mjs","names":[],"sources":["../../src/utility/compact-bit-array.ts"],"sourcesContent":["import type {\n CompactBitArray,\n} from \"../proto/tm2/multisig.js\";\n\n/**\n * Converts an amino-encoded compact bit array string to a CompactBitArray.\n * In the amino format, 'x' represents a set bit (1) and '_' represents\n * an unset bit (0). A null input produces an empty CompactBitArray.\n *\n * @example\n * compactBitArrayFromAmino(\"xx___\") // { extra_bits_stored: 5, elems: Uint8Array([0xC0]) }\n * compactBitArrayFromAmino(null) // { extra_bits_stored: 0, elems: Uint8Array([]) }\n */\nexport function compactBitArrayFromAmino(\n amino: string | null,\n): CompactBitArray {\n if (amino === null) {\n return {\n extra_bits_stored: 0,\n elems: new Uint8Array(0),\n };\n }\n\n const count = amino.length;\n const extraBits = count % 8;\n const numBytes = Math.ceil(count / 8);\n const elems = new Uint8Array(numBytes);\n\n for (let i = 0; i < count; i++) {\n if (amino[i] === \"x\") {\n const byteIndex = Math.floor(i / 8);\n const bitIndex = 7 - (i % 8);\n elems[byteIndex] |= 1 << bitIndex;\n }\n }\n\n return {\n extra_bits_stored: extraBits,\n elems,\n };\n}\n\n/**\n * Converts a CompactBitArray to its amino string representation.\n * Set bits (1) become 'x' and unset bits (0) become '_'.\n * Returns null for empty bit arrays (zero length).\n *\n * @example\n * compactBitArrayToAmino({ extra_bits_stored: 5, elems: Uint8Array([0xC0]) }) // \"xx___\"\n * compactBitArrayToAmino({ extra_bits_stored: 0, elems: Uint8Array([]) }) // null\n */\nexport function compactBitArrayToAmino(\n cba: CompactBitArray,\n): string | null {\n if (cba.elems.length === 0) {\n return null;\n }\n\n const fullBytes = cba.extra_bits_stored === 0\n ? cba.elems.length\n : cba.elems.length - 1;\n const totalBits = fullBytes * 8 + cba.extra_bits_stored;\n\n let result = \"\";\n for (let i = 0; i < totalBits; i++) {\n const byteIndex = Math.floor(i / 8);\n const bitIndex = 7 - (i % 8);\n const isSet = (cba.elems[byteIndex] & (1 << bitIndex)) !== 0;\n result += isSet ? \"x\" : \"_\";\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,yBACd,OACiB;
|
|
1
|
+
{"version":3,"file":"compact-bit-array.mjs","names":[],"sources":["../../src/utility/compact-bit-array.ts"],"sourcesContent":["import type {\n CompactBitArray,\n} from \"../proto/tm2/multisig.js\";\n\n/**\n * Converts an amino-encoded compact bit array string to a CompactBitArray.\n * In the amino format, 'x' represents a set bit (1) and '_' represents\n * an unset bit (0). A null input produces an empty CompactBitArray.\n *\n * @example\n * compactBitArrayFromAmino(\"xx___\") // { extra_bits_stored: 5, elems: Uint8Array([0xC0]) }\n * compactBitArrayFromAmino(null) // { extra_bits_stored: 0, elems: Uint8Array([]) }\n */\nexport function compactBitArrayFromAmino(\n amino: string | null,\n): CompactBitArray {\n if (amino === null) {\n return {\n extra_bits_stored: 0,\n elems: new Uint8Array(0),\n };\n }\n\n const count = amino.length;\n const extraBits = count % 8;\n const numBytes = Math.ceil(count / 8);\n const elems = new Uint8Array(numBytes);\n\n for (let i = 0; i < count; i++) {\n if (amino[i] === \"x\") {\n const byteIndex = Math.floor(i / 8);\n const bitIndex = 7 - (i % 8);\n elems[byteIndex] |= 1 << bitIndex;\n }\n }\n\n return {\n extra_bits_stored: extraBits,\n elems,\n };\n}\n\n/**\n * Converts a CompactBitArray to its amino string representation.\n * Set bits (1) become 'x' and unset bits (0) become '_'.\n * Returns null for empty bit arrays (zero length).\n *\n * @example\n * compactBitArrayToAmino({ extra_bits_stored: 5, elems: Uint8Array([0xC0]) }) // \"xx___\"\n * compactBitArrayToAmino({ extra_bits_stored: 0, elems: Uint8Array([]) }) // null\n */\nexport function compactBitArrayToAmino(\n cba: CompactBitArray,\n): string | null {\n if (cba.elems.length === 0) {\n return null;\n }\n\n const fullBytes = cba.extra_bits_stored === 0\n ? cba.elems.length\n : cba.elems.length - 1;\n const totalBits = fullBytes * 8 + cba.extra_bits_stored;\n\n let result = \"\";\n for (let i = 0; i < totalBits; i++) {\n const byteIndex = Math.floor(i / 8);\n const bitIndex = 7 - (i % 8);\n const isSet = (cba.elems[byteIndex] & (1 << bitIndex)) !== 0;\n result += isSet ? \"x\" : \"_\";\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,yBACd,OACiB;CACjB,IAAI,UAAU,MACZ,OAAO;EACL,mBAAmB;EACnB,uBAAO,IAAI,WAAW,CAAC;CACzB;CAGF,MAAM,QAAQ,MAAM;CACpB,MAAM,YAAY,QAAQ;CAC1B,MAAM,WAAW,KAAK,KAAK,QAAQ,CAAC;CACpC,MAAM,QAAQ,IAAI,WAAW,QAAQ;CAErC,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KACzB,IAAI,MAAM,OAAO,KAAK;EACpB,MAAM,YAAY,KAAK,MAAM,IAAI,CAAC;EAClC,MAAM,WAAW,IAAK,IAAI;EAC1B,MAAM,cAAc,KAAK;CAC3B;CAGF,OAAO;EACL,mBAAmB;EACnB;CACF;AACF;;;;;;;;;;AAWA,SAAgB,uBACd,KACe;CACf,IAAI,IAAI,MAAM,WAAW,GACvB,OAAO;CAMT,MAAM,aAHY,IAAI,sBAAsB,IACxC,IAAI,MAAM,SACV,IAAI,MAAM,SAAS,KACO,IAAI,IAAI;CAEtC,IAAI,SAAS;CACb,KAAK,IAAI,IAAI,GAAG,IAAI,WAAW,KAAK;EAClC,MAAM,YAAY,KAAK,MAAM,IAAI,CAAC;EAClC,MAAM,WAAW,IAAK,IAAI;EAC1B,MAAM,SAAS,IAAI,MAAM,aAAc,KAAK,cAAe;EAC3D,UAAU,QAAQ,MAAM;CAC1B;CAEA,OAAO;AACT"}
|
package/dist/utility/index.cjs
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
require("./compact-bit-array.cjs");
|
|
1
|
+
const require_compact_bit_array = require("./compact-bit-array.cjs");
|
|
2
|
+
exports.compactBitArrayFromAmino = require_compact_bit_array.compactBitArrayFromAmino;
|
|
3
|
+
exports.compactBitArrayToAmino = require_compact_bit_array.compactBitArrayToAmino;
|
package/dist/utility/index.d.cts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import { compactBitArrayFromAmino, compactBitArrayToAmino } from "./compact-bit-array.cjs";
|
|
1
|
+
import { compactBitArrayFromAmino, compactBitArrayToAmino } from "./compact-bit-array.cjs";
|
|
2
|
+
export { compactBitArrayFromAmino, compactBitArrayToAmino };
|
package/dist/utility/index.d.mts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import { compactBitArrayFromAmino, compactBitArrayToAmino } from "./compact-bit-array.mjs";
|
|
1
|
+
import { compactBitArrayFromAmino, compactBitArrayToAmino } from "./compact-bit-array.mjs";
|
|
2
|
+
export { compactBitArrayFromAmino, compactBitArrayToAmino };
|
package/dist/utility/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import "./compact-bit-array.mjs";
|
|
2
|
-
export {};
|
|
1
|
+
import { compactBitArrayFromAmino, compactBitArrayToAmino } from "./compact-bit-array.mjs";
|
|
2
|
+
export { compactBitArrayFromAmino, compactBitArrayToAmino };
|