Skip to content

Commit 1eab8ff

Browse files
committed
Add changeset and fix an issue with sharedPage not being rendered
1 parent 49f0583 commit 1eab8ff

File tree

10 files changed

+408
-13
lines changed

10 files changed

+408
-13
lines changed

.changeset/orange-ravens-sleep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@codama/renderers-rust': patch
3+
---
4+
5+
Fix a bug where sharedPage was not rendered in rust client

.changeset/violet-worms-move.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@codama/renderers-rust': patch
3+
---
4+
5+
Add account fetching helper functions to rust client
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//! This code was AUTOGENERATED using the codama library.
2+
//! Please DO NOT EDIT THIS FILE, instead use visitors
3+
//! to add features, then rerun codama to update it.
4+
//!
5+
//! <https://github.com/codama-idl/codama>
6+
//!
7+
8+
use std::fmt::Debug;
9+
use std::io::Write;
10+
use std::ops::{Deref, DerefMut};
11+
12+
use borsh::maybestd::io::Read;
13+
use borsh::{BorshDeserialize, BorshSerialize};
14+
15+
/// A vector that deserializes from a stream of bytes.
16+
///
17+
/// This is useful for deserializing a vector that does not have
18+
/// a length prefix. In order to determine how many elements to deserialize,
19+
/// the type of the elements must implement the trait `Sized`.
20+
pub struct RemainderVec<T: BorshSerialize + BorshDeserialize>(Vec<T>);
21+
22+
/// Deferences the inner `Vec` type.
23+
impl<T> Deref for RemainderVec<T>
24+
where
25+
T: BorshSerialize + BorshDeserialize,
26+
{
27+
type Target = Vec<T>;
28+
29+
fn deref(&self) -> &Self::Target {
30+
&self.0
31+
}
32+
}
33+
34+
/// Deferences the inner `Vec` type as mutable.
35+
impl<T> DerefMut for RemainderVec<T>
36+
where
37+
T: BorshSerialize + BorshDeserialize,
38+
{
39+
fn deref_mut(&mut self) -> &mut Self::Target {
40+
&mut self.0
41+
}
42+
}
43+
44+
/// `Debug` implementation for `RemainderVec`.
45+
///
46+
/// This implementation simply forwards to the inner `Vec` type.
47+
impl<T> Debug for RemainderVec<T>
48+
where
49+
T: BorshSerialize + BorshDeserialize + Debug,
50+
{
51+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52+
f.write_fmt(format_args!("{:?}", self.0))
53+
}
54+
}
55+
56+
impl<T> BorshDeserialize for RemainderVec<T>
57+
where
58+
T: BorshSerialize + BorshDeserialize,
59+
{
60+
fn deserialize_reader<R: Read>(reader: &mut R) -> borsh::maybestd::io::Result<Self> {
61+
let length = std::mem::size_of::<T>();
62+
// buffer to read the data
63+
let mut buffer = vec![0u8; length];
64+
// vec to store the items
65+
let mut items: Vec<T> = Vec::new();
66+
67+
loop {
68+
match reader.read(&mut buffer)? {
69+
0 => break,
70+
n if n == length => items.push(T::deserialize(&mut buffer.as_slice())?),
71+
e => {
72+
return Err(borsh::maybestd::io::Error::new(
73+
borsh::maybestd::io::ErrorKind::InvalidData,
74+
format!("unexpected number of bytes (read {e}, expected {length})"),
75+
))
76+
}
77+
}
78+
}
79+
80+
Ok(Self(items))
81+
}
82+
}
83+
84+
impl<T> BorshSerialize for RemainderVec<T>
85+
where
86+
T: BorshSerialize + BorshDeserialize,
87+
{
88+
fn serialize<W: Write>(&self, writer: &mut W) -> borsh::maybestd::io::Result<()> {
89+
// serialize each item without adding a prefix for the length
90+
for item in self.0.iter() {
91+
item.serialize(writer)?;
92+
}
93+
94+
Ok(())
95+
}
96+
}
97+
98+
99+
100+
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//! This code was AUTOGENERATED using the codama library.
2+
//! Please DO NOT EDIT THIS FILE, instead use visitors
3+
//! to add features, then rerun codama to update it.
4+
//!
5+
//! <https://github.com/codama-idl/codama>
6+
//!
7+
8+
use std::fmt::Debug;
9+
use std::io::Write;
10+
use std::ops::{Deref, DerefMut};
11+
12+
use borsh::maybestd::io::Read;
13+
use borsh::{BorshDeserialize, BorshSerialize};
14+
15+
/// A vector that deserializes from a stream of bytes.
16+
///
17+
/// This is useful for deserializing a vector that does not have
18+
/// a length prefix. In order to determine how many elements to deserialize,
19+
/// the type of the elements must implement the trait `Sized`.
20+
pub struct RemainderVec<T: BorshSerialize + BorshDeserialize>(Vec<T>);
21+
22+
/// Deferences the inner `Vec` type.
23+
impl<T> Deref for RemainderVec<T>
24+
where
25+
T: BorshSerialize + BorshDeserialize,
26+
{
27+
type Target = Vec<T>;
28+
29+
fn deref(&self) -> &Self::Target {
30+
&self.0
31+
}
32+
}
33+
34+
/// Deferences the inner `Vec` type as mutable.
35+
impl<T> DerefMut for RemainderVec<T>
36+
where
37+
T: BorshSerialize + BorshDeserialize,
38+
{
39+
fn deref_mut(&mut self) -> &mut Self::Target {
40+
&mut self.0
41+
}
42+
}
43+
44+
/// `Debug` implementation for `RemainderVec`.
45+
///
46+
/// This implementation simply forwards to the inner `Vec` type.
47+
impl<T> Debug for RemainderVec<T>
48+
where
49+
T: BorshSerialize + BorshDeserialize + Debug,
50+
{
51+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52+
f.write_fmt(format_args!("{:?}", self.0))
53+
}
54+
}
55+
56+
impl<T> BorshDeserialize for RemainderVec<T>
57+
where
58+
T: BorshSerialize + BorshDeserialize,
59+
{
60+
fn deserialize_reader<R: Read>(reader: &mut R) -> borsh::maybestd::io::Result<Self> {
61+
let length = std::mem::size_of::<T>();
62+
// buffer to read the data
63+
let mut buffer = vec![0u8; length];
64+
// vec to store the items
65+
let mut items: Vec<T> = Vec::new();
66+
67+
loop {
68+
match reader.read(&mut buffer)? {
69+
0 => break,
70+
n if n == length => items.push(T::deserialize(&mut buffer.as_slice())?),
71+
e => {
72+
return Err(borsh::maybestd::io::Error::new(
73+
borsh::maybestd::io::ErrorKind::InvalidData,
74+
format!("unexpected number of bytes (read {e}, expected {length})"),
75+
))
76+
}
77+
}
78+
}
79+
80+
Ok(Self(items))
81+
}
82+
}
83+
84+
impl<T> BorshSerialize for RemainderVec<T>
85+
where
86+
T: BorshSerialize + BorshDeserialize,
87+
{
88+
fn serialize<W: Write>(&self, writer: &mut W) -> borsh::maybestd::io::Result<()> {
89+
// serialize each item without adding a prefix for the length
90+
for item in self.0.iter() {
91+
item.serialize(writer)?;
92+
}
93+
94+
Ok(())
95+
}
96+
}
97+
98+
99+
100+

