@rialo/ts-cdk 0.1.3 → 0.1.4
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/README.md +27 -2
- package/dist/index.d.mts +325 -67
- package/dist/index.d.ts +325 -67
- package/dist/index.js +405 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +405 -47
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -449,8 +449,8 @@ var RialoError = class _RialoError extends Error {
|
|
|
449
449
|
|
|
450
450
|
// src/constants.ts
|
|
451
451
|
var DEFAULT_NUM_ACCOUNTS = 1;
|
|
452
|
-
var URL_MAINNET = "https://mainnet.rialo.io:
|
|
453
|
-
var URL_TESTNET = "https://testnet.rialo.io:
|
|
452
|
+
var URL_MAINNET = "https://mainnet.rialo.io:4101";
|
|
453
|
+
var URL_TESTNET = "https://testnet.rialo.io:4101";
|
|
454
454
|
var URL_DEVNET = "https://devnet.rialo.io:4101";
|
|
455
455
|
var URL_LOCALNET = "http://localhost:4100";
|
|
456
456
|
var RIALO_MAINNET_CHAIN = {
|
|
@@ -6601,6 +6601,7 @@ var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
|
|
|
6601
6601
|
RpcErrorCode2["INTERNAL_ERROR"] = "INTERNAL_ERROR";
|
|
6602
6602
|
RpcErrorCode2["TRANSACTION_REJECTED"] = "TRANSACTION_REJECTED";
|
|
6603
6603
|
RpcErrorCode2["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
|
|
6604
|
+
RpcErrorCode2["TRANSACTION_CONFIRMATION_TIMEOUT"] = "TRANSACTION_CONFIRMATION_TIMEOUT";
|
|
6604
6605
|
RpcErrorCode2["ACCOUNT_NOT_FOUND"] = "ACCOUNT_NOT_FOUND";
|
|
6605
6606
|
RpcErrorCode2["RATE_LIMIT_EXCEEDED"] = "RATE_LIMIT_EXCEEDED";
|
|
6606
6607
|
RpcErrorCode2["NODE_UNHEALTHY"] = "NODE_UNHEALTHY";
|
|
@@ -6686,7 +6687,7 @@ var RpcError = class _RpcError extends Error {
|
|
|
6686
6687
|
// src/rpc/clients/base-client.ts
|
|
6687
6688
|
var BaseRpcClient = class {
|
|
6688
6689
|
transport;
|
|
6689
|
-
requestId =
|
|
6690
|
+
requestId = 0;
|
|
6690
6691
|
constructor(transport) {
|
|
6691
6692
|
this.transport = transport;
|
|
6692
6693
|
}
|
|
@@ -6696,7 +6697,7 @@ var BaseRpcClient = class {
|
|
|
6696
6697
|
* Handles request serialization, response validation, and error mapping.
|
|
6697
6698
|
*/
|
|
6698
6699
|
async call(method, params = []) {
|
|
6699
|
-
const requestId = this.
|
|
6700
|
+
const requestId = this.nextRequestId();
|
|
6700
6701
|
const request = {
|
|
6701
6702
|
jsonrpc: "2.0",
|
|
6702
6703
|
id: requestId,
|
|
@@ -6737,6 +6738,14 @@ var BaseRpcClient = class {
|
|
|
6737
6738
|
const response = data;
|
|
6738
6739
|
return response.jsonrpc === "2.0" && typeof response.id === "number" && ("result" in response || "error" in response);
|
|
6739
6740
|
}
|
|
6741
|
+
/**
|
|
6742
|
+
* Generates the next request ID with Overflow Protection.
|
|
6743
|
+
* @returns The next request ID.
|
|
6744
|
+
*/
|
|
6745
|
+
nextRequestId() {
|
|
6746
|
+
this.requestId = (this.requestId + 1) % Number.MAX_SAFE_INTEGER;
|
|
6747
|
+
return this.requestId;
|
|
6748
|
+
}
|
|
6740
6749
|
/**
|
|
6741
6750
|
* Returns the configured RPC endpoint URL.
|
|
6742
6751
|
*/
|
|
@@ -6799,7 +6808,16 @@ function getLocalnetUrl() {
|
|
|
6799
6808
|
// src/rpc/clients/query-client.ts
|
|
6800
6809
|
var QueryRpcClient = class extends BaseRpcClient {
|
|
6801
6810
|
/**
|
|
6802
|
-
*
|
|
6811
|
+
* Retrieve the balance of an account in kelvins (smallest unit).
|
|
6812
|
+
*
|
|
6813
|
+
* @param pubkey - The public key of the account to query
|
|
6814
|
+
* @returns The account balance in kelvins
|
|
6815
|
+
*
|
|
6816
|
+
* @example
|
|
6817
|
+
* ```typescript
|
|
6818
|
+
* const balance = await client.getBalance(publicKey);
|
|
6819
|
+
* console.log(`Balance: ${balance} kelvins`);
|
|
6820
|
+
* ```
|
|
6803
6821
|
*/
|
|
6804
6822
|
async getBalance(pubkey) {
|
|
6805
6823
|
const result = await this.call("getBalance", [
|
|
@@ -6808,7 +6826,23 @@ var QueryRpcClient = class extends BaseRpcClient {
|
|
|
6808
6826
|
return BigInt(result.value);
|
|
6809
6827
|
}
|
|
6810
6828
|
/**
|
|
6811
|
-
*
|
|
6829
|
+
* Retrieve detailed information about an account.
|
|
6830
|
+
*
|
|
6831
|
+
* Returns account data including balance, owner program, stored data,
|
|
6832
|
+
* executable status, and rent epoch.
|
|
6833
|
+
*
|
|
6834
|
+
* @param pubkey - The public key of the account to query
|
|
6835
|
+
* @returns Account information, or null if the account does not exist
|
|
6836
|
+
*
|
|
6837
|
+
* @example
|
|
6838
|
+
* ```typescript
|
|
6839
|
+
* const info = await client.getAccountInfo(publicKey);
|
|
6840
|
+
* if (info) {
|
|
6841
|
+
* console.log(`Owner: ${info.owner}`);
|
|
6842
|
+
* console.log(`Balance: ${info.balance} kelvins`);
|
|
6843
|
+
* console.log(`Data length: ${info.data.length} bytes`);
|
|
6844
|
+
* }
|
|
6845
|
+
* ```
|
|
6812
6846
|
*/
|
|
6813
6847
|
async getAccountInfo(pubkey) {
|
|
6814
6848
|
const result = await this.call("getAccountInfo", [{ address: pubkey.toString(), encoding: "base64" }]);
|
|
@@ -6824,14 +6858,42 @@ var QueryRpcClient = class extends BaseRpcClient {
|
|
|
6824
6858
|
};
|
|
6825
6859
|
}
|
|
6826
6860
|
/**
|
|
6827
|
-
*
|
|
6861
|
+
* Retrieve the current block height of the blockchain.
|
|
6862
|
+
*
|
|
6863
|
+
* The block height represents the number of blocks that have been
|
|
6864
|
+
* confirmed on the chain since genesis.
|
|
6865
|
+
*
|
|
6866
|
+
* @returns The current block height
|
|
6867
|
+
*
|
|
6868
|
+
* @example
|
|
6869
|
+
* ```typescript
|
|
6870
|
+
* const height = await client.getBlockHeight();
|
|
6871
|
+
* console.log(`Current block height: ${height}`);
|
|
6872
|
+
* ```
|
|
6828
6873
|
*/
|
|
6829
6874
|
async getBlockHeight() {
|
|
6830
6875
|
const result = await this.call("getBlockHeight", []);
|
|
6831
6876
|
return BigInt(result);
|
|
6832
6877
|
}
|
|
6833
6878
|
/**
|
|
6834
|
-
*
|
|
6879
|
+
* Retrieve detailed information about a confirmed transaction.
|
|
6880
|
+
*
|
|
6881
|
+
* Returns transaction metadata including the block height it was
|
|
6882
|
+
* confirmed in and any execution errors.
|
|
6883
|
+
*
|
|
6884
|
+
* @param signature - The transaction signature to query
|
|
6885
|
+
* @returns Transaction information, or null if the transaction is not found
|
|
6886
|
+
*
|
|
6887
|
+
* @example
|
|
6888
|
+
* ```typescript
|
|
6889
|
+
* const tx = await client.getTransaction(signature);
|
|
6890
|
+
* if (tx) {
|
|
6891
|
+
* console.log(`Confirmed in block: ${tx.blockHeight}`);
|
|
6892
|
+
* if (tx.err) {
|
|
6893
|
+
* console.log(`Transaction failed: ${tx.err}`);
|
|
6894
|
+
* }
|
|
6895
|
+
* }
|
|
6896
|
+
* ```
|
|
6835
6897
|
*/
|
|
6836
6898
|
async getTransaction(signature) {
|
|
6837
6899
|
const result = await this.call("getTransaction", [signature]);
|
|
@@ -6840,20 +6902,45 @@ var QueryRpcClient = class extends BaseRpcClient {
|
|
|
6840
6902
|
}
|
|
6841
6903
|
return {
|
|
6842
6904
|
signature,
|
|
6843
|
-
|
|
6844
|
-
|
|
6845
|
-
err: result.err
|
|
6905
|
+
blockHeight: BigInt(result.block_height ?? 0),
|
|
6906
|
+
err: result.err ?? result.meta?.err ?? void 0
|
|
6846
6907
|
};
|
|
6847
6908
|
}
|
|
6848
6909
|
/**
|
|
6849
|
-
*
|
|
6910
|
+
* Retrieve the total number of transactions processed since genesis.
|
|
6911
|
+
*
|
|
6912
|
+
* @returns The total transaction count
|
|
6913
|
+
*
|
|
6914
|
+
* @example
|
|
6915
|
+
* ```typescript
|
|
6916
|
+
* const count = await client.getTransactionCount();
|
|
6917
|
+
* console.log(`Total transactions: ${count}`);
|
|
6918
|
+
* ```
|
|
6850
6919
|
*/
|
|
6851
6920
|
async getTransactionCount() {
|
|
6852
6921
|
const result = await this.call("getTransactionCount", []);
|
|
6853
6922
|
return BigInt(result);
|
|
6854
6923
|
}
|
|
6855
6924
|
/**
|
|
6856
|
-
*
|
|
6925
|
+
* Retrieve the status of multiple transaction signatures in a single request.
|
|
6926
|
+
*
|
|
6927
|
+
* Useful for batch-checking transaction confirmations. Returns null for
|
|
6928
|
+
* signatures that are not found or have expired from the status cache.
|
|
6929
|
+
*
|
|
6930
|
+
* @param signatures - Array of transaction signatures to query
|
|
6931
|
+
* @returns Array of signature statuses (null if signature not found)
|
|
6932
|
+
*
|
|
6933
|
+
* @example
|
|
6934
|
+
* ```typescript
|
|
6935
|
+
* const statuses = await client.getSignatureStatuses([sig1, sig2, sig3]);
|
|
6936
|
+
* statuses.forEach((status, i) => {
|
|
6937
|
+
* if (status) {
|
|
6938
|
+
* console.log(`${signatures[i]}: slot ${status.slot}, executed: ${status.executed}`);
|
|
6939
|
+
* } else {
|
|
6940
|
+
* console.log(`${signatures[i]}: not found`);
|
|
6941
|
+
* }
|
|
6942
|
+
* });
|
|
6943
|
+
* ```
|
|
6857
6944
|
*/
|
|
6858
6945
|
async getSignatureStatuses(signatures) {
|
|
6859
6946
|
const result = await this.call("getSignatureStatuses", [signatures]);
|
|
@@ -6863,13 +6950,26 @@ var QueryRpcClient = class extends BaseRpcClient {
|
|
|
6863
6950
|
}
|
|
6864
6951
|
return {
|
|
6865
6952
|
slot: BigInt(status.slot),
|
|
6866
|
-
|
|
6953
|
+
executed: status.executed,
|
|
6867
6954
|
err: status.err
|
|
6868
6955
|
};
|
|
6869
6956
|
});
|
|
6870
6957
|
}
|
|
6871
6958
|
/**
|
|
6872
|
-
*
|
|
6959
|
+
* Retrieve information about the current epoch.
|
|
6960
|
+
*
|
|
6961
|
+
* Returns epoch metadata including the current epoch number, slot position
|
|
6962
|
+
* within the epoch, total slots per epoch, and current block height.
|
|
6963
|
+
*
|
|
6964
|
+
* @returns Current epoch information
|
|
6965
|
+
*
|
|
6966
|
+
* @example
|
|
6967
|
+
* ```typescript
|
|
6968
|
+
* const info = await client.getEpochInfo();
|
|
6969
|
+
* console.log(`Epoch: ${info.epoch}`);
|
|
6970
|
+
* console.log(`Slot ${info.slotIndex} of ${info.slotsInEpoch}`);
|
|
6971
|
+
* console.log(`Block height: ${info.blockHeight}`);
|
|
6972
|
+
* ```
|
|
6873
6973
|
*/
|
|
6874
6974
|
async getEpochInfo() {
|
|
6875
6975
|
const result = await this.call("getEpochInfo", []);
|
|
@@ -6883,7 +6983,22 @@ var QueryRpcClient = class extends BaseRpcClient {
|
|
|
6883
6983
|
};
|
|
6884
6984
|
}
|
|
6885
6985
|
/**
|
|
6886
|
-
*
|
|
6986
|
+
* Check the health status of the RPC node.
|
|
6987
|
+
*
|
|
6988
|
+
* Returns "ok" if the node is healthy. If the node is unhealthy,
|
|
6989
|
+
* returns an error message describing the issue.
|
|
6990
|
+
*
|
|
6991
|
+
* @returns "ok" if healthy, otherwise an error message
|
|
6992
|
+
*
|
|
6993
|
+
* @example
|
|
6994
|
+
* ```typescript
|
|
6995
|
+
* const health = await client.getHealth();
|
|
6996
|
+
* if (health === "ok") {
|
|
6997
|
+
* console.log("Node is healthy");
|
|
6998
|
+
* } else {
|
|
6999
|
+
* console.log(`Node unhealthy: ${health}`);
|
|
7000
|
+
* }
|
|
7001
|
+
* ```
|
|
6887
7002
|
*/
|
|
6888
7003
|
async getHealth() {
|
|
6889
7004
|
const result = await this.call("getHealth", []);
|
|
@@ -6892,9 +7007,32 @@ var QueryRpcClient = class extends BaseRpcClient {
|
|
|
6892
7007
|
};
|
|
6893
7008
|
|
|
6894
7009
|
// src/rpc/clients/transaction-client.ts
|
|
7010
|
+
var DEFAULT_MAX_RETRIES = 10;
|
|
7011
|
+
var DEFAULT_RETRY_DELAY_MS = 200;
|
|
6895
7012
|
var TransactionRpcClient = class extends BaseRpcClient {
|
|
6896
7013
|
/**
|
|
6897
|
-
* Submit a signed transaction to the blockchain
|
|
7014
|
+
* Submit a signed transaction to the blockchain.
|
|
7015
|
+
*
|
|
7016
|
+
* Sends the transaction to the network for processing. The transaction
|
|
7017
|
+
* must be fully signed before submission. Returns immediately with the
|
|
7018
|
+
* transaction signature - use {@link confirmTransaction} or
|
|
7019
|
+
* {@link sendAndConfirmTransaction} to wait for confirmation.
|
|
7020
|
+
*
|
|
7021
|
+
* @param transaction - Serialized signed transaction bytes
|
|
7022
|
+
* @param options - Transaction submission options
|
|
7023
|
+
* @returns Transaction signature (base58 encoded)
|
|
7024
|
+
*
|
|
7025
|
+
* @example
|
|
7026
|
+
* ```typescript
|
|
7027
|
+
* const signature = await client.sendTransaction(signedTx);
|
|
7028
|
+
* console.log(`Submitted: ${signature}`);
|
|
7029
|
+
*
|
|
7030
|
+
* // With options
|
|
7031
|
+
* const signature = await client.sendTransaction(signedTx, {
|
|
7032
|
+
* skipPreflight: true,
|
|
7033
|
+
* maxRetries: 3,
|
|
7034
|
+
* });
|
|
7035
|
+
* ```
|
|
6898
7036
|
*/
|
|
6899
7037
|
async sendTransaction(transaction, options) {
|
|
6900
7038
|
const base64Tx = toBase64(transaction);
|
|
@@ -6910,15 +7048,162 @@ var TransactionRpcClient = class extends BaseRpcClient {
|
|
|
6910
7048
|
return signature;
|
|
6911
7049
|
}
|
|
6912
7050
|
/**
|
|
6913
|
-
*
|
|
7051
|
+
* Wait for a transaction to be confirmed.
|
|
7052
|
+
*
|
|
7053
|
+
* A transaction is considered confirmed when:
|
|
7054
|
+
* - It has been processed in a block (`blockHeight > 0`)
|
|
7055
|
+
*
|
|
7056
|
+
* @param signature - Transaction signature to monitor
|
|
7057
|
+
* @param options - Confirmation options
|
|
7058
|
+
* @returns Confirmed transaction details
|
|
7059
|
+
* @throws {TransactionFailedError} If the transaction fails on-chain
|
|
7060
|
+
* @throws {TransactionConfirmationTimeoutError} If confirmation times out
|
|
7061
|
+
*/
|
|
7062
|
+
async confirmTransaction(signature, options) {
|
|
7063
|
+
const maxRetries = options?.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
7064
|
+
const retryDelay = options?.retryDelay ?? DEFAULT_RETRY_DELAY_MS;
|
|
7065
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
7066
|
+
if (attempt > 0) {
|
|
7067
|
+
await this.sleep(retryDelay);
|
|
7068
|
+
}
|
|
7069
|
+
try {
|
|
7070
|
+
const txInfo = await this.getTransaction(signature);
|
|
7071
|
+
if (!txInfo) {
|
|
7072
|
+
continue;
|
|
7073
|
+
}
|
|
7074
|
+
if (txInfo.err) {
|
|
7075
|
+
return {
|
|
7076
|
+
signature,
|
|
7077
|
+
executed: false,
|
|
7078
|
+
err: txInfo.err
|
|
7079
|
+
};
|
|
7080
|
+
}
|
|
7081
|
+
if (txInfo.blockHeight && txInfo.blockHeight > 0n) {
|
|
7082
|
+
return {
|
|
7083
|
+
signature,
|
|
7084
|
+
executed: true,
|
|
7085
|
+
err: void 0
|
|
7086
|
+
};
|
|
7087
|
+
}
|
|
7088
|
+
} catch (error) {
|
|
7089
|
+
if (error instanceof RpcError && error.code === "TRANSACTION_REJECTED" /* TRANSACTION_REJECTED */) {
|
|
7090
|
+
throw error;
|
|
7091
|
+
}
|
|
7092
|
+
}
|
|
7093
|
+
}
|
|
7094
|
+
throw new RpcError(
|
|
7095
|
+
"TRANSACTION_CONFIRMATION_TIMEOUT" /* TRANSACTION_CONFIRMATION_TIMEOUT */,
|
|
7096
|
+
"Transaction confirmation timed out",
|
|
7097
|
+
{
|
|
7098
|
+
signature,
|
|
7099
|
+
maxRetries
|
|
7100
|
+
}
|
|
7101
|
+
);
|
|
7102
|
+
}
|
|
7103
|
+
/**
|
|
7104
|
+
* Submit a signed transaction and wait for confirmation.
|
|
7105
|
+
*
|
|
7106
|
+
* Polls the transaction status until it is confirmed (blockHeight > 0),
|
|
7107
|
+
* or until the maximum number of retries is reached.
|
|
7108
|
+
*
|
|
7109
|
+
* @param transaction - Serialized signed transaction bytes
|
|
7110
|
+
* @param options - Transaction submission and confirmation options
|
|
7111
|
+
* @returns Confirmed transaction details
|
|
7112
|
+
* @throws {TransactionFailedError} If the transaction fails on-chain
|
|
7113
|
+
* @throws {TransactionConfirmationTimeoutError} If confirmation times out
|
|
7114
|
+
*
|
|
7115
|
+
* @example
|
|
7116
|
+
* ```typescript
|
|
7117
|
+
* const result = await client.sendAndConfirmTransaction(signedTx);
|
|
7118
|
+
* console.log(`Confirmed in block ${result.blockHeight}, executed: ${result.executed}`);
|
|
7119
|
+
*
|
|
7120
|
+
* // With custom retry settings
|
|
7121
|
+
* const result = await client.sendAndConfirmTransaction(signedTx, {
|
|
7122
|
+
* maxRetries: 3,
|
|
7123
|
+
* retryDelay: 500,
|
|
7124
|
+
* });
|
|
7125
|
+
* ```
|
|
7126
|
+
*/
|
|
7127
|
+
async sendAndConfirmTransaction(transaction, options) {
|
|
7128
|
+
const signature = await this.sendTransaction(transaction, options);
|
|
7129
|
+
return await this.confirmTransaction(signature, options);
|
|
7130
|
+
}
|
|
7131
|
+
/**
|
|
7132
|
+
* Request an airdrop of tokens to an account.
|
|
7133
|
+
*
|
|
7134
|
+
* **Note**: Only available on devnet and testnet networks.
|
|
7135
|
+
*
|
|
7136
|
+
* Returns immediately with the airdrop transaction signature.
|
|
7137
|
+
* Use {@link requestAirdropAndConfirm} to wait for the airdrop to complete.
|
|
7138
|
+
*
|
|
7139
|
+
* @param pubkey - The public key of the account to receive tokens
|
|
7140
|
+
* @param amount - Amount to airdrop in kelvins (smallest unit)
|
|
7141
|
+
* @returns Airdrop transaction signature
|
|
7142
|
+
*
|
|
7143
|
+
* @example
|
|
7144
|
+
* ```typescript
|
|
7145
|
+
* const signature = await client.requestAirdrop(publicKey, 1_000_000_000n);
|
|
7146
|
+
* console.log(`Airdrop requested: ${signature}`);
|
|
7147
|
+
* ```
|
|
6914
7148
|
*/
|
|
6915
7149
|
async requestAirdrop(pubkey, amount) {
|
|
7150
|
+
if (amount > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
7151
|
+
throw new RpcError(
|
|
7152
|
+
"INVALID_PARAMS" /* INVALID_PARAMS */,
|
|
7153
|
+
`Airdrop amount ${amount} exceeds maximum safe value`
|
|
7154
|
+
);
|
|
7155
|
+
}
|
|
6916
7156
|
const signature = await this.call("requestAirdrop", [
|
|
6917
7157
|
pubkey.toString(),
|
|
6918
7158
|
Number(amount)
|
|
6919
7159
|
]);
|
|
6920
7160
|
return signature;
|
|
6921
7161
|
}
|
|
7162
|
+
/**
|
|
7163
|
+
* Request an airdrop of tokens and wait for confirmation.
|
|
7164
|
+
*
|
|
7165
|
+
* **Note**: Only available on devnet and testnet networks.
|
|
7166
|
+
*
|
|
7167
|
+
* Combines {@link requestAirdrop} and {@link confirmTransaction} into
|
|
7168
|
+
* a single call for convenience.
|
|
7169
|
+
*
|
|
7170
|
+
* @param pubkey - The public key of the account to receive tokens
|
|
7171
|
+
* @param amount - Amount to airdrop in kelvins (smallest unit)
|
|
7172
|
+
* @param options - Confirmation options (max retries, retry delay)
|
|
7173
|
+
* @returns Confirmed transaction details
|
|
7174
|
+
* @throws {RpcError} If the airdrop transaction fails or confirmation times out
|
|
7175
|
+
*
|
|
7176
|
+
* @example
|
|
7177
|
+
* ```typescript
|
|
7178
|
+
* const result = await client.requestAirdropAndConfirm(publicKey, 1_000_000_000n);
|
|
7179
|
+
* if (result.executed) {
|
|
7180
|
+
* console.log("Airdrop confirmed!");
|
|
7181
|
+
* }
|
|
7182
|
+
* ```
|
|
7183
|
+
*/
|
|
7184
|
+
async requestAirdropAndConfirm(pubkey, amount, options) {
|
|
7185
|
+
const signature = await this.requestAirdrop(pubkey, amount);
|
|
7186
|
+
return await this.confirmTransaction(signature, options);
|
|
7187
|
+
}
|
|
7188
|
+
async getTransaction(signature) {
|
|
7189
|
+
const result = await this.call("getTransaction", [signature]);
|
|
7190
|
+
if (!result) {
|
|
7191
|
+
return null;
|
|
7192
|
+
}
|
|
7193
|
+
return {
|
|
7194
|
+
signature,
|
|
7195
|
+
blockHeight: BigInt(result.block_height ?? 0),
|
|
7196
|
+
err: result.err ?? result.meta?.err ?? void 0
|
|
7197
|
+
};
|
|
7198
|
+
}
|
|
7199
|
+
/**
|
|
7200
|
+
* Sleeps for a given number of milliseconds.
|
|
7201
|
+
* @param ms - The number of milliseconds to sleep.
|
|
7202
|
+
* @returns A promise that resolves when the sleep is complete.
|
|
7203
|
+
*/
|
|
7204
|
+
sleep(ms) {
|
|
7205
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
7206
|
+
}
|
|
6922
7207
|
};
|
|
6923
7208
|
|
|
6924
7209
|
// src/rpc/clients/client.ts
|
|
@@ -6945,6 +7230,12 @@ var RialoClient = class {
|
|
|
6945
7230
|
getChainIdentifier() {
|
|
6946
7231
|
return this.chain.id;
|
|
6947
7232
|
}
|
|
7233
|
+
/**
|
|
7234
|
+
* Returns the chain configuration.
|
|
7235
|
+
*/
|
|
7236
|
+
getChainConfig() {
|
|
7237
|
+
return this.chain;
|
|
7238
|
+
}
|
|
6948
7239
|
/**
|
|
6949
7240
|
* Retrieves the balance of an account in kelvins (smallest unit).
|
|
6950
7241
|
*/
|
|
@@ -7021,6 +7312,49 @@ var RialoClient = class {
|
|
|
7021
7312
|
async requestAirdrop(pubkey, amount) {
|
|
7022
7313
|
return await this.transactionClient.requestAirdrop(pubkey, amount);
|
|
7023
7314
|
}
|
|
7315
|
+
/**
|
|
7316
|
+
* Submits a signed transaction and waits for confirmation.
|
|
7317
|
+
*
|
|
7318
|
+
* @param transaction - Serialized signed transaction bytes
|
|
7319
|
+
* @param options - Transaction submission and confirmation options
|
|
7320
|
+
* @returns Confirmed transaction details
|
|
7321
|
+
* @throws {TransactionFailedError} If the transaction fails on-chain
|
|
7322
|
+
* @throws {TransactionConfirmationTimeoutError} If confirmation times out
|
|
7323
|
+
*
|
|
7324
|
+
* @example
|
|
7325
|
+
* ```typescript
|
|
7326
|
+
* const result = await client.sendAndConfirmTransaction(signedTx);
|
|
7327
|
+
* console.log(`Confirmed in slot ${result.slot}`);
|
|
7328
|
+
* ```
|
|
7329
|
+
*/
|
|
7330
|
+
async sendAndConfirmTransaction(transaction, options) {
|
|
7331
|
+
return await this.transactionClient.sendAndConfirmTransaction(
|
|
7332
|
+
transaction,
|
|
7333
|
+
options
|
|
7334
|
+
);
|
|
7335
|
+
}
|
|
7336
|
+
/**
|
|
7337
|
+
* Waits for a transaction to be confirmed.
|
|
7338
|
+
*
|
|
7339
|
+
* @param signature - Transaction signature to monitor
|
|
7340
|
+
* @param options - Confirmation options
|
|
7341
|
+
* @returns Confirmed transaction details
|
|
7342
|
+
*/
|
|
7343
|
+
async confirmTransaction(signature, options) {
|
|
7344
|
+
return await this.transactionClient.confirmTransaction(signature, options);
|
|
7345
|
+
}
|
|
7346
|
+
/**
|
|
7347
|
+
* Requests an airdrop and waits for confirmation.
|
|
7348
|
+
*
|
|
7349
|
+
* **Note**: Only available on devnet and testnet.
|
|
7350
|
+
*/
|
|
7351
|
+
async requestAirdropAndConfirm(pubkey, amount, options) {
|
|
7352
|
+
return await this.transactionClient.requestAirdropAndConfirm(
|
|
7353
|
+
pubkey,
|
|
7354
|
+
amount,
|
|
7355
|
+
options
|
|
7356
|
+
);
|
|
7357
|
+
}
|
|
7024
7358
|
};
|
|
7025
7359
|
|
|
7026
7360
|
// src/rpc/http-transport.ts
|
|
@@ -7122,46 +7456,71 @@ var HttpTransport = class {
|
|
|
7122
7456
|
}
|
|
7123
7457
|
}
|
|
7124
7458
|
/**
|
|
7125
|
-
* Handle HTTP error responses
|
|
7459
|
+
* Handle HTTP error responses.
|
|
7460
|
+
*
|
|
7461
|
+
* Parses the response body to extract JSON-RPC error details when available,
|
|
7462
|
+
* regardless of HTTP status code. Falls back to HTTP status-based error handling.
|
|
7126
7463
|
*/
|
|
7127
7464
|
async handleHttpError(response, requestDetails, attempt) {
|
|
7128
7465
|
const status = response.status;
|
|
7466
|
+
const isRetryable = status >= 500 || status === 429;
|
|
7467
|
+
const baseDetails = {
|
|
7468
|
+
...requestDetails,
|
|
7469
|
+
httpStatus: status,
|
|
7470
|
+
url: this.url,
|
|
7471
|
+
attempts: attempt + 1
|
|
7472
|
+
};
|
|
7473
|
+
const { message, rpcCode, errorData } = await this.parseErrorResponse(
|
|
7474
|
+
response,
|
|
7475
|
+
status
|
|
7476
|
+
);
|
|
7129
7477
|
if (status === 429) {
|
|
7130
7478
|
return RpcError.rateLimitExceeded({
|
|
7131
|
-
...
|
|
7132
|
-
|
|
7133
|
-
|
|
7134
|
-
|
|
7479
|
+
...baseDetails,
|
|
7480
|
+
serverError: errorData
|
|
7481
|
+
});
|
|
7482
|
+
}
|
|
7483
|
+
if (rpcCode !== void 0) {
|
|
7484
|
+
return RpcError.fromRpcCode(rpcCode, message, {
|
|
7485
|
+
...baseDetails,
|
|
7486
|
+
serverError: errorData
|
|
7135
7487
|
});
|
|
7136
7488
|
}
|
|
7137
7489
|
if (status >= 500) {
|
|
7138
|
-
return RpcError.networkError(
|
|
7139
|
-
...
|
|
7140
|
-
|
|
7141
|
-
url: this.url,
|
|
7142
|
-
attempts: attempt + 1
|
|
7490
|
+
return RpcError.networkError(message, {
|
|
7491
|
+
...baseDetails,
|
|
7492
|
+
serverError: errorData
|
|
7143
7493
|
});
|
|
7144
7494
|
}
|
|
7495
|
+
return new RpcError("NETWORK_ERROR" /* NETWORK_ERROR */, message, baseDetails, isRetryable);
|
|
7496
|
+
}
|
|
7497
|
+
/**
|
|
7498
|
+
* Parse error response body to extract message and RPC error code.
|
|
7499
|
+
*
|
|
7500
|
+
* Handles multiple formats:
|
|
7501
|
+
* - JSON-RPC error: { error: { code, message, data? } }
|
|
7502
|
+
* - Simple JSON: { message: "..." }
|
|
7503
|
+
* - Non-JSON responses
|
|
7504
|
+
*/
|
|
7505
|
+
async parseErrorResponse(response, status) {
|
|
7145
7506
|
let message = `HTTP ${status}: ${response.statusText}`;
|
|
7507
|
+
let rpcCode;
|
|
7508
|
+
let errorData;
|
|
7146
7509
|
try {
|
|
7147
|
-
|
|
7148
|
-
if (errorData && typeof errorData === "object"
|
|
7149
|
-
|
|
7510
|
+
errorData = await response.json();
|
|
7511
|
+
if (errorData && typeof errorData === "object") {
|
|
7512
|
+
const data = errorData;
|
|
7513
|
+
if (data.error && typeof data.error === "object" && "message" in data.error) {
|
|
7514
|
+
const rpcError = data.error;
|
|
7515
|
+
message = String(rpcError.message);
|
|
7516
|
+
rpcCode = typeof rpcError.code === "number" ? rpcError.code : void 0;
|
|
7517
|
+
} else if ("message" in data) {
|
|
7518
|
+
message = String(data.message);
|
|
7519
|
+
}
|
|
7150
7520
|
}
|
|
7151
7521
|
} catch {
|
|
7152
7522
|
}
|
|
7153
|
-
return
|
|
7154
|
-
"NETWORK_ERROR" /* NETWORK_ERROR */,
|
|
7155
|
-
message,
|
|
7156
|
-
{
|
|
7157
|
-
...requestDetails,
|
|
7158
|
-
httpStatus: status,
|
|
7159
|
-
url: this.url,
|
|
7160
|
-
attempts: attempt + 1
|
|
7161
|
-
},
|
|
7162
|
-
false
|
|
7163
|
-
// 4xx errors are not retryable
|
|
7164
|
-
);
|
|
7523
|
+
return { message, rpcCode, errorData };
|
|
7165
7524
|
}
|
|
7166
7525
|
/**
|
|
7167
7526
|
* Returns the configured RPC endpoint URL.
|
|
@@ -7173,10 +7532,9 @@ var HttpTransport = class {
|
|
|
7173
7532
|
|
|
7174
7533
|
// src/rpc/index.ts
|
|
7175
7534
|
function createRialoClient(config) {
|
|
7176
|
-
const { chain: chain2,
|
|
7177
|
-
const
|
|
7178
|
-
|
|
7179
|
-
return new RialoClient(httpTransport, config.chain);
|
|
7535
|
+
const { chain: chain2, transport } = config;
|
|
7536
|
+
const httpTransport = new HttpTransport(chain2.rpcUrl, transport);
|
|
7537
|
+
return new RialoClient(httpTransport, chain2);
|
|
7180
7538
|
}
|
|
7181
7539
|
function getDefaultRialoClientConfig(network) {
|
|
7182
7540
|
switch (network) {
|