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