Expose a method for getting the Message from a Transaction
This currently constructs the message, but when message is integrated, it can return a `&Message`.
This commit is contained in:
parent
fc678f53ba
commit
98d60e6124
|
@ -356,7 +356,7 @@ mod tests {
|
|||
fn test_system_transaction_layout() {
|
||||
let tx = test_tx();
|
||||
let tx_bytes = serialize(&tx).unwrap();
|
||||
let message = tx.message();
|
||||
let message_data = tx.message_data();
|
||||
let packet = sigverify::make_packet_from_transaction(tx.clone());
|
||||
|
||||
let (sig_len, sig_start, msg_start_offset, pubkey_offset) =
|
||||
|
@ -371,7 +371,7 @@ mod tests {
|
|||
Some(pubkey_offset as usize)
|
||||
);
|
||||
assert_eq!(
|
||||
memfind(&tx_bytes, &message),
|
||||
memfind(&tx_bytes, &message_data),
|
||||
Some(msg_start_offset as usize)
|
||||
);
|
||||
assert_eq!(
|
||||
|
@ -386,7 +386,7 @@ mod tests {
|
|||
use crate::packet::PACKET_DATA_SIZE;
|
||||
let mut tx0 = test_tx();
|
||||
tx0.instructions[0].data = vec![1, 2, 3];
|
||||
let message0a = tx0.message();
|
||||
let message0a = tx0.message_data();
|
||||
let tx_bytes = serialize(&tx0).unwrap();
|
||||
assert!(tx_bytes.len() < PACKET_DATA_SIZE);
|
||||
assert_eq!(
|
||||
|
@ -398,7 +398,7 @@ mod tests {
|
|||
assert_eq!(tx1.instructions[0].data, vec![1, 2, 3]);
|
||||
|
||||
tx0.instructions[0].data = vec![1, 2, 4];
|
||||
let message0b = tx0.message();
|
||||
let message0b = tx0.message_data();
|
||||
assert_ne!(message0a, message0b);
|
||||
}
|
||||
|
||||
|
|
|
@ -174,26 +174,31 @@ impl Transaction {
|
|||
let program_ids_index = self.instructions[instruction_index].program_ids_index;
|
||||
&self.program_ids[program_ids_index as usize]
|
||||
}
|
||||
/// Get the transaction data to sign.
|
||||
pub fn message(&self) -> Vec<u8> {
|
||||
let message = Message {
|
||||
|
||||
/// Return a message containing all data that should be signed.
|
||||
pub fn message(&self) -> Message {
|
||||
Message {
|
||||
num_signatures: self.signatures.len() as u8,
|
||||
account_keys: self.account_keys.clone(),
|
||||
recent_blockhash: self.recent_blockhash,
|
||||
fee: self.fee,
|
||||
program_ids: self.program_ids.clone(),
|
||||
instructions: self.instructions.clone(),
|
||||
};
|
||||
serialize(&message).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the serialized message data to sign.
|
||||
pub fn message_data(&self) -> Vec<u8> {
|
||||
serialize(&self.message()).unwrap()
|
||||
}
|
||||
|
||||
/// Sign this transaction.
|
||||
pub fn sign_unchecked<T: KeypairUtil>(&mut self, keypairs: &[&T], recent_blockhash: Hash) {
|
||||
self.recent_blockhash = recent_blockhash;
|
||||
let message = self.message();
|
||||
let message_data = self.message_data();
|
||||
self.signatures = keypairs
|
||||
.iter()
|
||||
.map(|keypair| keypair.sign_message(&message))
|
||||
.map(|keypair| keypair.sign_message(&message_data))
|
||||
.collect();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue