Skip to content

Commit df654d5

Browse files
committed
enable StableAbi for Transaction
1 parent 45d6d88 commit df654d5

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

transaction/src/lib.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@
110110
//! # Ok::<(), anyhow::Error>(())
111111
//! ```
112112
113+
#[cfg(feature = "frozen-abi")]
114+
use solana_frozen_abi_macro::{frozen_abi, AbiExample, StableAbi};
115+
113116
#[cfg(feature = "serde")]
114117
use {
115118
serde_derive::{Deserialize, Serialize},
@@ -176,8 +179,11 @@ const NONCED_TX_MARKER_IX_INDEX: u8 = 0;
176179
/// redundantly specifying the fee-payer is not strictly required.
177180
#[cfg_attr(
178181
feature = "frozen-abi",
179-
derive(solana_frozen_abi_macro::AbiExample),
180-
solana_frozen_abi_macro::frozen_abi(digest = "BLig4G2ysd7dcensK9bhKtnKvCQc1n65XdanyzsdWGXN")
182+
derive(AbiExample, StableAbi),
183+
frozen_abi(
184+
api_digest = "BLig4G2ysd7dcensK9bhKtnKvCQc1n65XdanyzsdWGXN",
185+
abi_digest = "B9cGfEfYQtYccbPKXWBRoWhdfLRjaUBimic11Vp5Bjzx"
186+
)
181187
)]
182188
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
183189
#[derive(Debug, PartialEq, Default, Eq, Clone)]
@@ -198,6 +204,39 @@ pub struct Transaction {
198204
pub message: Message,
199205
}
200206

207+
#[cfg(feature = "frozen-abi")]
208+
impl solana_frozen_abi::rand::prelude::Distribution<Transaction>
209+
for solana_frozen_abi::rand::distr::StandardUniform
210+
{
211+
fn sample<R: solana_frozen_abi::rand::Rng + ?Sized>(&self, rng: &mut R) -> Transaction {
212+
let signatures: Vec<Signature> = (0..rng.random_range(1..100))
213+
.map(|_| Signature::from(std::array::from_fn(|_| rng.random::<u8>())))
214+
.collect();
215+
let accounts: Vec<AccountMeta> = (0..rng.random_range(1..100))
216+
.map(|_| AccountMeta {
217+
pubkey: Address::new_from_array(rng.random()),
218+
is_signer: rng.random(),
219+
is_writable: rng.random(),
220+
})
221+
.collect();
222+
let data: Vec<u8> = (0..rng.random_range(1..1000))
223+
.map(|_| rng.random())
224+
.collect();
225+
let instructions: Vec<Instruction> = (0..rng.random_range(1..100))
226+
.map(|_| Instruction {
227+
program_id: Address::new_from_array(rng.random()),
228+
accounts: accounts.clone(),
229+
data: data.clone(),
230+
})
231+
.collect();
232+
233+
Transaction {
234+
signatures,
235+
message: Message::new(&instructions, Some(&Address::new_from_array(rng.random()))),
236+
}
237+
}
238+
}
239+
201240
impl Sanitize for Transaction {
202241
fn sanitize(&self) -> result::Result<(), SanitizeError> {
203242
if self.message.header.num_required_signatures as usize > self.signatures.len() {

0 commit comments

Comments
 (0)