1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright (c) Subzero Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
use serde::{Deserialize, Serialize};
use validator::Validate;
use super::{get_account_info::EncodingConfig, rpc_response_context::RpcResponseContext};
/// The response message for a getTransaction request.
/// Solana specification: <https://solana.com/docs/rpc/http/gettransaction>
#[derive(Serialize, Deserialize, Debug)]
pub struct GetTransactionResponse {
pub context: RpcResponseContext,
/// The slot this transaction was processed in.
pub block_height: u64,
/// The blockhash of the block this transaction was processed in.
pub block_hash: String,
/// Estimated production time, as Unix timestamp (seconds since the Unix epoch) of when the
/// transaction was processed. None if not available.
pub block_time: Option<i64>,
/// The transaction data object.
pub transaction: Transaction,
/// The transaction status metadata object.
pub meta: TransactionStatusMetadata,
}
/// The transaction object data.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct Transaction {
/// A list of signatures applied to the transaction in base58.
pub signatures: Vec<String>,
/// The content of the transaction.
pub message: TransactionMessage,
}
/// The transaction message object.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct TransactionMessage {
/// List of public keys used by the transaction.
/// The first `message.header.num_required_signatures` public keys must sign the transaction.
pub account_keys: Vec<String>,
/// Details the account types and signatures required by the transaction.
pub header: MessageHeader,
/// The hash of a recent block in the ledger used to prevent transaction duplication and to give
/// transactions lifetimes.
pub recent_blockhash: String,
/// List of program instructions that will be executed in the transaction.
pub instructions: Vec<Instruction>,
}
/// The transaction header object.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct MessageHeader {
/// The total number of signatures required to make the transaction valid.
pub num_required_signatures: u8,
/// The last `num_readonly_signed_accounts` of the signed keys are read-only accounts.
pub num_readonly_signed_accounts: u8,
/// The last `num_readonly_unsigned_accounts` of the unsigned keys are read-only accounts.
pub num_readonly_unsigned_accounts: u8,
}
/// The transaction instruction object.
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct Instruction {
/// List of ordered indices into the message.account_keys array indicating which accounts to
/// pass to the program.
pub accounts: Vec<u8>,
/// The program input data encoded in a base-58 string.
pub data: String,
/// Index into the message.account_keys array indicating the program account that executes this
/// instruction.
pub program_id_index: u8,
}
/// The transaction status metadata.
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct TransactionStatusMetadata {
/// Error if transaction failed, None if transaction succeeded.
pub err: Option<serde_json::Value>,
/// Fee this transaction was charged, as u64 integer.
pub fee: u64,
/// Array of string log messages or None if log message recording was not enabled during
/// this transaction
pub log_messages: Option<Vec<String>>,
}
/// Request for getTransaction RPC call
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Validate)]
pub struct GetTransactionRequest {
/// Transaction signature (base58-encoded)
#[validate(length(min = 1, message = "Signature cannot be empty"))]
#[validate(custom(function = crate::validation::validate_signature))]
pub signature: String,
/// Optional configuration for encoding
pub config: Option<EncodingConfig>,
}
impl GetTransactionRequest {
pub fn new(signature: String, encoding: Option<String>) -> Self {
Self {
signature,
config: encoding.map(EncodingConfig::new),
}
}
pub fn with_signature(signature: String) -> Self {
Self {
signature,
config: None,
}
}
}