packages/renderers-rust/e2e/system/src/generated/accounts/nonce.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,69 @@ impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for Nonce {
5050
}
5151
}
5252

53+
#[cfg(feature = "fetch")]
54+
pub fn fetch_nonce(
55+
rpc: &solana_client::rpc_client::RpcClient,
56+
address: &Pubkey,
57+
) -> Result<super::DecodedAccount<Nonce>, Error> {
58+
let accounts = fetch_all_nonce(rpc, vec![address])?;
59+
Ok(accounts[0].clone())
60+
}
61+
62+
#[cfg(feature = "fetch")]
63+
pub fn fetch_all_nonce(
64+
rpc: &solana_client::rpc_client::RpcClient,
65+
addresses: Vec<Pubkey>,
66+
) -> Result<Vec<super::DecodedAccount<Nonce>>, Error> {
67+
let accounts = rpc.get_multiple_accounts(&addresses)?;
68+
let mut decoded_accounts: Vec<super::DecodedAccount<Nonce>> = Vec::new();
69+
for i in 0..addresses.len() {
70+
let address = addresses[i];
71+
let account = accounts[i]
72+
.as_ref()
73+
.ok_or(format!("Account not found: {}", address))?;
74+
let data = Nonce::from_bytes(&account.data)?;
75+
decoded_accounts.push(super::DecodedAccount {
76+
address,
77+
account: account.clone(),
78+
data,
79+
});
80+
}
81+
Ok(decoded_accounts)
82+
}
83+
84+
#[cfg(feature = "fetch")]
85+
pub fn fetch_maybe_nonce(
86+
rpc: &solana_client::rpc_client::RpcClient,
87+
address: &Pubkey,
88+
) -> Result<super::MaybeAccount<Nonce>, Error> {
89+
let accounts = fetch_all_maybe_nonce(rpc, vec![address])?;
90+
Ok(accounts[0].clone())
91+
}
92+
93+
#[cfg(feature = "fetch")]
94+
pub fn fetch_all_maybe_nonce(
95+
rpc: &solana_client::rpc_client::RpcClient,
96+
addresses: Vec<Pubkey>,
97+
) -> Result<Vec<super::MaybeAccount<Nonce>>, Error> {
98+
let accounts = rpc.get_multiple_accounts(&addresses)?;
99+
let mut decoded_accounts: Vec<super::MaybeAccount<Nonce>> = Vec::new();
100+
for i in 0..addresses.len() {
101+
let address = addresses[i];
102+
if let Some(account) = accounts[i].as_ref() {
103+
let data = Nonce::from_bytes(&account.data)?;
104+
decoded_accounts.push(super::MaybeAccount::Exists(super::DecodedAccount {
105+
address,
106+
account: account.clone(),
107+
data,
108+
}));
109+
} else {
110+
decoded_accounts.push(super::MaybeAccount::NotFound(address));
111+
}
112+
}
113+
Ok(decoded_accounts)
114+
}
115+
53116
#[cfg(feature = "anchor")]
54117
impl anchor_lang::AccountDeserialize for Nonce {
55118
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {

packages/renderers-rust/e2e/system/src/generated/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub mod accounts;
99
pub mod errors;
1010
pub mod instructions;
1111
pub mod programs;
12+
pub mod shared;
1213
pub mod types;
1314

1415
pub(crate) use programs::*;

0 commit comments

Comments
 (0)