|
|
@@ -24,284 +24,24 @@ use solana_program::{
|
|
|
program_error::ProgramError::InvalidAccountData,
|
|
|
pubkey::Pubkey,
|
|
|
};
|
|
|
-use solitaire::{
|
|
|
- processors::seeded::{
|
|
|
- AccountOwner,
|
|
|
- Owned,
|
|
|
- },
|
|
|
- SolitaireError,
|
|
|
-};
|
|
|
+use solitaire::SolitaireError;
|
|
|
use std::{
|
|
|
+ self,
|
|
|
io::{
|
|
|
Cursor,
|
|
|
Read,
|
|
|
Write,
|
|
|
},
|
|
|
- ops::{
|
|
|
- Deref,
|
|
|
- DerefMut,
|
|
|
- },
|
|
|
};
|
|
|
|
|
|
-#[derive(Default, BorshSerialize, BorshDeserialize, Serialize, Deserialize)]
|
|
|
-pub struct GuardianSetData {
|
|
|
- /// Version number of this guardian set.
|
|
|
- pub index: u32,
|
|
|
-
|
|
|
- /// public key hashes of the guardian set
|
|
|
- pub keys: Vec<[u8; 20]>,
|
|
|
-
|
|
|
- /// creation time
|
|
|
- pub creation_time: u32,
|
|
|
-
|
|
|
- /// expiration time when VAAs issued by this set are no longer valid
|
|
|
- pub expiration_time: u32,
|
|
|
-}
|
|
|
-
|
|
|
-impl GuardianSetData {
|
|
|
- /// Number of guardians in the set
|
|
|
- pub fn num_guardians(&self) -> u8 {
|
|
|
- self.keys.iter().filter(|v| **v != [0u8; 20]).count() as u8
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-impl Owned for GuardianSetData {
|
|
|
- fn owner(&self) -> AccountOwner {
|
|
|
- AccountOwner::This
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#[derive(Clone, Default, BorshSerialize, BorshDeserialize, Serialize, Deserialize)]
|
|
|
-pub struct BridgeConfig {
|
|
|
- /// Period for how long a guardian set is valid after it has been replaced by a new one. This
|
|
|
- /// guarantees that VAAs issued by that set can still be submitted for a certain period. In
|
|
|
- /// this period we still trust the old guardian set.
|
|
|
- pub guardian_set_expiration_time: u32,
|
|
|
-
|
|
|
- /// Amount of lamports that needs to be paid to the protocol to post a message
|
|
|
- pub fee: u64,
|
|
|
-}
|
|
|
-
|
|
|
-#[derive(Clone, Default, BorshSerialize, BorshDeserialize, Serialize, Deserialize)]
|
|
|
-pub struct BridgeData {
|
|
|
- /// The current guardian set index, used to decide which signature sets to accept.
|
|
|
- pub guardian_set_index: u32,
|
|
|
-
|
|
|
- /// Lamports in the collection account
|
|
|
- pub last_lamports: u64,
|
|
|
-
|
|
|
- /// Bridge configuration, which is set once upon initialization.
|
|
|
- pub config: BridgeConfig,
|
|
|
-}
|
|
|
-
|
|
|
-#[cfg(not(feature = "cpi"))]
|
|
|
-impl Owned for BridgeData {
|
|
|
- fn owner(&self) -> AccountOwner {
|
|
|
- AccountOwner::This
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#[cfg(feature = "cpi")]
|
|
|
-impl Owned for BridgeData {
|
|
|
- fn owner(&self) -> AccountOwner {
|
|
|
- use std::str::FromStr;
|
|
|
- AccountOwner::Other(Pubkey::from_str(env!("BRIDGE_ADDRESS")).unwrap())
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#[derive(Default, BorshSerialize, BorshDeserialize)]
|
|
|
-pub struct SignatureSet {
|
|
|
- /// Signatures of validators
|
|
|
- pub signatures: Vec<bool>,
|
|
|
-
|
|
|
- /// Hash of the data
|
|
|
- pub hash: [u8; 32],
|
|
|
-
|
|
|
- /// Index of the guardian set
|
|
|
- pub guardian_set_index: u32,
|
|
|
-}
|
|
|
-
|
|
|
-impl Owned for SignatureSet {
|
|
|
- fn owner(&self) -> AccountOwner {
|
|
|
- AccountOwner::This
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// This is using the same payload as the PostedVAA for backwards compatibility.
|
|
|
-// This will be deprecated in a future release.
|
|
|
-#[repr(transparent)]
|
|
|
-pub struct PostedMessageData(pub MessageData);
|
|
|
-
|
|
|
-impl BorshSerialize for PostedMessageData {
|
|
|
- fn serialize<W: Write>(&self, writer: &mut W) -> std::io::Result<()> {
|
|
|
- writer.write(b"msg")?;
|
|
|
- BorshSerialize::serialize(&self.0, writer)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-impl BorshDeserialize for PostedMessageData {
|
|
|
- fn deserialize(buf: &mut &[u8]) -> std::io::Result<Self> {
|
|
|
- *buf = &buf[3..];
|
|
|
- Ok(PostedMessageData(
|
|
|
- <MessageData as BorshDeserialize>::deserialize(buf)?,
|
|
|
- ))
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-impl Deref for PostedMessageData {
|
|
|
- type Target = MessageData;
|
|
|
-
|
|
|
- fn deref(&self) -> &Self::Target {
|
|
|
- unsafe { std::mem::transmute(&self.0) }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-impl DerefMut for PostedMessageData {
|
|
|
- fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
- unsafe { std::mem::transmute(&mut self.0) }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-impl Default for PostedMessageData {
|
|
|
- fn default() -> Self {
|
|
|
- PostedMessageData(MessageData::default())
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-impl Clone for PostedMessageData {
|
|
|
- fn clone(&self) -> Self {
|
|
|
- PostedMessageData(self.0.clone())
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#[cfg(not(feature = "cpi"))]
|
|
|
-impl Owned for PostedMessageData {
|
|
|
- fn owner(&self) -> AccountOwner {
|
|
|
- AccountOwner::This
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#[cfg(feature = "cpi")]
|
|
|
-impl Owned for PostedMessageData {
|
|
|
- fn owner(&self) -> AccountOwner {
|
|
|
- use std::str::FromStr;
|
|
|
- AccountOwner::Other(Pubkey::from_str(env!("BRIDGE_ADDRESS")).unwrap())
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#[repr(transparent)]
|
|
|
-pub struct PostedVAAData(pub MessageData);
|
|
|
-
|
|
|
-impl BorshSerialize for PostedVAAData {
|
|
|
- fn serialize<W: Write>(&self, writer: &mut W) -> std::io::Result<()> {
|
|
|
- writer.write(b"vaa")?;
|
|
|
- BorshSerialize::serialize(&self.0, writer)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-impl BorshDeserialize for PostedVAAData {
|
|
|
- fn deserialize(buf: &mut &[u8]) -> std::io::Result<Self> {
|
|
|
- *buf = &buf[3..];
|
|
|
- Ok(PostedVAAData(
|
|
|
- <MessageData as BorshDeserialize>::deserialize(buf)?,
|
|
|
- ))
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-impl Deref for PostedVAAData {
|
|
|
- type Target = MessageData;
|
|
|
-
|
|
|
- fn deref(&self) -> &Self::Target {
|
|
|
- unsafe { std::mem::transmute(&self.0) }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-impl DerefMut for PostedVAAData {
|
|
|
- fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
- unsafe { std::mem::transmute(&mut self.0) }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-impl Default for PostedVAAData {
|
|
|
- fn default() -> Self {
|
|
|
- PostedVAAData(MessageData::default())
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-impl Clone for PostedVAAData {
|
|
|
- fn clone(&self) -> Self {
|
|
|
- PostedVAAData(self.0.clone())
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#[derive(Default, BorshSerialize, BorshDeserialize, Clone, Serialize, Deserialize)]
|
|
|
-pub struct MessageData {
|
|
|
- /// Header of the posted VAA
|
|
|
- pub vaa_version: u8,
|
|
|
-
|
|
|
- /// Level of consistency requested by the emitter
|
|
|
- pub consistency_level: u8,
|
|
|
-
|
|
|
- /// Time the vaa was submitted
|
|
|
- pub vaa_time: u32,
|
|
|
-
|
|
|
- /// Account where signatures are stored
|
|
|
- pub vaa_signature_account: Pubkey,
|
|
|
-
|
|
|
- /// Time the posted message was created
|
|
|
- pub submission_time: u32,
|
|
|
-
|
|
|
- /// Unique nonce for this message
|
|
|
- pub nonce: u32,
|
|
|
-
|
|
|
- /// Sequence number of this message
|
|
|
- pub sequence: u64,
|
|
|
-
|
|
|
- /// Emitter of the message
|
|
|
- pub emitter_chain: u16,
|
|
|
+/// Type representing an Ethereum style public key for Guardians.
|
|
|
+pub type GuardianPublicKey = [u8; 20];
|
|
|
|
|
|
- /// Emitter of the message
|
|
|
- pub emitter_address: [u8; 32],
|
|
|
-
|
|
|
- /// Message payload
|
|
|
- pub payload: Vec<u8>,
|
|
|
-}
|
|
|
-
|
|
|
-#[cfg(not(feature = "cpi"))]
|
|
|
-impl Owned for PostedVAAData {
|
|
|
- fn owner(&self) -> AccountOwner {
|
|
|
- AccountOwner::This
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#[cfg(feature = "cpi")]
|
|
|
-impl Owned for PostedVAAData {
|
|
|
- fn owner(&self) -> AccountOwner {
|
|
|
- use std::str::FromStr;
|
|
|
- AccountOwner::Other(Pubkey::from_str(env!("BRIDGE_ADDRESS")).unwrap())
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#[derive(Default, Clone, Copy, BorshDeserialize, BorshSerialize)]
|
|
|
-pub struct SequenceTracker {
|
|
|
- pub sequence: u64,
|
|
|
-}
|
|
|
-
|
|
|
-impl Owned for SequenceTracker {
|
|
|
- fn owner(&self) -> AccountOwner {
|
|
|
- AccountOwner::This
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#[derive(Default, Clone, Copy, BorshDeserialize, BorshSerialize, Serialize, Deserialize)]
|
|
|
-pub struct ClaimData {
|
|
|
- pub claimed: bool,
|
|
|
-}
|
|
|
-
|
|
|
-impl Owned for ClaimData {
|
|
|
- fn owner(&self) -> AccountOwner {
|
|
|
- AccountOwner::This
|
|
|
- }
|
|
|
+#[repr(u8)]
|
|
|
+#[derive(BorshSerialize, BorshDeserialize, Clone, Serialize, Deserialize)]
|
|
|
+pub enum ConsistencyLevel {
|
|
|
+ Confirmed,
|
|
|
+ Finalized,
|
|
|
}
|
|
|
|
|
|
pub struct GovernancePayloadUpgrade {
|
|
|
@@ -493,10 +233,3 @@ impl SerializeGovernancePayload for GovernancePayloadTransferFees {
|
|
|
|
|
|
impl DeserializeGovernancePayload for GovernancePayloadTransferFees {
|
|
|
}
|
|
|
-
|
|
|
-#[repr(u8)]
|
|
|
-#[derive(BorshSerialize, BorshDeserialize, Clone, Serialize, Deserialize)]
|
|
|
-pub enum ConsistencyLevel {
|
|
|
- Confirmed,
|
|
|
- Finalized,
|
|
|
-}
|