Support u8 slice digester in frozen abi struct. (#23726)
* support u8 slice in frozen abi digester * use slice in account struct * add bpf cargo lock file * no need to pass account.data to serializer * fix comments
This commit is contained in:
parent
c694703e14
commit
f54e746fc5
|
@ -4882,6 +4882,7 @@ dependencies = [
|
|||
"memmap2 0.5.3",
|
||||
"rustc_version 0.4.0",
|
||||
"serde",
|
||||
"serde_bytes",
|
||||
"serde_derive",
|
||||
"sha2 0.10.2",
|
||||
"solana-frozen-abi-macro 1.10.4",
|
||||
|
|
|
@ -16,6 +16,7 @@ lazy_static = "1.4.0"
|
|||
log = "0.4.14"
|
||||
serde = "1.0.136"
|
||||
serde_derive = "1.0.103"
|
||||
serde_bytes = "0.11"
|
||||
sha2 = "0.10.2"
|
||||
solana-frozen-abi-macro = { path = "macro", version = "=1.10.4" }
|
||||
thiserror = "1.0"
|
||||
|
|
|
@ -562,6 +562,17 @@ mod tests {
|
|||
#[derive(Serialize, AbiExample)]
|
||||
struct TestNewtypeStruct(i8);
|
||||
|
||||
#[frozen_abi(digest = "Hbs1X2X7TF2gFEfsspwfZ1JKr8ZGbLY3uidQBebqcMYt")]
|
||||
#[derive(Serialize, AbiExample)]
|
||||
struct Foo<'a> {
|
||||
#[serde(with = "serde_bytes")]
|
||||
data1: Vec<u8>,
|
||||
#[serde(with = "serde_bytes")]
|
||||
data2: &'a [u8],
|
||||
#[serde(with = "serde_bytes")]
|
||||
data3: &'a Vec<u8>,
|
||||
}
|
||||
|
||||
#[frozen_abi(digest = "5qio5qYurHDv6fq5kcwP2ue2RBEazSZF8CPk2kUuwC2j")]
|
||||
#[derive(Serialize, AbiExample)]
|
||||
struct TestStructReversed {
|
||||
|
|
|
@ -415,6 +415,13 @@ impl AbiExample for &Vec<u8> {
|
|||
}
|
||||
}
|
||||
|
||||
impl AbiExample for &[u8] {
|
||||
fn example() -> Self {
|
||||
info!("AbiExample for (&[u8]): {}", type_name::<Self>());
|
||||
&VEC_U8[..]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AbiExample> AbiExample for VecDeque<T> {
|
||||
fn example() -> Self {
|
||||
info!("AbiExample for (Vec<T>): {}", type_name::<Self>());
|
||||
|
|
|
@ -3370,6 +3370,7 @@ dependencies = [
|
|||
"memmap2 0.5.3",
|
||||
"rustc_version 0.4.0",
|
||||
"serde",
|
||||
"serde_bytes",
|
||||
"serde_derive",
|
||||
"sha2 0.10.2",
|
||||
"solana-frozen-abi-macro 1.10.4",
|
||||
|
|
|
@ -46,8 +46,8 @@ mod account_serialize {
|
|||
struct Account<'a> {
|
||||
lamports: u64,
|
||||
#[serde(with = "serde_bytes")]
|
||||
// a ref so we don't have to make a copy just to serialize this
|
||||
data: &'a Vec<u8>,
|
||||
// a slice so we don't have to make a copy just to serialize this
|
||||
data: &'a [u8],
|
||||
// can't be &pubkey because abi example doesn't support it
|
||||
owner: Pubkey,
|
||||
executable: bool,
|
||||
|
@ -57,7 +57,6 @@ mod account_serialize {
|
|||
/// allows us to implement serialize on AccountSharedData that is equivalent to Account::serialize without making a copy of the Vec<u8>
|
||||
pub fn serialize_account<S>(
|
||||
account: &(impl ReadableAccount + Serialize),
|
||||
data: &Vec<u8>,
|
||||
serializer: S,
|
||||
) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
|
@ -65,8 +64,7 @@ mod account_serialize {
|
|||
{
|
||||
let temp = Account {
|
||||
lamports: account.lamports(),
|
||||
// note this is a ref, which is the whole point of 'account_serialize'
|
||||
data,
|
||||
data: account.data(),
|
||||
owner: *account.owner(),
|
||||
executable: account.executable(),
|
||||
rent_epoch: account.rent_epoch(),
|
||||
|
@ -80,7 +78,7 @@ impl Serialize for Account {
|
|||
where
|
||||
S: Serializer,
|
||||
{
|
||||
crate::account::account_serialize::serialize_account(self, &self.data, serializer)
|
||||
crate::account::account_serialize::serialize_account(self, serializer)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +87,7 @@ impl Serialize for AccountSharedData {
|
|||
where
|
||||
S: Serializer,
|
||||
{
|
||||
crate::account::account_serialize::serialize_account(self, &self.data, serializer)
|
||||
crate::account::account_serialize::serialize_account(self, serializer)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue