rialo_shared_types/lib.rs
1// Copyright (c) Subzero Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4//! # Rialo Shared Types
5//!
6//! This crate contains shared RPC types used across the Rialo ecosystem,
7//! including the CDK and other components. These types are kept separate
8//! from implementation-specific functionality to minimize dependencies.
9
10use serde::{Deserialize, Serialize};
11
12/// Account information that is returned by the Rialo RPC API.
13#[derive(Serialize, Deserialize, Debug, Clone)]
14pub struct AccountInfoResponseValue {
15 pub kelvin: u64,
16 pub owner: String,
17 pub data: Vec<String>,
18 pub executable: bool,
19 #[serde(rename = "rentEpoch")]
20 pub rent_epoch: u64,
21 pub space: usize,
22}
23
24/// Subscription returned by Rialo RPC to describe a `Subscription` object stored by a user for
25/// a given topic.
26#[derive(Serialize, Deserialize, Debug, Clone)]
27pub struct Subscription {
28 /// Subscription kind.
29 pub kind: SubscriptionKind,
30 /// Topic.
31 pub topic: String,
32 /// Instructions to be executed.
33 pub instructions: Vec<Instruction>,
34 /// Subscriber pubkey in base58.
35 pub subscriber: String,
36 /// The account pubkey in base58 that stores the event data. Used when
37 /// the subscription precisely targets a specific event account.
38 pub event_account: Option<String>,
39 /// The timestamp range to trigger the transaction, if provided.
40 /// Left boundary is inclusive, right boundary is exclusive.
41 pub timestamp_range: Option<(u64, u64)>,
42}
43
44/// A representation of an instruction in Subscription.
45#[derive(Serialize, Deserialize, Debug, Clone)]
46pub struct Instruction {
47 /// The program ID invoked, as a base58-encoded string.
48 pub program_id: String,
49 /// Metadata for the accounts involved in the instruction.
50 pub accounts: Vec<AccountMeta>,
51 /// Opaque binary data passed to the program.
52 pub data: Vec<u8>,
53}
54
55/// Metadata about an account used in an Instruction.
56#[derive(Serialize, Deserialize, Debug, Clone)]
57pub struct AccountMeta {
58 /// The account's public key, in base58-encoded form.
59 pub pubkey: String,
60 /// Whether the account must sign the transaction.
61 pub is_signer: bool,
62 /// Whether the account can be written to during instruction execution.
63 pub is_writable: bool,
64}
65
66/// Subscription kind of the Subscription.
67#[derive(Serialize, Deserialize, Debug, Clone)]
68pub enum SubscriptionKind {
69 /// Persistent subscription which fires every time a matching event is received
70 Persistent,
71 /// One-shot subscription which fires a single time when a matching event is received
72 OneShot,
73}
74
75/// Errors that can occur during instruction execution.
76///
77/// These errors represent various failure modes that can occur when
78/// executing program instructions within a transaction.
79#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
80pub enum InstructionError {
81 /// Deprecated! Use CustomError instead!
82 /// The program instruction returned an error
83 GenericError,
84
85 /// The arguments provided to a program were invalid
86 InvalidArgument,
87
88 /// An instruction's data contents were invalid
89 InvalidInstructionData,
90
91 /// An account's data contents was invalid
92 InvalidAccountData,
93
94 /// An account's data was too small
95 AccountDataTooSmall,
96
97 /// An account's balance was too small to complete the instruction
98 InsufficientFunds,
99
100 /// The account did not have the expected program id
101 IncorrectProgramId,
102
103 /// A signature was required but not found
104 MissingRequiredSignature,
105
106 /// An initialize instruction was sent to an account that has already been initialized.
107 AccountAlreadyInitialized,
108
109 /// An attempt to operate on an account that hasn't been initialized.
110 UninitializedAccount,
111
112 /// Program's instruction kelvin balance does not equal the balance after the instruction
113 UnbalancedInstruction,
114
115 /// Program illegally modified an account's program id
116 ModifiedProgramId,
117
118 /// Program spent the kelvins of an account that doesn't belong to it
119 ExternalAccountKelvinSpend,
120
121 /// Program modified the data of an account that doesn't belong to it
122 ExternalAccountDataModified,
123
124 /// Read-only account's kelvins modified
125 ReadonlyKelvinChange,
126
127 /// Read-only account's data was modified
128 ReadonlyDataModified,
129
130 /// An account was referenced more than once in a single instruction
131 // Deprecated, instructions can now contain duplicate accounts
132 DuplicateAccountIndex,
133
134 /// Executable bit on account changed, but shouldn't have
135 ExecutableModified,
136
137 /// Rent_epoch account changed, but shouldn't have
138 RentEpochModified,
139
140 /// The instruction expected additional account keys
141 NotEnoughAccountKeys,
142
143 /// Program other than the account's owner changed the size of the account data
144 AccountDataSizeChanged,
145
146 /// The instruction expected an executable account
147 AccountNotExecutable,
148
149 /// Failed to borrow a reference to account data, already borrowed
150 AccountBorrowFailed,
151
152 /// Account data has an outstanding reference after a program's execution
153 AccountBorrowOutstanding,
154
155 /// The same account was multiply passed to an on-chain program's entrypoint, but the program
156 /// modified them differently. A program can only modify one instance of the account because
157 /// the runtime cannot determine which changes to pick or how to merge them if both are modified
158 DuplicateAccountOutOfSync,
159
160 /// Allows on-chain programs to implement program-specific error types and see them returned
161 /// by the Solana runtime. A program-specific error may be any type that is represented as
162 /// or serialized to a u32 integer.
163 Custom(u32),
164
165 /// The return value from the program was invalid. Valid errors are either a defined builtin
166 /// error value or a user-defined error in the lower 32 bits.
167 InvalidError,
168
169 /// Executable account's data was modified
170 ExecutableDataModified,
171
172 /// Executable account's kelvins modified
173 ExecutableKelvinChange,
174
175 /// Executable accounts must be rent exempt
176 ExecutableAccountNotRentExempt,
177
178 /// Unsupported program id
179 UnsupportedProgramId,
180
181 /// Cross-program invocation call depth too deep
182 CallDepth,
183
184 /// An account required by the instruction is missing
185 MissingAccount,
186
187 /// Cross-program invocation reentrancy not allowed for this instruction
188 ReentrancyNotAllowed,
189
190 /// Length of the seed is too long for address generation
191 MaxSeedLengthExceeded,
192
193 /// Provided seeds do not result in a valid address
194 InvalidSeeds,
195
196 /// Failed to reallocate account data of this length
197 InvalidRealloc,
198
199 /// Computational budget exceeded
200 ComputationalBudgetExceeded,
201
202 /// Cross-program invocation with unauthorized signer or writable account
203 PrivilegeEscalation,
204
205 /// Failed to create program execution environment
206 ProgramEnvironmentSetupFailure,
207
208 /// Program failed to complete
209 ProgramFailedToComplete,
210
211 /// Program failed to compile
212 ProgramFailedToCompile,
213
214 /// Account is immutable
215 Immutable,
216
217 /// Incorrect authority provided
218 IncorrectAuthority,
219
220 /// Failed to serialize or deserialize account data
221 ///
222 /// Warning: This error should never be emitted by the runtime.
223 ///
224 /// This error includes strings from the underlying 3rd party Borsh crate
225 /// which can be dangerous because the error strings could change across
226 /// Borsh versions. Only programs can use this error because they are
227 /// consistent across Solana software versions.
228 ///
229 BorshIoError(String),
230
231 /// An account does not have enough kelvins to be rent-exempt
232 AccountNotRentExempt,
233
234 /// Invalid account owner
235 InvalidAccountOwner,
236
237 /// Program arithmetic overflowed
238 ArithmeticOverflow,
239
240 /// Unsupported sysvar
241 UnsupportedSysvar,
242
243 /// Illegal account owner
244 IllegalOwner,
245
246 /// Accounts data allocations exceeded the maximum allowed per transaction
247 MaxAccountsDataAllocationsExceeded,
248
249 /// Max accounts exceeded
250 MaxAccountsExceeded,
251
252 /// Max instruction trace length exceeded
253 MaxInstructionTraceLengthExceeded,
254
255 /// Builtin programs must consume compute units
256 BuiltinProgramsMustConsumeComputeUnits,
257 // Note: For any new error added here an equivalent ProgramError and its
258 // conversions must also be added
259}
260
261/// Reasons a transaction might be rejected.
262///
263/// This enum represents all the possible ways a transaction can fail
264/// during processing, validation, or execution.
265#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
266pub enum TransactionError {
267 /// An account is already being processed in another transaction in a way
268 /// that does not support parallelism
269 AccountInUse,
270
271 /// A `Pubkey` appears twice in the transaction's `account_keys`. Instructions can reference
272 /// `Pubkey`s more than once but the message must contain a list with no duplicate keys
273 AccountLoadedTwice,
274
275 /// Attempt to debit an account but found no record of a prior credit.
276 AccountNotFound,
277
278 /// Attempt to load a program that does not exist
279 ProgramAccountNotFound,
280
281 /// The from `Pubkey` does not have sufficient balance to pay the fee to schedule the transaction
282 InsufficientFundsForFee,
283
284 /// This account may not be used to pay transaction fees
285 InvalidAccountForFee,
286
287 /// The bank has seen this transaction before. This can occur under normal operation
288 /// when a UDP packet is duplicated, as a user error from a client not updating
289 /// its `recent_blockhash`, or as a double-spend attack.
290 AlreadyProcessed,
291
292 /// The transaction is too stale (seconds since `UNIX_EPOCH`).
293 TimestampTooStale,
294
295 /// The transaction is too far in the future (seconds since `UNIX_EPOCH`).
296 TimestampInFuture,
297
298 /// An error occurred while processing an instruction. The first element of the tuple
299 /// indicates the instruction index in which the error occurred.
300 InstructionError(u8, InstructionError),
301
302 /// Transaction contains an invalid account reference
303 InvalidAccountIndex,
304
305 /// Transaction did not pass signature verification
306 SignatureFailure,
307
308 /// This program may not be used for executing instructions
309 InvalidProgramForExecution,
310
311 /// Transaction failed to sanitize accounts offsets correctly
312 /// implies that account locks are not taken for this TX, and should
313 /// not be unlocked.
314 SanitizeFailure,
315
316 /// Transaction processing left an account with an outstanding borrowed reference
317 AccountBorrowOutstanding,
318
319 /// Transaction would exceed max Block Cost Limit
320 WouldExceedMaxBlockCostLimit,
321
322 /// Transaction version is unsupported
323 UnsupportedVersion,
324
325 /// Transaction loads a writable account that cannot be written
326 InvalidWritableAccount,
327
328 /// Transaction would exceed max account limit within the block
329 WouldExceedMaxAccountCostLimit,
330
331 /// Transaction would exceed account data limit within the block
332 WouldExceedAccountDataBlockLimit,
333
334 /// Transaction locked too many accounts
335 TooManyAccountLocks,
336
337 /// Transaction leaves an account with a lower balance than rent-exempt minimum
338 InvalidRentPayingAccount,
339
340 /// Transaction would exceed max Vote Cost Limit
341 WouldExceedMaxVoteCostLimit,
342
343 /// Transaction contains a duplicate instruction that is not allowed
344 DuplicateInstruction(u8),
345
346 /// Transaction results in an account with insufficient funds for rent
347 InsufficientFundsForRent { account_index: u8 },
348
349 /// Transaction exceeded max loaded accounts data size cap
350 MaxLoadedAccountsDataSizeExceeded,
351
352 /// LoadedAccountsDataSizeLimit set for transaction must be greater than 0.
353 InvalidLoadedAccountsDataSizeLimit,
354
355 /// Sanitized transaction differed before/after feature activiation. Needs to be resanitized.
356 ResanitizationNeeded,
357
358 /// The total balance before the transaction does not equal the total balance after the transaction
359 UnbalancedTransaction,
360
361 /// Program cache hit max limit.
362 ProgramCacheHitMaxLimit,
363
364 /// Failed to serialize transaction instructions.
365 SerializationFailure,
366}