Rename TransactionBuilder to TransactionCompiler
This commit is contained in:
@ -15,7 +15,7 @@ pub mod system_program;
|
|||||||
pub mod system_transaction;
|
pub mod system_transaction;
|
||||||
pub mod timing;
|
pub mod timing;
|
||||||
pub mod transaction;
|
pub mod transaction;
|
||||||
mod transaction_builder;
|
mod transaction_compiler;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
@ -10,7 +10,7 @@ use crate::shortvec::{
|
|||||||
};
|
};
|
||||||
use crate::signature::{KeypairUtil, Signature};
|
use crate::signature::{KeypairUtil, Signature};
|
||||||
use crate::system_instruction::SystemError;
|
use crate::system_instruction::SystemError;
|
||||||
use crate::transaction_builder::TransactionBuilder;
|
use crate::transaction_compiler::TransactionCompiler;
|
||||||
use bincode::{serialize, Error};
|
use bincode::{serialize, Error};
|
||||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use serde::{Deserialize, Serialize, Serializer};
|
use serde::{Deserialize, Serialize, Serializer};
|
||||||
@ -168,7 +168,7 @@ pub struct Transaction {
|
|||||||
|
|
||||||
impl Transaction {
|
impl Transaction {
|
||||||
pub fn new(instructions: Vec<Instruction>) -> Self {
|
pub fn new(instructions: Vec<Instruction>) -> Self {
|
||||||
TransactionBuilder::new(instructions).compile()
|
TransactionCompiler::new(instructions).compile()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_with_blockhash_and_fee<T: Serialize>(
|
pub fn new_with_blockhash_and_fee<T: Serialize>(
|
||||||
|
@ -33,11 +33,11 @@ fn compile_instructions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A utility for constructing transactions
|
/// A utility for constructing transactions
|
||||||
pub struct TransactionBuilder {
|
pub struct TransactionCompiler {
|
||||||
instructions: Vec<Instruction>,
|
instructions: Vec<Instruction>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TransactionBuilder {
|
impl TransactionCompiler {
|
||||||
/// Create a new unsigned transaction from a single instruction
|
/// Create a new unsigned transaction from a single instruction
|
||||||
pub fn new(instructions: Vec<Instruction>) -> Self {
|
pub fn new(instructions: Vec<Instruction>) -> Self {
|
||||||
Self { instructions }
|
Self { instructions }
|
||||||
@ -100,7 +100,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_transaction_builder_unique_program_ids() {
|
fn test_transaction_builder_unique_program_ids() {
|
||||||
let program_id0 = Pubkey::default();
|
let program_id0 = Pubkey::default();
|
||||||
let program_ids = TransactionBuilder::new(vec![
|
let program_ids = TransactionCompiler::new(vec![
|
||||||
Instruction::new(program_id0, &0, vec![]),
|
Instruction::new(program_id0, &0, vec![]),
|
||||||
Instruction::new(program_id0, &0, vec![]),
|
Instruction::new(program_id0, &0, vec![]),
|
||||||
])
|
])
|
||||||
@ -112,7 +112,7 @@ mod tests {
|
|||||||
fn test_transaction_builder_unique_program_ids_not_adjacent() {
|
fn test_transaction_builder_unique_program_ids_not_adjacent() {
|
||||||
let program_id0 = Pubkey::default();
|
let program_id0 = Pubkey::default();
|
||||||
let program_id1 = Keypair::new().pubkey();
|
let program_id1 = Keypair::new().pubkey();
|
||||||
let program_ids = TransactionBuilder::new(vec![
|
let program_ids = TransactionCompiler::new(vec![
|
||||||
Instruction::new(program_id0, &0, vec![]),
|
Instruction::new(program_id0, &0, vec![]),
|
||||||
Instruction::new(program_id1, &0, vec![]),
|
Instruction::new(program_id1, &0, vec![]),
|
||||||
Instruction::new(program_id0, &0, vec![]),
|
Instruction::new(program_id0, &0, vec![]),
|
||||||
@ -125,7 +125,7 @@ mod tests {
|
|||||||
fn test_transaction_builder_unique_program_ids_order_preserved() {
|
fn test_transaction_builder_unique_program_ids_order_preserved() {
|
||||||
let program_id0 = Keypair::new().pubkey();
|
let program_id0 = Keypair::new().pubkey();
|
||||||
let program_id1 = Pubkey::default(); // Key less than program_id0
|
let program_id1 = Pubkey::default(); // Key less than program_id0
|
||||||
let program_ids = TransactionBuilder::new(vec![
|
let program_ids = TransactionCompiler::new(vec![
|
||||||
Instruction::new(program_id0, &0, vec![]),
|
Instruction::new(program_id0, &0, vec![]),
|
||||||
Instruction::new(program_id1, &0, vec![]),
|
Instruction::new(program_id1, &0, vec![]),
|
||||||
Instruction::new(program_id0, &0, vec![]),
|
Instruction::new(program_id0, &0, vec![]),
|
||||||
@ -138,7 +138,7 @@ mod tests {
|
|||||||
fn test_transaction_builder_unique_keys_both_signed() {
|
fn test_transaction_builder_unique_keys_both_signed() {
|
||||||
let program_id = Pubkey::default();
|
let program_id = Pubkey::default();
|
||||||
let id0 = Pubkey::default();
|
let id0 = Pubkey::default();
|
||||||
let keys = TransactionBuilder::new(vec![
|
let keys = TransactionCompiler::new(vec![
|
||||||
Instruction::new(program_id, &0, vec![(id0, true)]),
|
Instruction::new(program_id, &0, vec![(id0, true)]),
|
||||||
Instruction::new(program_id, &0, vec![(id0, true)]),
|
Instruction::new(program_id, &0, vec![(id0, true)]),
|
||||||
])
|
])
|
||||||
@ -150,7 +150,7 @@ mod tests {
|
|||||||
fn test_transaction_builder_unique_keys_one_signed() {
|
fn test_transaction_builder_unique_keys_one_signed() {
|
||||||
let program_id = Pubkey::default();
|
let program_id = Pubkey::default();
|
||||||
let id0 = Pubkey::default();
|
let id0 = Pubkey::default();
|
||||||
let keys = TransactionBuilder::new(vec![
|
let keys = TransactionCompiler::new(vec![
|
||||||
Instruction::new(program_id, &0, vec![(id0, false)]),
|
Instruction::new(program_id, &0, vec![(id0, false)]),
|
||||||
Instruction::new(program_id, &0, vec![(id0, true)]),
|
Instruction::new(program_id, &0, vec![(id0, true)]),
|
||||||
])
|
])
|
||||||
@ -163,7 +163,7 @@ mod tests {
|
|||||||
let program_id = Pubkey::default();
|
let program_id = Pubkey::default();
|
||||||
let id0 = Keypair::new().pubkey();
|
let id0 = Keypair::new().pubkey();
|
||||||
let id1 = Pubkey::default(); // Key less than id0
|
let id1 = Pubkey::default(); // Key less than id0
|
||||||
let keys = TransactionBuilder::new(vec![
|
let keys = TransactionCompiler::new(vec![
|
||||||
Instruction::new(program_id, &0, vec![(id0, false)]),
|
Instruction::new(program_id, &0, vec![(id0, false)]),
|
||||||
Instruction::new(program_id, &0, vec![(id1, false)]),
|
Instruction::new(program_id, &0, vec![(id1, false)]),
|
||||||
])
|
])
|
||||||
@ -176,7 +176,7 @@ mod tests {
|
|||||||
let program_id = Pubkey::default();
|
let program_id = Pubkey::default();
|
||||||
let id0 = Pubkey::default();
|
let id0 = Pubkey::default();
|
||||||
let id1 = Keypair::new().pubkey();
|
let id1 = Keypair::new().pubkey();
|
||||||
let keys = TransactionBuilder::new(vec![
|
let keys = TransactionCompiler::new(vec![
|
||||||
Instruction::new(program_id, &0, vec![(id0, false)]),
|
Instruction::new(program_id, &0, vec![(id0, false)]),
|
||||||
Instruction::new(program_id, &0, vec![(id1, false)]),
|
Instruction::new(program_id, &0, vec![(id1, false)]),
|
||||||
Instruction::new(program_id, &0, vec![(id0, true)]),
|
Instruction::new(program_id, &0, vec![(id0, true)]),
|
||||||
@ -190,7 +190,7 @@ mod tests {
|
|||||||
let program_id = Pubkey::default();
|
let program_id = Pubkey::default();
|
||||||
let id0 = Pubkey::default();
|
let id0 = Pubkey::default();
|
||||||
let id1 = Keypair::new().pubkey();
|
let id1 = Keypair::new().pubkey();
|
||||||
let keys = TransactionBuilder::new(vec![
|
let keys = TransactionCompiler::new(vec![
|
||||||
Instruction::new(program_id, &0, vec![(id0, false)]),
|
Instruction::new(program_id, &0, vec![(id0, false)]),
|
||||||
Instruction::new(program_id, &0, vec![(id1, true)]),
|
Instruction::new(program_id, &0, vec![(id1, true)]),
|
||||||
])
|
])
|
||||||
@ -204,12 +204,13 @@ mod tests {
|
|||||||
let program_id = Pubkey::default();
|
let program_id = Pubkey::default();
|
||||||
let id0 = Pubkey::default();
|
let id0 = Pubkey::default();
|
||||||
let tx =
|
let tx =
|
||||||
TransactionBuilder::new(vec![Instruction::new(program_id, &0, vec![(id0, false)])])
|
TransactionCompiler::new(vec![Instruction::new(program_id, &0, vec![(id0, false)])])
|
||||||
.compile();
|
.compile();
|
||||||
assert_eq!(tx.signatures.capacity(), 0);
|
assert_eq!(tx.signatures.capacity(), 0);
|
||||||
|
|
||||||
let tx = TransactionBuilder::new(vec![Instruction::new(program_id, &0, vec![(id0, true)])])
|
let tx =
|
||||||
.compile();
|
TransactionCompiler::new(vec![Instruction::new(program_id, &0, vec![(id0, true)])])
|
||||||
|
.compile();
|
||||||
assert_eq!(tx.signatures.capacity(), 1);
|
assert_eq!(tx.signatures.capacity(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +221,7 @@ mod tests {
|
|||||||
let id0 = Pubkey::default();
|
let id0 = Pubkey::default();
|
||||||
let keypair1 = Keypair::new();
|
let keypair1 = Keypair::new();
|
||||||
let id1 = keypair1.pubkey();
|
let id1 = keypair1.pubkey();
|
||||||
let tx = TransactionBuilder::new(vec![
|
let tx = TransactionCompiler::new(vec![
|
||||||
Instruction::new(program_id0, &0, vec![(id0, false)]),
|
Instruction::new(program_id0, &0, vec![(id0, false)]),
|
||||||
Instruction::new(program_id1, &0, vec![(id1, true)]),
|
Instruction::new(program_id1, &0, vec![(id1, true)]),
|
||||||
Instruction::new(program_id0, &0, vec![(id1, false)]),
|
Instruction::new(program_id0, &0, vec![(id1, false)]),
|
Reference in New Issue
Block a user