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 21, 2021
1 parent 395ee4e commit 22e23c8
Show file tree
Hide file tree
Showing 4 changed files with 675 additions and 22 deletions.
27 changes: 27 additions & 0 deletions sdk/program/src/message/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! 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;

#[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,
}
24 changes: 2 additions & 22 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,27 +164,6 @@ 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 = "2KnLEqfLcTBQqitE22Pp8JYkaqVVbAkGbCfdeHoyxcAU")]
#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone, AbiExample)]
#[serde(rename_all = "camelCase")]
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 22e23c8

Please sign in to comment.