Skip to content

Commit

Permalink
Version transaction message and add new message format
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Jul 16, 2021
1 parent abe5a0a commit 4636482
Show file tree
Hide file tree
Showing 4 changed files with 678 additions and 23 deletions.
28 changes: 28 additions & 0 deletions sdk/program/src/message/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//! A library for generating a message from a sequence of instructions
mod original;
mod v0;
mod versions;

pub use original::Message;

pub const MESSAGE_HEADER_LENGTH: usize = 3;

#[frozen_abi(digest = "BVC5RhetsNpheGipt5rUrkR6RDDUHtD5sCLK1UjymL4S")]
#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone, AbiExample)]
#[serde(rename_all = "camelCase")]
pub struct MessageHeader {
/// The number of signatures required for this message to be considered valid. The
/// signatures must match the first `num_required_signatures` of `account_keys`.
/// NOTE: Serialization-related changes must be paired with the direct read at sigverify.
pub num_required_signatures: u8,

/// The last num_readonly_signed_accounts of the signed keys are read-only accounts. Programs
/// may process multiple transactions that load read-only accounts within a single PoH entry,
/// but are not permitted to credit or debit lamports or modify account data. Transactions
/// targeting the same read-write account are evaluated sequentially.
pub num_readonly_signed_accounts: u8,

/// The last num_readonly_unsigned_accounts of the unsigned keys are read-only accounts.
pub num_readonly_unsigned_accounts: u8,
}
26 changes: 3 additions & 23 deletions sdk/program/src/message.rs → sdk/program/src/message/original.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable,
hash::Hash,
instruction::{AccountMeta, CompiledInstruction, Instruction},
message::MessageHeader,
pubkey::Pubkey,
short_vec, system_instruction, system_program, sysvar,
};
Expand Down Expand Up @@ -163,28 +164,7 @@ fn get_program_ids(instructions: &[Instruction]) -> Vec<Pubkey> {
.collect()
}

pub const MESSAGE_HEADER_LENGTH: usize = 3;

#[frozen_abi(digest = "BVC5RhetsNpheGipt5rUrkR6RDDUHtD5sCLK1UjymL4S")]
#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone, AbiExample)]
#[serde(rename_all = "camelCase")]
pub struct MessageHeader {
/// The number of signatures required for this message to be considered valid. The
/// signatures must match the first `num_required_signatures` of `account_keys`.
/// NOTE: Serialization-related changes must be paired with the direct read at sigverify.
pub num_required_signatures: u8,

/// The last num_readonly_signed_accounts of the signed keys are read-only accounts. Programs
/// may process multiple transactions that load read-only accounts within a single PoH entry,
/// but are not permitted to credit or debit lamports or modify account data. Transactions
/// targeting the same read-write account are evaluated sequentially.
pub num_readonly_signed_accounts: u8,

/// The last num_readonly_unsigned_accounts of the unsigned keys are read-only accounts.
pub num_readonly_unsigned_accounts: u8,
}

#[frozen_abi(digest = "BPBJZxpRQ4JS7LGJtsgoyctg4BXyBbbY4uc7FjowtxLV")]
#[frozen_abi(digest = "8Rf1mAQbCgnTLkS4CUK9Tx2i7puRp3aq1qw6AGZCrj1L")]
#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone, AbiExample)]
#[serde(rename_all = "camelCase")]
pub struct Message {
Expand Down Expand Up @@ -508,7 +488,7 @@ impl Message {
#[cfg(test)]
mod tests {
use super::*;
use crate::{hash, instruction::AccountMeta};
use crate::{hash, instruction::AccountMeta, message::MESSAGE_HEADER_LENGTH};
use std::collections::HashSet;

#[test]
Expand Down
Loading

0 comments on commit 4636482

Please sign in to comment.