From 4ddc6681b301a8597c8b1fb6eb93e84fb357505b Mon Sep 17 00:00:00 2001 From: Austin Adams Date: Tue, 21 Feb 2023 12:24:59 -0600 Subject: [PATCH] new types for better indexing when 1.15 comes out, adds rpc serializer to avoid code duplication (#43) --- Cargo.lock | 12 +- plerkle/Cargo.toml | 8 +- plerkle_messenger/Cargo.toml | 2 +- plerkle_serialization/Cargo.toml | 6 +- .../compiled_instruction.fbs | 4 + .../src/account_info_generated.rs | 512 ++++----- .../src/block_info_generated.rs | 793 ++++++------- plerkle_serialization/src/common_generated.rs | 96 +- .../src/compiled_instruction_generated.rs | 397 ++++--- plerkle_serialization/src/lib.rs | 1 + plerkle_serialization/src/serializer/mod.rs | 2 +- .../src/serializer/serializer_stable.rs | 239 +++- .../src/slot_status_info_generated.rs | 406 ++++--- .../src/transaction_info_generated.rs | 1004 +++++++++-------- plerkle_serialization/transaction_info.fbs | 17 +- 15 files changed, 1853 insertions(+), 1646 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 02ef1474..e00b35e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -843,9 +843,9 @@ dependencies = [ [[package]] name = "flatbuffers" -version = "22.12.6" +version = "23.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ae1bfc84d904f75e7ef6f8796b020c606a9e8e271e2004c0a74f7edeedba45f" +checksum = "77f5399c2c9c50ae9418e522842ad362f61ee48b346ac106807bd355a8a7c619" dependencies = [ "bitflags", "rustc_version", @@ -1723,7 +1723,7 @@ checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] name = "plerkle" -version = "1.4.1" +version = "1.5.0" dependencies = [ "async-trait", "base64 0.21.0", @@ -1755,7 +1755,7 @@ dependencies = [ [[package]] name = "plerkle_messenger" -version = "1.4.1" +version = "1.5.0" dependencies = [ "async-mutex", "async-trait", @@ -1770,13 +1770,15 @@ dependencies = [ [[package]] name = "plerkle_serialization" -version = "1.4.1" +version = "1.5.0" dependencies = [ + "bs58", "chrono", "flatbuffers", "serde", "solana-sdk", "solana-transaction-status", + "thiserror", ] [[package]] diff --git a/plerkle/Cargo.toml b/plerkle/Cargo.toml index ff595594..eab90f21 100644 --- a/plerkle/Cargo.toml +++ b/plerkle/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "plerkle" description = "Geyser plugin with dynamic config reloading, message bus agnostic abstractions and a whole lot of fun." -version = "1.4.1" +version = "1.5.0" authors = ["Metaplex Developers "] repository = "https://github.com/metaplex-foundation/digital-asset-validator-plugin" license = "AGPL-3.0" @@ -31,9 +31,9 @@ cadence-macros = "0.29.0" chrono = "0.4.19" tracing = "0.1.35" hex = "0.4.3" -plerkle_messenger = { path = "../plerkle_messenger", version = "1.4.1", features = ["redis"] } -flatbuffers = "22.10.26" -plerkle_serialization = { path = "../plerkle_serialization", version = "1.4.1" } +plerkle_messenger = { path = "../plerkle_messenger", version = "1.5.0", features = ["redis"] } +flatbuffers = "23.1.21" +plerkle_serialization = { path = "../plerkle_serialization", version = "1.5.0" } tokio = { version = "1.23.0", features = ["full"] } figment = { version = "0.10.6", features = ["env", "test"] } dashmap = {version = "5.4.0"} diff --git a/plerkle_messenger/Cargo.toml b/plerkle_messenger/Cargo.toml index 5f0403f7..b0ecc905 100644 --- a/plerkle_messenger/Cargo.toml +++ b/plerkle_messenger/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "plerkle_messenger" description = "Metaplex Messenger trait for Geyser plugin producer/consumer patterns." -version = "1.4.1" +version = "1.5.0" authors = ["Metaplex Developers "] repository = "https://github.com/metaplex-foundation/digital-asset-validator-plugin" license = "AGPL-3.0" diff --git a/plerkle_serialization/Cargo.toml b/plerkle_serialization/Cargo.toml index df85ce5f..d4d1627a 100644 --- a/plerkle_serialization/Cargo.toml +++ b/plerkle_serialization/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "plerkle_serialization" description = "Metaplex Flatbuffers Plerkle Serialization for Geyser plugin producer/consumer patterns." -version = "1.4.1" +version = "1.5.0" authors = ["Metaplex Developers "] repository = "https://github.com/metaplex-foundation/digital-asset-validator-plugin" license = "AGPL-3.0" @@ -9,10 +9,12 @@ edition = "2021" readme = "Readme.md" [dependencies] -flatbuffers = "22.10.26" +flatbuffers = "23.1.21" chrono = "0.4.22" serde = { version = "1.0.152"} solana-sdk = { version = "~1.14"} solana-transaction-status = { version = "~1.14" } +bs58 = "0.4.0" +thiserror = "1.0.38" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/plerkle_serialization/compiled_instruction.fbs b/plerkle_serialization/compiled_instruction.fbs index b02c8d15..146787b7 100644 --- a/plerkle_serialization/compiled_instruction.fbs +++ b/plerkle_serialization/compiled_instruction.fbs @@ -9,5 +9,9 @@ table CompiledInstruction { data:[uint8]; } +table CompiledInnerInstruction { + compiled_instruction: CompiledInstruction; + stack_height:uint8; +} root_type CompiledInstruction; diff --git a/plerkle_serialization/src/account_info_generated.rs b/plerkle_serialization/src/account_info_generated.rs index dbb85f13..fbc20a1a 100644 --- a/plerkle_serialization/src/account_info_generated.rs +++ b/plerkle_serialization/src/account_info_generated.rs @@ -1,199 +1,158 @@ // automatically generated by the FlatBuffers compiler, do not modify + // @generated use crate::common_generated::*; -use core::cmp::Ordering; use core::mem; +use core::cmp::Ordering; extern crate flatbuffers; use self::flatbuffers::{EndianScalar, Follow}; pub enum AccountInfoOffset {} -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq)] pub struct AccountInfo<'a> { - pub _tab: flatbuffers::Table<'a>, + pub _tab: flatbuffers::Table<'a>, } impl<'a> flatbuffers::Follow<'a> for AccountInfo<'a> { - type Inner = AccountInfo<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { - _tab: flatbuffers::Table::new(buf, loc), - } - } + type Inner = AccountInfo<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } } impl<'a> AccountInfo<'a> { - pub const VT_PUBKEY: flatbuffers::VOffsetT = 4; - pub const VT_LAMPORTS: flatbuffers::VOffsetT = 6; - pub const VT_OWNER: flatbuffers::VOffsetT = 8; - pub const VT_EXECUTABLE: flatbuffers::VOffsetT = 10; - pub const VT_RENT_EPOCH: flatbuffers::VOffsetT = 12; - pub const VT_DATA: flatbuffers::VOffsetT = 14; - pub const VT_WRITE_VERSION: flatbuffers::VOffsetT = 16; - pub const VT_SLOT: flatbuffers::VOffsetT = 18; - pub const VT_IS_STARTUP: flatbuffers::VOffsetT = 20; - pub const VT_SEEN_AT: flatbuffers::VOffsetT = 22; + pub const VT_PUBKEY: flatbuffers::VOffsetT = 4; + pub const VT_LAMPORTS: flatbuffers::VOffsetT = 6; + pub const VT_OWNER: flatbuffers::VOffsetT = 8; + pub const VT_EXECUTABLE: flatbuffers::VOffsetT = 10; + pub const VT_RENT_EPOCH: flatbuffers::VOffsetT = 12; + pub const VT_DATA: flatbuffers::VOffsetT = 14; + pub const VT_WRITE_VERSION: flatbuffers::VOffsetT = 16; + pub const VT_SLOT: flatbuffers::VOffsetT = 18; + pub const VT_IS_STARTUP: flatbuffers::VOffsetT = 20; + pub const VT_SEEN_AT: flatbuffers::VOffsetT = 22; - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - AccountInfo { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, - args: &'args AccountInfoArgs<'args>, - ) -> flatbuffers::WIPOffset> { - let mut builder = AccountInfoBuilder::new(_fbb); - builder.add_seen_at(args.seen_at); - builder.add_slot(args.slot); - builder.add_write_version(args.write_version); - builder.add_rent_epoch(args.rent_epoch); - builder.add_lamports(args.lamports); - if let Some(x) = args.data { - builder.add_data(x); - } - if let Some(x) = args.owner { - builder.add_owner(x); - } - if let Some(x) = args.pubkey { - builder.add_pubkey(x); - } - builder.add_is_startup(args.is_startup); - builder.add_executable(args.executable); - builder.finish() - } + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + AccountInfo { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args AccountInfoArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = AccountInfoBuilder::new(_fbb); + builder.add_seen_at(args.seen_at); + builder.add_slot(args.slot); + builder.add_write_version(args.write_version); + builder.add_rent_epoch(args.rent_epoch); + builder.add_lamports(args.lamports); + if let Some(x) = args.data { builder.add_data(x); } + if let Some(x) = args.owner { builder.add_owner(x); } + if let Some(x) = args.pubkey { builder.add_pubkey(x); } + builder.add_is_startup(args.is_startup); + builder.add_executable(args.executable); + builder.finish() + } - #[inline] - pub fn pubkey(&self) -> Option<&'a Pubkey> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(AccountInfo::VT_PUBKEY, None) } - } - #[inline] - pub fn lamports(&self) -> u64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::(AccountInfo::VT_LAMPORTS, Some(0)) - .unwrap() - } - } - #[inline] - pub fn owner(&self) -> Option<&'a Pubkey> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(AccountInfo::VT_OWNER, None) } - } - #[inline] - pub fn executable(&self) -> bool { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::(AccountInfo::VT_EXECUTABLE, Some(false)) - .unwrap() - } - } - #[inline] - pub fn rent_epoch(&self) -> u64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::(AccountInfo::VT_RENT_EPOCH, Some(0)) - .unwrap() - } - } - #[inline] - pub fn data(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::>>( - AccountInfo::VT_DATA, - None, - ) - } - } - #[inline] - pub fn write_version(&self) -> u64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::(AccountInfo::VT_WRITE_VERSION, Some(0)) - .unwrap() - } - } - #[inline] - pub fn slot(&self) -> u64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(AccountInfo::VT_SLOT, Some(0)).unwrap() } - } - #[inline] - pub fn is_startup(&self) -> bool { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::(AccountInfo::VT_IS_STARTUP, Some(false)) - .unwrap() - } - } - #[inline] - pub fn seen_at(&self) -> i64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::(AccountInfo::VT_SEEN_AT, Some(0)) - .unwrap() - } - } + + #[inline] + pub fn pubkey(&self) -> Option<&'a Pubkey> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(AccountInfo::VT_PUBKEY, None)} + } + #[inline] + pub fn lamports(&self) -> u64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(AccountInfo::VT_LAMPORTS, Some(0)).unwrap()} + } + #[inline] + pub fn owner(&self) -> Option<&'a Pubkey> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(AccountInfo::VT_OWNER, None)} + } + #[inline] + pub fn executable(&self) -> bool { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(AccountInfo::VT_EXECUTABLE, Some(false)).unwrap()} + } + #[inline] + pub fn rent_epoch(&self) -> u64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(AccountInfo::VT_RENT_EPOCH, Some(0)).unwrap()} + } + #[inline] + pub fn data(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(AccountInfo::VT_DATA, None)} + } + #[inline] + pub fn write_version(&self) -> u64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(AccountInfo::VT_WRITE_VERSION, Some(0)).unwrap()} + } + #[inline] + pub fn slot(&self) -> u64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(AccountInfo::VT_SLOT, Some(0)).unwrap()} + } + #[inline] + pub fn is_startup(&self) -> bool { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(AccountInfo::VT_IS_STARTUP, Some(false)).unwrap()} + } + #[inline] + pub fn seen_at(&self) -> i64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(AccountInfo::VT_SEEN_AT, Some(0)).unwrap()} + } } impl flatbuffers::Verifiable for AccountInfo<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::("pubkey", Self::VT_PUBKEY, false)? - .visit_field::("lamports", Self::VT_LAMPORTS, false)? - .visit_field::("owner", Self::VT_OWNER, false)? - .visit_field::("executable", Self::VT_EXECUTABLE, false)? - .visit_field::("rent_epoch", Self::VT_RENT_EPOCH, false)? - .visit_field::>>( - "data", - Self::VT_DATA, - false, - )? - .visit_field::("write_version", Self::VT_WRITE_VERSION, false)? - .visit_field::("slot", Self::VT_SLOT, false)? - .visit_field::("is_startup", Self::VT_IS_STARTUP, false)? - .visit_field::("seen_at", Self::VT_SEEN_AT, false)? - .finish(); - Ok(()) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("pubkey", Self::VT_PUBKEY, false)? + .visit_field::("lamports", Self::VT_LAMPORTS, false)? + .visit_field::("owner", Self::VT_OWNER, false)? + .visit_field::("executable", Self::VT_EXECUTABLE, false)? + .visit_field::("rent_epoch", Self::VT_RENT_EPOCH, false)? + .visit_field::>>("data", Self::VT_DATA, false)? + .visit_field::("write_version", Self::VT_WRITE_VERSION, false)? + .visit_field::("slot", Self::VT_SLOT, false)? + .visit_field::("is_startup", Self::VT_IS_STARTUP, false)? + .visit_field::("seen_at", Self::VT_SEEN_AT, false)? + .finish(); + Ok(()) + } } pub struct AccountInfoArgs<'a> { pub pubkey: Option<&'a Pubkey>, @@ -208,107 +167,98 @@ pub struct AccountInfoArgs<'a> { pub seen_at: i64, } impl<'a> Default for AccountInfoArgs<'a> { - #[inline] - fn default() -> Self { - AccountInfoArgs { - pubkey: None, - lamports: 0, - owner: None, - executable: false, - rent_epoch: 0, - data: None, - write_version: 0, - slot: 0, - is_startup: false, - seen_at: 0, - } + #[inline] + fn default() -> Self { + AccountInfoArgs { + pubkey: None, + lamports: 0, + owner: None, + executable: false, + rent_epoch: 0, + data: None, + write_version: 0, + slot: 0, + is_startup: false, + seen_at: 0, } + } } pub struct AccountInfoBuilder<'a: 'b, 'b> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, - start_: flatbuffers::WIPOffset, + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, } impl<'a: 'b, 'b> AccountInfoBuilder<'a, 'b> { - #[inline] - pub fn add_pubkey(&mut self, pubkey: &Pubkey) { - self.fbb_ - .push_slot_always::<&Pubkey>(AccountInfo::VT_PUBKEY, pubkey); - } - #[inline] - pub fn add_lamports(&mut self, lamports: u64) { - self.fbb_ - .push_slot::(AccountInfo::VT_LAMPORTS, lamports, 0); - } - #[inline] - pub fn add_owner(&mut self, owner: &Pubkey) { - self.fbb_ - .push_slot_always::<&Pubkey>(AccountInfo::VT_OWNER, owner); - } - #[inline] - pub fn add_executable(&mut self, executable: bool) { - self.fbb_ - .push_slot::(AccountInfo::VT_EXECUTABLE, executable, false); - } - #[inline] - pub fn add_rent_epoch(&mut self, rent_epoch: u64) { - self.fbb_ - .push_slot::(AccountInfo::VT_RENT_EPOCH, rent_epoch, 0); - } - #[inline] - pub fn add_data(&mut self, data: flatbuffers::WIPOffset>) { - self.fbb_ - .push_slot_always::>(AccountInfo::VT_DATA, data); - } - #[inline] - pub fn add_write_version(&mut self, write_version: u64) { - self.fbb_ - .push_slot::(AccountInfo::VT_WRITE_VERSION, write_version, 0); - } - #[inline] - pub fn add_slot(&mut self, slot: u64) { - self.fbb_.push_slot::(AccountInfo::VT_SLOT, slot, 0); - } - #[inline] - pub fn add_is_startup(&mut self, is_startup: bool) { - self.fbb_ - .push_slot::(AccountInfo::VT_IS_STARTUP, is_startup, false); - } - #[inline] - pub fn add_seen_at(&mut self, seen_at: i64) { - self.fbb_ - .push_slot::(AccountInfo::VT_SEEN_AT, seen_at, 0); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> AccountInfoBuilder<'a, 'b> { - let start = _fbb.start_table(); - AccountInfoBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) + #[inline] + pub fn add_pubkey(&mut self, pubkey: &Pubkey) { + self.fbb_.push_slot_always::<&Pubkey>(AccountInfo::VT_PUBKEY, pubkey); + } + #[inline] + pub fn add_lamports(&mut self, lamports: u64) { + self.fbb_.push_slot::(AccountInfo::VT_LAMPORTS, lamports, 0); + } + #[inline] + pub fn add_owner(&mut self, owner: &Pubkey) { + self.fbb_.push_slot_always::<&Pubkey>(AccountInfo::VT_OWNER, owner); + } + #[inline] + pub fn add_executable(&mut self, executable: bool) { + self.fbb_.push_slot::(AccountInfo::VT_EXECUTABLE, executable, false); + } + #[inline] + pub fn add_rent_epoch(&mut self, rent_epoch: u64) { + self.fbb_.push_slot::(AccountInfo::VT_RENT_EPOCH, rent_epoch, 0); + } + #[inline] + pub fn add_data(&mut self, data: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(AccountInfo::VT_DATA, data); + } + #[inline] + pub fn add_write_version(&mut self, write_version: u64) { + self.fbb_.push_slot::(AccountInfo::VT_WRITE_VERSION, write_version, 0); + } + #[inline] + pub fn add_slot(&mut self, slot: u64) { + self.fbb_.push_slot::(AccountInfo::VT_SLOT, slot, 0); + } + #[inline] + pub fn add_is_startup(&mut self, is_startup: bool) { + self.fbb_.push_slot::(AccountInfo::VT_IS_STARTUP, is_startup, false); + } + #[inline] + pub fn add_seen_at(&mut self, seen_at: i64) { + self.fbb_.push_slot::(AccountInfo::VT_SEEN_AT, seen_at, 0); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> AccountInfoBuilder<'a, 'b> { + let start = _fbb.start_table(); + AccountInfoBuilder { + fbb_: _fbb, + start_: start, } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } } impl core::fmt::Debug for AccountInfo<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("AccountInfo"); - ds.field("pubkey", &self.pubkey()); - ds.field("lamports", &self.lamports()); - ds.field("owner", &self.owner()); - ds.field("executable", &self.executable()); - ds.field("rent_epoch", &self.rent_epoch()); - ds.field("data", &self.data()); - ds.field("write_version", &self.write_version()); - ds.field("slot", &self.slot()); - ds.field("is_startup", &self.is_startup()); - ds.field("seen_at", &self.seen_at()); - ds.finish() - } + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("AccountInfo"); + ds.field("pubkey", &self.pubkey()); + ds.field("lamports", &self.lamports()); + ds.field("owner", &self.owner()); + ds.field("executable", &self.executable()); + ds.field("rent_epoch", &self.rent_epoch()); + ds.field("data", &self.data()); + ds.field("write_version", &self.write_version()); + ds.field("slot", &self.slot()); + ds.field("is_startup", &self.is_startup()); + ds.field("seen_at", &self.seen_at()); + ds.finish() + } } #[inline] /// Verifies that a buffer of bytes contains a `AccountInfo` @@ -318,7 +268,7 @@ impl core::fmt::Debug for AccountInfo<'_> { /// previous, unchecked, behavior use /// `root_as_account_info_unchecked`. pub fn root_as_account_info(buf: &[u8]) -> Result { - flatbuffers::root::(buf) + flatbuffers::root::(buf) } #[inline] /// Verifies that a buffer of bytes contains a size prefixed @@ -327,10 +277,8 @@ pub fn root_as_account_info(buf: &[u8]) -> Result Result { - flatbuffers::size_prefixed_root::(buf) +pub fn size_prefixed_root_as_account_info(buf: &[u8]) -> Result { + flatbuffers::size_prefixed_root::(buf) } #[inline] /// Verifies, with the given options, that a buffer of bytes @@ -340,10 +288,10 @@ pub fn size_prefixed_root_as_account_info( /// previous, unchecked, behavior use /// `root_as_account_info_unchecked`. pub fn root_as_account_info_with_opts<'b, 'o>( - opts: &'o flatbuffers::VerifierOptions, - buf: &'b [u8], + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], ) -> Result, flatbuffers::InvalidFlatbuffer> { - flatbuffers::root_with_opts::>(opts, buf) + flatbuffers::root_with_opts::>(opts, buf) } #[inline] /// Verifies, with the given verifier options, that a buffer of @@ -353,37 +301,33 @@ pub fn root_as_account_info_with_opts<'b, 'o>( /// previous, unchecked, behavior use /// `root_as_account_info_unchecked`. pub fn size_prefixed_root_as_account_info_with_opts<'b, 'o>( - opts: &'o flatbuffers::VerifierOptions, - buf: &'b [u8], + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], ) -> Result, flatbuffers::InvalidFlatbuffer> { - flatbuffers::size_prefixed_root_with_opts::>(opts, buf) + flatbuffers::size_prefixed_root_with_opts::>(opts, buf) } #[inline] /// Assumes, without verification, that a buffer of bytes contains a AccountInfo and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid `AccountInfo`. pub unsafe fn root_as_account_info_unchecked(buf: &[u8]) -> AccountInfo { - flatbuffers::root_unchecked::(buf) + flatbuffers::root_unchecked::(buf) } #[inline] /// Assumes, without verification, that a buffer of bytes contains a size prefixed AccountInfo and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid size prefixed `AccountInfo`. pub unsafe fn size_prefixed_root_as_account_info_unchecked(buf: &[u8]) -> AccountInfo { - flatbuffers::size_prefixed_root_unchecked::(buf) + flatbuffers::size_prefixed_root_unchecked::(buf) } #[inline] pub fn finish_account_info_buffer<'a, 'b>( fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - root: flatbuffers::WIPOffset>, -) { - fbb.finish(root, None); + root: flatbuffers::WIPOffset>) { + fbb.finish(root, None); } #[inline] -pub fn finish_size_prefixed_account_info_buffer<'a, 'b>( - fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - root: flatbuffers::WIPOffset>, -) { - fbb.finish_size_prefixed(root, None); +pub fn finish_size_prefixed_account_info_buffer<'a, 'b>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, root: flatbuffers::WIPOffset>) { + fbb.finish_size_prefixed(root, None); } diff --git a/plerkle_serialization/src/block_info_generated.rs b/plerkle_serialization/src/block_info_generated.rs index 16b54219..4acb8e40 100644 --- a/plerkle_serialization/src/block_info_generated.rs +++ b/plerkle_serialization/src/block_info_generated.rs @@ -1,33 +1,25 @@ // automatically generated by the FlatBuffers compiler, do not modify + // @generated -use core::cmp::Ordering; use core::mem; +use core::cmp::Ordering; extern crate flatbuffers; use self::flatbuffers::{EndianScalar, Follow}; -#[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." -)] +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_REWARD_TYPE: u8 = 0; -#[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." -)] +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_REWARD_TYPE: u8 = 3; -#[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." -)] +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_REWARD_TYPE: [RewardType; 4] = [ - RewardType::Fee, - RewardType::Rent, - RewardType::Staking, - RewardType::Voting, + RewardType::Fee, + RewardType::Rent, + RewardType::Staking, + RewardType::Voting, ]; #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] @@ -35,41 +27,46 @@ pub const ENUM_VALUES_REWARD_TYPE: [RewardType; 4] = [ pub struct RewardType(pub u8); #[allow(non_upper_case_globals)] impl RewardType { - pub const Fee: Self = Self(0); - pub const Rent: Self = Self(1); - pub const Staking: Self = Self(2); - pub const Voting: Self = Self(3); + pub const Fee: Self = Self(0); + pub const Rent: Self = Self(1); + pub const Staking: Self = Self(2); + pub const Voting: Self = Self(3); - pub const ENUM_MIN: u8 = 0; - pub const ENUM_MAX: u8 = 3; - pub const ENUM_VALUES: &'static [Self] = &[Self::Fee, Self::Rent, Self::Staking, Self::Voting]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::Fee => Some("Fee"), - Self::Rent => Some("Rent"), - Self::Staking => Some("Staking"), - Self::Voting => Some("Voting"), - _ => None, - } - } + pub const ENUM_MIN: u8 = 0; + pub const ENUM_MAX: u8 = 3; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::Fee, + Self::Rent, + Self::Staking, + Self::Voting, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::Fee => Some("Fee"), + Self::Rent => Some("Rent"), + Self::Staking => Some("Staking"), + Self::Voting => Some("Voting"), + _ => None, + } + } } impl core::fmt::Debug for RewardType { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) - } + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) } + } } impl<'a> flatbuffers::Follow<'a> for RewardType { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = flatbuffers::read_scalar_at::(buf, loc); - Self(b) - } + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } } impl flatbuffers::Push for RewardType { @@ -81,146 +78,123 @@ impl flatbuffers::Push for RewardType { } impl flatbuffers::EndianScalar for RewardType { - type Scalar = u8; - #[inline] - fn to_little_endian(self) -> u8 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: u8) -> Self { - let b = u8::from_le(v); - Self(b) - } + type Scalar = u8; + #[inline] + fn to_little_endian(self) -> u8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: u8) -> Self { + let b = u8::from_le(v); + Self(b) + } } impl<'a> flatbuffers::Verifiable for RewardType { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - u8::run_verifier(v, pos) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + u8::run_verifier(v, pos) + } } impl flatbuffers::SimpleToVerifyInSlice for RewardType {} pub enum RewardOffset {} -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq)] pub struct Reward<'a> { - pub _tab: flatbuffers::Table<'a>, + pub _tab: flatbuffers::Table<'a>, } impl<'a> flatbuffers::Follow<'a> for Reward<'a> { - type Inner = Reward<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { - _tab: flatbuffers::Table::new(buf, loc), - } - } + type Inner = Reward<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } } impl<'a> Reward<'a> { - pub const VT_PUBKEY: flatbuffers::VOffsetT = 4; - pub const VT_LAMPORTS: flatbuffers::VOffsetT = 6; - pub const VT_POST_BALANCE: flatbuffers::VOffsetT = 8; - pub const VT_REWARD_TYPE: flatbuffers::VOffsetT = 10; - pub const VT_COMMISSION: flatbuffers::VOffsetT = 12; + pub const VT_PUBKEY: flatbuffers::VOffsetT = 4; + pub const VT_LAMPORTS: flatbuffers::VOffsetT = 6; + pub const VT_POST_BALANCE: flatbuffers::VOffsetT = 8; + pub const VT_REWARD_TYPE: flatbuffers::VOffsetT = 10; + pub const VT_COMMISSION: flatbuffers::VOffsetT = 12; - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - Reward { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, - args: &'args RewardArgs<'args>, - ) -> flatbuffers::WIPOffset> { - let mut builder = RewardBuilder::new(_fbb); - builder.add_post_balance(args.post_balance); - builder.add_lamports(args.lamports); - if let Some(x) = args.pubkey { - builder.add_pubkey(x); - } - if let Some(x) = args.commission { - builder.add_commission(x); - } - if let Some(x) = args.reward_type { - builder.add_reward_type(x); - } - builder.finish() - } + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Reward { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args RewardArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = RewardBuilder::new(_fbb); + builder.add_post_balance(args.post_balance); + builder.add_lamports(args.lamports); + if let Some(x) = args.pubkey { builder.add_pubkey(x); } + if let Some(x) = args.commission { builder.add_commission(x); } + if let Some(x) = args.reward_type { builder.add_reward_type(x); } + builder.finish() + } - #[inline] - pub fn pubkey(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::>>( - Reward::VT_PUBKEY, - None, - ) - } - } - #[inline] - pub fn lamports(&self) -> i64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Reward::VT_LAMPORTS, Some(0)).unwrap() } - } - #[inline] - pub fn post_balance(&self) -> u64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::(Reward::VT_POST_BALANCE, Some(0)) - .unwrap() - } - } - #[inline] - pub fn reward_type(&self) -> Option { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Reward::VT_REWARD_TYPE, None) } - } - #[inline] - pub fn commission(&self) -> Option { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Reward::VT_COMMISSION, None) } - } + + #[inline] + pub fn pubkey(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(Reward::VT_PUBKEY, None)} + } + #[inline] + pub fn lamports(&self) -> i64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Reward::VT_LAMPORTS, Some(0)).unwrap()} + } + #[inline] + pub fn post_balance(&self) -> u64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Reward::VT_POST_BALANCE, Some(0)).unwrap()} + } + #[inline] + pub fn reward_type(&self) -> Option { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Reward::VT_REWARD_TYPE, None)} + } + #[inline] + pub fn commission(&self) -> Option { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Reward::VT_COMMISSION, None)} + } } impl flatbuffers::Verifiable for Reward<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::>>( - "pubkey", - Self::VT_PUBKEY, - false, - )? - .visit_field::("lamports", Self::VT_LAMPORTS, false)? - .visit_field::("post_balance", Self::VT_POST_BALANCE, false)? - .visit_field::("reward_type", Self::VT_REWARD_TYPE, false)? - .visit_field::("commission", Self::VT_COMMISSION, false)? - .finish(); - Ok(()) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>>("pubkey", Self::VT_PUBKEY, false)? + .visit_field::("lamports", Self::VT_LAMPORTS, false)? + .visit_field::("post_balance", Self::VT_POST_BALANCE, false)? + .visit_field::("reward_type", Self::VT_REWARD_TYPE, false)? + .visit_field::("commission", Self::VT_COMMISSION, false)? + .finish(); + Ok(()) + } } pub struct RewardArgs<'a> { pub pubkey: Option>>, @@ -230,295 +204,250 @@ pub struct RewardArgs<'a> { pub commission: Option, } impl<'a> Default for RewardArgs<'a> { - #[inline] - fn default() -> Self { - RewardArgs { - pubkey: None, - lamports: 0, - post_balance: 0, - reward_type: None, - commission: None, - } + #[inline] + fn default() -> Self { + RewardArgs { + pubkey: None, + lamports: 0, + post_balance: 0, + reward_type: None, + commission: None, } + } } pub struct RewardBuilder<'a: 'b, 'b> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, - start_: flatbuffers::WIPOffset, + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, } impl<'a: 'b, 'b> RewardBuilder<'a, 'b> { - #[inline] - pub fn add_pubkey(&mut self, pubkey: flatbuffers::WIPOffset>) { - self.fbb_ - .push_slot_always::>(Reward::VT_PUBKEY, pubkey); - } - #[inline] - pub fn add_lamports(&mut self, lamports: i64) { - self.fbb_.push_slot::(Reward::VT_LAMPORTS, lamports, 0); - } - #[inline] - pub fn add_post_balance(&mut self, post_balance: u64) { - self.fbb_ - .push_slot::(Reward::VT_POST_BALANCE, post_balance, 0); - } - #[inline] - pub fn add_reward_type(&mut self, reward_type: RewardType) { - self.fbb_ - .push_slot_always::(Reward::VT_REWARD_TYPE, reward_type); - } - #[inline] - pub fn add_commission(&mut self, commission: u8) { - self.fbb_ - .push_slot_always::(Reward::VT_COMMISSION, commission); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> RewardBuilder<'a, 'b> { - let start = _fbb.start_table(); - RewardBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) - } + #[inline] + pub fn add_pubkey(&mut self, pubkey: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Reward::VT_PUBKEY, pubkey); + } + #[inline] + pub fn add_lamports(&mut self, lamports: i64) { + self.fbb_.push_slot::(Reward::VT_LAMPORTS, lamports, 0); + } + #[inline] + pub fn add_post_balance(&mut self, post_balance: u64) { + self.fbb_.push_slot::(Reward::VT_POST_BALANCE, post_balance, 0); + } + #[inline] + pub fn add_reward_type(&mut self, reward_type: RewardType) { + self.fbb_.push_slot_always::(Reward::VT_REWARD_TYPE, reward_type); + } + #[inline] + pub fn add_commission(&mut self, commission: u8) { + self.fbb_.push_slot_always::(Reward::VT_COMMISSION, commission); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> RewardBuilder<'a, 'b> { + let start = _fbb.start_table(); + RewardBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } } impl core::fmt::Debug for Reward<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("Reward"); - ds.field("pubkey", &self.pubkey()); - ds.field("lamports", &self.lamports()); - ds.field("post_balance", &self.post_balance()); - ds.field("reward_type", &self.reward_type()); - ds.field("commission", &self.commission()); - ds.finish() - } + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Reward"); + ds.field("pubkey", &self.pubkey()); + ds.field("lamports", &self.lamports()); + ds.field("post_balance", &self.post_balance()); + ds.field("reward_type", &self.reward_type()); + ds.field("commission", &self.commission()); + ds.finish() + } } pub enum BlockInfoOffset {} -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq)] pub struct BlockInfo<'a> { - pub _tab: flatbuffers::Table<'a>, + pub _tab: flatbuffers::Table<'a>, } impl<'a> flatbuffers::Follow<'a> for BlockInfo<'a> { - type Inner = BlockInfo<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { - _tab: flatbuffers::Table::new(buf, loc), - } - } + type Inner = BlockInfo<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } } impl<'a> BlockInfo<'a> { - pub const VT_SLOT: flatbuffers::VOffsetT = 4; - pub const VT_BLOCKHASH: flatbuffers::VOffsetT = 6; - pub const VT_REWARDS: flatbuffers::VOffsetT = 8; - pub const VT_BLOCK_TIME: flatbuffers::VOffsetT = 10; - pub const VT_BLOCK_HEIGHT: flatbuffers::VOffsetT = 12; - pub const VT_SEEN_AT: flatbuffers::VOffsetT = 14; + pub const VT_SLOT: flatbuffers::VOffsetT = 4; + pub const VT_BLOCKHASH: flatbuffers::VOffsetT = 6; + pub const VT_REWARDS: flatbuffers::VOffsetT = 8; + pub const VT_BLOCK_TIME: flatbuffers::VOffsetT = 10; + pub const VT_BLOCK_HEIGHT: flatbuffers::VOffsetT = 12; + pub const VT_SEEN_AT: flatbuffers::VOffsetT = 14; - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - BlockInfo { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, - args: &'args BlockInfoArgs<'args>, - ) -> flatbuffers::WIPOffset> { - let mut builder = BlockInfoBuilder::new(_fbb); - builder.add_seen_at(args.seen_at); - if let Some(x) = args.block_height { - builder.add_block_height(x); - } - if let Some(x) = args.block_time { - builder.add_block_time(x); - } - builder.add_slot(args.slot); - if let Some(x) = args.rewards { - builder.add_rewards(x); - } - if let Some(x) = args.blockhash { - builder.add_blockhash(x); - } - builder.finish() - } + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + BlockInfo { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args BlockInfoArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = BlockInfoBuilder::new(_fbb); + builder.add_seen_at(args.seen_at); + if let Some(x) = args.block_height { builder.add_block_height(x); } + if let Some(x) = args.block_time { builder.add_block_time(x); } + builder.add_slot(args.slot); + if let Some(x) = args.rewards { builder.add_rewards(x); } + if let Some(x) = args.blockhash { builder.add_blockhash(x); } + builder.finish() + } - #[inline] - pub fn slot(&self) -> u64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(BlockInfo::VT_SLOT, Some(0)).unwrap() } - } - #[inline] - pub fn blockhash(&self) -> Option<&'a str> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::>(BlockInfo::VT_BLOCKHASH, None) - } - } - #[inline] - pub fn rewards( - &self, - ) -> Option>>> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab.get::>, - >>(BlockInfo::VT_REWARDS, None) - } - } - #[inline] - pub fn block_time(&self) -> Option { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(BlockInfo::VT_BLOCK_TIME, None) } - } - #[inline] - pub fn block_height(&self) -> Option { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(BlockInfo::VT_BLOCK_HEIGHT, None) } - } - #[inline] - pub fn seen_at(&self) -> i64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::(BlockInfo::VT_SEEN_AT, Some(0)) - .unwrap() - } - } + + #[inline] + pub fn slot(&self) -> u64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(BlockInfo::VT_SLOT, Some(0)).unwrap()} + } + #[inline] + pub fn blockhash(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(BlockInfo::VT_BLOCKHASH, None)} + } + #[inline] + pub fn rewards(&self) -> Option>>> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>>(BlockInfo::VT_REWARDS, None)} + } + #[inline] + pub fn block_time(&self) -> Option { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(BlockInfo::VT_BLOCK_TIME, None)} + } + #[inline] + pub fn block_height(&self) -> Option { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(BlockInfo::VT_BLOCK_HEIGHT, None)} + } + #[inline] + pub fn seen_at(&self) -> i64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(BlockInfo::VT_SEEN_AT, Some(0)).unwrap()} + } } impl flatbuffers::Verifiable for BlockInfo<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::("slot", Self::VT_SLOT, false)? - .visit_field::>( - "blockhash", - Self::VT_BLOCKHASH, - false, - )? - .visit_field::>, - >>("rewards", Self::VT_REWARDS, false)? - .visit_field::("block_time", Self::VT_BLOCK_TIME, false)? - .visit_field::("block_height", Self::VT_BLOCK_HEIGHT, false)? - .visit_field::("seen_at", Self::VT_SEEN_AT, false)? - .finish(); - Ok(()) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("slot", Self::VT_SLOT, false)? + .visit_field::>("blockhash", Self::VT_BLOCKHASH, false)? + .visit_field::>>>("rewards", Self::VT_REWARDS, false)? + .visit_field::("block_time", Self::VT_BLOCK_TIME, false)? + .visit_field::("block_height", Self::VT_BLOCK_HEIGHT, false)? + .visit_field::("seen_at", Self::VT_SEEN_AT, false)? + .finish(); + Ok(()) + } } pub struct BlockInfoArgs<'a> { pub slot: u64, pub blockhash: Option>, - pub rewards: Option< - flatbuffers::WIPOffset>>>, - >, + pub rewards: Option>>>>, pub block_time: Option, pub block_height: Option, pub seen_at: i64, } impl<'a> Default for BlockInfoArgs<'a> { - #[inline] - fn default() -> Self { - BlockInfoArgs { - slot: 0, - blockhash: None, - rewards: None, - block_time: None, - block_height: None, - seen_at: 0, - } - } + #[inline] + fn default() -> Self { + BlockInfoArgs { + slot: 0, + blockhash: None, + rewards: None, + block_time: None, + block_height: None, + seen_at: 0, + } + } } pub struct BlockInfoBuilder<'a: 'b, 'b> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, - start_: flatbuffers::WIPOffset, + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, } impl<'a: 'b, 'b> BlockInfoBuilder<'a, 'b> { - #[inline] - pub fn add_slot(&mut self, slot: u64) { - self.fbb_.push_slot::(BlockInfo::VT_SLOT, slot, 0); - } - #[inline] - pub fn add_blockhash(&mut self, blockhash: flatbuffers::WIPOffset<&'b str>) { - self.fbb_ - .push_slot_always::>(BlockInfo::VT_BLOCKHASH, blockhash); - } - #[inline] - pub fn add_rewards( - &mut self, - rewards: flatbuffers::WIPOffset< - flatbuffers::Vector<'b, flatbuffers::ForwardsUOffset>>, - >, - ) { - self.fbb_ - .push_slot_always::>(BlockInfo::VT_REWARDS, rewards); - } - #[inline] - pub fn add_block_time(&mut self, block_time: i64) { - self.fbb_ - .push_slot_always::(BlockInfo::VT_BLOCK_TIME, block_time); - } - #[inline] - pub fn add_block_height(&mut self, block_height: u64) { - self.fbb_ - .push_slot_always::(BlockInfo::VT_BLOCK_HEIGHT, block_height); - } - #[inline] - pub fn add_seen_at(&mut self, seen_at: i64) { - self.fbb_ - .push_slot::(BlockInfo::VT_SEEN_AT, seen_at, 0); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> BlockInfoBuilder<'a, 'b> { - let start = _fbb.start_table(); - BlockInfoBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) - } + #[inline] + pub fn add_slot(&mut self, slot: u64) { + self.fbb_.push_slot::(BlockInfo::VT_SLOT, slot, 0); + } + #[inline] + pub fn add_blockhash(&mut self, blockhash: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(BlockInfo::VT_BLOCKHASH, blockhash); + } + #[inline] + pub fn add_rewards(&mut self, rewards: flatbuffers::WIPOffset>>>) { + self.fbb_.push_slot_always::>(BlockInfo::VT_REWARDS, rewards); + } + #[inline] + pub fn add_block_time(&mut self, block_time: i64) { + self.fbb_.push_slot_always::(BlockInfo::VT_BLOCK_TIME, block_time); + } + #[inline] + pub fn add_block_height(&mut self, block_height: u64) { + self.fbb_.push_slot_always::(BlockInfo::VT_BLOCK_HEIGHT, block_height); + } + #[inline] + pub fn add_seen_at(&mut self, seen_at: i64) { + self.fbb_.push_slot::(BlockInfo::VT_SEEN_AT, seen_at, 0); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> BlockInfoBuilder<'a, 'b> { + let start = _fbb.start_table(); + BlockInfoBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } } impl core::fmt::Debug for BlockInfo<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("BlockInfo"); - ds.field("slot", &self.slot()); - ds.field("blockhash", &self.blockhash()); - ds.field("rewards", &self.rewards()); - ds.field("block_time", &self.block_time()); - ds.field("block_height", &self.block_height()); - ds.field("seen_at", &self.seen_at()); - ds.finish() - } + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("BlockInfo"); + ds.field("slot", &self.slot()); + ds.field("blockhash", &self.blockhash()); + ds.field("rewards", &self.rewards()); + ds.field("block_time", &self.block_time()); + ds.field("block_height", &self.block_height()); + ds.field("seen_at", &self.seen_at()); + ds.finish() + } } #[inline] /// Verifies that a buffer of bytes contains a `BlockInfo` @@ -528,7 +457,7 @@ impl core::fmt::Debug for BlockInfo<'_> { /// previous, unchecked, behavior use /// `root_as_block_info_unchecked`. pub fn root_as_block_info(buf: &[u8]) -> Result { - flatbuffers::root::(buf) + flatbuffers::root::(buf) } #[inline] /// Verifies that a buffer of bytes contains a size prefixed @@ -537,10 +466,8 @@ pub fn root_as_block_info(buf: &[u8]) -> Result Result { - flatbuffers::size_prefixed_root::(buf) +pub fn size_prefixed_root_as_block_info(buf: &[u8]) -> Result { + flatbuffers::size_prefixed_root::(buf) } #[inline] /// Verifies, with the given options, that a buffer of bytes @@ -550,10 +477,10 @@ pub fn size_prefixed_root_as_block_info( /// previous, unchecked, behavior use /// `root_as_block_info_unchecked`. pub fn root_as_block_info_with_opts<'b, 'o>( - opts: &'o flatbuffers::VerifierOptions, - buf: &'b [u8], + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], ) -> Result, flatbuffers::InvalidFlatbuffer> { - flatbuffers::root_with_opts::>(opts, buf) + flatbuffers::root_with_opts::>(opts, buf) } #[inline] /// Verifies, with the given verifier options, that a buffer of @@ -563,37 +490,33 @@ pub fn root_as_block_info_with_opts<'b, 'o>( /// previous, unchecked, behavior use /// `root_as_block_info_unchecked`. pub fn size_prefixed_root_as_block_info_with_opts<'b, 'o>( - opts: &'o flatbuffers::VerifierOptions, - buf: &'b [u8], + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], ) -> Result, flatbuffers::InvalidFlatbuffer> { - flatbuffers::size_prefixed_root_with_opts::>(opts, buf) + flatbuffers::size_prefixed_root_with_opts::>(opts, buf) } #[inline] /// Assumes, without verification, that a buffer of bytes contains a BlockInfo and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid `BlockInfo`. pub unsafe fn root_as_block_info_unchecked(buf: &[u8]) -> BlockInfo { - flatbuffers::root_unchecked::(buf) + flatbuffers::root_unchecked::(buf) } #[inline] /// Assumes, without verification, that a buffer of bytes contains a size prefixed BlockInfo and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid size prefixed `BlockInfo`. pub unsafe fn size_prefixed_root_as_block_info_unchecked(buf: &[u8]) -> BlockInfo { - flatbuffers::size_prefixed_root_unchecked::(buf) + flatbuffers::size_prefixed_root_unchecked::(buf) } #[inline] pub fn finish_block_info_buffer<'a, 'b>( fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - root: flatbuffers::WIPOffset>, -) { - fbb.finish(root, None); + root: flatbuffers::WIPOffset>) { + fbb.finish(root, None); } #[inline] -pub fn finish_size_prefixed_block_info_buffer<'a, 'b>( - fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - root: flatbuffers::WIPOffset>, -) { - fbb.finish_size_prefixed(root, None); +pub fn finish_size_prefixed_block_info_buffer<'a, 'b>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, root: flatbuffers::WIPOffset>) { + fbb.finish_size_prefixed(root, None); } diff --git a/plerkle_serialization/src/common_generated.rs b/plerkle_serialization/src/common_generated.rs index e8c8b857..00cc2704 100644 --- a/plerkle_serialization/src/common_generated.rs +++ b/plerkle_serialization/src/common_generated.rs @@ -1,42 +1,45 @@ // automatically generated by the FlatBuffers compiler, do not modify + // @generated -use core::cmp::Ordering; use core::mem; +use core::cmp::Ordering; extern crate flatbuffers; use self::flatbuffers::{EndianScalar, Follow}; // struct Pubkey, aligned to 1 #[repr(transparent)] -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, PartialEq)] pub struct Pubkey(pub [u8; 32]); -impl Default for Pubkey { - fn default() -> Self { - Self([0; 32]) - } +impl Default for Pubkey { + fn default() -> Self { + Self([0; 32]) + } } impl core::fmt::Debug for Pubkey { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - f.debug_struct("Pubkey").field("key", &self.key()).finish() - } + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + f.debug_struct("Pubkey") + .field("key", &self.key()) + .finish() + } } impl flatbuffers::SimpleToVerifyInSlice for Pubkey {} impl<'a> flatbuffers::Follow<'a> for Pubkey { - type Inner = &'a Pubkey; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - <&'a Pubkey>::follow(buf, loc) - } + type Inner = &'a Pubkey; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + <&'a Pubkey>::follow(buf, loc) + } } impl<'a> flatbuffers::Follow<'a> for &'a Pubkey { - type Inner = &'a Pubkey; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - flatbuffers::follow_cast_ref::(buf, loc) - } + type Inner = &'a Pubkey; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + flatbuffers::follow_cast_ref::(buf, loc) + } } impl<'b> flatbuffers::Push for Pubkey { type Output = Pubkey; @@ -48,35 +51,38 @@ impl<'b> flatbuffers::Push for Pubkey { } impl<'a> flatbuffers::Verifiable for Pubkey { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.in_buffer::(pos) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.in_buffer::(pos) + } } impl<'a> Pubkey { - #[allow(clippy::too_many_arguments)] - pub fn new(key: &[u8; 32]) -> Self { - let mut s = Self([0; 32]); - s.set_key(key); - s - } + #[allow(clippy::too_many_arguments)] + pub fn new( + key: &[u8; 32], + ) -> Self { + let mut s = Self([0; 32]); + s.set_key(key); + s + } - pub fn key(&'a self) -> flatbuffers::Array<'a, u8, 32> { - // Safety: - // Created from a valid Table for this object - // Which contains a valid array in this slot - unsafe { flatbuffers::Array::follow(&self.0, 0) } - } + pub fn key(&'a self) -> flatbuffers::Array<'a, u8, 32> { + // Safety: + // Created from a valid Table for this object + // Which contains a valid array in this slot + unsafe { flatbuffers::Array::follow(&self.0, 0) } + } + + pub fn set_key(&mut self, items: &[u8; 32]) { + // Safety: + // Created from a valid Table for this object + // Which contains a valid array in this slot + unsafe { flatbuffers::emplace_scalar_array(&mut self.0, 0, items) }; + } - pub fn set_key(&mut self, items: &[u8; 32]) { - // Safety: - // Created from a valid Table for this object - // Which contains a valid array in this slot - unsafe { flatbuffers::emplace_scalar_array(&mut self.0, 0, items) }; - } } + diff --git a/plerkle_serialization/src/compiled_instruction_generated.rs b/plerkle_serialization/src/compiled_instruction_generated.rs index 66ffd968..32ae8be8 100644 --- a/plerkle_serialization/src/compiled_instruction_generated.rs +++ b/plerkle_serialization/src/compiled_instruction_generated.rs @@ -1,117 +1,88 @@ // automatically generated by the FlatBuffers compiler, do not modify + // @generated use crate::common_generated::*; -use core::cmp::Ordering; use core::mem; +use core::cmp::Ordering; extern crate flatbuffers; use self::flatbuffers::{EndianScalar, Follow}; pub enum CompiledInstructionOffset {} -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq)] pub struct CompiledInstruction<'a> { - pub _tab: flatbuffers::Table<'a>, + pub _tab: flatbuffers::Table<'a>, } impl<'a> flatbuffers::Follow<'a> for CompiledInstruction<'a> { - type Inner = CompiledInstruction<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { - _tab: flatbuffers::Table::new(buf, loc), - } - } + type Inner = CompiledInstruction<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } } impl<'a> CompiledInstruction<'a> { - pub const VT_PROGRAM_ID_INDEX: flatbuffers::VOffsetT = 4; - pub const VT_ACCOUNTS: flatbuffers::VOffsetT = 6; - pub const VT_DATA: flatbuffers::VOffsetT = 8; + pub const VT_PROGRAM_ID_INDEX: flatbuffers::VOffsetT = 4; + pub const VT_ACCOUNTS: flatbuffers::VOffsetT = 6; + pub const VT_DATA: flatbuffers::VOffsetT = 8; - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - CompiledInstruction { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, - args: &'args CompiledInstructionArgs<'args>, - ) -> flatbuffers::WIPOffset> { - let mut builder = CompiledInstructionBuilder::new(_fbb); - if let Some(x) = args.data { - builder.add_data(x); - } - if let Some(x) = args.accounts { - builder.add_accounts(x); - } - builder.add_program_id_index(args.program_id_index); - builder.finish() - } + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + CompiledInstruction { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args CompiledInstructionArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = CompiledInstructionBuilder::new(_fbb); + if let Some(x) = args.data { builder.add_data(x); } + if let Some(x) = args.accounts { builder.add_accounts(x); } + builder.add_program_id_index(args.program_id_index); + builder.finish() + } - #[inline] - pub fn program_id_index(&self) -> u8 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::(CompiledInstruction::VT_PROGRAM_ID_INDEX, Some(0)) - .unwrap() - } - } - #[inline] - pub fn accounts(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::>>( - CompiledInstruction::VT_ACCOUNTS, - None, - ) - } - } - #[inline] - pub fn data(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::>>( - CompiledInstruction::VT_DATA, - None, - ) - } - } + + #[inline] + pub fn program_id_index(&self) -> u8 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(CompiledInstruction::VT_PROGRAM_ID_INDEX, Some(0)).unwrap()} + } + #[inline] + pub fn accounts(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(CompiledInstruction::VT_ACCOUNTS, None)} + } + #[inline] + pub fn data(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(CompiledInstruction::VT_DATA, None)} + } } impl flatbuffers::Verifiable for CompiledInstruction<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::("program_id_index", Self::VT_PROGRAM_ID_INDEX, false)? - .visit_field::>>( - "accounts", - Self::VT_ACCOUNTS, - false, - )? - .visit_field::>>( - "data", - Self::VT_DATA, - false, - )? - .finish(); - Ok(()) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("program_id_index", Self::VT_PROGRAM_ID_INDEX, false)? + .visit_field::>>("accounts", Self::VT_ACCOUNTS, false)? + .visit_field::>>("data", Self::VT_DATA, false)? + .finish(); + Ok(()) + } } pub struct CompiledInstructionArgs<'a> { pub program_id_index: u8, @@ -119,66 +90,170 @@ pub struct CompiledInstructionArgs<'a> { pub data: Option>>, } impl<'a> Default for CompiledInstructionArgs<'a> { - #[inline] - fn default() -> Self { - CompiledInstructionArgs { - program_id_index: 0, - accounts: None, - data: None, - } + #[inline] + fn default() -> Self { + CompiledInstructionArgs { + program_id_index: 0, + accounts: None, + data: None, } + } } pub struct CompiledInstructionBuilder<'a: 'b, 'b> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, - start_: flatbuffers::WIPOffset, + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, } impl<'a: 'b, 'b> CompiledInstructionBuilder<'a, 'b> { - #[inline] - pub fn add_program_id_index(&mut self, program_id_index: u8) { - self.fbb_.push_slot::( - CompiledInstruction::VT_PROGRAM_ID_INDEX, - program_id_index, - 0, - ); - } - #[inline] - pub fn add_accounts(&mut self, accounts: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>( - CompiledInstruction::VT_ACCOUNTS, - accounts, - ); - } - #[inline] - pub fn add_data(&mut self, data: flatbuffers::WIPOffset>) { - self.fbb_ - .push_slot_always::>(CompiledInstruction::VT_DATA, data); - } - #[inline] - pub fn new( - _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - ) -> CompiledInstructionBuilder<'a, 'b> { - let start = _fbb.start_table(); - CompiledInstructionBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) + #[inline] + pub fn add_program_id_index(&mut self, program_id_index: u8) { + self.fbb_.push_slot::(CompiledInstruction::VT_PROGRAM_ID_INDEX, program_id_index, 0); + } + #[inline] + pub fn add_accounts(&mut self, accounts: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(CompiledInstruction::VT_ACCOUNTS, accounts); + } + #[inline] + pub fn add_data(&mut self, data: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(CompiledInstruction::VT_DATA, data); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> CompiledInstructionBuilder<'a, 'b> { + let start = _fbb.start_table(); + CompiledInstructionBuilder { + fbb_: _fbb, + start_: start, } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } } impl core::fmt::Debug for CompiledInstruction<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("CompiledInstruction"); - ds.field("program_id_index", &self.program_id_index()); - ds.field("accounts", &self.accounts()); - ds.field("data", &self.data()); - ds.finish() + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("CompiledInstruction"); + ds.field("program_id_index", &self.program_id_index()); + ds.field("accounts", &self.accounts()); + ds.field("data", &self.data()); + ds.finish() + } +} +pub enum CompiledInnerInstructionOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct CompiledInnerInstruction<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for CompiledInnerInstruction<'a> { + type Inner = CompiledInnerInstruction<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> CompiledInnerInstruction<'a> { + pub const VT_COMPILED_INSTRUCTION: flatbuffers::VOffsetT = 4; + pub const VT_STACK_HEIGHT: flatbuffers::VOffsetT = 6; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + CompiledInnerInstruction { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args CompiledInnerInstructionArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = CompiledInnerInstructionBuilder::new(_fbb); + if let Some(x) = args.compiled_instruction { builder.add_compiled_instruction(x); } + builder.add_stack_height(args.stack_height); + builder.finish() + } + + + #[inline] + pub fn compiled_instruction(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(CompiledInnerInstruction::VT_COMPILED_INSTRUCTION, None)} + } + #[inline] + pub fn stack_height(&self) -> u8 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(CompiledInnerInstruction::VT_STACK_HEIGHT, Some(0)).unwrap()} + } +} + +impl flatbuffers::Verifiable for CompiledInnerInstruction<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>("compiled_instruction", Self::VT_COMPILED_INSTRUCTION, false)? + .visit_field::("stack_height", Self::VT_STACK_HEIGHT, false)? + .finish(); + Ok(()) + } +} +pub struct CompiledInnerInstructionArgs<'a> { + pub compiled_instruction: Option>>, + pub stack_height: u8, +} +impl<'a> Default for CompiledInnerInstructionArgs<'a> { + #[inline] + fn default() -> Self { + CompiledInnerInstructionArgs { + compiled_instruction: None, + stack_height: 0, + } + } +} + +pub struct CompiledInnerInstructionBuilder<'a: 'b, 'b> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b> CompiledInnerInstructionBuilder<'a, 'b> { + #[inline] + pub fn add_compiled_instruction(&mut self, compiled_instruction: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(CompiledInnerInstruction::VT_COMPILED_INSTRUCTION, compiled_instruction); + } + #[inline] + pub fn add_stack_height(&mut self, stack_height: u8) { + self.fbb_.push_slot::(CompiledInnerInstruction::VT_STACK_HEIGHT, stack_height, 0); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> CompiledInnerInstructionBuilder<'a, 'b> { + let start = _fbb.start_table(); + CompiledInnerInstructionBuilder { + fbb_: _fbb, + start_: start, } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for CompiledInnerInstruction<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("CompiledInnerInstruction"); + ds.field("compiled_instruction", &self.compiled_instruction()); + ds.field("stack_height", &self.stack_height()); + ds.finish() + } } #[inline] /// Verifies that a buffer of bytes contains a `CompiledInstruction` @@ -187,10 +262,8 @@ impl core::fmt::Debug for CompiledInstruction<'_> { /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_compiled_instruction_unchecked`. -pub fn root_as_compiled_instruction( - buf: &[u8], -) -> Result { - flatbuffers::root::(buf) +pub fn root_as_compiled_instruction(buf: &[u8]) -> Result { + flatbuffers::root::(buf) } #[inline] /// Verifies that a buffer of bytes contains a size prefixed @@ -199,10 +272,8 @@ pub fn root_as_compiled_instruction( /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `size_prefixed_root_as_compiled_instruction_unchecked`. -pub fn size_prefixed_root_as_compiled_instruction( - buf: &[u8], -) -> Result { - flatbuffers::size_prefixed_root::(buf) +pub fn size_prefixed_root_as_compiled_instruction(buf: &[u8]) -> Result { + flatbuffers::size_prefixed_root::(buf) } #[inline] /// Verifies, with the given options, that a buffer of bytes @@ -212,10 +283,10 @@ pub fn size_prefixed_root_as_compiled_instruction( /// previous, unchecked, behavior use /// `root_as_compiled_instruction_unchecked`. pub fn root_as_compiled_instruction_with_opts<'b, 'o>( - opts: &'o flatbuffers::VerifierOptions, - buf: &'b [u8], + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], ) -> Result, flatbuffers::InvalidFlatbuffer> { - flatbuffers::root_with_opts::>(opts, buf) + flatbuffers::root_with_opts::>(opts, buf) } #[inline] /// Verifies, with the given verifier options, that a buffer of @@ -225,39 +296,33 @@ pub fn root_as_compiled_instruction_with_opts<'b, 'o>( /// previous, unchecked, behavior use /// `root_as_compiled_instruction_unchecked`. pub fn size_prefixed_root_as_compiled_instruction_with_opts<'b, 'o>( - opts: &'o flatbuffers::VerifierOptions, - buf: &'b [u8], + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], ) -> Result, flatbuffers::InvalidFlatbuffer> { - flatbuffers::size_prefixed_root_with_opts::>(opts, buf) + flatbuffers::size_prefixed_root_with_opts::>(opts, buf) } #[inline] /// Assumes, without verification, that a buffer of bytes contains a CompiledInstruction and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid `CompiledInstruction`. pub unsafe fn root_as_compiled_instruction_unchecked(buf: &[u8]) -> CompiledInstruction { - flatbuffers::root_unchecked::(buf) + flatbuffers::root_unchecked::(buf) } #[inline] /// Assumes, without verification, that a buffer of bytes contains a size prefixed CompiledInstruction and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid size prefixed `CompiledInstruction`. -pub unsafe fn size_prefixed_root_as_compiled_instruction_unchecked( - buf: &[u8], -) -> CompiledInstruction { - flatbuffers::size_prefixed_root_unchecked::(buf) +pub unsafe fn size_prefixed_root_as_compiled_instruction_unchecked(buf: &[u8]) -> CompiledInstruction { + flatbuffers::size_prefixed_root_unchecked::(buf) } #[inline] pub fn finish_compiled_instruction_buffer<'a, 'b>( fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - root: flatbuffers::WIPOffset>, -) { - fbb.finish(root, None); + root: flatbuffers::WIPOffset>) { + fbb.finish(root, None); } #[inline] -pub fn finish_size_prefixed_compiled_instruction_buffer<'a, 'b>( - fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - root: flatbuffers::WIPOffset>, -) { - fbb.finish_size_prefixed(root, None); +pub fn finish_size_prefixed_compiled_instruction_buffer<'a, 'b>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, root: flatbuffers::WIPOffset>) { + fbb.finish_size_prefixed(root, None); } diff --git a/plerkle_serialization/src/lib.rs b/plerkle_serialization/src/lib.rs index e2a6d553..b5ecb4b3 100644 --- a/plerkle_serialization/src/lib.rs +++ b/plerkle_serialization/src/lib.rs @@ -12,6 +12,7 @@ mod slot_status_info_generated; mod transaction_info_generated; pub mod serializer; +pub mod error; pub use account_info_generated::*; pub use block_info_generated::*; pub use common_generated::*; diff --git a/plerkle_serialization/src/serializer/mod.rs b/plerkle_serialization/src/serializer/mod.rs index d8feb865..86ce6efb 100644 --- a/plerkle_serialization/src/serializer/mod.rs +++ b/plerkle_serialization/src/serializer/mod.rs @@ -1,3 +1,3 @@ mod serializer_common; mod serializer_stable; -pub use serializer_stable::*; +pub use serializer_stable::*; \ No newline at end of file diff --git a/plerkle_serialization/src/serializer/serializer_stable.rs b/plerkle_serialization/src/serializer/serializer_stable.rs index dd5d6fa6..38fd325f 100644 --- a/plerkle_serialization/src/serializer/serializer_stable.rs +++ b/plerkle_serialization/src/serializer/serializer_stable.rs @@ -1,14 +1,23 @@ +use crate::error::PlerkleSerializationError; use crate::solana_geyser_plugin_interface_shims::{ ReplicaAccountInfoV2, ReplicaBlockInfoV2, ReplicaTransactionInfoV2, SlotStatus, }; use crate::{ - AccountInfo, AccountInfoArgs, BlockInfo, BlockInfoArgs, CompiledInstruction, - CompiledInstructionArgs, InnerInstructions, InnerInstructionsArgs, Pubkey as FBPubkey, Pubkey, - SlotStatusInfo, SlotStatusInfoArgs, Status as FBSlotStatus, TransactionInfo, - TransactionInfoArgs, + AccountInfo, AccountInfoArgs, BlockInfo, BlockInfoArgs, CompiledInnerInstruction, + CompiledInnerInstructionArgs, CompiledInnerInstructions, CompiledInnerInstructionsArgs, + CompiledInstruction, CompiledInstructionArgs, InnerInstructions, InnerInstructionsArgs, + Pubkey as FBPubkey, Pubkey, SlotStatusInfo, SlotStatusInfoArgs, Status as FBSlotStatus, + TransactionInfo, TransactionInfoArgs, TransactionVersion, }; use chrono::Utc; -use flatbuffers::FlatBufferBuilder; +use flatbuffers::{FlatBufferBuilder, WIPOffset}; +use solana_sdk::message::{SanitizedMessage, VersionedMessage}; +use solana_sdk::transaction::VersionedTransaction; +use solana_transaction_status::option_serializer::OptionSerializer; +use solana_transaction_status::{ + EncodedConfirmedTransactionWithStatusMeta, UiInstruction, UiTransactionStatusMeta, +}; + pub fn serialize_account<'a>( mut builder: FlatBufferBuilder<'a>, account: &ReplicaAccountInfoV2, @@ -80,17 +89,29 @@ pub fn serialize_transaction<'a>( ) -> FlatBufferBuilder<'a> { // Flatten and serialize account keys. let account_keys = transaction_info.transaction.message().account_keys(); - let account_keys_len = account_keys.len(); + let atl_keys = &transaction_info.transaction_status_meta.loaded_addresses; - let account_keys = if account_keys_len > 0 { - let mut account_keys_fb_vec = Vec::with_capacity(account_keys_len); + let account_keys = { + let mut account_keys_fb_vec = vec![]; for key in account_keys.iter() { - let pubkey = FBPubkey::new(&key.to_bytes()); + account_keys_fb_vec.push(FBPubkey(key.to_bytes())); + } + + for i in &atl_keys.writable { + let pubkey = FBPubkey(i.to_bytes()); account_keys_fb_vec.push(pubkey); } - Some(builder.create_vector(&account_keys_fb_vec)) - } else { - None + + for i in &atl_keys.readonly { + let pubkey = FBPubkey(i.to_bytes()); + account_keys_fb_vec.push(pubkey); + } + + if account_keys_fb_vec.len() > 0 { + Some(builder.create_vector(&account_keys_fb_vec)) + } else { + None + } }; // Serialize log messages. @@ -119,20 +140,27 @@ pub fn serialize_transaction<'a>( let program_id_index = compiled_instruction.program_id_index; let accounts = Some(builder.create_vector(&compiled_instruction.accounts)); let data = Some(builder.create_vector(&compiled_instruction.data)); - instructions_fb_vec.push(CompiledInstruction::create( + let compiled = CompiledInstruction::create( &mut builder, &CompiledInstructionArgs { program_id_index, accounts, data, }, + ); + instructions_fb_vec.push(CompiledInnerInstruction::create( + &mut builder, + &CompiledInnerInstructionArgs { + compiled_instruction: Some(compiled), + stack_height: 0, // Desperatley need this when it comes in 1.15 + }, )); } let instructions = Some(builder.create_vector(&instructions_fb_vec)); - overall_fb_vec.push(InnerInstructions::create( + overall_fb_vec.push(CompiledInnerInstructions::create( &mut builder, - &InnerInstructionsArgs { + &CompiledInnerInstructionsArgs { index, instructions, }, @@ -143,9 +171,14 @@ pub fn serialize_transaction<'a>( } else { None }; - + let message = transaction_info.transaction.message(); + let version = match message { + SanitizedMessage::Legacy(_) => TransactionVersion::Legacy, + SanitizedMessage::V0(_) => TransactionVersion::V0, + }; + // Serialize outer instructions. - let outer_instructions = transaction_info.transaction.message().instructions(); + let outer_instructions = message.instructions(); let outer_instructions = if !outer_instructions.is_empty() { let mut instructions_fb_vec = Vec::with_capacity(outer_instructions.len()); for compiled_instruction in outer_instructions.iter() { @@ -177,12 +210,14 @@ pub fn serialize_transaction<'a>( is_vote: transaction_info.is_vote, account_keys, log_messages, - inner_instructions, + inner_instructions: None, outer_instructions, slot, slot_index: Some(slot_index_offset), seen_at: seen_at.timestamp_millis(), signature: Some(signature_offset), + compiled_inner_instructions: inner_instructions, + version }, ); @@ -219,3 +254,171 @@ pub fn serialize_block<'a>( builder.finish(block_info, None); builder } + +/// Serialize a `EncodedConfirmedTransactionWithStatusMeta` from RPC into a FlatBuffer. +/// The Transaction must be base54 encoded. +pub fn seralize_encoded_transaction_with_status<'a>( + mut builder: FlatBufferBuilder<'a>, + tx: EncodedConfirmedTransactionWithStatusMeta, +) -> Result, PlerkleSerializationError> { + let meta: UiTransactionStatusMeta = tx.transaction.meta.ok_or( + PlerkleSerializationError::SerializationError("Missing meta data for transaction".to_string()), + )?; + // Get `UiTransaction` out of `EncodedTransactionWithStatusMeta`. + let ui_transaction: VersionedTransaction = tx.transaction.transaction.decode().ok_or( + PlerkleSerializationError::SerializationError("Transaction cannot be decoded".to_string()), + )?; + let msg = ui_transaction.message; + let atl_keys = msg.address_table_lookups(); + let account_keys = msg.static_account_keys(); + let sig = ui_transaction.signatures[0].to_string(); + let account_keys = { + let mut account_keys_fb_vec = vec![]; + for key in account_keys.iter() { + account_keys_fb_vec.push(FBPubkey(key.to_bytes())); + } + if atl_keys.is_some() { + if let OptionSerializer::Some(ad) = meta.loaded_addresses { + for i in ad.writable { + let mut output: [u8; 32] = [0; 32]; + bs58::decode(i).into(&mut output).map_err(|e| { + PlerkleSerializationError::SerializationError(e.to_string()) + })?; + let pubkey = FBPubkey(output); + account_keys_fb_vec.push(pubkey); + } + + for i in ad.readonly { + let mut output: [u8; 32] = [0; 32]; + bs58::decode(i).into(&mut output).map_err(|e| { + PlerkleSerializationError::SerializationError(e.to_string()) + })?; + let pubkey = FBPubkey(output); + account_keys_fb_vec.push(pubkey); + } + } + } + if account_keys_fb_vec.len() > 0 { + Some(builder.create_vector(&account_keys_fb_vec)) + } else { + None + } + }; + + // Serialize log messages. + let log_messages = + if let OptionSerializer::Some(log_messages) = &meta.log_messages { + let mut log_messages_fb_vec = Vec::with_capacity(log_messages.len()); + for message in log_messages { + log_messages_fb_vec.push(builder.create_string(message)); + } + Some(builder.create_vector(&log_messages_fb_vec)) + } else { + None + }; + + // Serialize inner instructions. + let inner_instructions = if let OptionSerializer::Some(inner_instructions_vec) = + meta.inner_instructions.as_ref() + { + let mut overall_fb_vec = Vec::with_capacity(inner_instructions_vec.len()); + for inner_instructions in inner_instructions_vec.iter() { + let index = inner_instructions.index; + let mut instructions_fb_vec = Vec::with_capacity(inner_instructions.instructions.len()); + for ui_instruction in inner_instructions.instructions.iter() { + if let UiInstruction::Compiled(ui_compiled_instruction) = ui_instruction { + let program_id_index = ui_compiled_instruction.program_id_index; + let accounts = Some(builder.create_vector(&ui_compiled_instruction.accounts)); + let data = bs58::decode(&ui_compiled_instruction.data) + .into_vec() + .map_err(|e| { + PlerkleSerializationError::SerializationError(e.to_string()) + })?; + let data = Some(builder.create_vector(&data)); + let compiled = CompiledInstruction::create( + &mut builder, + &CompiledInstructionArgs { + program_id_index, + accounts, + data, + }, + ); + instructions_fb_vec.push( + CompiledInnerInstruction::create( + &mut builder, + &CompiledInnerInstructionArgs { + compiled_instruction: Some(compiled), + stack_height: 0, // Desperatley need this when it comes in 1.15 + }, + ) + ); + } + } + + let instructions = Some(builder.create_vector(&instructions_fb_vec)); + overall_fb_vec.push(CompiledInnerInstructions::create( + &mut builder, + &CompiledInnerInstructionsArgs { + index, + instructions + }, + )); + } + + Some(builder.create_vector(&overall_fb_vec)) + } else { + let empty: Vec> = Vec::new(); + Some(builder.create_vector(empty.as_slice())) + }; + + // Serialize outer instructions. + let outer_instructions = &msg.instructions(); + let outer_instructions = if !outer_instructions.is_empty() { + let mut instructions_fb_vec = Vec::with_capacity(outer_instructions.len()); + for ui_compiled_instruction in outer_instructions.iter() { + let program_id_index = ui_compiled_instruction.program_id_index; + let accounts = Some(builder.create_vector(&ui_compiled_instruction.accounts)); + + let data = Some(builder.create_vector(&ui_compiled_instruction.data)); + instructions_fb_vec.push(CompiledInstruction::create( + &mut builder, + &CompiledInstructionArgs { + program_id_index, + accounts, + data, + }, + )); + } + Some(builder.create_vector(&instructions_fb_vec)) + } else { + None + }; + let version = match msg { + VersionedMessage::Legacy(_) => TransactionVersion::Legacy, + VersionedMessage::V0(_) => TransactionVersion::V0, + }; + + // Serialize everything into Transaction Info table. + + let sig_db = builder.create_string(&sig); + let transaction_info = TransactionInfo::create( + &mut builder, + &TransactionInfoArgs { + is_vote: false, + account_keys, + log_messages, + inner_instructions: None, + outer_instructions, + slot: tx.slot, + seen_at: 0, + slot_index: None, + signature: Some(sig_db), + compiled_inner_instructions: inner_instructions, + version + }, + ); + + // Finalize buffer and return to caller. + builder.finish(transaction_info, None); + Ok(builder) +} diff --git a/plerkle_serialization/src/slot_status_info_generated.rs b/plerkle_serialization/src/slot_status_info_generated.rs index 14444f0f..2f4d2c9f 100644 --- a/plerkle_serialization/src/slot_status_info_generated.rs +++ b/plerkle_serialization/src/slot_status_info_generated.rs @@ -1,68 +1,68 @@ // automatically generated by the FlatBuffers compiler, do not modify + // @generated -use core::cmp::Ordering; use core::mem; +use core::cmp::Ordering; extern crate flatbuffers; use self::flatbuffers::{EndianScalar, Follow}; -#[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." -)] +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_STATUS: i8 = 0; -#[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." -)] +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_STATUS: i8 = 2; -#[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." -)] +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] -pub const ENUM_VALUES_STATUS: [Status; 3] = [Status::Processed, Status::Rooted, Status::Confirmed]; +pub const ENUM_VALUES_STATUS: [Status; 3] = [ + Status::Processed, + Status::Rooted, + Status::Confirmed, +]; #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct Status(pub i8); #[allow(non_upper_case_globals)] impl Status { - pub const Processed: Self = Self(0); - pub const Rooted: Self = Self(1); - pub const Confirmed: Self = Self(2); + pub const Processed: Self = Self(0); + pub const Rooted: Self = Self(1); + pub const Confirmed: Self = Self(2); - pub const ENUM_MIN: i8 = 0; - pub const ENUM_MAX: i8 = 2; - pub const ENUM_VALUES: &'static [Self] = &[Self::Processed, Self::Rooted, Self::Confirmed]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::Processed => Some("Processed"), - Self::Rooted => Some("Rooted"), - Self::Confirmed => Some("Confirmed"), - _ => None, - } + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 2; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::Processed, + Self::Rooted, + Self::Confirmed, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::Processed => Some("Processed"), + Self::Rooted => Some("Rooted"), + Self::Confirmed => Some("Confirmed"), + _ => None, } + } } impl core::fmt::Debug for Status { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) - } + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) } + } } impl<'a> flatbuffers::Follow<'a> for Status { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = flatbuffers::read_scalar_at::(buf, loc); - Self(b) - } + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } } impl flatbuffers::Push for Status { @@ -74,130 +74,113 @@ impl flatbuffers::Push for Status { } impl flatbuffers::EndianScalar for Status { - type Scalar = i8; - #[inline] - fn to_little_endian(self) -> i8 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: i8) -> Self { - let b = i8::from_le(v); - Self(b) - } + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } } impl<'a> flatbuffers::Verifiable for Status { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - i8::run_verifier(v, pos) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } } impl flatbuffers::SimpleToVerifyInSlice for Status {} pub enum SlotStatusInfoOffset {} -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq)] pub struct SlotStatusInfo<'a> { - pub _tab: flatbuffers::Table<'a>, + pub _tab: flatbuffers::Table<'a>, } impl<'a> flatbuffers::Follow<'a> for SlotStatusInfo<'a> { - type Inner = SlotStatusInfo<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { - _tab: flatbuffers::Table::new(buf, loc), - } - } + type Inner = SlotStatusInfo<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } } impl<'a> SlotStatusInfo<'a> { - pub const VT_SLOT: flatbuffers::VOffsetT = 4; - pub const VT_PARENT: flatbuffers::VOffsetT = 6; - pub const VT_STATUS: flatbuffers::VOffsetT = 8; - pub const VT_SEEN_AT: flatbuffers::VOffsetT = 10; + pub const VT_SLOT: flatbuffers::VOffsetT = 4; + pub const VT_PARENT: flatbuffers::VOffsetT = 6; + pub const VT_STATUS: flatbuffers::VOffsetT = 8; + pub const VT_SEEN_AT: flatbuffers::VOffsetT = 10; - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - SlotStatusInfo { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, - args: &'args SlotStatusInfoArgs, - ) -> flatbuffers::WIPOffset> { - let mut builder = SlotStatusInfoBuilder::new(_fbb); - builder.add_seen_at(args.seen_at); - if let Some(x) = args.parent { - builder.add_parent(x); - } - builder.add_slot(args.slot); - builder.add_status(args.status); - builder.finish() - } + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + SlotStatusInfo { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args SlotStatusInfoArgs + ) -> flatbuffers::WIPOffset> { + let mut builder = SlotStatusInfoBuilder::new(_fbb); + builder.add_seen_at(args.seen_at); + if let Some(x) = args.parent { builder.add_parent(x); } + builder.add_slot(args.slot); + builder.add_status(args.status); + builder.finish() + } - #[inline] - pub fn slot(&self) -> u64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::(SlotStatusInfo::VT_SLOT, Some(0)) - .unwrap() - } - } - #[inline] - pub fn parent(&self) -> Option { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(SlotStatusInfo::VT_PARENT, None) } - } - #[inline] - pub fn status(&self) -> Status { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::(SlotStatusInfo::VT_STATUS, Some(Status::Processed)) - .unwrap() - } - } - #[inline] - pub fn seen_at(&self) -> i64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::(SlotStatusInfo::VT_SEEN_AT, Some(0)) - .unwrap() - } - } + + #[inline] + pub fn slot(&self) -> u64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(SlotStatusInfo::VT_SLOT, Some(0)).unwrap()} + } + #[inline] + pub fn parent(&self) -> Option { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(SlotStatusInfo::VT_PARENT, None)} + } + #[inline] + pub fn status(&self) -> Status { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(SlotStatusInfo::VT_STATUS, Some(Status::Processed)).unwrap()} + } + #[inline] + pub fn seen_at(&self) -> i64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(SlotStatusInfo::VT_SEEN_AT, Some(0)).unwrap()} + } } impl flatbuffers::Verifiable for SlotStatusInfo<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::("slot", Self::VT_SLOT, false)? - .visit_field::("parent", Self::VT_PARENT, false)? - .visit_field::("status", Self::VT_STATUS, false)? - .visit_field::("seen_at", Self::VT_SEEN_AT, false)? - .finish(); - Ok(()) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("slot", Self::VT_SLOT, false)? + .visit_field::("parent", Self::VT_PARENT, false)? + .visit_field::("status", Self::VT_STATUS, false)? + .visit_field::("seen_at", Self::VT_SEEN_AT, false)? + .finish(); + Ok(()) + } } pub struct SlotStatusInfoArgs { pub slot: u64, @@ -206,65 +189,62 @@ pub struct SlotStatusInfoArgs { pub seen_at: i64, } impl<'a> Default for SlotStatusInfoArgs { - #[inline] - fn default() -> Self { - SlotStatusInfoArgs { - slot: 0, - parent: None, - status: Status::Processed, - seen_at: 0, - } + #[inline] + fn default() -> Self { + SlotStatusInfoArgs { + slot: 0, + parent: None, + status: Status::Processed, + seen_at: 0, } + } } pub struct SlotStatusInfoBuilder<'a: 'b, 'b> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, - start_: flatbuffers::WIPOffset, + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, } impl<'a: 'b, 'b> SlotStatusInfoBuilder<'a, 'b> { - #[inline] - pub fn add_slot(&mut self, slot: u64) { - self.fbb_.push_slot::(SlotStatusInfo::VT_SLOT, slot, 0); - } - #[inline] - pub fn add_parent(&mut self, parent: u64) { - self.fbb_ - .push_slot_always::(SlotStatusInfo::VT_PARENT, parent); - } - #[inline] - pub fn add_status(&mut self, status: Status) { - self.fbb_ - .push_slot::(SlotStatusInfo::VT_STATUS, status, Status::Processed); - } - #[inline] - pub fn add_seen_at(&mut self, seen_at: i64) { - self.fbb_ - .push_slot::(SlotStatusInfo::VT_SEEN_AT, seen_at, 0); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> SlotStatusInfoBuilder<'a, 'b> { - let start = _fbb.start_table(); - SlotStatusInfoBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) + #[inline] + pub fn add_slot(&mut self, slot: u64) { + self.fbb_.push_slot::(SlotStatusInfo::VT_SLOT, slot, 0); + } + #[inline] + pub fn add_parent(&mut self, parent: u64) { + self.fbb_.push_slot_always::(SlotStatusInfo::VT_PARENT, parent); + } + #[inline] + pub fn add_status(&mut self, status: Status) { + self.fbb_.push_slot::(SlotStatusInfo::VT_STATUS, status, Status::Processed); + } + #[inline] + pub fn add_seen_at(&mut self, seen_at: i64) { + self.fbb_.push_slot::(SlotStatusInfo::VT_SEEN_AT, seen_at, 0); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> SlotStatusInfoBuilder<'a, 'b> { + let start = _fbb.start_table(); + SlotStatusInfoBuilder { + fbb_: _fbb, + start_: start, } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } } impl core::fmt::Debug for SlotStatusInfo<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("SlotStatusInfo"); - ds.field("slot", &self.slot()); - ds.field("parent", &self.parent()); - ds.field("status", &self.status()); - ds.field("seen_at", &self.seen_at()); - ds.finish() - } + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("SlotStatusInfo"); + ds.field("slot", &self.slot()); + ds.field("parent", &self.parent()); + ds.field("status", &self.status()); + ds.field("seen_at", &self.seen_at()); + ds.finish() + } } #[inline] /// Verifies that a buffer of bytes contains a `SlotStatusInfo` @@ -273,10 +253,8 @@ impl core::fmt::Debug for SlotStatusInfo<'_> { /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_slot_status_info_unchecked`. -pub fn root_as_slot_status_info( - buf: &[u8], -) -> Result { - flatbuffers::root::(buf) +pub fn root_as_slot_status_info(buf: &[u8]) -> Result { + flatbuffers::root::(buf) } #[inline] /// Verifies that a buffer of bytes contains a size prefixed @@ -285,10 +263,8 @@ pub fn root_as_slot_status_info( /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `size_prefixed_root_as_slot_status_info_unchecked`. -pub fn size_prefixed_root_as_slot_status_info( - buf: &[u8], -) -> Result { - flatbuffers::size_prefixed_root::(buf) +pub fn size_prefixed_root_as_slot_status_info(buf: &[u8]) -> Result { + flatbuffers::size_prefixed_root::(buf) } #[inline] /// Verifies, with the given options, that a buffer of bytes @@ -298,10 +274,10 @@ pub fn size_prefixed_root_as_slot_status_info( /// previous, unchecked, behavior use /// `root_as_slot_status_info_unchecked`. pub fn root_as_slot_status_info_with_opts<'b, 'o>( - opts: &'o flatbuffers::VerifierOptions, - buf: &'b [u8], + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], ) -> Result, flatbuffers::InvalidFlatbuffer> { - flatbuffers::root_with_opts::>(opts, buf) + flatbuffers::root_with_opts::>(opts, buf) } #[inline] /// Verifies, with the given verifier options, that a buffer of @@ -311,37 +287,33 @@ pub fn root_as_slot_status_info_with_opts<'b, 'o>( /// previous, unchecked, behavior use /// `root_as_slot_status_info_unchecked`. pub fn size_prefixed_root_as_slot_status_info_with_opts<'b, 'o>( - opts: &'o flatbuffers::VerifierOptions, - buf: &'b [u8], + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], ) -> Result, flatbuffers::InvalidFlatbuffer> { - flatbuffers::size_prefixed_root_with_opts::>(opts, buf) + flatbuffers::size_prefixed_root_with_opts::>(opts, buf) } #[inline] /// Assumes, without verification, that a buffer of bytes contains a SlotStatusInfo and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid `SlotStatusInfo`. pub unsafe fn root_as_slot_status_info_unchecked(buf: &[u8]) -> SlotStatusInfo { - flatbuffers::root_unchecked::(buf) + flatbuffers::root_unchecked::(buf) } #[inline] /// Assumes, without verification, that a buffer of bytes contains a size prefixed SlotStatusInfo and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid size prefixed `SlotStatusInfo`. pub unsafe fn size_prefixed_root_as_slot_status_info_unchecked(buf: &[u8]) -> SlotStatusInfo { - flatbuffers::size_prefixed_root_unchecked::(buf) + flatbuffers::size_prefixed_root_unchecked::(buf) } #[inline] pub fn finish_slot_status_info_buffer<'a, 'b>( fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - root: flatbuffers::WIPOffset>, -) { - fbb.finish(root, None); + root: flatbuffers::WIPOffset>) { + fbb.finish(root, None); } #[inline] -pub fn finish_size_prefixed_slot_status_info_buffer<'a, 'b>( - fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - root: flatbuffers::WIPOffset>, -) { - fbb.finish_size_prefixed(root, None); +pub fn finish_size_prefixed_slot_status_info_buffer<'a, 'b>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, root: flatbuffers::WIPOffset>) { + fbb.finish_size_prefixed(root, None); } diff --git a/plerkle_serialization/src/transaction_info_generated.rs b/plerkle_serialization/src/transaction_info_generated.rs index 161aa4bb..9e1f2756 100644 --- a/plerkle_serialization/src/transaction_info_generated.rs +++ b/plerkle_serialization/src/transaction_info_generated.rs @@ -1,517 +1,595 @@ // automatically generated by the FlatBuffers compiler, do not modify + // @generated -use crate::common_generated::*; use crate::compiled_instruction_generated::*; -use core::cmp::Ordering; +use crate::common_generated::*; use core::mem; +use core::cmp::Ordering; extern crate flatbuffers; use self::flatbuffers::{EndianScalar, Follow}; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MIN_TRANSACTION_VERSION: i8 = 0; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MAX_TRANSACTION_VERSION: i8 = 1; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[allow(non_camel_case_types)] +pub const ENUM_VALUES_TRANSACTION_VERSION: [TransactionVersion; 2] = [ + TransactionVersion::Legacy, + TransactionVersion::V0, +]; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[repr(transparent)] +pub struct TransactionVersion(pub i8); +#[allow(non_upper_case_globals)] +impl TransactionVersion { + pub const Legacy: Self = Self(0); + pub const V0: Self = Self(1); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 1; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::Legacy, + Self::V0, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::Legacy => Some("Legacy"), + Self::V0 => Some("V0"), + _ => None, + } + } +} +impl core::fmt::Debug for TransactionVersion { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } +} +impl<'a> flatbuffers::Follow<'a> for TransactionVersion { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } +} + +impl flatbuffers::Push for TransactionVersion { + type Output = TransactionVersion; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } +} + +impl flatbuffers::EndianScalar for TransactionVersion { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } +} + +impl<'a> flatbuffers::Verifiable for TransactionVersion { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } +} + +impl flatbuffers::SimpleToVerifyInSlice for TransactionVersion {} pub enum TransactionInfoOffset {} -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq)] pub struct TransactionInfo<'a> { - pub _tab: flatbuffers::Table<'a>, + pub _tab: flatbuffers::Table<'a>, } impl<'a> flatbuffers::Follow<'a> for TransactionInfo<'a> { - type Inner = TransactionInfo<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { - _tab: flatbuffers::Table::new(buf, loc), - } - } + type Inner = TransactionInfo<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } } impl<'a> TransactionInfo<'a> { - pub const VT_IS_VOTE: flatbuffers::VOffsetT = 4; - pub const VT_ACCOUNT_KEYS: flatbuffers::VOffsetT = 6; - pub const VT_LOG_MESSAGES: flatbuffers::VOffsetT = 8; - pub const VT_INNER_INSTRUCTIONS: flatbuffers::VOffsetT = 10; - pub const VT_OUTER_INSTRUCTIONS: flatbuffers::VOffsetT = 12; - pub const VT_SLOT: flatbuffers::VOffsetT = 14; - pub const VT_SLOT_INDEX: flatbuffers::VOffsetT = 16; - pub const VT_SEEN_AT: flatbuffers::VOffsetT = 18; - pub const VT_SIGNATURE: flatbuffers::VOffsetT = 20; + pub const VT_IS_VOTE: flatbuffers::VOffsetT = 4; + pub const VT_ACCOUNT_KEYS: flatbuffers::VOffsetT = 6; + pub const VT_LOG_MESSAGES: flatbuffers::VOffsetT = 8; + pub const VT_INNER_INSTRUCTIONS: flatbuffers::VOffsetT = 10; + pub const VT_OUTER_INSTRUCTIONS: flatbuffers::VOffsetT = 12; + pub const VT_SLOT: flatbuffers::VOffsetT = 14; + pub const VT_SLOT_INDEX: flatbuffers::VOffsetT = 16; + pub const VT_SEEN_AT: flatbuffers::VOffsetT = 18; + pub const VT_SIGNATURE: flatbuffers::VOffsetT = 20; + pub const VT_COMPILED_INNER_INSTRUCTIONS: flatbuffers::VOffsetT = 22; + pub const VT_VERSION: flatbuffers::VOffsetT = 24; - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - TransactionInfo { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, - args: &'args TransactionInfoArgs<'args>, - ) -> flatbuffers::WIPOffset> { - let mut builder = TransactionInfoBuilder::new(_fbb); - builder.add_seen_at(args.seen_at); - builder.add_slot(args.slot); - if let Some(x) = args.signature { - builder.add_signature(x); - } - if let Some(x) = args.slot_index { - builder.add_slot_index(x); - } - if let Some(x) = args.outer_instructions { - builder.add_outer_instructions(x); - } - if let Some(x) = args.inner_instructions { - builder.add_inner_instructions(x); - } - if let Some(x) = args.log_messages { - builder.add_log_messages(x); - } - if let Some(x) = args.account_keys { - builder.add_account_keys(x); - } - builder.add_is_vote(args.is_vote); - builder.finish() - } + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + TransactionInfo { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args TransactionInfoArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = TransactionInfoBuilder::new(_fbb); + builder.add_seen_at(args.seen_at); + builder.add_slot(args.slot); + if let Some(x) = args.compiled_inner_instructions { builder.add_compiled_inner_instructions(x); } + if let Some(x) = args.signature { builder.add_signature(x); } + if let Some(x) = args.slot_index { builder.add_slot_index(x); } + if let Some(x) = args.outer_instructions { builder.add_outer_instructions(x); } + if let Some(x) = args.inner_instructions { builder.add_inner_instructions(x); } + if let Some(x) = args.log_messages { builder.add_log_messages(x); } + if let Some(x) = args.account_keys { builder.add_account_keys(x); } + builder.add_version(args.version); + builder.add_is_vote(args.is_vote); + builder.finish() + } - #[inline] - pub fn is_vote(&self) -> bool { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::(TransactionInfo::VT_IS_VOTE, Some(false)) - .unwrap() - } - } - #[inline] - pub fn account_keys(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::>>( - TransactionInfo::VT_ACCOUNT_KEYS, - None, - ) - } - } - #[inline] - pub fn log_messages( - &self, - ) -> Option>> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab.get::>, - >>(TransactionInfo::VT_LOG_MESSAGES, None) - } - } - #[inline] - pub fn inner_instructions( - &self, - ) -> Option>>> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab.get::>, - >>(TransactionInfo::VT_INNER_INSTRUCTIONS, None) - } - } - #[inline] - pub fn outer_instructions( - &self, - ) -> Option>>> - { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab.get::>, - >>(TransactionInfo::VT_OUTER_INSTRUCTIONS, None) - } - } - #[inline] - pub fn slot(&self) -> u64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::(TransactionInfo::VT_SLOT, Some(0)) - .unwrap() - } - } - #[inline] - pub fn slot_index(&self) -> Option<&'a str> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::>(TransactionInfo::VT_SLOT_INDEX, None) - } - } - #[inline] - pub fn seen_at(&self) -> i64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::(TransactionInfo::VT_SEEN_AT, Some(0)) - .unwrap() - } - } - #[inline] - pub fn signature(&self) -> Option<&'a str> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::>(TransactionInfo::VT_SIGNATURE, None) - } - } + + #[inline] + pub fn is_vote(&self) -> bool { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(TransactionInfo::VT_IS_VOTE, Some(false)).unwrap()} + } + #[inline] + pub fn account_keys(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(TransactionInfo::VT_ACCOUNT_KEYS, None)} + } + #[inline] + pub fn log_messages(&self) -> Option>> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>>(TransactionInfo::VT_LOG_MESSAGES, None)} + } + #[inline] + pub fn inner_instructions(&self) -> Option>>> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>>(TransactionInfo::VT_INNER_INSTRUCTIONS, None)} + } + #[inline] + pub fn outer_instructions(&self) -> Option>>> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>>(TransactionInfo::VT_OUTER_INSTRUCTIONS, None)} + } + #[inline] + pub fn slot(&self) -> u64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(TransactionInfo::VT_SLOT, Some(0)).unwrap()} + } + #[inline] + pub fn slot_index(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(TransactionInfo::VT_SLOT_INDEX, None)} + } + #[inline] + pub fn seen_at(&self) -> i64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(TransactionInfo::VT_SEEN_AT, Some(0)).unwrap()} + } + #[inline] + pub fn signature(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(TransactionInfo::VT_SIGNATURE, None)} + } + #[inline] + pub fn compiled_inner_instructions(&self) -> Option>>> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>>(TransactionInfo::VT_COMPILED_INNER_INSTRUCTIONS, None)} + } + #[inline] + pub fn version(&self) -> TransactionVersion { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(TransactionInfo::VT_VERSION, Some(TransactionVersion::Legacy)).unwrap()} + } } impl flatbuffers::Verifiable for TransactionInfo<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::("is_vote", Self::VT_IS_VOTE, false)? - .visit_field::>>( - "account_keys", - Self::VT_ACCOUNT_KEYS, - false, - )? - .visit_field::>, - >>("log_messages", Self::VT_LOG_MESSAGES, false)? - .visit_field::>, - >>("inner_instructions", Self::VT_INNER_INSTRUCTIONS, false)? - .visit_field::>, - >>("outer_instructions", Self::VT_OUTER_INSTRUCTIONS, false)? - .visit_field::("slot", Self::VT_SLOT, false)? - .visit_field::>( - "slot_index", - Self::VT_SLOT_INDEX, - false, - )? - .visit_field::("seen_at", Self::VT_SEEN_AT, false)? - .visit_field::>( - "signature", - Self::VT_SIGNATURE, - false, - )? - .finish(); - Ok(()) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("is_vote", Self::VT_IS_VOTE, false)? + .visit_field::>>("account_keys", Self::VT_ACCOUNT_KEYS, false)? + .visit_field::>>>("log_messages", Self::VT_LOG_MESSAGES, false)? + .visit_field::>>>("inner_instructions", Self::VT_INNER_INSTRUCTIONS, false)? + .visit_field::>>>("outer_instructions", Self::VT_OUTER_INSTRUCTIONS, false)? + .visit_field::("slot", Self::VT_SLOT, false)? + .visit_field::>("slot_index", Self::VT_SLOT_INDEX, false)? + .visit_field::("seen_at", Self::VT_SEEN_AT, false)? + .visit_field::>("signature", Self::VT_SIGNATURE, false)? + .visit_field::>>>("compiled_inner_instructions", Self::VT_COMPILED_INNER_INSTRUCTIONS, false)? + .visit_field::("version", Self::VT_VERSION, false)? + .finish(); + Ok(()) + } } pub struct TransactionInfoArgs<'a> { pub is_vote: bool, pub account_keys: Option>>, - pub log_messages: Option< - flatbuffers::WIPOffset>>, - >, - pub inner_instructions: Option< - flatbuffers::WIPOffset< - flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset>>, - >, - >, - pub outer_instructions: Option< - flatbuffers::WIPOffset< - flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset>>, - >, - >, + pub log_messages: Option>>>, + pub inner_instructions: Option>>>>, + pub outer_instructions: Option>>>>, pub slot: u64, pub slot_index: Option>, pub seen_at: i64, pub signature: Option>, + pub compiled_inner_instructions: Option>>>>, + pub version: TransactionVersion, } impl<'a> Default for TransactionInfoArgs<'a> { - #[inline] - fn default() -> Self { - TransactionInfoArgs { - is_vote: false, - account_keys: None, - log_messages: None, - inner_instructions: None, - outer_instructions: None, - slot: 0, - slot_index: None, - seen_at: 0, - signature: None, - } - } + #[inline] + fn default() -> Self { + TransactionInfoArgs { + is_vote: false, + account_keys: None, + log_messages: None, + inner_instructions: None, + outer_instructions: None, + slot: 0, + slot_index: None, + seen_at: 0, + signature: None, + compiled_inner_instructions: None, + version: TransactionVersion::Legacy, + } + } } pub struct TransactionInfoBuilder<'a: 'b, 'b> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, - start_: flatbuffers::WIPOffset, + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, } impl<'a: 'b, 'b> TransactionInfoBuilder<'a, 'b> { - #[inline] - pub fn add_is_vote(&mut self, is_vote: bool) { - self.fbb_ - .push_slot::(TransactionInfo::VT_IS_VOTE, is_vote, false); - } - #[inline] - pub fn add_account_keys( - &mut self, - account_keys: flatbuffers::WIPOffset>, - ) { - self.fbb_.push_slot_always::>( - TransactionInfo::VT_ACCOUNT_KEYS, - account_keys, - ); - } - #[inline] - pub fn add_log_messages( - &mut self, - log_messages: flatbuffers::WIPOffset< - flatbuffers::Vector<'b, flatbuffers::ForwardsUOffset<&'b str>>, - >, - ) { - self.fbb_.push_slot_always::>( - TransactionInfo::VT_LOG_MESSAGES, - log_messages, - ); - } - #[inline] - pub fn add_inner_instructions( - &mut self, - inner_instructions: flatbuffers::WIPOffset< - flatbuffers::Vector<'b, flatbuffers::ForwardsUOffset>>, - >, - ) { - self.fbb_.push_slot_always::>( - TransactionInfo::VT_INNER_INSTRUCTIONS, - inner_instructions, - ); - } - #[inline] - pub fn add_outer_instructions( - &mut self, - outer_instructions: flatbuffers::WIPOffset< - flatbuffers::Vector<'b, flatbuffers::ForwardsUOffset>>, - >, - ) { - self.fbb_.push_slot_always::>( - TransactionInfo::VT_OUTER_INSTRUCTIONS, - outer_instructions, - ); - } - #[inline] - pub fn add_slot(&mut self, slot: u64) { - self.fbb_ - .push_slot::(TransactionInfo::VT_SLOT, slot, 0); - } - #[inline] - pub fn add_slot_index(&mut self, slot_index: flatbuffers::WIPOffset<&'b str>) { - self.fbb_.push_slot_always::>( - TransactionInfo::VT_SLOT_INDEX, - slot_index, - ); - } - #[inline] - pub fn add_seen_at(&mut self, seen_at: i64) { - self.fbb_ - .push_slot::(TransactionInfo::VT_SEEN_AT, seen_at, 0); - } - #[inline] - pub fn add_signature(&mut self, signature: flatbuffers::WIPOffset<&'b str>) { - self.fbb_.push_slot_always::>( - TransactionInfo::VT_SIGNATURE, - signature, - ); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> TransactionInfoBuilder<'a, 'b> { - let start = _fbb.start_table(); - TransactionInfoBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) - } + #[inline] + pub fn add_is_vote(&mut self, is_vote: bool) { + self.fbb_.push_slot::(TransactionInfo::VT_IS_VOTE, is_vote, false); + } + #[inline] + pub fn add_account_keys(&mut self, account_keys: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(TransactionInfo::VT_ACCOUNT_KEYS, account_keys); + } + #[inline] + pub fn add_log_messages(&mut self, log_messages: flatbuffers::WIPOffset>>) { + self.fbb_.push_slot_always::>(TransactionInfo::VT_LOG_MESSAGES, log_messages); + } + #[inline] + pub fn add_inner_instructions(&mut self, inner_instructions: flatbuffers::WIPOffset>>>) { + self.fbb_.push_slot_always::>(TransactionInfo::VT_INNER_INSTRUCTIONS, inner_instructions); + } + #[inline] + pub fn add_outer_instructions(&mut self, outer_instructions: flatbuffers::WIPOffset>>>) { + self.fbb_.push_slot_always::>(TransactionInfo::VT_OUTER_INSTRUCTIONS, outer_instructions); + } + #[inline] + pub fn add_slot(&mut self, slot: u64) { + self.fbb_.push_slot::(TransactionInfo::VT_SLOT, slot, 0); + } + #[inline] + pub fn add_slot_index(&mut self, slot_index: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(TransactionInfo::VT_SLOT_INDEX, slot_index); + } + #[inline] + pub fn add_seen_at(&mut self, seen_at: i64) { + self.fbb_.push_slot::(TransactionInfo::VT_SEEN_AT, seen_at, 0); + } + #[inline] + pub fn add_signature(&mut self, signature: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(TransactionInfo::VT_SIGNATURE, signature); + } + #[inline] + pub fn add_compiled_inner_instructions(&mut self, compiled_inner_instructions: flatbuffers::WIPOffset>>>) { + self.fbb_.push_slot_always::>(TransactionInfo::VT_COMPILED_INNER_INSTRUCTIONS, compiled_inner_instructions); + } + #[inline] + pub fn add_version(&mut self, version: TransactionVersion) { + self.fbb_.push_slot::(TransactionInfo::VT_VERSION, version, TransactionVersion::Legacy); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> TransactionInfoBuilder<'a, 'b> { + let start = _fbb.start_table(); + TransactionInfoBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } } impl core::fmt::Debug for TransactionInfo<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("TransactionInfo"); - ds.field("is_vote", &self.is_vote()); - ds.field("account_keys", &self.account_keys()); - ds.field("log_messages", &self.log_messages()); - ds.field("inner_instructions", &self.inner_instructions()); - ds.field("outer_instructions", &self.outer_instructions()); - ds.field("slot", &self.slot()); - ds.field("slot_index", &self.slot_index()); - ds.field("seen_at", &self.seen_at()); - ds.field("signature", &self.signature()); - ds.finish() - } + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("TransactionInfo"); + ds.field("is_vote", &self.is_vote()); + ds.field("account_keys", &self.account_keys()); + ds.field("log_messages", &self.log_messages()); + ds.field("inner_instructions", &self.inner_instructions()); + ds.field("outer_instructions", &self.outer_instructions()); + ds.field("slot", &self.slot()); + ds.field("slot_index", &self.slot_index()); + ds.field("seen_at", &self.seen_at()); + ds.field("signature", &self.signature()); + ds.field("compiled_inner_instructions", &self.compiled_inner_instructions()); + ds.field("version", &self.version()); + ds.finish() + } } pub enum InnerInstructionsOffset {} -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq)] pub struct InnerInstructions<'a> { - pub _tab: flatbuffers::Table<'a>, + pub _tab: flatbuffers::Table<'a>, } impl<'a> flatbuffers::Follow<'a> for InnerInstructions<'a> { - type Inner = InnerInstructions<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { - _tab: flatbuffers::Table::new(buf, loc), - } - } + type Inner = InnerInstructions<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } } impl<'a> InnerInstructions<'a> { - pub const VT_INDEX: flatbuffers::VOffsetT = 4; - pub const VT_INSTRUCTIONS: flatbuffers::VOffsetT = 6; + pub const VT_INDEX: flatbuffers::VOffsetT = 4; + pub const VT_INSTRUCTIONS: flatbuffers::VOffsetT = 6; - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - InnerInstructions { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, - args: &'args InnerInstructionsArgs<'args>, - ) -> flatbuffers::WIPOffset> { - let mut builder = InnerInstructionsBuilder::new(_fbb); - if let Some(x) = args.instructions { - builder.add_instructions(x); - } - builder.add_index(args.index); - builder.finish() - } + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + InnerInstructions { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args InnerInstructionsArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = InnerInstructionsBuilder::new(_fbb); + if let Some(x) = args.instructions { builder.add_instructions(x); } + builder.add_index(args.index); + builder.finish() + } - #[inline] - pub fn index(&self) -> u8 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab - .get::(InnerInstructions::VT_INDEX, Some(0)) - .unwrap() - } - } - #[inline] - pub fn instructions( - &self, - ) -> Option>>> - { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { - self._tab.get::>, - >>(InnerInstructions::VT_INSTRUCTIONS, None) - } - } + + #[inline] + pub fn index(&self) -> u8 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(InnerInstructions::VT_INDEX, Some(0)).unwrap()} + } + #[inline] + pub fn instructions(&self) -> Option>>> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>>(InnerInstructions::VT_INSTRUCTIONS, None)} + } } impl flatbuffers::Verifiable for InnerInstructions<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::("index", Self::VT_INDEX, false)? - .visit_field::>, - >>("instructions", Self::VT_INSTRUCTIONS, false)? - .finish(); - Ok(()) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("index", Self::VT_INDEX, false)? + .visit_field::>>>("instructions", Self::VT_INSTRUCTIONS, false)? + .finish(); + Ok(()) + } } pub struct InnerInstructionsArgs<'a> { pub index: u8, - pub instructions: Option< - flatbuffers::WIPOffset< - flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset>>, - >, - >, + pub instructions: Option>>>>, } impl<'a> Default for InnerInstructionsArgs<'a> { - #[inline] - fn default() -> Self { - InnerInstructionsArgs { - index: 0, - instructions: None, - } + #[inline] + fn default() -> Self { + InnerInstructionsArgs { + index: 0, + instructions: None, } + } } pub struct InnerInstructionsBuilder<'a: 'b, 'b> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, - start_: flatbuffers::WIPOffset, + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, } impl<'a: 'b, 'b> InnerInstructionsBuilder<'a, 'b> { - #[inline] - pub fn add_index(&mut self, index: u8) { - self.fbb_ - .push_slot::(InnerInstructions::VT_INDEX, index, 0); - } - #[inline] - pub fn add_instructions( - &mut self, - instructions: flatbuffers::WIPOffset< - flatbuffers::Vector<'b, flatbuffers::ForwardsUOffset>>, - >, - ) { - self.fbb_.push_slot_always::>( - InnerInstructions::VT_INSTRUCTIONS, - instructions, - ); - } - #[inline] - pub fn new( - _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - ) -> InnerInstructionsBuilder<'a, 'b> { - let start = _fbb.start_table(); - InnerInstructionsBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) - } + #[inline] + pub fn add_index(&mut self, index: u8) { + self.fbb_.push_slot::(InnerInstructions::VT_INDEX, index, 0); + } + #[inline] + pub fn add_instructions(&mut self, instructions: flatbuffers::WIPOffset>>>) { + self.fbb_.push_slot_always::>(InnerInstructions::VT_INSTRUCTIONS, instructions); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> InnerInstructionsBuilder<'a, 'b> { + let start = _fbb.start_table(); + InnerInstructionsBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } } impl core::fmt::Debug for InnerInstructions<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("InnerInstructions"); - ds.field("index", &self.index()); - ds.field("instructions", &self.instructions()); - ds.finish() - } + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("InnerInstructions"); + ds.field("index", &self.index()); + ds.field("instructions", &self.instructions()); + ds.finish() + } +} +pub enum CompiledInnerInstructionsOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct CompiledInnerInstructions<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for CompiledInnerInstructions<'a> { + type Inner = CompiledInnerInstructions<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> CompiledInnerInstructions<'a> { + pub const VT_INDEX: flatbuffers::VOffsetT = 4; + pub const VT_INSTRUCTIONS: flatbuffers::VOffsetT = 6; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + CompiledInnerInstructions { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args CompiledInnerInstructionsArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = CompiledInnerInstructionsBuilder::new(_fbb); + if let Some(x) = args.instructions { builder.add_instructions(x); } + builder.add_index(args.index); + builder.finish() + } + + + #[inline] + pub fn index(&self) -> u8 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(CompiledInnerInstructions::VT_INDEX, Some(0)).unwrap()} + } + #[inline] + pub fn instructions(&self) -> Option>>> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>>(CompiledInnerInstructions::VT_INSTRUCTIONS, None)} + } +} + +impl flatbuffers::Verifiable for CompiledInnerInstructions<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("index", Self::VT_INDEX, false)? + .visit_field::>>>("instructions", Self::VT_INSTRUCTIONS, false)? + .finish(); + Ok(()) + } +} +pub struct CompiledInnerInstructionsArgs<'a> { + pub index: u8, + pub instructions: Option>>>>, +} +impl<'a> Default for CompiledInnerInstructionsArgs<'a> { + #[inline] + fn default() -> Self { + CompiledInnerInstructionsArgs { + index: 0, + instructions: None, + } + } +} + +pub struct CompiledInnerInstructionsBuilder<'a: 'b, 'b> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b> CompiledInnerInstructionsBuilder<'a, 'b> { + #[inline] + pub fn add_index(&mut self, index: u8) { + self.fbb_.push_slot::(CompiledInnerInstructions::VT_INDEX, index, 0); + } + #[inline] + pub fn add_instructions(&mut self, instructions: flatbuffers::WIPOffset>>>) { + self.fbb_.push_slot_always::>(CompiledInnerInstructions::VT_INSTRUCTIONS, instructions); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> CompiledInnerInstructionsBuilder<'a, 'b> { + let start = _fbb.start_table(); + CompiledInnerInstructionsBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for CompiledInnerInstructions<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("CompiledInnerInstructions"); + ds.field("index", &self.index()); + ds.field("instructions", &self.instructions()); + ds.finish() + } } #[inline] /// Verifies that a buffer of bytes contains a `TransactionInfo` @@ -520,10 +598,8 @@ impl core::fmt::Debug for InnerInstructions<'_> { /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_transaction_info_unchecked`. -pub fn root_as_transaction_info( - buf: &[u8], -) -> Result { - flatbuffers::root::(buf) +pub fn root_as_transaction_info(buf: &[u8]) -> Result { + flatbuffers::root::(buf) } #[inline] /// Verifies that a buffer of bytes contains a size prefixed @@ -532,10 +608,8 @@ pub fn root_as_transaction_info( /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `size_prefixed_root_as_transaction_info_unchecked`. -pub fn size_prefixed_root_as_transaction_info( - buf: &[u8], -) -> Result { - flatbuffers::size_prefixed_root::(buf) +pub fn size_prefixed_root_as_transaction_info(buf: &[u8]) -> Result { + flatbuffers::size_prefixed_root::(buf) } #[inline] /// Verifies, with the given options, that a buffer of bytes @@ -545,10 +619,10 @@ pub fn size_prefixed_root_as_transaction_info( /// previous, unchecked, behavior use /// `root_as_transaction_info_unchecked`. pub fn root_as_transaction_info_with_opts<'b, 'o>( - opts: &'o flatbuffers::VerifierOptions, - buf: &'b [u8], + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], ) -> Result, flatbuffers::InvalidFlatbuffer> { - flatbuffers::root_with_opts::>(opts, buf) + flatbuffers::root_with_opts::>(opts, buf) } #[inline] /// Verifies, with the given verifier options, that a buffer of @@ -558,37 +632,33 @@ pub fn root_as_transaction_info_with_opts<'b, 'o>( /// previous, unchecked, behavior use /// `root_as_transaction_info_unchecked`. pub fn size_prefixed_root_as_transaction_info_with_opts<'b, 'o>( - opts: &'o flatbuffers::VerifierOptions, - buf: &'b [u8], + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], ) -> Result, flatbuffers::InvalidFlatbuffer> { - flatbuffers::size_prefixed_root_with_opts::>(opts, buf) + flatbuffers::size_prefixed_root_with_opts::>(opts, buf) } #[inline] /// Assumes, without verification, that a buffer of bytes contains a TransactionInfo and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid `TransactionInfo`. pub unsafe fn root_as_transaction_info_unchecked(buf: &[u8]) -> TransactionInfo { - flatbuffers::root_unchecked::(buf) + flatbuffers::root_unchecked::(buf) } #[inline] /// Assumes, without verification, that a buffer of bytes contains a size prefixed TransactionInfo and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid size prefixed `TransactionInfo`. pub unsafe fn size_prefixed_root_as_transaction_info_unchecked(buf: &[u8]) -> TransactionInfo { - flatbuffers::size_prefixed_root_unchecked::(buf) + flatbuffers::size_prefixed_root_unchecked::(buf) } #[inline] pub fn finish_transaction_info_buffer<'a, 'b>( fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - root: flatbuffers::WIPOffset>, -) { - fbb.finish(root, None); + root: flatbuffers::WIPOffset>) { + fbb.finish(root, None); } #[inline] -pub fn finish_size_prefixed_transaction_info_buffer<'a, 'b>( - fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - root: flatbuffers::WIPOffset>, -) { - fbb.finish_size_prefixed(root, None); +pub fn finish_size_prefixed_transaction_info_buffer<'a, 'b>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, root: flatbuffers::WIPOffset>) { + fbb.finish_size_prefixed(root, None); } diff --git a/plerkle_serialization/transaction_info.fbs b/plerkle_serialization/transaction_info.fbs index e07233a4..224dc9e8 100644 --- a/plerkle_serialization/transaction_info.fbs +++ b/plerkle_serialization/transaction_info.fbs @@ -2,17 +2,25 @@ include "./compiled_instruction.fbs"; include "./common.fbs"; +//Legacy is default for unknown +enum TransactionVersion:byte { + Legacy, + V0 +} table TransactionInfo { is_vote: bool; account_keys:[Pubkey]; log_messages:[string]; - inner_instructions:[InnerInstructions]; + // To be deprecated + inner_instructions: [InnerInstructions]; outer_instructions: [CompiledInstruction]; slot: uint64; slot_index: string; seen_at: int64; signature: string; + compiled_inner_instructions: [CompiledInnerInstructions]; + version: TransactionVersion; } table InnerInstructions { @@ -22,4 +30,11 @@ table InnerInstructions { instructions: [CompiledInstruction]; } +table CompiledInnerInstructions { + // Transaction instruction index. + index:uint8; + // List of inner instructions. + instructions: [CompiledInnerInstruction]; +} + root_type TransactionInfo;