Remove fee-payer guesswork from Message and Transaction (#10776)
* Make Message::new_with_payer the default constructor * Remove Transaction::new_[un]signed_instructions These guess the fee-payer instead of stating it explicitly
This commit is contained in:
@ -14,6 +14,7 @@ use solana_metrics::datapoint_info;
|
|||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
client::{Client, SyncClient},
|
client::{Client, SyncClient},
|
||||||
commitment_config::CommitmentConfig,
|
commitment_config::CommitmentConfig,
|
||||||
|
message::Message,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{Keypair, Signer},
|
signature::{Keypair, Signer},
|
||||||
timing::{duration_as_ms, duration_as_s},
|
timing::{duration_as_ms, duration_as_s},
|
||||||
@ -457,16 +458,14 @@ fn swapper<T>(
|
|||||||
.map(|(signer, swap, profit)| {
|
.map(|(signer, swap, profit)| {
|
||||||
let s: &Keypair = &signer;
|
let s: &Keypair = &signer;
|
||||||
let owner = &signer.pubkey();
|
let owner = &signer.pubkey();
|
||||||
Transaction::new_signed_instructions(
|
let instruction = exchange_instruction::swap_request(
|
||||||
&[s],
|
|
||||||
&[exchange_instruction::swap_request(
|
|
||||||
owner,
|
owner,
|
||||||
&swap.0.pubkey,
|
&swap.0.pubkey,
|
||||||
&swap.1.pubkey,
|
&swap.1.pubkey,
|
||||||
&profit,
|
&profit,
|
||||||
)],
|
);
|
||||||
blockhash,
|
let message = Message::new(&[instruction], Some(&s.pubkey()));
|
||||||
)
|
Transaction::new(&[s], message, blockhash)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@ -588,9 +587,7 @@ fn trader<T>(
|
|||||||
let owner_pubkey = &owner.pubkey();
|
let owner_pubkey = &owner.pubkey();
|
||||||
let trade_pubkey = &trade.pubkey();
|
let trade_pubkey = &trade.pubkey();
|
||||||
let space = mem::size_of::<ExchangeState>() as u64;
|
let space = mem::size_of::<ExchangeState>() as u64;
|
||||||
Transaction::new_signed_instructions(
|
let instructions = [
|
||||||
&[owner.as_ref(), trade],
|
|
||||||
&[
|
|
||||||
system_instruction::create_account(
|
system_instruction::create_account(
|
||||||
owner_pubkey,
|
owner_pubkey,
|
||||||
trade_pubkey,
|
trade_pubkey,
|
||||||
@ -607,9 +604,9 @@ fn trader<T>(
|
|||||||
price,
|
price,
|
||||||
src,
|
src,
|
||||||
),
|
),
|
||||||
],
|
];
|
||||||
blockhash,
|
let message = Message::new(&instructions, Some(&owner_pubkey));
|
||||||
)
|
Transaction::new(&[owner.as_ref(), trade], message, blockhash)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@ -747,13 +744,9 @@ pub fn fund_keys<T: Client>(client: &T, source: &Keypair, dests: &[Arc<Keypair>]
|
|||||||
let mut to_fund_txs: Vec<_> = chunk
|
let mut to_fund_txs: Vec<_> = chunk
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.map(|(k, m)| {
|
.map(|(k, m)| {
|
||||||
(
|
let instructions = system_instruction::transfer_many(&k.pubkey(), &m);
|
||||||
k.clone(),
|
let message = Message::new(&instructions, Some(&k.pubkey()));
|
||||||
Transaction::new_unsigned_instructions(&system_instruction::transfer_many(
|
(k.clone(), Transaction::new_unsigned(message))
|
||||||
&k.pubkey(),
|
|
||||||
&m,
|
|
||||||
)),
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@ -848,9 +841,10 @@ pub fn create_token_accounts<T: Client>(
|
|||||||
);
|
);
|
||||||
let request_ix =
|
let request_ix =
|
||||||
exchange_instruction::account_request(owner_pubkey, &new_keypair.pubkey());
|
exchange_instruction::account_request(owner_pubkey, &new_keypair.pubkey());
|
||||||
|
let message = Message::new(&[create_ix, request_ix], Some(&owner_pubkey));
|
||||||
(
|
(
|
||||||
(from_keypair, new_keypair),
|
(from_keypair, new_keypair),
|
||||||
Transaction::new_unsigned_instructions(&[create_ix, request_ix]),
|
Transaction::new_unsigned(message),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -14,6 +14,7 @@ use solana_sdk::{
|
|||||||
commitment_config::CommitmentConfig,
|
commitment_config::CommitmentConfig,
|
||||||
fee_calculator::FeeCalculator,
|
fee_calculator::FeeCalculator,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
|
message::Message,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{Keypair, Signer},
|
signature::{Keypair, Signer},
|
||||||
system_instruction, system_transaction,
|
system_instruction, system_transaction,
|
||||||
@ -652,10 +653,9 @@ impl<'a> FundingTransactions<'a> for Vec<(&'a Keypair, Transaction)> {
|
|||||||
let to_fund_txs: Vec<(&Keypair, Transaction)> = to_fund
|
let to_fund_txs: Vec<(&Keypair, Transaction)> = to_fund
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.map(|(k, t)| {
|
.map(|(k, t)| {
|
||||||
let tx = Transaction::new_unsigned_instructions(
|
let instructions = system_instruction::transfer_many(&k.pubkey(), &t);
|
||||||
&system_instruction::transfer_many(&k.pubkey(), &t),
|
let message = Message::new(&instructions, Some(&k.pubkey()));
|
||||||
);
|
(*k, Transaction::new_unsigned(message))
|
||||||
(*k, tx)
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
make_txs.stop();
|
make_txs.stop();
|
||||||
@ -1023,11 +1023,9 @@ fn fund_move_keys<T: Client>(
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|key| (key.pubkey(), total / NUM_FUNDING_KEYS as u64))
|
.map(|key| (key.pubkey(), total / NUM_FUNDING_KEYS as u64))
|
||||||
.collect();
|
.collect();
|
||||||
let tx = Transaction::new_signed_instructions(
|
let instructions = system_instruction::transfer_many(&funding_key.pubkey(), &pubkey_amounts);
|
||||||
&[funding_key],
|
let message = Message::new(&instructions, Some(&funding_key.pubkey()));
|
||||||
&system_instruction::transfer_many(&funding_key.pubkey(), &pubkey_amounts),
|
let tx = Transaction::new(&[funding_key], message, blockhash);
|
||||||
blockhash,
|
|
||||||
);
|
|
||||||
client.send_message(&[funding_key], tx.message).unwrap();
|
client.send_message(&[funding_key], tx.message).unwrap();
|
||||||
let mut balance = 0;
|
let mut balance = 0;
|
||||||
for _ in 0..20 {
|
for _ in 0..20 {
|
||||||
|
@ -137,11 +137,11 @@ mod tests {
|
|||||||
let pubkey0 = Pubkey::new(&[0; 32]);
|
let pubkey0 = Pubkey::new(&[0; 32]);
|
||||||
let pubkey1 = Pubkey::new(&[1; 32]);
|
let pubkey1 = Pubkey::new(&[1; 32]);
|
||||||
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
||||||
let message0 = Message::new(&[ix0]);
|
let message0 = Message::new(&[ix0], Some(&pubkey0));
|
||||||
|
|
||||||
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
||||||
let ix1 = system_instruction::transfer(&pubkey1, &pubkey0, 1);
|
let ix1 = system_instruction::transfer(&pubkey1, &pubkey0, 1);
|
||||||
let message1 = Message::new(&[ix0, ix1]);
|
let message1 = Message::new(&[ix0, ix1], Some(&pubkey0));
|
||||||
|
|
||||||
let mut mocks = HashMap::new();
|
let mut mocks = HashMap::new();
|
||||||
mocks.insert(RpcRequest::GetBalance, account_balance_response.clone());
|
mocks.insert(RpcRequest::GetBalance, account_balance_response.clone());
|
||||||
@ -225,13 +225,13 @@ mod tests {
|
|||||||
let pubkey0 = Pubkey::new(&[0; 32]);
|
let pubkey0 = Pubkey::new(&[0; 32]);
|
||||||
let pubkey1 = Pubkey::new(&[1; 32]);
|
let pubkey1 = Pubkey::new(&[1; 32]);
|
||||||
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
||||||
let message0 = Message::new(&[ix0]);
|
let message0 = Message::new(&[ix0], Some(&pubkey0));
|
||||||
assert_eq!(calculate_fee(&fee_calculator, &[&message0]), 1);
|
assert_eq!(calculate_fee(&fee_calculator, &[&message0]), 1);
|
||||||
|
|
||||||
// Two messages, additive fees.
|
// Two messages, additive fees.
|
||||||
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
||||||
let ix1 = system_instruction::transfer(&pubkey1, &pubkey0, 1);
|
let ix1 = system_instruction::transfer(&pubkey1, &pubkey0, 1);
|
||||||
let message1 = Message::new(&[ix0, ix1]);
|
let message1 = Message::new(&[ix0, ix1], Some(&pubkey0));
|
||||||
assert_eq!(calculate_fee(&fee_calculator, &[&message0, &message1]), 3);
|
assert_eq!(calculate_fee(&fee_calculator, &[&message0, &message1]), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1377,7 +1377,7 @@ fn process_deploy(
|
|||||||
program_data.len() as u64,
|
program_data.len() as u64,
|
||||||
&bpf_loader::id(),
|
&bpf_loader::id(),
|
||||||
);
|
);
|
||||||
let message = Message::new(&[ix]);
|
let message = Message::new(&[ix], Some(&config.signers[0].pubkey()));
|
||||||
let mut create_account_tx = Transaction::new_unsigned(message);
|
let mut create_account_tx = Transaction::new_unsigned(message);
|
||||||
let signers = [config.signers[0], program_id];
|
let signers = [config.signers[0], program_id];
|
||||||
create_account_tx.try_sign(&signers, blockhash)?;
|
create_account_tx.try_sign(&signers, blockhash)?;
|
||||||
@ -1390,7 +1390,7 @@ fn process_deploy(
|
|||||||
(i * DATA_CHUNK_SIZE) as u32,
|
(i * DATA_CHUNK_SIZE) as u32,
|
||||||
chunk.to_vec(),
|
chunk.to_vec(),
|
||||||
);
|
);
|
||||||
let message = Message::new_with_payer(&[instruction], Some(&signers[0].pubkey()));
|
let message = Message::new(&[instruction], Some(&signers[0].pubkey()));
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&signers, blockhash)?;
|
tx.try_sign(&signers, blockhash)?;
|
||||||
write_transactions.push(tx);
|
write_transactions.push(tx);
|
||||||
@ -1400,7 +1400,7 @@ fn process_deploy(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let instruction = loader_instruction::finalize(&program_id.pubkey(), &bpf_loader::id());
|
let instruction = loader_instruction::finalize(&program_id.pubkey(), &bpf_loader::id());
|
||||||
let message = Message::new_with_payer(&[instruction], Some(&signers[0].pubkey()));
|
let message = Message::new(&[instruction], Some(&signers[0].pubkey()));
|
||||||
let mut finalize_tx = Transaction::new_unsigned(message);
|
let mut finalize_tx = Transaction::new_unsigned(message);
|
||||||
finalize_tx.try_sign(&signers, blockhash)?;
|
finalize_tx.try_sign(&signers, blockhash)?;
|
||||||
messages.push(&finalize_tx.message);
|
messages.push(&finalize_tx.message);
|
||||||
@ -1483,7 +1483,7 @@ fn process_pay(
|
|||||||
if let Some(nonce_account) = &nonce_account {
|
if let Some(nonce_account) = &nonce_account {
|
||||||
Message::new_with_nonce(vec![ix], None, nonce_account, &nonce_authority.pubkey())
|
Message::new_with_nonce(vec![ix], None, nonce_account, &nonce_authority.pubkey())
|
||||||
} else {
|
} else {
|
||||||
Message::new(&[ix])
|
Message::new(&[ix], Some(&config.signers[0].pubkey()))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1539,7 +1539,7 @@ fn process_pay(
|
|||||||
cancelable,
|
cancelable,
|
||||||
lamports,
|
lamports,
|
||||||
);
|
);
|
||||||
Message::new(&ixs)
|
Message::new(&ixs, Some(&config.signers[0].pubkey()))
|
||||||
};
|
};
|
||||||
let (message, _) = resolve_spend_tx_and_check_account_balance(
|
let (message, _) = resolve_spend_tx_and_check_account_balance(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
@ -1590,7 +1590,7 @@ fn process_pay(
|
|||||||
cancelable,
|
cancelable,
|
||||||
lamports,
|
lamports,
|
||||||
);
|
);
|
||||||
Message::new(&ixs)
|
Message::new(&ixs, Some(&config.signers[0].pubkey()))
|
||||||
};
|
};
|
||||||
let (message, _) = resolve_spend_tx_and_check_account_balance(
|
let (message, _) = resolve_spend_tx_and_check_account_balance(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
@ -1633,7 +1633,7 @@ fn process_cancel(rpc_client: &RpcClient, config: &CliConfig, pubkey: &Pubkey) -
|
|||||||
pubkey,
|
pubkey,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
);
|
);
|
||||||
let message = Message::new(&[ix]);
|
let message = Message::new(&[ix], Some(&config.signers[0].pubkey()));
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, blockhash)?;
|
tx.try_sign(&config.signers, blockhash)?;
|
||||||
check_account_for_fee_with_commitment(
|
check_account_for_fee_with_commitment(
|
||||||
@ -1663,7 +1663,7 @@ fn process_time_elapsed(
|
|||||||
.value;
|
.value;
|
||||||
|
|
||||||
let ix = budget_instruction::apply_timestamp(&config.signers[0].pubkey(), pubkey, to, dt);
|
let ix = budget_instruction::apply_timestamp(&config.signers[0].pubkey(), pubkey, to, dt);
|
||||||
let message = Message::new(&[ix]);
|
let message = Message::new(&[ix], Some(&config.signers[0].pubkey()));
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, blockhash)?;
|
tx.try_sign(&config.signers, blockhash)?;
|
||||||
check_account_for_fee_with_commitment(
|
check_account_for_fee_with_commitment(
|
||||||
@ -1714,7 +1714,7 @@ fn process_transfer(
|
|||||||
&nonce_authority.pubkey(),
|
&nonce_authority.pubkey(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Message::new_with_payer(&ixs, Some(&fee_payer.pubkey()))
|
Message::new(&ixs, Some(&fee_payer.pubkey()))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1765,7 +1765,7 @@ fn process_witness(
|
|||||||
.value;
|
.value;
|
||||||
|
|
||||||
let ix = budget_instruction::apply_signature(&config.signers[0].pubkey(), pubkey, to);
|
let ix = budget_instruction::apply_signature(&config.signers[0].pubkey(), pubkey, to);
|
||||||
let message = Message::new(&[ix]);
|
let message = Message::new(&[ix], Some(&config.signers[0].pubkey()));
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, blockhash)?;
|
tx.try_sign(&config.signers, blockhash)?;
|
||||||
check_account_for_fee_with_commitment(
|
check_account_for_fee_with_commitment(
|
||||||
|
@ -892,7 +892,7 @@ pub fn process_ping(
|
|||||||
|
|
||||||
let build_message = |lamports| {
|
let build_message = |lamports| {
|
||||||
let ix = system_instruction::transfer(&config.signers[0].pubkey(), &to, lamports);
|
let ix = system_instruction::transfer(&config.signers[0].pubkey(), &to, lamports);
|
||||||
Message::new(&[ix])
|
Message::new(&[ix], Some(&config.signers[0].pubkey()))
|
||||||
};
|
};
|
||||||
let (message, _) = resolve_spend_tx_and_check_account_balance(
|
let (message, _) = resolve_spend_tx_and_check_account_balance(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
|
@ -453,7 +453,7 @@ pub fn process_authorize_nonce_account(
|
|||||||
|
|
||||||
let nonce_authority = config.signers[nonce_authority];
|
let nonce_authority = config.signers[nonce_authority];
|
||||||
let ix = authorize_nonce_account(nonce_account, &nonce_authority.pubkey(), new_authority);
|
let ix = authorize_nonce_account(nonce_account, &nonce_authority.pubkey(), new_authority);
|
||||||
let message = Message::new_with_payer(&[ix], Some(&config.signers[0].pubkey()));
|
let message = Message::new(&[ix], Some(&config.signers[0].pubkey()));
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
|
|
||||||
@ -512,7 +512,7 @@ pub fn process_create_nonce_account(
|
|||||||
lamports,
|
lamports,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
Message::new_with_payer(&ixs, Some(&config.signers[0].pubkey()))
|
Message::new(&ixs, Some(&config.signers[0].pubkey()))
|
||||||
};
|
};
|
||||||
|
|
||||||
let (recent_blockhash, fee_calculator, _) = rpc_client
|
let (recent_blockhash, fee_calculator, _) = rpc_client
|
||||||
@ -600,7 +600,7 @@ pub fn process_new_nonce(
|
|||||||
let (recent_blockhash, fee_calculator, _) = rpc_client
|
let (recent_blockhash, fee_calculator, _) = rpc_client
|
||||||
.get_recent_blockhash_with_commitment(config.commitment)?
|
.get_recent_blockhash_with_commitment(config.commitment)?
|
||||||
.value;
|
.value;
|
||||||
let message = Message::new_with_payer(&[ix], Some(&config.signers[0].pubkey()));
|
let message = Message::new(&[ix], Some(&config.signers[0].pubkey()));
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
check_account_for_fee_with_commitment(
|
check_account_for_fee_with_commitment(
|
||||||
@ -667,7 +667,7 @@ pub fn process_withdraw_from_nonce_account(
|
|||||||
destination_account_pubkey,
|
destination_account_pubkey,
|
||||||
lamports,
|
lamports,
|
||||||
);
|
);
|
||||||
let message = Message::new_with_payer(&[ix], Some(&config.signers[0].pubkey()));
|
let message = Message::new(&[ix], Some(&config.signers[0].pubkey()));
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
check_account_for_fee_with_commitment(
|
check_account_for_fee_with_commitment(
|
||||||
|
@ -891,7 +891,7 @@ pub fn process_create_stake_account(
|
|||||||
&nonce_authority.pubkey(),
|
&nonce_authority.pubkey(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Message::new_with_payer(&ixs, Some(&fee_payer.pubkey()))
|
Message::new(&ixs, Some(&fee_payer.pubkey()))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -996,7 +996,7 @@ pub fn process_stake_authorize(
|
|||||||
&nonce_authority.pubkey(),
|
&nonce_authority.pubkey(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Message::new_with_payer(&ixs, Some(&fee_payer.pubkey()))
|
Message::new(&ixs, Some(&fee_payer.pubkey()))
|
||||||
};
|
};
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
|
|
||||||
@ -1056,7 +1056,7 @@ pub fn process_deactivate_stake_account(
|
|||||||
&nonce_authority.pubkey(),
|
&nonce_authority.pubkey(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Message::new_with_payer(&ixs, Some(&fee_payer.pubkey()))
|
Message::new(&ixs, Some(&fee_payer.pubkey()))
|
||||||
};
|
};
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
|
|
||||||
@ -1125,7 +1125,7 @@ pub fn process_withdraw_stake(
|
|||||||
&nonce_authority.pubkey(),
|
&nonce_authority.pubkey(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Message::new_with_payer(&ixs, Some(&fee_payer.pubkey()))
|
Message::new(&ixs, Some(&fee_payer.pubkey()))
|
||||||
};
|
};
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
|
|
||||||
@ -1265,7 +1265,7 @@ pub fn process_split_stake(
|
|||||||
&nonce_authority.pubkey(),
|
&nonce_authority.pubkey(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Message::new_with_payer(&ixs, Some(&fee_payer.pubkey()))
|
Message::new(&ixs, Some(&fee_payer.pubkey()))
|
||||||
};
|
};
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
|
|
||||||
@ -1364,7 +1364,7 @@ pub fn process_merge_stake(
|
|||||||
&nonce_authority.pubkey(),
|
&nonce_authority.pubkey(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Message::new_with_payer(&ixs, Some(&fee_payer.pubkey()))
|
Message::new(&ixs, Some(&fee_payer.pubkey()))
|
||||||
};
|
};
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
|
|
||||||
@ -1427,7 +1427,7 @@ pub fn process_stake_set_lockup(
|
|||||||
&nonce_authority.pubkey(),
|
&nonce_authority.pubkey(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Message::new_with_payer(&ixs, Some(&fee_payer.pubkey()))
|
Message::new(&ixs, Some(&fee_payer.pubkey()))
|
||||||
};
|
};
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
|
|
||||||
@ -1712,7 +1712,7 @@ pub fn process_delegate_stake(
|
|||||||
&nonce_authority.pubkey(),
|
&nonce_authority.pubkey(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Message::new_with_payer(&ixs, Some(&fee_payer.pubkey()))
|
Message::new(&ixs, Some(&fee_payer.pubkey()))
|
||||||
};
|
};
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
|
|
||||||
|
@ -346,7 +346,7 @@ pub fn process_set_validator_info(
|
|||||||
keys,
|
keys,
|
||||||
&validator_info,
|
&validator_info,
|
||||||
)]);
|
)]);
|
||||||
Message::new(&instructions)
|
Message::new(&instructions, Some(&config.signers[0].pubkey()))
|
||||||
} else {
|
} else {
|
||||||
println!(
|
println!(
|
||||||
"Updating Validator {:?} info at: {:?}",
|
"Updating Validator {:?} info at: {:?}",
|
||||||
@ -359,7 +359,7 @@ pub fn process_set_validator_info(
|
|||||||
keys,
|
keys,
|
||||||
&validator_info,
|
&validator_info,
|
||||||
)];
|
)];
|
||||||
Message::new_with_payer(&instructions, Some(&config.signers[0].pubkey()))
|
Message::new(&instructions, Some(&config.signers[0].pubkey()))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -469,7 +469,7 @@ pub fn process_create_vote_account(
|
|||||||
lamports,
|
lamports,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
Message::new(&ixs)
|
Message::new(&ixs, Some(&config.signers[0].pubkey()))
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Ok(response) =
|
if let Ok(response) =
|
||||||
@ -540,7 +540,7 @@ pub fn process_vote_authorize(
|
|||||||
vote_authorize, // vote or withdraw
|
vote_authorize, // vote or withdraw
|
||||||
)];
|
)];
|
||||||
|
|
||||||
let message = Message::new_with_payer(&ixs, Some(&config.signers[0].pubkey()));
|
let message = Message::new(&ixs, Some(&config.signers[0].pubkey()));
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
check_account_for_fee_with_commitment(
|
check_account_for_fee_with_commitment(
|
||||||
@ -580,7 +580,7 @@ pub fn process_vote_update_validator(
|
|||||||
&new_identity_pubkey,
|
&new_identity_pubkey,
|
||||||
)];
|
)];
|
||||||
|
|
||||||
let message = Message::new_with_payer(&ixs, Some(&config.signers[0].pubkey()));
|
let message = Message::new(&ixs, Some(&config.signers[0].pubkey()));
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
check_account_for_fee_with_commitment(
|
check_account_for_fee_with_commitment(
|
||||||
@ -614,7 +614,7 @@ pub fn process_vote_update_commission(
|
|||||||
commission,
|
commission,
|
||||||
)];
|
)];
|
||||||
|
|
||||||
let message = Message::new_with_payer(&ixs, Some(&config.signers[0].pubkey()));
|
let message = Message::new(&ixs, Some(&config.signers[0].pubkey()));
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
check_account_for_fee_with_commitment(
|
check_account_for_fee_with_commitment(
|
||||||
@ -743,7 +743,7 @@ pub fn process_withdraw_from_vote_account(
|
|||||||
destination_account_pubkey,
|
destination_account_pubkey,
|
||||||
);
|
);
|
||||||
|
|
||||||
let message = Message::new_with_payer(&[ix], Some(&config.signers[0].pubkey()));
|
let message = Message::new(&[ix], Some(&config.signers[0].pubkey()));
|
||||||
let mut transaction = Transaction::new_unsigned(message);
|
let mut transaction = Transaction::new_unsigned(message);
|
||||||
transaction.try_sign(&config.signers, recent_blockhash)?;
|
transaction.try_sign(&config.signers, recent_blockhash)?;
|
||||||
check_account_for_fee_with_commitment(
|
check_account_for_fee_with_commitment(
|
||||||
|
@ -336,7 +336,7 @@ impl SyncClient for ThinClient {
|
|||||||
keypair: &Keypair,
|
keypair: &Keypair,
|
||||||
instruction: Instruction,
|
instruction: Instruction,
|
||||||
) -> TransportResult<Signature> {
|
) -> TransportResult<Signature> {
|
||||||
let message = Message::new(&[instruction]);
|
let message = Message::new(&[instruction], Some(&keypair.pubkey()));
|
||||||
self.send_message(&[keypair], message)
|
self.send_message(&[keypair], message)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -574,7 +574,7 @@ impl AsyncClient for ThinClient {
|
|||||||
instruction: Instruction,
|
instruction: Instruction,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
) -> TransportResult<Signature> {
|
) -> TransportResult<Signature> {
|
||||||
let message = Message::new(&[instruction]);
|
let message = Message::new(&[instruction], Some(&keypair.pubkey()));
|
||||||
self.async_send_message(&[keypair], message, recent_blockhash)
|
self.async_send_message(&[keypair], message, recent_blockhash)
|
||||||
}
|
}
|
||||||
fn async_transfer(
|
fn async_transfer(
|
||||||
|
@ -19,6 +19,7 @@ use solana_perf::test_tx::test_tx;
|
|||||||
use solana_runtime::bank::Bank;
|
use solana_runtime::bank::Bank;
|
||||||
use solana_sdk::genesis_config::GenesisConfig;
|
use solana_sdk::genesis_config::GenesisConfig;
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
|
use solana_sdk::message::Message;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::Keypair;
|
use solana_sdk::signature::Keypair;
|
||||||
use solana_sdk::signature::Signature;
|
use solana_sdk::signature::Signature;
|
||||||
@ -116,9 +117,8 @@ fn make_programs_txs(txes: usize, hash: Hash) -> Vec<Transaction> {
|
|||||||
let to_key = Pubkey::new_rand();
|
let to_key = Pubkey::new_rand();
|
||||||
instructions.push(system_instruction::transfer(&from_key.pubkey(), &to_key, 1));
|
instructions.push(system_instruction::transfer(&from_key.pubkey(), &to_key, 1));
|
||||||
}
|
}
|
||||||
let mut new = Transaction::new_unsigned_instructions(&instructions);
|
let message = Message::new(&instructions, Some(&from_key.pubkey()));
|
||||||
new.sign(&[&from_key], hash);
|
Transaction::new(&[&from_key], message, hash)
|
||||||
new
|
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -1711,7 +1711,7 @@ pub mod tests {
|
|||||||
&leader_vote_keypair.pubkey(),
|
&leader_vote_keypair.pubkey(),
|
||||||
vote,
|
vote,
|
||||||
);
|
);
|
||||||
let vote_msg = Message::new_with_payer(&[vote_ix], Some(&leader_vote_keypair.pubkey()));
|
let vote_msg = Message::new(&[vote_ix], Some(&leader_vote_keypair.pubkey()));
|
||||||
let vote_tx = Transaction::new(&[&leader_vote_keypair], vote_msg, Hash::default());
|
let vote_tx = Transaction::new(&[&leader_vote_keypair], vote_msg, Hash::default());
|
||||||
let shreds = entries_to_test_shreds(
|
let shreds = entries_to_test_shreds(
|
||||||
vec![next_entry_mut(&mut Hash::default(), 0, vec![vote_tx])],
|
vec![next_entry_mut(&mut Hash::default(), 0, vec![vote_tx])],
|
||||||
@ -3425,7 +3425,7 @@ pub mod tests {
|
|||||||
bank.get_minimum_balance_for_rent_exemption(VoteState::size_of()),
|
bank.get_minimum_balance_for_rent_exemption(VoteState::size_of()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let message = Message::new_with_payer(&instructions, Some(&alice.pubkey()));
|
let message = Message::new(&instructions, Some(&alice.pubkey()));
|
||||||
let transaction = Transaction::new(
|
let transaction = Transaction::new(
|
||||||
&[&alice, &alice_vote_keypair],
|
&[&alice, &alice_vote_keypair],
|
||||||
message,
|
message,
|
||||||
|
@ -376,6 +376,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
|
message::Message,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{Keypair, Signer},
|
signature::{Keypair, Signer},
|
||||||
system_program, system_transaction,
|
system_program, system_transaction,
|
||||||
@ -571,11 +572,8 @@ mod tests {
|
|||||||
None,
|
None,
|
||||||
51,
|
51,
|
||||||
);
|
);
|
||||||
let tx = Transaction::new_signed_instructions(
|
let message = Message::new(&ixs, Some(&contract_funds.pubkey()));
|
||||||
&[&contract_funds, &contract_state],
|
let tx = Transaction::new(&[&contract_funds, &contract_state], message, blockhash);
|
||||||
&ixs,
|
|
||||||
blockhash,
|
|
||||||
);
|
|
||||||
process_transaction_and_notify(&bank_forks, &tx, &rpc.subscriptions, 1).unwrap();
|
process_transaction_and_notify(&bank_forks, &tx, &rpc.subscriptions, 1).unwrap();
|
||||||
sleep(Duration::from_millis(200));
|
sleep(Duration::from_millis(200));
|
||||||
|
|
||||||
@ -617,7 +615,8 @@ mod tests {
|
|||||||
&contract_state.pubkey(),
|
&contract_state.pubkey(),
|
||||||
&bob_pubkey,
|
&bob_pubkey,
|
||||||
);
|
);
|
||||||
let tx = Transaction::new_signed_instructions(&[&witness], &[ix], blockhash);
|
let message = Message::new(&[ix], Some(&witness.pubkey()));
|
||||||
|
let tx = Transaction::new(&[&witness], message, blockhash);
|
||||||
process_transaction_and_notify(&bank_forks, &tx, &rpc.subscriptions, 1).unwrap();
|
process_transaction_and_notify(&bank_forks, &tx, &rpc.subscriptions, 1).unwrap();
|
||||||
sleep(Duration::from_millis(200));
|
sleep(Duration::from_millis(200));
|
||||||
|
|
||||||
|
@ -125,9 +125,10 @@ impl Faucet {
|
|||||||
);
|
);
|
||||||
info!("Requesting airdrop of {} to {:?}", lamports, to);
|
info!("Requesting airdrop of {} to {:?}", lamports, to);
|
||||||
|
|
||||||
|
let mint_pubkey = self.mint_keypair.pubkey();
|
||||||
let create_instruction =
|
let create_instruction =
|
||||||
system_instruction::transfer(&self.mint_keypair.pubkey(), &to, lamports);
|
system_instruction::transfer(&mint_pubkey, &to, lamports);
|
||||||
let message = Message::new(&[create_instruction]);
|
let message = Message::new(&[create_instruction], Some(&mint_pubkey));
|
||||||
Ok(Transaction::new(&[&self.mint_keypair], message, blockhash))
|
Ok(Transaction::new(&[&self.mint_keypair], message, blockhash))
|
||||||
} else {
|
} else {
|
||||||
Err(Error::new(
|
Err(Error::new(
|
||||||
@ -413,7 +414,7 @@ mod tests {
|
|||||||
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let expected_instruction = system_instruction::transfer(&keypair.pubkey(), &to, lamports);
|
let expected_instruction = system_instruction::transfer(&keypair.pubkey(), &to, lamports);
|
||||||
let message = Message::new(&[expected_instruction]);
|
let message = Message::new(&[expected_instruction], Some(&keypair.pubkey()));
|
||||||
let expected_tx = Transaction::new(&[&keypair], message, blockhash);
|
let expected_tx = Transaction::new(&[&keypair], message, blockhash);
|
||||||
let expected_bytes = serialize(&expected_tx).unwrap();
|
let expected_bytes = serialize(&expected_tx).unwrap();
|
||||||
let mut expected_vec_with_length = vec![0; 2];
|
let mut expected_vec_with_length = vec![0; 2];
|
||||||
|
@ -16,7 +16,7 @@ fn test_local_faucet() {
|
|||||||
let lamports = 50;
|
let lamports = 50;
|
||||||
let blockhash = Hash::new(&to.as_ref());
|
let blockhash = Hash::new(&to.as_ref());
|
||||||
let create_instruction = system_instruction::transfer(&keypair.pubkey(), &to, lamports);
|
let create_instruction = system_instruction::transfer(&keypair.pubkey(), &to, lamports);
|
||||||
let message = Message::new(&[create_instruction]);
|
let message = Message::new(&[create_instruction], Some(&keypair.pubkey()));
|
||||||
let expected_tx = Transaction::new(&[&keypair], message, blockhash);
|
let expected_tx = Transaction::new(&[&keypair], message, blockhash);
|
||||||
|
|
||||||
let (sender, receiver) = channel();
|
let (sender, receiver) = channel();
|
||||||
|
@ -218,9 +218,9 @@ fn new_update_manifest(
|
|||||||
lamports,
|
lamports,
|
||||||
vec![], // additional keys
|
vec![], // additional keys
|
||||||
);
|
);
|
||||||
let mut transaction = Transaction::new_unsigned_instructions(&instructions);
|
let message = Message::new(&instructions, Some(&from_keypair.pubkey()));
|
||||||
let signers = [from_keypair, update_manifest_keypair];
|
let signers = [from_keypair, update_manifest_keypair];
|
||||||
transaction.sign(&signers, recent_blockhash);
|
let transaction = Transaction::new(&signers, message, recent_blockhash);
|
||||||
rpc_client.send_and_confirm_transaction(&transaction)?;
|
rpc_client.send_and_confirm_transaction(&transaction)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -243,7 +243,7 @@ fn store_update_manifest(
|
|||||||
update_manifest,
|
update_manifest,
|
||||||
);
|
);
|
||||||
|
|
||||||
let message = Message::new_with_payer(&[instruction], Some(&from_keypair.pubkey()));
|
let message = Message::new(&[instruction], Some(&from_keypair.pubkey()));
|
||||||
let transaction = Transaction::new(&signers, message, recent_blockhash);
|
let transaction = Transaction::new(&signers, message, recent_blockhash);
|
||||||
rpc_client.send_and_confirm_transaction(&transaction)?;
|
rpc_client.send_and_confirm_transaction(&transaction)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -592,11 +592,14 @@ fn do_main(matches: &ArgMatches<'_>) -> Result<(), Box<dyn error::Error>> {
|
|||||||
}
|
}
|
||||||
("verify", Some(matches)) => {
|
("verify", Some(matches)) => {
|
||||||
let keypair = get_keypair_from_matches(matches, config, &mut wallet_manager)?;
|
let keypair = get_keypair_from_matches(matches, config, &mut wallet_manager)?;
|
||||||
let simple_message = Message::new(&[Instruction::new(
|
let simple_message = Message::new(
|
||||||
|
&[Instruction::new(
|
||||||
Pubkey::default(),
|
Pubkey::default(),
|
||||||
&0,
|
&0,
|
||||||
vec![AccountMeta::new(keypair.pubkey(), true)],
|
vec![AccountMeta::new(keypair.pubkey(), true)],
|
||||||
)])
|
)],
|
||||||
|
Some(&keypair.pubkey()),
|
||||||
|
)
|
||||||
.serialize();
|
.serialize();
|
||||||
let signature = keypair.try_sign_message(&simple_message)?;
|
let signature = keypair.try_sign_message(&simple_message)?;
|
||||||
let pubkey_bs58 = matches.value_of("pubkey").unwrap();
|
let pubkey_bs58 = matches.value_of("pubkey").unwrap();
|
||||||
|
@ -5225,7 +5225,7 @@ pub mod tests {
|
|||||||
timestamp,
|
timestamp,
|
||||||
};
|
};
|
||||||
let vote_ix = vote_instruction::vote(&keypair.pubkey(), &keypair.pubkey(), vote);
|
let vote_ix = vote_instruction::vote(&keypair.pubkey(), &keypair.pubkey(), vote);
|
||||||
let vote_msg = Message::new_with_payer(&[vote_ix], Some(&keypair.pubkey()));
|
let vote_msg = Message::new(&[vote_ix], Some(&keypair.pubkey()));
|
||||||
let vote_tx = Transaction::new(&[keypair], vote_msg, Hash::default());
|
let vote_tx = Transaction::new(&[keypair], vote_msg, Hash::default());
|
||||||
|
|
||||||
vote_entries.push(next_entry_mut(&mut Hash::default(), 0, vec![vote_tx]));
|
vote_entries.push(next_entry_mut(&mut Hash::default(), 0, vec![vote_tx]));
|
||||||
|
@ -677,6 +677,7 @@ mod tests {
|
|||||||
use solana_budget_program::budget_instruction;
|
use solana_budget_program::budget_instruction;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
hash::{hash, Hash},
|
hash::{hash, Hash},
|
||||||
|
message::Message,
|
||||||
signature::{Keypair, Signer},
|
signature::{Keypair, Signer},
|
||||||
system_transaction,
|
system_transaction,
|
||||||
transaction::Transaction,
|
transaction::Transaction,
|
||||||
@ -687,19 +688,22 @@ mod tests {
|
|||||||
let budget_contract = Keypair::new();
|
let budget_contract = Keypair::new();
|
||||||
let budget_pubkey = budget_contract.pubkey();
|
let budget_pubkey = budget_contract.pubkey();
|
||||||
let ixs = budget_instruction::payment(&pubkey, &pubkey, &budget_pubkey, 1);
|
let ixs = budget_instruction::payment(&pubkey, &pubkey, &budget_pubkey, 1);
|
||||||
Transaction::new_signed_instructions(&[keypair, &budget_contract], &ixs, hash)
|
let message = Message::new(&ixs, Some(&pubkey));
|
||||||
|
Transaction::new(&[keypair, &budget_contract], message, hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_sample_timestamp(keypair: &Keypair, hash: Hash) -> Transaction {
|
fn create_sample_timestamp(keypair: &Keypair, hash: Hash) -> Transaction {
|
||||||
let pubkey = keypair.pubkey();
|
let pubkey = keypair.pubkey();
|
||||||
let ix = budget_instruction::apply_timestamp(&pubkey, &pubkey, &pubkey, Utc::now());
|
let ix = budget_instruction::apply_timestamp(&pubkey, &pubkey, &pubkey, Utc::now());
|
||||||
Transaction::new_signed_instructions(&[keypair], &[ix], hash)
|
let message = Message::new(&[ix], Some(&pubkey));
|
||||||
|
Transaction::new(&[keypair], message, hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_sample_apply_signature(keypair: &Keypair, hash: Hash) -> Transaction {
|
fn create_sample_apply_signature(keypair: &Keypair, hash: Hash) -> Transaction {
|
||||||
let pubkey = keypair.pubkey();
|
let pubkey = keypair.pubkey();
|
||||||
let ix = budget_instruction::apply_signature(&pubkey, &pubkey, &pubkey);
|
let ix = budget_instruction::apply_signature(&pubkey, &pubkey, &pubkey);
|
||||||
Transaction::new_signed_instructions(&[keypair], &[ix], hash)
|
let message = Message::new(&[ix], Some(&pubkey));
|
||||||
|
Transaction::new(&[keypair], message, hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -21,6 +21,7 @@ use solana_sdk::{
|
|||||||
commitment_config::CommitmentConfig,
|
commitment_config::CommitmentConfig,
|
||||||
epoch_schedule::EpochSchedule,
|
epoch_schedule::EpochSchedule,
|
||||||
genesis_config::{GenesisConfig, OperatingMode},
|
genesis_config::{GenesisConfig, OperatingMode},
|
||||||
|
message::Message,
|
||||||
poh_config::PohConfig,
|
poh_config::PohConfig,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{Keypair, Signer},
|
signature::{Keypair, Signer},
|
||||||
@ -407,9 +408,7 @@ impl LocalCluster {
|
|||||||
{
|
{
|
||||||
// 1) Create vote account
|
// 1) Create vote account
|
||||||
|
|
||||||
let mut transaction = Transaction::new_signed_instructions(
|
let instructions = vote_instruction::create_account(
|
||||||
&[from_account.as_ref(), vote_account],
|
|
||||||
&vote_instruction::create_account(
|
|
||||||
&from_account.pubkey(),
|
&from_account.pubkey(),
|
||||||
&vote_account_pubkey,
|
&vote_account_pubkey,
|
||||||
&VoteInit {
|
&VoteInit {
|
||||||
@ -419,7 +418,11 @@ impl LocalCluster {
|
|||||||
commission: 0,
|
commission: 0,
|
||||||
},
|
},
|
||||||
amount,
|
amount,
|
||||||
),
|
);
|
||||||
|
let message = Message::new(&instructions, Some(&from_account.pubkey()));
|
||||||
|
let mut transaction = Transaction::new(
|
||||||
|
&[from_account.as_ref(), vote_account],
|
||||||
|
message,
|
||||||
client
|
client
|
||||||
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -436,16 +439,18 @@ impl LocalCluster {
|
|||||||
)
|
)
|
||||||
.expect("get balance");
|
.expect("get balance");
|
||||||
|
|
||||||
let mut transaction = Transaction::new_signed_instructions(
|
let instructions = stake_instruction::create_account_and_delegate_stake(
|
||||||
&[from_account.as_ref(), &stake_account_keypair],
|
|
||||||
&stake_instruction::create_account_and_delegate_stake(
|
|
||||||
&from_account.pubkey(),
|
&from_account.pubkey(),
|
||||||
&stake_account_pubkey,
|
&stake_account_pubkey,
|
||||||
&vote_account_pubkey,
|
&vote_account_pubkey,
|
||||||
&Authorized::auto(&stake_account_pubkey),
|
&Authorized::auto(&stake_account_pubkey),
|
||||||
&Lockup::default(),
|
&Lockup::default(),
|
||||||
amount,
|
amount,
|
||||||
),
|
);
|
||||||
|
let message = Message::new(&instructions, Some(&from_account.pubkey()));
|
||||||
|
let mut transaction = Transaction::new(
|
||||||
|
&[from_account.as_ref(), &stake_account_keypair],
|
||||||
|
message,
|
||||||
client
|
client
|
||||||
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -308,7 +308,6 @@ mod bpf {
|
|||||||
result.unwrap_err().unwrap(),
|
result.unwrap_err().unwrap(),
|
||||||
TransactionError::InstructionError(0, InstructionError::MaxSeedLengthExceeded)
|
TransactionError::InstructionError(0, InstructionError::MaxSeedLengthExceeded)
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,10 +363,12 @@ mod bpf {
|
|||||||
let derived_key2 =
|
let derived_key2 =
|
||||||
Pubkey::create_program_address(&[b"Lil'", b"Bits"], &invoked_program_id).unwrap();
|
Pubkey::create_program_address(&[b"Lil'", b"Bits"], &invoked_program_id).unwrap();
|
||||||
let derived_key3 =
|
let derived_key3 =
|
||||||
Pubkey::create_program_address(&[derived_key2.as_ref()], &invoked_program_id).unwrap();
|
Pubkey::create_program_address(&[derived_key2.as_ref()], &invoked_program_id)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mint_pubkey = mint_keypair.pubkey();
|
||||||
let account_metas = vec![
|
let account_metas = vec![
|
||||||
AccountMeta::new(mint_keypair.pubkey(), true),
|
AccountMeta::new(mint_pubkey, true),
|
||||||
AccountMeta::new(argument_keypair.pubkey(), true),
|
AccountMeta::new(argument_keypair.pubkey(), true),
|
||||||
AccountMeta::new_readonly(invoked_program_id, false),
|
AccountMeta::new_readonly(invoked_program_id, false),
|
||||||
AccountMeta::new(invoked_argument_keypair.pubkey(), true),
|
AccountMeta::new(invoked_argument_keypair.pubkey(), true),
|
||||||
@ -384,7 +385,7 @@ mod bpf {
|
|||||||
|
|
||||||
let instruction =
|
let instruction =
|
||||||
Instruction::new(invoke_program_id, &TEST_SUCCESS, account_metas.clone());
|
Instruction::new(invoke_program_id, &TEST_SUCCESS, account_metas.clone());
|
||||||
let message = Message::new(&[instruction]);
|
let message = Message::new(&[instruction], Some(&mint_pubkey));
|
||||||
assert!(bank_client
|
assert!(bank_client
|
||||||
.send_message(
|
.send_message(
|
||||||
&[
|
&[
|
||||||
@ -404,7 +405,7 @@ mod bpf {
|
|||||||
&TEST_PRIVILEGE_ESCALATION_SIGNER,
|
&TEST_PRIVILEGE_ESCALATION_SIGNER,
|
||||||
account_metas.clone(),
|
account_metas.clone(),
|
||||||
);
|
);
|
||||||
let message = Message::new(&[instruction]);
|
let message = Message::new(&[instruction], Some(&mint_pubkey));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(
|
.send_message(
|
||||||
@ -426,7 +427,7 @@ mod bpf {
|
|||||||
&TEST_PRIVILEGE_ESCALATION_WRITABLE,
|
&TEST_PRIVILEGE_ESCALATION_WRITABLE,
|
||||||
account_metas.clone(),
|
account_metas.clone(),
|
||||||
);
|
);
|
||||||
let message = Message::new(&[instruction]);
|
let message = Message::new(&[instruction], Some(&mint_pubkey));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(
|
.send_message(
|
||||||
|
@ -774,7 +774,7 @@ fn call<'a>(
|
|||||||
ro_regions,
|
ro_regions,
|
||||||
)?;
|
)?;
|
||||||
verify_instruction(syscall, &instruction, &signers)?;
|
verify_instruction(syscall, &instruction, &signers)?;
|
||||||
let message = Message::new_with_payer(&[instruction], None);
|
let message = Message::new(&[instruction], None);
|
||||||
let callee_program_id_index = message.instructions[0].program_id_index as usize;
|
let callee_program_id_index = message.instructions[0].program_id_index as usize;
|
||||||
let callee_program_id = message.account_keys[callee_program_id_index];
|
let callee_program_id = message.account_keys[callee_program_id_index];
|
||||||
let (accounts, refs) = syscall.translate_accounts(
|
let (accounts, refs) = syscall.translate_accounts(
|
||||||
|
@ -256,7 +256,7 @@ mod tests {
|
|||||||
budget_instruction::payment(&alice_pubkey, &bob_pubkey, &budget_pubkey, 1);
|
budget_instruction::payment(&alice_pubkey, &bob_pubkey, &budget_pubkey, 1);
|
||||||
instructions[1].accounts = vec![]; // <!-- Attack! Prevent accounts from being passed into processor.
|
instructions[1].accounts = vec![]; // <!-- Attack! Prevent accounts from being passed into processor.
|
||||||
|
|
||||||
let message = Message::new(&instructions);
|
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||||
@ -276,7 +276,7 @@ mod tests {
|
|||||||
let budget_pubkey = budget_keypair.pubkey();
|
let budget_pubkey = budget_keypair.pubkey();
|
||||||
let instructions =
|
let instructions =
|
||||||
budget_instruction::payment(&alice_pubkey, &bob_pubkey, &budget_pubkey, 100);
|
budget_instruction::payment(&alice_pubkey, &bob_pubkey, &budget_pubkey, 100);
|
||||||
let message = Message::new(&instructions);
|
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -302,7 +302,7 @@ mod tests {
|
|||||||
None,
|
None,
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
let message = Message::new(&instructions);
|
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -315,7 +315,7 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let instruction =
|
let instruction =
|
||||||
budget_instruction::apply_signature(&mallory_pubkey, &budget_pubkey, &bob_pubkey);
|
budget_instruction::apply_signature(&mallory_pubkey, &budget_pubkey, &bob_pubkey);
|
||||||
let mut message = Message::new(&[instruction]);
|
let mut message = Message::new(&[instruction], Some(&mallory_pubkey));
|
||||||
|
|
||||||
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
||||||
message.account_keys.insert(3, alice_pubkey);
|
message.account_keys.insert(3, alice_pubkey);
|
||||||
@ -352,7 +352,7 @@ mod tests {
|
|||||||
None,
|
None,
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
let message = Message::new(&instructions);
|
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -365,7 +365,7 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let instruction =
|
let instruction =
|
||||||
budget_instruction::apply_timestamp(&mallory_pubkey, &budget_pubkey, &bob_pubkey, dt);
|
budget_instruction::apply_timestamp(&mallory_pubkey, &budget_pubkey, &bob_pubkey, dt);
|
||||||
let mut message = Message::new(&[instruction]);
|
let mut message = Message::new(&[instruction], Some(&mallory_pubkey));
|
||||||
|
|
||||||
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
||||||
message.account_keys.insert(3, alice_pubkey);
|
message.account_keys.insert(3, alice_pubkey);
|
||||||
@ -402,7 +402,7 @@ mod tests {
|
|||||||
None,
|
None,
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
let message = Message::new(&instructions);
|
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -472,7 +472,7 @@ mod tests {
|
|||||||
Some(alice_pubkey),
|
Some(alice_pubkey),
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
let message = Message::new(&instructions);
|
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -550,7 +550,7 @@ mod tests {
|
|||||||
game_hash,
|
game_hash,
|
||||||
41,
|
41,
|
||||||
);
|
);
|
||||||
let message = Message::new(&instructions);
|
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -570,7 +570,7 @@ mod tests {
|
|||||||
|
|
||||||
// Anyone can sign the message, but presumably it's Bob, since he's the
|
// Anyone can sign the message, but presumably it's Bob, since he's the
|
||||||
// one claiming the payout.
|
// one claiming the payout.
|
||||||
let message = Message::new_with_payer(&[instruction], Some(&bob_pubkey));
|
let message = Message::new(&[instruction], Some(&bob_pubkey));
|
||||||
bank_client.send_message(&[&bob_keypair], message).unwrap();
|
bank_client.send_message(&[&bob_keypair], message).unwrap();
|
||||||
|
|
||||||
assert_eq!(bank_client.get_balance(&alice_pubkey).unwrap(), 0);
|
assert_eq!(bank_client.get_balance(&alice_pubkey).unwrap(), 0);
|
||||||
|
@ -604,7 +604,10 @@ mod test {
|
|||||||
);
|
);
|
||||||
|
|
||||||
client
|
client
|
||||||
.send_message(&[owner, &new], Message::new(&[instruction]))
|
.send_message(
|
||||||
|
&[owner, &new],
|
||||||
|
Message::new(&[instruction], Some(&owner.pubkey())),
|
||||||
|
)
|
||||||
.unwrap_or_else(|_| panic!("{}:{}", line!(), file!()));
|
.unwrap_or_else(|_| panic!("{}:{}", line!(), file!()));
|
||||||
new.pubkey()
|
new.pubkey()
|
||||||
}
|
}
|
||||||
|
@ -30,11 +30,14 @@ pub fn create_genesis<T: Client>(from: &Keypair, client: &T, amount: u64) -> Key
|
|||||||
);
|
);
|
||||||
|
|
||||||
client
|
client
|
||||||
.send_message(&[&from, &genesis], Message::new(&[instruction]))
|
.send_message(
|
||||||
|
&[&from, &genesis],
|
||||||
|
Message::new(&[instruction], Some(&from.pubkey())),
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let instruction = librapay_instruction::genesis(&genesis.pubkey(), amount);
|
let instruction = librapay_instruction::genesis(&genesis.pubkey(), amount);
|
||||||
let message = Message::new_with_payer(&[instruction], Some(&from.pubkey()));
|
let message = Message::new(&[instruction], Some(&from.pubkey()));
|
||||||
client.send_message(&[from, &genesis], message).unwrap();
|
client.send_message(&[from, &genesis], message).unwrap();
|
||||||
|
|
||||||
genesis
|
genesis
|
||||||
|
@ -8,6 +8,7 @@ use solana_sdk::{
|
|||||||
client::Client,
|
client::Client,
|
||||||
commitment_config::CommitmentConfig,
|
commitment_config::CommitmentConfig,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
|
message::Message,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{Keypair, Signer},
|
signature::{Keypair, Signer},
|
||||||
system_instruction,
|
system_instruction,
|
||||||
@ -87,7 +88,8 @@ pub fn create_accounts(
|
|||||||
|
|
||||||
let mut from_signers = vec![from_keypair];
|
let mut from_signers = vec![from_keypair];
|
||||||
from_signers.extend_from_slice(to_keypair);
|
from_signers.extend_from_slice(to_keypair);
|
||||||
Transaction::new_signed_instructions(&from_signers, &instructions, recent_blockhash)
|
let message = Message::new(&instructions, Some(&from_keypair.pubkey()));
|
||||||
|
Transaction::new(&from_signers, message, recent_blockhash)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_account(
|
pub fn create_account(
|
||||||
|
@ -93,7 +93,7 @@ mod tests {
|
|||||||
owner_pubkey,
|
owner_pubkey,
|
||||||
lamports,
|
lamports,
|
||||||
);
|
);
|
||||||
let message = Message::new(&instructions);
|
let message = Message::new(&instructions, Some(&payer_keypair.pubkey()));
|
||||||
bank_client.send_message(&[payer_keypair, account_keypair], message)
|
bank_client.send_message(&[payer_keypair, account_keypair], message)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ mod tests {
|
|||||||
&old_owner_keypair.pubkey(),
|
&old_owner_keypair.pubkey(),
|
||||||
new_owner_pubkey,
|
new_owner_pubkey,
|
||||||
);
|
);
|
||||||
let message = Message::new_with_payer(&[instruction], Some(&payer_keypair.pubkey()));
|
let message = Message::new(&[instruction], Some(&payer_keypair.pubkey()));
|
||||||
bank_client.send_message(&[payer_keypair, old_owner_keypair], message)
|
bank_client.send_message(&[payer_keypair, old_owner_keypair], message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ mod tests {
|
|||||||
date_instruction::create_account(&payer_keypair.pubkey(), &date_pubkey, 1);
|
date_instruction::create_account(&payer_keypair.pubkey(), &date_pubkey, 1);
|
||||||
instructions.push(date_instruction::store(&date_pubkey, date));
|
instructions.push(date_instruction::store(&date_pubkey, date));
|
||||||
|
|
||||||
let message = Message::new(&instructions);
|
let message = Message::new(&instructions, Some(&payer_keypair.pubkey()));
|
||||||
bank_client.send_message(&[payer_keypair, date_keypair], message)
|
bank_client.send_message(&[payer_keypair, date_keypair], message)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ mod tests {
|
|||||||
) -> Result<Signature> {
|
) -> Result<Signature> {
|
||||||
let date_pubkey = date_keypair.pubkey();
|
let date_pubkey = date_keypair.pubkey();
|
||||||
let instruction = date_instruction::store(&date_pubkey, date);
|
let instruction = date_instruction::store(&date_pubkey, date);
|
||||||
let message = Message::new_with_payer(&[instruction], Some(&payer_keypair.pubkey()));
|
let message = Message::new(&[instruction], Some(&payer_keypair.pubkey()));
|
||||||
bank_client.send_message(&[payer_keypair, date_keypair], message)
|
bank_client.send_message(&[payer_keypair, date_keypair], message)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ mod tests {
|
|||||||
&date_pubkey,
|
&date_pubkey,
|
||||||
lamports,
|
lamports,
|
||||||
);
|
);
|
||||||
let message = Message::new(&instructions);
|
let message = Message::new(&instructions, Some(&payer_keypair.pubkey()));
|
||||||
bank_client.send_message(&[payer_keypair, contract_keypair], message)
|
bank_client.send_message(&[payer_keypair, contract_keypair], message)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +253,7 @@ mod tests {
|
|||||||
) -> Result<Signature> {
|
) -> Result<Signature> {
|
||||||
let instruction =
|
let instruction =
|
||||||
vest_instruction::redeem_tokens(&contract_pubkey, &date_pubkey, &payee_pubkey);
|
vest_instruction::redeem_tokens(&contract_pubkey, &date_pubkey, &payee_pubkey);
|
||||||
let message = Message::new_with_payer(&[instruction], Some(&payer_keypair.pubkey()));
|
let message = Message::new(&[instruction], Some(&payer_keypair.pubkey()));
|
||||||
bank_client.send_message(&[payer_keypair], message)
|
bank_client.send_message(&[payer_keypair], message)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,7 +349,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
instructions[1].accounts = vec![]; // <!-- Attack! Prevent accounts from being passed into processor.
|
instructions[1].accounts = vec![]; // <!-- Attack! Prevent accounts from being passed into processor.
|
||||||
|
|
||||||
let message = Message::new(&instructions);
|
let message = Message::new(&instructions, Some(&alice_keypair.pubkey()));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&alice_keypair, &contract_keypair], message)
|
.send_message(&[&alice_keypair, &contract_keypair], message)
|
||||||
|
@ -5,6 +5,7 @@ use solana_notifier::Notifier;
|
|||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
clock::Slot,
|
clock::Slot,
|
||||||
epoch_schedule::EpochSchedule,
|
epoch_schedule::EpochSchedule,
|
||||||
|
message::Message,
|
||||||
native_token::sol_to_lamports,
|
native_token::sol_to_lamports,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{Keypair, Signer},
|
signature::{Keypair, Signer},
|
||||||
@ -138,16 +139,18 @@ fn delegate_stake(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let transaction = Transaction::new_signed_instructions(
|
let instructions = stake_instruction::create_account_and_delegate_stake(
|
||||||
&[faucet_keypair, &stake_account_keypair],
|
|
||||||
&stake_instruction::create_account_and_delegate_stake(
|
|
||||||
&faucet_keypair.pubkey(),
|
&faucet_keypair.pubkey(),
|
||||||
&stake_account_keypair.pubkey(),
|
&stake_account_keypair.pubkey(),
|
||||||
&vote_account_pubkey,
|
&vote_account_pubkey,
|
||||||
&StakeAuthorized::auto(&faucet_keypair.pubkey()),
|
&StakeAuthorized::auto(&faucet_keypair.pubkey()),
|
||||||
&Lockup::default(),
|
&Lockup::default(),
|
||||||
sol_to_lamports(sol_gift as f64),
|
sol_to_lamports(sol_gift as f64),
|
||||||
),
|
);
|
||||||
|
let message = Message::new(&instructions, Some(&faucet_keypair.pubkey()));
|
||||||
|
let transaction = Transaction::new(
|
||||||
|
&[faucet_keypair, &stake_account_keypair],
|
||||||
|
message,
|
||||||
recent_blockhash,
|
recent_blockhash,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ use solana_sdk::{
|
|||||||
clock::MAX_RECENT_BLOCKHASHES,
|
clock::MAX_RECENT_BLOCKHASHES,
|
||||||
genesis_config::create_genesis_config,
|
genesis_config::create_genesis_config,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
|
message::Message,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{Keypair, Signer},
|
signature::{Keypair, Signer},
|
||||||
transaction::Transaction,
|
transaction::Transaction,
|
||||||
@ -52,7 +53,8 @@ pub fn create_builtin_transactions(
|
|||||||
|
|
||||||
let instruction = create_invoke_instruction(rando0.pubkey(), program_id, &1u8);
|
let instruction = create_invoke_instruction(rando0.pubkey(), program_id, &1u8);
|
||||||
let (blockhash, _fee_calculator) = bank_client.get_recent_blockhash().unwrap();
|
let (blockhash, _fee_calculator) = bank_client.get_recent_blockhash().unwrap();
|
||||||
Transaction::new_signed_instructions(&[&rando0], &[instruction], blockhash)
|
let message = Message::new(&[instruction], Some(&mint_keypair.pubkey()));
|
||||||
|
Transaction::new(&[&rando0], message, blockhash)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
@ -73,7 +75,8 @@ pub fn create_native_loader_transactions(
|
|||||||
|
|
||||||
let instruction = create_invoke_instruction(rando0.pubkey(), program_id, &1u8);
|
let instruction = create_invoke_instruction(rando0.pubkey(), program_id, &1u8);
|
||||||
let (blockhash, _fee_calculator) = bank_client.get_recent_blockhash().unwrap();
|
let (blockhash, _fee_calculator) = bank_client.get_recent_blockhash().unwrap();
|
||||||
Transaction::new_signed_instructions(&[&rando0], &[instruction], blockhash)
|
let message = Message::new(&[instruction], Some(&mint_keypair.pubkey()));
|
||||||
|
Transaction::new(&[&rando0], message, blockhash)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -4273,11 +4273,8 @@ mod tests {
|
|||||||
let bank = Bank::new(&genesis_config);
|
let bank = Bank::new(&genesis_config);
|
||||||
let instructions =
|
let instructions =
|
||||||
system_instruction::transfer_many(&mint_keypair.pubkey(), &[(key1, 1), (key2, 1)]);
|
system_instruction::transfer_many(&mint_keypair.pubkey(), &[(key1, 1), (key2, 1)]);
|
||||||
let tx = Transaction::new_signed_instructions(
|
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
|
||||||
&[&mint_keypair],
|
let tx = Transaction::new(&[&mint_keypair], message, genesis_config.hash());
|
||||||
&instructions,
|
|
||||||
genesis_config.hash(),
|
|
||||||
);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.process_transaction(&tx).unwrap_err(),
|
bank.process_transaction(&tx).unwrap_err(),
|
||||||
TransactionError::InstructionError(
|
TransactionError::InstructionError(
|
||||||
@ -4298,11 +4295,8 @@ mod tests {
|
|||||||
let bank = Bank::new(&genesis_config);
|
let bank = Bank::new(&genesis_config);
|
||||||
let instructions =
|
let instructions =
|
||||||
system_instruction::transfer_many(&mint_keypair.pubkey(), &[(key1, 1), (key2, 1)]);
|
system_instruction::transfer_many(&mint_keypair.pubkey(), &[(key1, 1), (key2, 1)]);
|
||||||
let tx = Transaction::new_signed_instructions(
|
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
|
||||||
&[&mint_keypair],
|
let tx = Transaction::new(&[&mint_keypair], message, genesis_config.hash());
|
||||||
&instructions,
|
|
||||||
genesis_config.hash(),
|
|
||||||
);
|
|
||||||
bank.process_transaction(&tx).unwrap();
|
bank.process_transaction(&tx).unwrap();
|
||||||
assert_eq!(bank.get_balance(&mint_keypair.pubkey()), 0);
|
assert_eq!(bank.get_balance(&mint_keypair.pubkey()), 0);
|
||||||
assert_eq!(bank.get_balance(&key1), 1);
|
assert_eq!(bank.get_balance(&key1), 1);
|
||||||
@ -5452,7 +5446,7 @@ mod tests {
|
|||||||
let mut transfer_instruction =
|
let mut transfer_instruction =
|
||||||
system_instruction::transfer(&mint_keypair.pubkey(), &key.pubkey(), 0);
|
system_instruction::transfer(&mint_keypair.pubkey(), &key.pubkey(), 0);
|
||||||
transfer_instruction.accounts[0].is_signer = false;
|
transfer_instruction.accounts[0].is_signer = false;
|
||||||
let message = Message::new_with_payer(&[transfer_instruction], None);
|
let message = Message::new(&[transfer_instruction], None);
|
||||||
let tx = Transaction::new(&[&Keypair::new(); 0], message, bank.last_blockhash());
|
let tx = Transaction::new(&[&Keypair::new(); 0], message, bank.last_blockhash());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -5633,9 +5627,10 @@ mod tests {
|
|||||||
10,
|
10,
|
||||||
);
|
);
|
||||||
|
|
||||||
let transaction = Transaction::new_signed_instructions(
|
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
|
||||||
|
let transaction = Transaction::new(
|
||||||
&[&mint_keypair, &vote_keypair],
|
&[&mint_keypair, &vote_keypair],
|
||||||
&instructions,
|
message,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -5690,9 +5685,10 @@ mod tests {
|
|||||||
10,
|
10,
|
||||||
));
|
));
|
||||||
|
|
||||||
let transaction = Transaction::new_signed_instructions(
|
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
|
||||||
|
let transaction = Transaction::new(
|
||||||
&[&mint_keypair, &vote_keypair, &stake_keypair],
|
&[&mint_keypair, &vote_keypair, &stake_keypair],
|
||||||
&instructions,
|
message,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -5889,9 +5885,10 @@ mod tests {
|
|||||||
);
|
);
|
||||||
instructions[1].program_id = mock_vote_program_id();
|
instructions[1].program_id = mock_vote_program_id();
|
||||||
|
|
||||||
let transaction = Transaction::new_signed_instructions(
|
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
|
||||||
|
let transaction = Transaction::new(
|
||||||
&[&mint_keypair, &mock_account, &mock_validator_identity],
|
&[&mint_keypair, &mock_account, &mock_validator_identity],
|
||||||
&instructions,
|
message,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -5933,9 +5930,10 @@ mod tests {
|
|||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
|
|
||||||
let transaction = Transaction::new_signed_instructions(
|
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
|
||||||
|
let transaction = Transaction::new(
|
||||||
&[&mint_keypair, &mock_account, &mock_validator_identity],
|
&[&mint_keypair, &mock_account, &mock_validator_identity],
|
||||||
&instructions,
|
message,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -6123,9 +6121,10 @@ mod tests {
|
|||||||
&nonce_authority,
|
&nonce_authority,
|
||||||
nonce_lamports,
|
nonce_lamports,
|
||||||
));
|
));
|
||||||
let setup_tx = Transaction::new_signed_instructions(
|
let message = Message::new(&setup_ixs, Some(&mint_keypair.pubkey()));
|
||||||
|
let setup_tx = Transaction::new(
|
||||||
&[mint_keypair, &custodian_keypair, &nonce_keypair],
|
&[mint_keypair, &custodian_keypair, &nonce_keypair],
|
||||||
&setup_ixs,
|
message,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
);
|
);
|
||||||
bank.process_transaction(&setup_tx)?;
|
bank.process_transaction(&setup_tx)?;
|
||||||
@ -6286,14 +6285,9 @@ mod tests {
|
|||||||
let blockhash = bank.last_blockhash();
|
let blockhash = bank.last_blockhash();
|
||||||
bank.store_account(&nonce.pubkey(), &nonce_account);
|
bank.store_account(&nonce.pubkey(), &nonce_account);
|
||||||
|
|
||||||
let tx = Transaction::new_signed_instructions(
|
let ix = system_instruction::assign(&nonce.pubkey(), &Pubkey::new(&[9u8; 32]));
|
||||||
&[&nonce],
|
let message = Message::new(&[ix], Some(&nonce.pubkey()));
|
||||||
&[system_instruction::assign(
|
let tx = Transaction::new(&[&nonce], message, blockhash);
|
||||||
&nonce.pubkey(),
|
|
||||||
&Pubkey::new(&[9u8; 32]),
|
|
||||||
)],
|
|
||||||
blockhash,
|
|
||||||
);
|
|
||||||
|
|
||||||
let expect = Err(TransactionError::InstructionError(
|
let expect = Err(TransactionError::InstructionError(
|
||||||
0,
|
0,
|
||||||
|
@ -60,7 +60,7 @@ impl AsyncClient for BankClient {
|
|||||||
instruction: Instruction,
|
instruction: Instruction,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
) -> Result<Signature> {
|
) -> Result<Signature> {
|
||||||
let message = Message::new(&[instruction]);
|
let message = Message::new(&[instruction], Some(&keypair.pubkey()));
|
||||||
self.async_send_message(&[keypair], message, recent_blockhash)
|
self.async_send_message(&[keypair], message, recent_blockhash)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ impl SyncClient for BankClient {
|
|||||||
|
|
||||||
/// Create and process a transaction from a single instruction.
|
/// Create and process a transaction from a single instruction.
|
||||||
fn send_instruction(&self, keypair: &Keypair, instruction: Instruction) -> Result<Signature> {
|
fn send_instruction(&self, keypair: &Keypair, instruction: Instruction) -> Result<Signature> {
|
||||||
let message = Message::new(&[instruction]);
|
let message = Message::new(&[instruction], Some(&keypair.pubkey()));
|
||||||
self.send_message(&[keypair], message)
|
self.send_message(&[keypair], message)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,7 +306,7 @@ mod tests {
|
|||||||
.accounts
|
.accounts
|
||||||
.push(AccountMeta::new(jane_pubkey, true));
|
.push(AccountMeta::new(jane_pubkey, true));
|
||||||
|
|
||||||
let message = Message::new(&[transfer_instruction]);
|
let message = Message::new(&[transfer_instruction], Some(&john_pubkey));
|
||||||
bank_client.send_message(&doe_keypairs, message).unwrap();
|
bank_client.send_message(&doe_keypairs, message).unwrap();
|
||||||
assert_eq!(bank_client.get_balance(&bob_pubkey).unwrap(), 42);
|
assert_eq!(bank_client.get_balance(&bob_pubkey).unwrap(), 42);
|
||||||
}
|
}
|
||||||
|
@ -906,7 +906,7 @@ mod tests {
|
|||||||
.transfer(50, &mint_keypair, &alice_pubkey)
|
.transfer(50, &mint_keypair, &alice_pubkey)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let allocate_with_seed = Message::new_with_payer(
|
let allocate_with_seed = Message::new(
|
||||||
&[system_instruction::allocate_with_seed(
|
&[system_instruction::allocate_with_seed(
|
||||||
&alice_with_seed,
|
&alice_with_seed,
|
||||||
&alice_pubkey,
|
&alice_pubkey,
|
||||||
@ -959,7 +959,7 @@ mod tests {
|
|||||||
let bank = Arc::new(Bank::new_from_parent(&bank, &collector, bank.slot() + 1));
|
let bank = Arc::new(Bank::new_from_parent(&bank, &collector, bank.slot() + 1));
|
||||||
let bank_client = BankClient::new_shared(&bank);
|
let bank_client = BankClient::new_shared(&bank);
|
||||||
let ix = system_instruction::create_account(&alice_pubkey, &bob_pubkey, 0, len1, &program);
|
let ix = system_instruction::create_account(&alice_pubkey, &bob_pubkey, 0, len1, &program);
|
||||||
let message = Message::new(&[ix]);
|
let message = Message::new(&[ix], Some(&alice_pubkey));
|
||||||
let r = bank_client.send_message(&[&alice_keypair, &bob_keypair], message);
|
let r = bank_client.send_message(&[&alice_keypair, &bob_keypair], message);
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok());
|
||||||
|
|
||||||
@ -977,7 +977,7 @@ mod tests {
|
|||||||
let bank = Arc::new(Bank::new_from_parent(&bank, &collector, bank.slot() + 1));
|
let bank = Arc::new(Bank::new_from_parent(&bank, &collector, bank.slot() + 1));
|
||||||
let bank_client = BankClient::new_shared(&bank);
|
let bank_client = BankClient::new_shared(&bank);
|
||||||
let ix = system_instruction::create_account(&alice_pubkey, &bob_pubkey, 1, len2, &program);
|
let ix = system_instruction::create_account(&alice_pubkey, &bob_pubkey, 1, len2, &program);
|
||||||
let message = Message::new(&[ix]);
|
let message = Message::new(&[ix], Some(&alice_pubkey));
|
||||||
let r = bank_client.send_message(&[&alice_keypair, &bob_keypair], message);
|
let r = bank_client.send_message(&[&alice_keypair, &bob_keypair], message);
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok());
|
||||||
}
|
}
|
||||||
@ -1016,7 +1016,7 @@ mod tests {
|
|||||||
.transfer(50, &mint_keypair, &alice_pubkey)
|
.transfer(50, &mint_keypair, &alice_pubkey)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let assign_with_seed = Message::new_with_payer(
|
let assign_with_seed = Message::new(
|
||||||
&[system_instruction::assign_with_seed(
|
&[system_instruction::assign_with_seed(
|
||||||
&alice_with_seed,
|
&alice_with_seed,
|
||||||
&alice_pubkey,
|
&alice_pubkey,
|
||||||
|
@ -28,7 +28,7 @@ pub fn load_program<T: Client>(
|
|||||||
bank_client
|
bank_client
|
||||||
.send_message(
|
.send_message(
|
||||||
&[from_keypair, &program_keypair],
|
&[from_keypair, &program_keypair],
|
||||||
Message::new(&[instruction]),
|
Message::new(&[instruction], Some(&from_keypair.pubkey())),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ pub fn load_program<T: Client>(
|
|||||||
for chunk in program.chunks(chunk_size) {
|
for chunk in program.chunks(chunk_size) {
|
||||||
let instruction =
|
let instruction =
|
||||||
loader_instruction::write(&program_pubkey, loader_pubkey, offset, chunk.to_vec());
|
loader_instruction::write(&program_pubkey, loader_pubkey, offset, chunk.to_vec());
|
||||||
let message = Message::new_with_payer(&[instruction], Some(&from_keypair.pubkey()));
|
let message = Message::new(&[instruction], Some(&from_keypair.pubkey()));
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[from_keypair, &program_keypair], message)
|
.send_message(&[from_keypair, &program_keypair], message)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -45,7 +45,7 @@ pub fn load_program<T: Client>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let instruction = loader_instruction::finalize(&program_pubkey, loader_pubkey);
|
let instruction = loader_instruction::finalize(&program_pubkey, loader_pubkey);
|
||||||
let message = Message::new_with_payer(&[instruction], Some(&from_keypair.pubkey()));
|
let message = Message::new(&[instruction], Some(&from_keypair.pubkey()));
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[from_keypair, &program_keypair], message)
|
.send_message(&[from_keypair, &program_keypair], message)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -606,7 +606,7 @@ mod tests {
|
|||||||
AccountMeta::new(keys[not_owned_index], false),
|
AccountMeta::new(keys[not_owned_index], false),
|
||||||
AccountMeta::new(keys[owned_index], false),
|
AccountMeta::new(keys[owned_index], false),
|
||||||
];
|
];
|
||||||
let message = Message::new_with_payer(
|
let message = Message::new(
|
||||||
&[Instruction::new(program_ids[owned_index], &[0_u8], metas)],
|
&[Instruction::new(program_ids[owned_index], &[0_u8], metas)],
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
@ -1103,11 +1103,14 @@ mod tests {
|
|||||||
AccountMeta::new(from_pubkey, true),
|
AccountMeta::new(from_pubkey, true),
|
||||||
AccountMeta::new_readonly(to_pubkey, false),
|
AccountMeta::new_readonly(to_pubkey, false),
|
||||||
];
|
];
|
||||||
let message = Message::new(&[Instruction::new(
|
let message = Message::new(
|
||||||
|
&[Instruction::new(
|
||||||
mock_system_program_id,
|
mock_system_program_id,
|
||||||
&MockSystemInstruction::Correct,
|
&MockSystemInstruction::Correct,
|
||||||
account_metas.clone(),
|
account_metas.clone(),
|
||||||
)]);
|
)],
|
||||||
|
Some(&from_pubkey),
|
||||||
|
);
|
||||||
|
|
||||||
let result =
|
let result =
|
||||||
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
||||||
@ -1115,11 +1118,14 @@ mod tests {
|
|||||||
assert_eq!(accounts[0].borrow().lamports, 100);
|
assert_eq!(accounts[0].borrow().lamports, 100);
|
||||||
assert_eq!(accounts[1].borrow().lamports, 0);
|
assert_eq!(accounts[1].borrow().lamports, 0);
|
||||||
|
|
||||||
let message = Message::new(&[Instruction::new(
|
let message = Message::new(
|
||||||
|
&[Instruction::new(
|
||||||
mock_system_program_id,
|
mock_system_program_id,
|
||||||
&MockSystemInstruction::AttemptCredit { lamports: 50 },
|
&MockSystemInstruction::AttemptCredit { lamports: 50 },
|
||||||
account_metas.clone(),
|
account_metas.clone(),
|
||||||
)]);
|
)],
|
||||||
|
Some(&from_pubkey),
|
||||||
|
);
|
||||||
|
|
||||||
let result =
|
let result =
|
||||||
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
||||||
@ -1131,11 +1137,14 @@ mod tests {
|
|||||||
))
|
))
|
||||||
);
|
);
|
||||||
|
|
||||||
let message = Message::new(&[Instruction::new(
|
let message = Message::new(
|
||||||
|
&[Instruction::new(
|
||||||
mock_system_program_id,
|
mock_system_program_id,
|
||||||
&MockSystemInstruction::AttemptDataChange { data: 50 },
|
&MockSystemInstruction::AttemptDataChange { data: 50 },
|
||||||
account_metas,
|
account_metas,
|
||||||
)]);
|
)],
|
||||||
|
Some(&from_pubkey),
|
||||||
|
);
|
||||||
|
|
||||||
let result =
|
let result =
|
||||||
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
||||||
@ -1229,11 +1238,14 @@ mod tests {
|
|||||||
];
|
];
|
||||||
|
|
||||||
// Try to borrow mut the same account
|
// Try to borrow mut the same account
|
||||||
let message = Message::new(&[Instruction::new(
|
let message = Message::new(
|
||||||
|
&[Instruction::new(
|
||||||
mock_program_id,
|
mock_program_id,
|
||||||
&MockSystemInstruction::BorrowFail,
|
&MockSystemInstruction::BorrowFail,
|
||||||
account_metas.clone(),
|
account_metas.clone(),
|
||||||
)]);
|
)],
|
||||||
|
Some(&from_pubkey),
|
||||||
|
);
|
||||||
let result =
|
let result =
|
||||||
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -1245,24 +1257,30 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Try to borrow mut the same account in a safe way
|
// Try to borrow mut the same account in a safe way
|
||||||
let message = Message::new(&[Instruction::new(
|
let message = Message::new(
|
||||||
|
&[Instruction::new(
|
||||||
mock_program_id,
|
mock_program_id,
|
||||||
&MockSystemInstruction::MultiBorrowMut,
|
&MockSystemInstruction::MultiBorrowMut,
|
||||||
account_metas.clone(),
|
account_metas.clone(),
|
||||||
)]);
|
)],
|
||||||
|
Some(&from_pubkey),
|
||||||
|
);
|
||||||
let result =
|
let result =
|
||||||
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
||||||
assert_eq!(result, Ok(()));
|
assert_eq!(result, Ok(()));
|
||||||
|
|
||||||
// Do work on the same account but at different location in keyed_accounts[]
|
// Do work on the same account but at different location in keyed_accounts[]
|
||||||
let message = Message::new(&[Instruction::new(
|
let message = Message::new(
|
||||||
|
&[Instruction::new(
|
||||||
mock_program_id,
|
mock_program_id,
|
||||||
&MockSystemInstruction::DoWork {
|
&MockSystemInstruction::DoWork {
|
||||||
lamports: 10,
|
lamports: 10,
|
||||||
data: 42,
|
data: 42,
|
||||||
},
|
},
|
||||||
account_metas,
|
account_metas,
|
||||||
)]);
|
)],
|
||||||
|
Some(&from_pubkey),
|
||||||
|
);
|
||||||
let result =
|
let result =
|
||||||
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
message_processor.process_message(&message, &loaders, &accounts, &rent_collector, None);
|
||||||
assert_eq!(result, Ok(()));
|
assert_eq!(result, Ok(()));
|
||||||
@ -1349,7 +1367,7 @@ mod tests {
|
|||||||
&MockInstruction::NoopSuccess,
|
&MockInstruction::NoopSuccess,
|
||||||
metas.clone(),
|
metas.clone(),
|
||||||
);
|
);
|
||||||
let message = Message::new_with_payer(&[instruction], None);
|
let message = Message::new(&[instruction], None);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
message_processor.process_cross_program_instruction(
|
message_processor.process_cross_program_instruction(
|
||||||
&message,
|
&message,
|
||||||
@ -1376,7 +1394,7 @@ mod tests {
|
|||||||
|
|
||||||
for case in cases {
|
for case in cases {
|
||||||
let instruction = Instruction::new(callee_program_id, &case.0, metas.clone());
|
let instruction = Instruction::new(callee_program_id, &case.0, metas.clone());
|
||||||
let message = Message::new_with_payer(&[instruction], None);
|
let message = Message::new(&[instruction], None);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
message_processor.process_cross_program_instruction(
|
message_processor.process_cross_program_instruction(
|
||||||
&message,
|
&message,
|
||||||
|
@ -93,6 +93,7 @@ mod tests {
|
|||||||
account_utils::State as AccountUtilsState,
|
account_utils::State as AccountUtilsState,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
|
message::Message,
|
||||||
nonce::{self, account::with_test_keyed_account, Account as NonceAccount, State},
|
nonce::{self, account::with_test_keyed_account, Account as NonceAccount, State},
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{Keypair, Signer},
|
signature::{Keypair, Signer},
|
||||||
@ -106,14 +107,12 @@ mod tests {
|
|||||||
let from_pubkey = from_keypair.pubkey();
|
let from_pubkey = from_keypair.pubkey();
|
||||||
let nonce_keypair = Keypair::new();
|
let nonce_keypair = Keypair::new();
|
||||||
let nonce_pubkey = nonce_keypair.pubkey();
|
let nonce_pubkey = nonce_keypair.pubkey();
|
||||||
let tx = Transaction::new_signed_instructions(
|
let instructions = [
|
||||||
&[&from_keypair, &nonce_keypair],
|
|
||||||
&[
|
|
||||||
system_instruction::advance_nonce_account(&nonce_pubkey, &nonce_pubkey),
|
system_instruction::advance_nonce_account(&nonce_pubkey, &nonce_pubkey),
|
||||||
system_instruction::transfer(&from_pubkey, &nonce_pubkey, 42),
|
system_instruction::transfer(&from_pubkey, &nonce_pubkey, 42),
|
||||||
],
|
];
|
||||||
Hash::default(),
|
let message = Message::new(&instructions, Some(&nonce_pubkey));
|
||||||
);
|
let tx = Transaction::new(&[&from_keypair, &nonce_keypair], message, Hash::default());
|
||||||
(from_pubkey, nonce_pubkey, tx)
|
(from_pubkey, nonce_pubkey, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,14 +140,12 @@ mod tests {
|
|||||||
let from_pubkey = from_keypair.pubkey();
|
let from_pubkey = from_keypair.pubkey();
|
||||||
let nonce_keypair = Keypair::new();
|
let nonce_keypair = Keypair::new();
|
||||||
let nonce_pubkey = nonce_keypair.pubkey();
|
let nonce_pubkey = nonce_keypair.pubkey();
|
||||||
let tx = Transaction::new_signed_instructions(
|
let instructions = [
|
||||||
&[&from_keypair, &nonce_keypair],
|
|
||||||
&[
|
|
||||||
system_instruction::transfer(&from_pubkey, &nonce_pubkey, 42),
|
system_instruction::transfer(&from_pubkey, &nonce_pubkey, 42),
|
||||||
system_instruction::advance_nonce_account(&nonce_pubkey, &nonce_pubkey),
|
system_instruction::advance_nonce_account(&nonce_pubkey, &nonce_pubkey),
|
||||||
],
|
];
|
||||||
Hash::default(),
|
let message = Message::new(&instructions, Some(&from_pubkey));
|
||||||
);
|
let tx = Transaction::new(&[&from_keypair, &nonce_keypair], message, Hash::default());
|
||||||
assert!(transaction_uses_durable_nonce(&tx).is_none());
|
assert!(transaction_uses_durable_nonce(&tx).is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,9 +155,7 @@ mod tests {
|
|||||||
let from_pubkey = from_keypair.pubkey();
|
let from_pubkey = from_keypair.pubkey();
|
||||||
let nonce_keypair = Keypair::new();
|
let nonce_keypair = Keypair::new();
|
||||||
let nonce_pubkey = nonce_keypair.pubkey();
|
let nonce_pubkey = nonce_keypair.pubkey();
|
||||||
let tx = Transaction::new_signed_instructions(
|
let instructions = [
|
||||||
&[&from_keypair, &nonce_keypair],
|
|
||||||
&[
|
|
||||||
system_instruction::withdraw_nonce_account(
|
system_instruction::withdraw_nonce_account(
|
||||||
&nonce_pubkey,
|
&nonce_pubkey,
|
||||||
&nonce_pubkey,
|
&nonce_pubkey,
|
||||||
@ -168,9 +163,9 @@ mod tests {
|
|||||||
42,
|
42,
|
||||||
),
|
),
|
||||||
system_instruction::transfer(&from_pubkey, &nonce_pubkey, 42),
|
system_instruction::transfer(&from_pubkey, &nonce_pubkey, 42),
|
||||||
],
|
];
|
||||||
Hash::default(),
|
let message = Message::new(&instructions, Some(&nonce_pubkey));
|
||||||
);
|
let tx = Transaction::new(&[&from_keypair, &nonce_keypair], message, Hash::default());
|
||||||
assert!(transaction_uses_durable_nonce(&tx).is_none());
|
assert!(transaction_uses_durable_nonce(&tx).is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -909,7 +909,7 @@ mod tests {
|
|||||||
.transfer(50, &mint_keypair, &alice_pubkey)
|
.transfer(50, &mint_keypair, &alice_pubkey)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let allocate_with_seed = Message::new_with_payer(
|
let allocate_with_seed = Message::new(
|
||||||
&[system_instruction::allocate_with_seed(
|
&[system_instruction::allocate_with_seed(
|
||||||
&alice_with_seed,
|
&alice_with_seed,
|
||||||
&alice_pubkey,
|
&alice_pubkey,
|
||||||
@ -962,7 +962,7 @@ mod tests {
|
|||||||
let bank = Arc::new(Bank::new_from_parent(&bank, &collector, bank.slot() + 1));
|
let bank = Arc::new(Bank::new_from_parent(&bank, &collector, bank.slot() + 1));
|
||||||
let bank_client = BankClient::new_shared(&bank);
|
let bank_client = BankClient::new_shared(&bank);
|
||||||
let ix = system_instruction::create_account(&alice_pubkey, &bob_pubkey, 0, len1, &program);
|
let ix = system_instruction::create_account(&alice_pubkey, &bob_pubkey, 0, len1, &program);
|
||||||
let message = Message::new(&[ix]);
|
let message = Message::new(&[ix], Some(&alice_keypair.pubkey()));
|
||||||
let r = bank_client.send_message(&[&alice_keypair, &bob_keypair], message);
|
let r = bank_client.send_message(&[&alice_keypair, &bob_keypair], message);
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok());
|
||||||
|
|
||||||
@ -980,7 +980,7 @@ mod tests {
|
|||||||
let bank = Arc::new(Bank::new_from_parent(&bank, &collector, bank.slot() + 1));
|
let bank = Arc::new(Bank::new_from_parent(&bank, &collector, bank.slot() + 1));
|
||||||
let bank_client = BankClient::new_shared(&bank);
|
let bank_client = BankClient::new_shared(&bank);
|
||||||
let ix = system_instruction::create_account(&alice_pubkey, &bob_pubkey, 1, len2, &program);
|
let ix = system_instruction::create_account(&alice_pubkey, &bob_pubkey, 1, len2, &program);
|
||||||
let message = Message::new(&[ix]);
|
let message = Message::new(&[ix], Some(&alice_pubkey));
|
||||||
let r = bank_client.send_message(&[&alice_keypair, &bob_keypair], message);
|
let r = bank_client.send_message(&[&alice_keypair, &bob_keypair], message);
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok());
|
||||||
}
|
}
|
||||||
@ -1019,7 +1019,7 @@ mod tests {
|
|||||||
.transfer(50, &mint_keypair, &alice_pubkey)
|
.transfer(50, &mint_keypair, &alice_pubkey)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let assign_with_seed = Message::new_with_payer(
|
let assign_with_seed = Message::new(
|
||||||
&[system_instruction::assign_with_seed(
|
&[system_instruction::assign_with_seed(
|
||||||
&alice_with_seed,
|
&alice_with_seed,
|
||||||
&alice_pubkey,
|
&alice_pubkey,
|
||||||
|
@ -53,7 +53,7 @@ fn fill_epoch_with_votes(
|
|||||||
let bank_client = BankClient::new_shared(&bank);
|
let bank_client = BankClient::new_shared(&bank);
|
||||||
let parent = bank.parent().unwrap();
|
let parent = bank.parent().unwrap();
|
||||||
|
|
||||||
let message = Message::new_with_payer(
|
let message = Message::new(
|
||||||
&[vote_instruction::vote(
|
&[vote_instruction::vote(
|
||||||
&vote_pubkey,
|
&vote_pubkey,
|
||||||
&vote_pubkey,
|
&vote_pubkey,
|
||||||
@ -119,7 +119,8 @@ fn test_stake_create_and_split_single_signature() {
|
|||||||
let lamports = 1_000_000;
|
let lamports = 1_000_000;
|
||||||
|
|
||||||
// Create stake account with seed
|
// Create stake account with seed
|
||||||
let message = Message::new(&stake_instruction::create_account_with_seed(
|
let message = Message::new(
|
||||||
|
&stake_instruction::create_account_with_seed(
|
||||||
&staker_pubkey, // from
|
&staker_pubkey, // from
|
||||||
&stake_address, // to
|
&stake_address, // to
|
||||||
&staker_pubkey, // base
|
&staker_pubkey, // base
|
||||||
@ -127,7 +128,9 @@ fn test_stake_create_and_split_single_signature() {
|
|||||||
&authorized,
|
&authorized,
|
||||||
&stake_state::Lockup::default(),
|
&stake_state::Lockup::default(),
|
||||||
lamports,
|
lamports,
|
||||||
));
|
),
|
||||||
|
Some(&staker_pubkey),
|
||||||
|
);
|
||||||
|
|
||||||
// only one signature required
|
// only one signature required
|
||||||
bank_client
|
bank_client
|
||||||
@ -139,7 +142,7 @@ fn test_stake_create_and_split_single_signature() {
|
|||||||
Pubkey::create_with_seed(&staker_pubkey, "split_stake", &solana_stake_program::id())
|
Pubkey::create_with_seed(&staker_pubkey, "split_stake", &solana_stake_program::id())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// Test split
|
// Test split
|
||||||
let message = Message::new_with_payer(
|
let message = Message::new(
|
||||||
&stake_instruction::split_with_seed(
|
&stake_instruction::split_with_seed(
|
||||||
&stake_address, // original
|
&stake_address, // original
|
||||||
&staker_pubkey, // authorized
|
&staker_pubkey, // authorized
|
||||||
@ -183,7 +186,8 @@ fn test_stake_create_and_split_to_existing_system_account() {
|
|||||||
let lamports = 1_000_000;
|
let lamports = 1_000_000;
|
||||||
|
|
||||||
// Create stake account with seed
|
// Create stake account with seed
|
||||||
let message = Message::new(&stake_instruction::create_account_with_seed(
|
let message = Message::new(
|
||||||
|
&stake_instruction::create_account_with_seed(
|
||||||
&staker_pubkey, // from
|
&staker_pubkey, // from
|
||||||
&stake_address, // to
|
&stake_address, // to
|
||||||
&staker_pubkey, // base
|
&staker_pubkey, // base
|
||||||
@ -191,7 +195,9 @@ fn test_stake_create_and_split_to_existing_system_account() {
|
|||||||
&authorized,
|
&authorized,
|
||||||
&stake_state::Lockup::default(),
|
&stake_state::Lockup::default(),
|
||||||
lamports,
|
lamports,
|
||||||
));
|
),
|
||||||
|
Some(&staker_pubkey),
|
||||||
|
);
|
||||||
|
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&staker_keypair], message)
|
.send_message(&[&staker_keypair], message)
|
||||||
@ -212,7 +218,7 @@ fn test_stake_create_and_split_to_existing_system_account() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Verify the split fails because the account is already in use
|
// Verify the split fails because the account is already in use
|
||||||
let message = Message::new_with_payer(
|
let message = Message::new(
|
||||||
&stake_instruction::split_with_seed(
|
&stake_instruction::split_with_seed(
|
||||||
&stake_address, // original
|
&stake_address, // original
|
||||||
&staker_pubkey, // authorized
|
&staker_pubkey, // authorized
|
||||||
@ -256,7 +262,8 @@ fn test_stake_account_lifetime() {
|
|||||||
let bank_client = BankClient::new_shared(&bank);
|
let bank_client = BankClient::new_shared(&bank);
|
||||||
|
|
||||||
// Create Vote Account
|
// Create Vote Account
|
||||||
let message = Message::new(&vote_instruction::create_account(
|
let message = Message::new(
|
||||||
|
&vote_instruction::create_account(
|
||||||
&mint_pubkey,
|
&mint_pubkey,
|
||||||
&vote_pubkey,
|
&vote_pubkey,
|
||||||
&VoteInit {
|
&VoteInit {
|
||||||
@ -266,21 +273,26 @@ fn test_stake_account_lifetime() {
|
|||||||
commission: 50,
|
commission: 50,
|
||||||
},
|
},
|
||||||
10,
|
10,
|
||||||
));
|
),
|
||||||
|
Some(&mint_pubkey),
|
||||||
|
);
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&mint_keypair, &vote_keypair, &identity_keypair], message)
|
.send_message(&[&mint_keypair, &vote_keypair, &identity_keypair], message)
|
||||||
.expect("failed to create vote account");
|
.expect("failed to create vote account");
|
||||||
|
|
||||||
let authorized = stake_state::Authorized::auto(&stake_pubkey);
|
let authorized = stake_state::Authorized::auto(&stake_pubkey);
|
||||||
// Create stake account and delegate to vote account
|
// Create stake account and delegate to vote account
|
||||||
let message = Message::new(&stake_instruction::create_account_and_delegate_stake(
|
let message = Message::new(
|
||||||
|
&stake_instruction::create_account_and_delegate_stake(
|
||||||
&mint_pubkey,
|
&mint_pubkey,
|
||||||
&stake_pubkey,
|
&stake_pubkey,
|
||||||
&vote_pubkey,
|
&vote_pubkey,
|
||||||
&authorized,
|
&authorized,
|
||||||
&stake_state::Lockup::default(),
|
&stake_state::Lockup::default(),
|
||||||
1_000_000,
|
1_000_000,
|
||||||
));
|
),
|
||||||
|
Some(&mint_pubkey),
|
||||||
|
);
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&mint_keypair, &stake_keypair], message)
|
.send_message(&[&mint_keypair, &stake_keypair], message)
|
||||||
.expect("failed to create and delegate stake account");
|
.expect("failed to create and delegate stake account");
|
||||||
@ -295,7 +307,7 @@ fn test_stake_account_lifetime() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test that we cannot withdraw anything until deactivation
|
// Test that we cannot withdraw anything until deactivation
|
||||||
let message = Message::new_with_payer(
|
let message = Message::new(
|
||||||
&[stake_instruction::withdraw(
|
&[stake_instruction::withdraw(
|
||||||
&stake_pubkey,
|
&stake_pubkey,
|
||||||
&stake_pubkey,
|
&stake_pubkey,
|
||||||
@ -359,7 +371,7 @@ fn test_stake_account_lifetime() {
|
|||||||
|
|
||||||
let bank_client = BankClient::new_shared(&bank);
|
let bank_client = BankClient::new_shared(&bank);
|
||||||
// Test split
|
// Test split
|
||||||
let message = Message::new_with_payer(
|
let message = Message::new(
|
||||||
&stake_instruction::split(
|
&stake_instruction::split(
|
||||||
&stake_pubkey,
|
&stake_pubkey,
|
||||||
&stake_pubkey,
|
&stake_pubkey,
|
||||||
@ -376,7 +388,7 @@ fn test_stake_account_lifetime() {
|
|||||||
.is_ok());
|
.is_ok());
|
||||||
|
|
||||||
// Deactivate the split
|
// Deactivate the split
|
||||||
let message = Message::new_with_payer(
|
let message = Message::new(
|
||||||
&[stake_instruction::deactivate_stake(
|
&[stake_instruction::deactivate_stake(
|
||||||
&split_stake_pubkey,
|
&split_stake_pubkey,
|
||||||
&stake_pubkey,
|
&stake_pubkey,
|
||||||
@ -390,7 +402,7 @@ fn test_stake_account_lifetime() {
|
|||||||
let split_staked = get_staked(&bank, &split_stake_pubkey);
|
let split_staked = get_staked(&bank, &split_stake_pubkey);
|
||||||
|
|
||||||
// Test that we cannot withdraw above what's staked
|
// Test that we cannot withdraw above what's staked
|
||||||
let message = Message::new_with_payer(
|
let message = Message::new(
|
||||||
&[stake_instruction::withdraw(
|
&[stake_instruction::withdraw(
|
||||||
&split_stake_pubkey,
|
&split_stake_pubkey,
|
||||||
&stake_pubkey,
|
&stake_pubkey,
|
||||||
@ -412,7 +424,7 @@ fn test_stake_account_lifetime() {
|
|||||||
assert!(split_staked > 0);
|
assert!(split_staked > 0);
|
||||||
|
|
||||||
// withdrawal in cooldown
|
// withdrawal in cooldown
|
||||||
let message = Message::new_with_payer(
|
let message = Message::new(
|
||||||
&[stake_instruction::withdraw(
|
&[stake_instruction::withdraw(
|
||||||
&split_stake_pubkey,
|
&split_stake_pubkey,
|
||||||
&stake_pubkey,
|
&stake_pubkey,
|
||||||
@ -428,7 +440,7 @@ fn test_stake_account_lifetime() {
|
|||||||
.is_err());
|
.is_err());
|
||||||
|
|
||||||
// but we can withdraw unstaked
|
// but we can withdraw unstaked
|
||||||
let message = Message::new_with_payer(
|
let message = Message::new(
|
||||||
&[stake_instruction::withdraw(
|
&[stake_instruction::withdraw(
|
||||||
&split_stake_pubkey,
|
&split_stake_pubkey,
|
||||||
&stake_pubkey,
|
&stake_pubkey,
|
||||||
@ -453,7 +465,7 @@ fn test_stake_account_lifetime() {
|
|||||||
let bank_client = BankClient::new_shared(&bank);
|
let bank_client = BankClient::new_shared(&bank);
|
||||||
|
|
||||||
// Test that we can withdraw everything else out of the split
|
// Test that we can withdraw everything else out of the split
|
||||||
let message = Message::new_with_payer(
|
let message = Message::new(
|
||||||
&[stake_instruction::withdraw(
|
&[stake_instruction::withdraw(
|
||||||
&split_stake_pubkey,
|
&split_stake_pubkey,
|
||||||
&stake_pubkey,
|
&stake_pubkey,
|
||||||
@ -494,7 +506,8 @@ fn test_create_stake_account_from_seed() {
|
|||||||
Pubkey::create_with_seed(&mint_pubkey, seed, &solana_stake_program::id()).unwrap();
|
Pubkey::create_with_seed(&mint_pubkey, seed, &solana_stake_program::id()).unwrap();
|
||||||
|
|
||||||
// Create Vote Account
|
// Create Vote Account
|
||||||
let message = Message::new(&vote_instruction::create_account(
|
let message = Message::new(
|
||||||
|
&vote_instruction::create_account(
|
||||||
&mint_pubkey,
|
&mint_pubkey,
|
||||||
&vote_pubkey,
|
&vote_pubkey,
|
||||||
&VoteInit {
|
&VoteInit {
|
||||||
@ -504,7 +517,9 @@ fn test_create_stake_account_from_seed() {
|
|||||||
commission: 50,
|
commission: 50,
|
||||||
},
|
},
|
||||||
10,
|
10,
|
||||||
));
|
),
|
||||||
|
Some(&mint_pubkey),
|
||||||
|
);
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&mint_keypair, &vote_keypair, &identity_keypair], message)
|
.send_message(&[&mint_keypair, &vote_keypair, &identity_keypair], message)
|
||||||
.expect("failed to create vote account");
|
.expect("failed to create vote account");
|
||||||
@ -522,6 +537,7 @@ fn test_create_stake_account_from_seed() {
|
|||||||
&stake_state::Lockup::default(),
|
&stake_state::Lockup::default(),
|
||||||
1_000_000,
|
1_000_000,
|
||||||
),
|
),
|
||||||
|
Some(&mint_pubkey),
|
||||||
);
|
);
|
||||||
bank_client
|
bank_client
|
||||||
.send_message(&[&mint_keypair], message)
|
.send_message(&[&mint_keypair], message)
|
||||||
|
@ -193,13 +193,13 @@ mod tests {
|
|||||||
let pubkey0 = Pubkey::new(&[0; 32]);
|
let pubkey0 = Pubkey::new(&[0; 32]);
|
||||||
let pubkey1 = Pubkey::new(&[1; 32]);
|
let pubkey1 = Pubkey::new(&[1; 32]);
|
||||||
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
||||||
let message = Message::new(&[ix0]);
|
let message = Message::new(&[ix0], Some(&pubkey0));
|
||||||
assert_eq!(FeeCalculator::new(2).calculate_fee(&message), 2);
|
assert_eq!(FeeCalculator::new(2).calculate_fee(&message), 2);
|
||||||
|
|
||||||
// Two signatures, double the fee.
|
// Two signatures, double the fee.
|
||||||
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
||||||
let ix1 = system_instruction::transfer(&pubkey1, &pubkey0, 1);
|
let ix1 = system_instruction::transfer(&pubkey1, &pubkey0, 1);
|
||||||
let message = Message::new(&[ix0, ix1]);
|
let message = Message::new(&[ix0, ix1], Some(&pubkey0));
|
||||||
assert_eq!(FeeCalculator::new(2).calculate_fee(&message), 4);
|
assert_eq!(FeeCalculator::new(2).calculate_fee(&message), 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,18 +57,6 @@ impl InstructionKeys {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the pubkey of the first writable signer in the given set of instructions.
|
|
||||||
fn find_writable_signer(instructions: &[Instruction]) -> Option<&Pubkey> {
|
|
||||||
for instruction in instructions {
|
|
||||||
for account in &instruction.accounts {
|
|
||||||
if account.is_signer && account.is_writable {
|
|
||||||
return Some(&account.pubkey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return pubkeys referenced by all instructions, with the ones needing signatures first. If the
|
/// Return pubkeys referenced by all instructions, with the ones needing signatures first. If the
|
||||||
/// payer key is provided, it is always placed first in the list of signed keys. Read-only signed
|
/// payer key is provided, it is always placed first in the list of signed keys. Read-only signed
|
||||||
/// accounts are placed last in the set of signed accounts. Read-only unsigned accounts,
|
/// accounts are placed last in the set of signed accounts. Read-only unsigned accounts,
|
||||||
@ -245,12 +233,7 @@ impl Message {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(instructions: &[Instruction]) -> Self {
|
pub fn new(instructions: &[Instruction], payer: Option<&Pubkey>) -> Self {
|
||||||
let payer = find_writable_signer(instructions).expect("no suitable key for fee-payer");
|
|
||||||
Self::new_with_payer(instructions, Some(payer))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_with_payer(instructions: &[Instruction], payer: Option<&Pubkey>) -> Self {
|
|
||||||
let InstructionKeys {
|
let InstructionKeys {
|
||||||
mut signed_keys,
|
mut signed_keys,
|
||||||
unsigned_keys,
|
unsigned_keys,
|
||||||
@ -281,7 +264,7 @@ impl Message {
|
|||||||
&nonce_authority_pubkey,
|
&nonce_authority_pubkey,
|
||||||
);
|
);
|
||||||
instructions.insert(0, nonce_ix);
|
instructions.insert(0, nonce_ix);
|
||||||
Self::new_with_payer(&instructions, payer)
|
Self::new(&instructions, payer)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn serialize(&self) -> Vec<u8> {
|
pub fn serialize(&self) -> Vec<u8> {
|
||||||
@ -523,11 +506,11 @@ mod tests {
|
|||||||
let program_id = Pubkey::default();
|
let program_id = Pubkey::default();
|
||||||
let id0 = Pubkey::default();
|
let id0 = Pubkey::default();
|
||||||
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, false)]);
|
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, false)]);
|
||||||
let message = Message::new_with_payer(&[ix], None);
|
let message = Message::new(&[ix], None);
|
||||||
assert_eq!(message.header.num_required_signatures, 0);
|
assert_eq!(message.header.num_required_signatures, 0);
|
||||||
|
|
||||||
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, true)]);
|
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, true)]);
|
||||||
let message = Message::new(&[ix]);
|
let message = Message::new(&[ix], Some(&id0));
|
||||||
assert_eq!(message.header.num_required_signatures, 1);
|
assert_eq!(message.header.num_required_signatures, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -560,11 +543,14 @@ 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 message = Message::new(&[
|
let message = Message::new(
|
||||||
|
&[
|
||||||
Instruction::new(program_id0, &0, vec![AccountMeta::new(id0, false)]),
|
Instruction::new(program_id0, &0, vec![AccountMeta::new(id0, false)]),
|
||||||
Instruction::new(program_id1, &0, vec![AccountMeta::new(id1, true)]),
|
Instruction::new(program_id1, &0, vec![AccountMeta::new(id1, true)]),
|
||||||
Instruction::new(program_id0, &0, vec![AccountMeta::new(id1, false)]),
|
Instruction::new(program_id0, &0, vec![AccountMeta::new(id1, false)]),
|
||||||
]);
|
],
|
||||||
|
Some(&id1),
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
message.instructions[0],
|
message.instructions[0],
|
||||||
CompiledInstruction::new(2, &0, vec![1])
|
CompiledInstruction::new(2, &0, vec![1])
|
||||||
@ -586,11 +572,11 @@ mod tests {
|
|||||||
let id0 = Pubkey::default();
|
let id0 = Pubkey::default();
|
||||||
|
|
||||||
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, false)]);
|
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, false)]);
|
||||||
let message = Message::new_with_payer(&[ix], Some(&payer));
|
let message = Message::new(&[ix], Some(&payer));
|
||||||
assert_eq!(message.header.num_required_signatures, 1);
|
assert_eq!(message.header.num_required_signatures, 1);
|
||||||
|
|
||||||
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, true)]);
|
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, true)]);
|
||||||
let message = Message::new_with_payer(&[ix], Some(&payer));
|
let message = Message::new(&[ix], Some(&payer));
|
||||||
assert_eq!(message.header.num_required_signatures, 2);
|
assert_eq!(message.header.num_required_signatures, 2);
|
||||||
|
|
||||||
let ix = Instruction::new(
|
let ix = Instruction::new(
|
||||||
@ -598,7 +584,7 @@ mod tests {
|
|||||||
&0,
|
&0,
|
||||||
vec![AccountMeta::new(payer, true), AccountMeta::new(id0, true)],
|
vec![AccountMeta::new(payer, true), AccountMeta::new(id0, true)],
|
||||||
);
|
);
|
||||||
let message = Message::new_with_payer(&[ix], Some(&payer));
|
let message = Message::new(&[ix], Some(&payer));
|
||||||
assert_eq!(message.header.num_required_signatures, 2);
|
assert_eq!(message.header.num_required_signatures, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -625,10 +611,13 @@ mod tests {
|
|||||||
let program_id0 = Pubkey::default();
|
let program_id0 = Pubkey::default();
|
||||||
let program_id1 = Pubkey::new_rand();
|
let program_id1 = Pubkey::new_rand();
|
||||||
let id = Pubkey::new_rand();
|
let id = Pubkey::new_rand();
|
||||||
let message = Message::new(&[
|
let message = Message::new(
|
||||||
|
&[
|
||||||
Instruction::new(program_id0, &0, vec![AccountMeta::new(id, false)]),
|
Instruction::new(program_id0, &0, vec![AccountMeta::new(id, false)]),
|
||||||
Instruction::new(program_id1, &0, vec![AccountMeta::new(id, true)]),
|
Instruction::new(program_id1, &0, vec![AccountMeta::new(id, true)]),
|
||||||
]);
|
],
|
||||||
|
Some(&id),
|
||||||
|
);
|
||||||
assert_eq!(message.program_position(0), None);
|
assert_eq!(message.program_position(0), None);
|
||||||
assert_eq!(message.program_position(1), Some(0));
|
assert_eq!(message.program_position(1), Some(0));
|
||||||
assert_eq!(message.program_position(2), Some(1));
|
assert_eq!(message.program_position(2), Some(1));
|
||||||
@ -668,12 +657,15 @@ mod tests {
|
|||||||
let id1 = Pubkey::new_rand();
|
let id1 = Pubkey::new_rand();
|
||||||
let id2 = Pubkey::new_rand();
|
let id2 = Pubkey::new_rand();
|
||||||
let id3 = Pubkey::new_rand();
|
let id3 = Pubkey::new_rand();
|
||||||
let message = Message::new(&[
|
let message = Message::new(
|
||||||
|
&[
|
||||||
Instruction::new(program_id, &0, vec![AccountMeta::new(id0, false)]),
|
Instruction::new(program_id, &0, vec![AccountMeta::new(id0, false)]),
|
||||||
Instruction::new(program_id, &0, vec![AccountMeta::new(id1, true)]),
|
Instruction::new(program_id, &0, vec![AccountMeta::new(id1, true)]),
|
||||||
Instruction::new(program_id, &0, vec![AccountMeta::new_readonly(id2, false)]),
|
Instruction::new(program_id, &0, vec![AccountMeta::new_readonly(id2, false)]),
|
||||||
Instruction::new(program_id, &0, vec![AccountMeta::new_readonly(id3, true)]),
|
Instruction::new(program_id, &0, vec![AccountMeta::new_readonly(id3, true)]),
|
||||||
]);
|
],
|
||||||
|
Some(&id1),
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
message.get_account_keys_by_lock_type(),
|
message.get_account_keys_by_lock_type(),
|
||||||
(vec![&id1, &id0], vec![&id3, &id2, &program_id])
|
(vec![&id1, &id0], vec![&id3, &id2, &program_id])
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
|
message::Message,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{Keypair, Signer},
|
signature::{Keypair, Signer},
|
||||||
system_instruction,
|
system_instruction,
|
||||||
@ -19,20 +20,18 @@ pub fn create_account(
|
|||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let from_pubkey = from_keypair.pubkey();
|
let from_pubkey = from_keypair.pubkey();
|
||||||
let to_pubkey = to_keypair.pubkey();
|
let to_pubkey = to_keypair.pubkey();
|
||||||
let create_instruction =
|
let instruction =
|
||||||
system_instruction::create_account(&from_pubkey, &to_pubkey, lamports, space, program_id);
|
system_instruction::create_account(&from_pubkey, &to_pubkey, lamports, space, program_id);
|
||||||
Transaction::new_signed_instructions(
|
let message = Message::new(&[instruction], Some(&from_pubkey));
|
||||||
&[from_keypair, to_keypair],
|
Transaction::new(&[from_keypair, to_keypair], message, recent_blockhash)
|
||||||
&[create_instruction],
|
|
||||||
recent_blockhash,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create and sign new system_instruction::Assign transaction
|
/// Create and sign new system_instruction::Assign transaction
|
||||||
pub fn assign(from_keypair: &Keypair, recent_blockhash: Hash, program_id: &Pubkey) -> Transaction {
|
pub fn assign(from_keypair: &Keypair, recent_blockhash: Hash, program_id: &Pubkey) -> Transaction {
|
||||||
let from_pubkey = from_keypair.pubkey();
|
let from_pubkey = from_keypair.pubkey();
|
||||||
let assign_instruction = system_instruction::assign(&from_pubkey, program_id);
|
let instruction = system_instruction::assign(&from_pubkey, program_id);
|
||||||
Transaction::new_signed_instructions(&[from_keypair], &[assign_instruction], recent_blockhash)
|
let message = Message::new(&[instruction], Some(&from_pubkey));
|
||||||
|
Transaction::new(&[from_keypair], message, recent_blockhash)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create and sign new system_instruction::Transfer transaction
|
/// Create and sign new system_instruction::Transfer transaction
|
||||||
@ -43,8 +42,9 @@ pub fn transfer(
|
|||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let from_pubkey = from_keypair.pubkey();
|
let from_pubkey = from_keypair.pubkey();
|
||||||
let transfer_instruction = system_instruction::transfer(&from_pubkey, to, lamports);
|
let instruction = system_instruction::transfer(&from_pubkey, to, lamports);
|
||||||
Transaction::new_signed_instructions(&[from_keypair], &[transfer_instruction], recent_blockhash)
|
let message = Message::new(&[instruction], Some(&from_pubkey));
|
||||||
|
Transaction::new(&[from_keypair], message, recent_blockhash)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create and sign new nonced system_instruction::Transfer transaction
|
/// Create and sign new nonced system_instruction::Transfer transaction
|
||||||
@ -57,14 +57,12 @@ pub fn nonced_transfer(
|
|||||||
nonce_hash: Hash,
|
nonce_hash: Hash,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let from_pubkey = from_keypair.pubkey();
|
let from_pubkey = from_keypair.pubkey();
|
||||||
let transfer_instruction = system_instruction::transfer(&from_pubkey, to, lamports);
|
let instruction = system_instruction::transfer(&from_pubkey, to, lamports);
|
||||||
let instructions = vec![transfer_instruction];
|
let message = Message::new_with_nonce(
|
||||||
Transaction::new_signed_with_nonce(
|
vec![instruction],
|
||||||
instructions,
|
|
||||||
Some(&from_pubkey),
|
Some(&from_pubkey),
|
||||||
&[from_keypair, nonce_authority],
|
|
||||||
nonce_account,
|
nonce_account,
|
||||||
&nonce_authority.pubkey(),
|
&nonce_authority.pubkey(),
|
||||||
nonce_hash,
|
);
|
||||||
)
|
Transaction::new(&[from_keypair, nonce_authority], message, nonce_hash)
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ use crate::{
|
|||||||
short_vec,
|
short_vec,
|
||||||
signature::{Signature, SignerError},
|
signature::{Signature, SignerError},
|
||||||
signers::Signers,
|
signers::Signers,
|
||||||
system_instruction,
|
|
||||||
};
|
};
|
||||||
use std::result;
|
use std::result;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
@ -122,7 +121,7 @@ impl Transaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_with_payer(instructions: &[Instruction], payer: Option<&Pubkey>) -> Self {
|
pub fn new_with_payer(instructions: &[Instruction], payer: Option<&Pubkey>) -> Self {
|
||||||
let message = Message::new_with_payer(instructions, payer);
|
let message = Message::new(instructions, payer);
|
||||||
Self::new_unsigned(message)
|
Self::new_unsigned(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,31 +131,10 @@ impl Transaction {
|
|||||||
signing_keypairs: &T,
|
signing_keypairs: &T,
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let message = Message::new_with_payer(instructions, payer);
|
let message = Message::new(instructions, payer);
|
||||||
Self::new(signing_keypairs, message, recent_blockhash)
|
Self::new(signing_keypairs, message, recent_blockhash)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_signed_with_nonce<T: Signers>(
|
|
||||||
mut instructions: Vec<Instruction>,
|
|
||||||
payer: Option<&Pubkey>,
|
|
||||||
signing_keypairs: &T,
|
|
||||||
nonce_account_pubkey: &Pubkey,
|
|
||||||
nonce_authority_pubkey: &Pubkey,
|
|
||||||
nonce_hash: Hash,
|
|
||||||
) -> Self {
|
|
||||||
let nonce_ix = system_instruction::advance_nonce_account(
|
|
||||||
&nonce_account_pubkey,
|
|
||||||
&nonce_authority_pubkey,
|
|
||||||
);
|
|
||||||
instructions.insert(0, nonce_ix);
|
|
||||||
Self::new_signed_with_payer(&instructions, payer, signing_keypairs, nonce_hash)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_unsigned_instructions(instructions: &[Instruction]) -> Self {
|
|
||||||
let message = Message::new(instructions);
|
|
||||||
Self::new_unsigned(message)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new<T: Signers>(
|
pub fn new<T: Signers>(
|
||||||
from_keypairs: &T,
|
from_keypairs: &T,
|
||||||
message: Message,
|
message: Message,
|
||||||
@ -167,15 +145,6 @@ impl Transaction {
|
|||||||
tx
|
tx
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_signed_instructions<T: Signers>(
|
|
||||||
from_keypairs: &T,
|
|
||||||
instructions: &[Instruction],
|
|
||||||
recent_blockhash: Hash,
|
|
||||||
) -> Transaction {
|
|
||||||
let message = Message::new(instructions);
|
|
||||||
Self::new(from_keypairs, message, recent_blockhash)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a signed transaction
|
/// Create a signed transaction
|
||||||
/// * `from_keypairs` - The keys used to sign the transaction.
|
/// * `from_keypairs` - The keys used to sign the transaction.
|
||||||
/// * `keys` - The keys for the transaction. These are the program state
|
/// * `keys` - The keys for the transaction. These are the program state
|
||||||
@ -563,7 +532,7 @@ mod tests {
|
|||||||
AccountMeta::new(to, false),
|
AccountMeta::new(to, false),
|
||||||
];
|
];
|
||||||
let instruction = Instruction::new(program_id, &(1u8, 2u8, 3u8), account_metas);
|
let instruction = Instruction::new(program_id, &(1u8, 2u8, 3u8), account_metas);
|
||||||
let message = Message::new(&[instruction]);
|
let message = Message::new(&[instruction], Some(&keypair.pubkey()));
|
||||||
Transaction::new(&[&keypair], message, Hash::default())
|
Transaction::new(&[&keypair], message, Hash::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -594,7 +563,7 @@ mod tests {
|
|||||||
let expected_instruction_size = 1 + 1 + ix.accounts.len() + 1 + expected_data_size;
|
let expected_instruction_size = 1 + 1 + ix.accounts.len() + 1 + expected_data_size;
|
||||||
assert_eq!(expected_instruction_size, 17);
|
assert_eq!(expected_instruction_size, 17);
|
||||||
|
|
||||||
let message = Message::new(&[ix]);
|
let message = Message::new(&[ix], Some(&alice_pubkey));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serialized_size(&message.instructions[0]).unwrap() as usize,
|
serialized_size(&message.instructions[0]).unwrap() as usize,
|
||||||
expected_instruction_size,
|
expected_instruction_size,
|
||||||
@ -650,19 +619,22 @@ mod tests {
|
|||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_transaction_missing_key() {
|
fn test_transaction_missing_key() {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
Transaction::new_unsigned_instructions(&[]).sign(&[&keypair], Hash::default());
|
let message = Message::new(&[], None);
|
||||||
|
Transaction::new_unsigned(message).sign(&[&keypair], Hash::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_partial_sign_mismatched_key() {
|
fn test_partial_sign_mismatched_key() {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
Transaction::new_unsigned_instructions(&[Instruction::new(
|
let fee_payer = Pubkey::new_rand();
|
||||||
|
let ix = Instruction::new(
|
||||||
Pubkey::default(),
|
Pubkey::default(),
|
||||||
&0,
|
&0,
|
||||||
vec![AccountMeta::new(Pubkey::new_rand(), true)],
|
vec![AccountMeta::new(fee_payer, true)],
|
||||||
)])
|
);
|
||||||
.partial_sign(&[&keypair], Hash::default());
|
let message = Message::new(&[ix], Some(&fee_payer));
|
||||||
|
Transaction::new_unsigned(message).partial_sign(&[&keypair], Hash::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -670,7 +642,7 @@ mod tests {
|
|||||||
let keypair0 = Keypair::new();
|
let keypair0 = Keypair::new();
|
||||||
let keypair1 = Keypair::new();
|
let keypair1 = Keypair::new();
|
||||||
let keypair2 = Keypair::new();
|
let keypair2 = Keypair::new();
|
||||||
let mut tx = Transaction::new_unsigned_instructions(&[Instruction::new(
|
let ix = Instruction::new(
|
||||||
Pubkey::default(),
|
Pubkey::default(),
|
||||||
&0,
|
&0,
|
||||||
vec![
|
vec![
|
||||||
@ -678,7 +650,9 @@ mod tests {
|
|||||||
AccountMeta::new(keypair1.pubkey(), true),
|
AccountMeta::new(keypair1.pubkey(), true),
|
||||||
AccountMeta::new(keypair2.pubkey(), true),
|
AccountMeta::new(keypair2.pubkey(), true),
|
||||||
],
|
],
|
||||||
)]);
|
);
|
||||||
|
let message = Message::new(&[ix], Some(&keypair0.pubkey()));
|
||||||
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
|
|
||||||
tx.partial_sign(&[&keypair0, &keypair2], Hash::default());
|
tx.partial_sign(&[&keypair0, &keypair2], Hash::default());
|
||||||
assert!(!tx.is_signed());
|
assert!(!tx.is_signed());
|
||||||
@ -699,8 +673,8 @@ mod tests {
|
|||||||
let keypair0 = Keypair::new();
|
let keypair0 = Keypair::new();
|
||||||
let id0 = keypair0.pubkey();
|
let id0 = keypair0.pubkey();
|
||||||
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, true)]);
|
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, true)]);
|
||||||
Transaction::new_unsigned_instructions(&[ix])
|
let message = Message::new(&[ix], Some(&id0));
|
||||||
.sign(&Vec::<&Keypair>::new(), Hash::default());
|
Transaction::new_unsigned(message).sign(&Vec::<&Keypair>::new(), Hash::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -710,7 +684,8 @@ mod tests {
|
|||||||
let keypair0 = Keypair::new();
|
let keypair0 = Keypair::new();
|
||||||
let wrong_id = Pubkey::default();
|
let wrong_id = Pubkey::default();
|
||||||
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(wrong_id, true)]);
|
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(wrong_id, true)]);
|
||||||
Transaction::new_unsigned_instructions(&[ix]).sign(&[&keypair0], Hash::default());
|
let message = Message::new(&[ix], Some(&wrong_id));
|
||||||
|
Transaction::new_unsigned(message).sign(&[&keypair0], Hash::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -719,7 +694,8 @@ mod tests {
|
|||||||
let keypair0 = Keypair::new();
|
let keypair0 = Keypair::new();
|
||||||
let id0 = keypair0.pubkey();
|
let id0 = keypair0.pubkey();
|
||||||
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, true)]);
|
let ix = Instruction::new(program_id, &0, vec![AccountMeta::new(id0, true)]);
|
||||||
let mut tx = Transaction::new_unsigned_instructions(&[ix]);
|
let message = Message::new(&[ix], Some(&id0));
|
||||||
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.sign(&[&keypair0], Hash::default());
|
tx.sign(&[&keypair0], Hash::default());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
tx.message.instructions[0],
|
tx.message.instructions[0],
|
||||||
@ -744,7 +720,8 @@ mod tests {
|
|||||||
AccountMeta::new(id1, false),
|
AccountMeta::new(id1, false),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
let mut tx = Transaction::new_unsigned_instructions(&[ix]);
|
let message = Message::new(&[ix], Some(&id0));
|
||||||
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.sign(&[&keypair0], Hash::default());
|
tx.sign(&[&keypair0], Hash::default());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
tx.message.instructions[0],
|
tx.message.instructions[0],
|
||||||
@ -769,7 +746,8 @@ mod tests {
|
|||||||
AccountMeta::new(presigner_pubkey, true),
|
AccountMeta::new(presigner_pubkey, true),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
let mut tx = Transaction::new_unsigned_instructions(&[ix]);
|
let message = Message::new(&[ix], Some(&pubkey));
|
||||||
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
|
|
||||||
let presigner_sig = presigner_keypair.sign_message(&tx.message_data());
|
let presigner_sig = presigner_keypair.sign_message(&tx.message_data());
|
||||||
let presigner = Presigner::new(&presigner_pubkey, &presigner_sig);
|
let presigner = Presigner::new(&presigner_pubkey, &presigner_sig);
|
||||||
@ -791,7 +769,8 @@ mod tests {
|
|||||||
AccountMeta::new(presigner_pubkey, true),
|
AccountMeta::new(presigner_pubkey, true),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
let mut tx = Transaction::new_unsigned_instructions(&[ix]);
|
let message = Message::new(&[ix], Some(&another_pubkey));
|
||||||
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
|
|
||||||
let res = tx.try_sign(&signers, Hash::default());
|
let res = tx.try_sign(&signers, Hash::default());
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
|
@ -51,7 +51,7 @@ pub(crate) fn new_stake_account(
|
|||||||
&lockup,
|
&lockup,
|
||||||
lamports,
|
lamports,
|
||||||
);
|
);
|
||||||
Message::new_with_payer(&instructions, Some(fee_payer_pubkey))
|
Message::new(&instructions, Some(fee_payer_pubkey))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn authorize_stake_accounts_instructions(
|
fn authorize_stake_accounts_instructions(
|
||||||
@ -96,7 +96,7 @@ fn rebase_stake_account(
|
|||||||
new_base_pubkey,
|
new_base_pubkey,
|
||||||
&i.to_string(),
|
&i.to_string(),
|
||||||
);
|
);
|
||||||
let message = Message::new_with_payer(&instructions, Some(&fee_payer_pubkey));
|
let message = Message::new(&instructions, Some(&fee_payer_pubkey));
|
||||||
Some(message)
|
Some(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ fn move_stake_account(
|
|||||||
);
|
);
|
||||||
|
|
||||||
instructions.extend(authorize_instructions.into_iter());
|
instructions.extend(authorize_instructions.into_iter());
|
||||||
let message = Message::new_with_payer(&instructions, Some(&fee_payer_pubkey));
|
let message = Message::new(&instructions, Some(&fee_payer_pubkey));
|
||||||
Some(message)
|
Some(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ pub(crate) fn authorize_stake_accounts(
|
|||||||
new_stake_authority_pubkey,
|
new_stake_authority_pubkey,
|
||||||
new_withdraw_authority_pubkey,
|
new_withdraw_authority_pubkey,
|
||||||
);
|
);
|
||||||
Message::new_with_payer(&instructions, Some(&fee_payer_pubkey))
|
Message::new(&instructions, Some(&fee_payer_pubkey))
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
}
|
}
|
||||||
@ -217,7 +217,7 @@ pub(crate) fn lockup_stake_accounts(
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let instruction = stake_instruction::set_lockup(address, &lockup, custodian_pubkey);
|
let instruction = stake_instruction::set_lockup(address, &lockup, custodian_pubkey);
|
||||||
let message = Message::new_with_payer(&[instruction], Some(&fee_payer_pubkey));
|
let message = Message::new(&[instruction], Some(&fee_payer_pubkey));
|
||||||
Some(message)
|
Some(message)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -396,16 +396,18 @@ mod test {
|
|||||||
|
|
||||||
// Configure stake1
|
// Configure stake1
|
||||||
let stake1_keypair = Keypair::new();
|
let stake1_keypair = Keypair::new();
|
||||||
let stake1_signature = rpc_client
|
let instructions = stake_instruction::create_account(
|
||||||
.send_transaction(&Transaction::new_signed_instructions(
|
|
||||||
&[&payer, &stake1_keypair],
|
|
||||||
&stake_instruction::create_account(
|
|
||||||
&payer.pubkey(),
|
&payer.pubkey(),
|
||||||
&stake1_keypair.pubkey(),
|
&stake1_keypair.pubkey(),
|
||||||
&Authorized::auto(&payer.pubkey()),
|
&Authorized::auto(&payer.pubkey()),
|
||||||
&Lockup::default(),
|
&Lockup::default(),
|
||||||
one_sol,
|
one_sol,
|
||||||
),
|
);
|
||||||
|
let message = Message::new(&instructions, Some(&payer.pubkey()));
|
||||||
|
let stake1_signature = rpc_client
|
||||||
|
.send_transaction(&Transaction::new(
|
||||||
|
&[&payer, &stake1_keypair],
|
||||||
|
message,
|
||||||
blockhash,
|
blockhash,
|
||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -426,10 +428,7 @@ mod test {
|
|||||||
|
|
||||||
// Configure stake2 with non-compliant lockup
|
// Configure stake2 with non-compliant lockup
|
||||||
let stake2_keypair = Keypair::new();
|
let stake2_keypair = Keypair::new();
|
||||||
let stake2_signature = rpc_client
|
let instructions = stake_instruction::create_account(
|
||||||
.send_transaction(&Transaction::new_signed_instructions(
|
|
||||||
&[&payer, &stake2_keypair],
|
|
||||||
&stake_instruction::create_account(
|
|
||||||
&payer.pubkey(),
|
&payer.pubkey(),
|
||||||
&stake2_keypair.pubkey(),
|
&stake2_keypair.pubkey(),
|
||||||
&Authorized::auto(&payer.pubkey()),
|
&Authorized::auto(&payer.pubkey()),
|
||||||
@ -438,23 +437,30 @@ mod test {
|
|||||||
..Lockup::default()
|
..Lockup::default()
|
||||||
},
|
},
|
||||||
one_sol,
|
one_sol,
|
||||||
),
|
);
|
||||||
|
let message = Message::new(&instructions, Some(&payer.pubkey()));
|
||||||
|
let stake2_signature = rpc_client
|
||||||
|
.send_transaction(&Transaction::new(
|
||||||
|
&[&payer, &stake2_keypair],
|
||||||
|
message,
|
||||||
blockhash,
|
blockhash,
|
||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Configure stake3
|
// Configure stake3
|
||||||
let stake3_keypair = Keypair::new();
|
let stake3_keypair = Keypair::new();
|
||||||
let stake3_initialize_signature = rpc_client
|
let instructions = stake_instruction::create_account(
|
||||||
.send_transaction(&Transaction::new_signed_instructions(
|
|
||||||
&[&payer, &stake3_keypair],
|
|
||||||
&stake_instruction::create_account(
|
|
||||||
&payer.pubkey(),
|
&payer.pubkey(),
|
||||||
&stake3_keypair.pubkey(),
|
&stake3_keypair.pubkey(),
|
||||||
&Authorized::auto(&payer.pubkey()),
|
&Authorized::auto(&payer.pubkey()),
|
||||||
&Lockup::default(),
|
&Lockup::default(),
|
||||||
one_sol,
|
one_sol,
|
||||||
),
|
);
|
||||||
|
let message = Message::new(&instructions, Some(&payer.pubkey()));
|
||||||
|
let stake3_initialize_signature = rpc_client
|
||||||
|
.send_transaction(&Transaction::new(
|
||||||
|
&[&payer, &stake3_keypair],
|
||||||
|
message,
|
||||||
blockhash,
|
blockhash,
|
||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -471,7 +477,7 @@ mod test {
|
|||||||
.send_transaction_with_config(
|
.send_transaction_with_config(
|
||||||
&Transaction::new(
|
&Transaction::new(
|
||||||
&[&payer, &stake3_keypair],
|
&[&payer, &stake3_keypair],
|
||||||
Message::new_with_payer(
|
Message::new(
|
||||||
&[stake_instruction::withdraw(
|
&[stake_instruction::withdraw(
|
||||||
&stake3_keypair.pubkey(),
|
&stake3_keypair.pubkey(),
|
||||||
&stake3_keypair.pubkey(),
|
&stake3_keypair.pubkey(),
|
||||||
@ -498,16 +504,18 @@ mod test {
|
|||||||
|
|
||||||
// Configure stake4
|
// Configure stake4
|
||||||
let stake4_keypair = Keypair::new();
|
let stake4_keypair = Keypair::new();
|
||||||
let stake4_initialize_signature = rpc_client
|
let instructions = stake_instruction::create_account(
|
||||||
.send_transaction(&Transaction::new_signed_instructions(
|
|
||||||
&[&payer, &stake4_keypair],
|
|
||||||
&stake_instruction::create_account(
|
|
||||||
&payer.pubkey(),
|
&payer.pubkey(),
|
||||||
&stake4_keypair.pubkey(),
|
&stake4_keypair.pubkey(),
|
||||||
&Authorized::auto(&payer.pubkey()),
|
&Authorized::auto(&payer.pubkey()),
|
||||||
&Lockup::default(),
|
&Lockup::default(),
|
||||||
2 * one_sol,
|
2 * one_sol,
|
||||||
),
|
);
|
||||||
|
let message = Message::new(&instructions, Some(&payer.pubkey()));
|
||||||
|
let stake4_initialize_signature = rpc_client
|
||||||
|
.send_transaction(&Transaction::new(
|
||||||
|
&[&payer, &stake4_keypair],
|
||||||
|
message,
|
||||||
blockhash,
|
blockhash,
|
||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -525,7 +533,7 @@ mod test {
|
|||||||
.send_transaction_with_config(
|
.send_transaction_with_config(
|
||||||
&Transaction::new(
|
&Transaction::new(
|
||||||
&[&payer, &stake5_keypair],
|
&[&payer, &stake5_keypair],
|
||||||
Message::new_with_payer(
|
Message::new(
|
||||||
&stake_instruction::split(
|
&stake_instruction::split(
|
||||||
&stake4_keypair.pubkey(),
|
&stake4_keypair.pubkey(),
|
||||||
&payer.pubkey(),
|
&payer.pubkey(),
|
||||||
|
@ -642,7 +642,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||||||
);
|
);
|
||||||
source_stake_lamports_required += config.baseline_stake_amount;
|
source_stake_lamports_required += config.baseline_stake_amount;
|
||||||
create_stake_transactions.push((
|
create_stake_transactions.push((
|
||||||
Transaction::new_unsigned(Message::new_with_payer(
|
Transaction::new_unsigned(Message::new(
|
||||||
&stake_instruction::split_with_seed(
|
&stake_instruction::split_with_seed(
|
||||||
&config.source_stake_address,
|
&config.source_stake_address,
|
||||||
&config.authorized_staker.pubkey(),
|
&config.authorized_staker.pubkey(),
|
||||||
@ -680,7 +680,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||||||
);
|
);
|
||||||
source_stake_lamports_required += config.bonus_stake_amount;
|
source_stake_lamports_required += config.bonus_stake_amount;
|
||||||
create_stake_transactions.push((
|
create_stake_transactions.push((
|
||||||
Transaction::new_unsigned(Message::new_with_payer(
|
Transaction::new_unsigned(Message::new(
|
||||||
&stake_instruction::split_with_seed(
|
&stake_instruction::split_with_seed(
|
||||||
&config.source_stake_address,
|
&config.source_stake_address,
|
||||||
&config.authorized_staker.pubkey(),
|
&config.authorized_staker.pubkey(),
|
||||||
@ -712,7 +712,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||||||
// Delegate baseline stake
|
// Delegate baseline stake
|
||||||
if !stake_activated_in_current_epoch.contains(&baseline_stake_address) {
|
if !stake_activated_in_current_epoch.contains(&baseline_stake_address) {
|
||||||
delegate_stake_transactions.push((
|
delegate_stake_transactions.push((
|
||||||
Transaction::new_unsigned(Message::new_with_payer(
|
Transaction::new_unsigned(Message::new(
|
||||||
&[stake_instruction::delegate_stake(
|
&[stake_instruction::delegate_stake(
|
||||||
&baseline_stake_address,
|
&baseline_stake_address,
|
||||||
&config.authorized_staker.pubkey(),
|
&config.authorized_staker.pubkey(),
|
||||||
@ -734,7 +734,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||||||
if !stake_activated_in_current_epoch.contains(&bonus_stake_address) {
|
if !stake_activated_in_current_epoch.contains(&bonus_stake_address) {
|
||||||
delegate_stake_transactions.push((
|
delegate_stake_transactions.push((
|
||||||
Transaction::new_unsigned(
|
Transaction::new_unsigned(
|
||||||
Message::new_with_payer(
|
Message::new(
|
||||||
&[stake_instruction::delegate_stake(
|
&[stake_instruction::delegate_stake(
|
||||||
&bonus_stake_address,
|
&bonus_stake_address,
|
||||||
&config.authorized_staker.pubkey(),
|
&config.authorized_staker.pubkey(),
|
||||||
@ -754,7 +754,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||||||
// Deactivate bonus stake
|
// Deactivate bonus stake
|
||||||
delegate_stake_transactions.push((
|
delegate_stake_transactions.push((
|
||||||
Transaction::new_unsigned(
|
Transaction::new_unsigned(
|
||||||
Message::new_with_payer(
|
Message::new(
|
||||||
&[stake_instruction::deactivate_stake(
|
&[stake_instruction::deactivate_stake(
|
||||||
&bonus_stake_address,
|
&bonus_stake_address,
|
||||||
&config.authorized_staker.pubkey(),
|
&config.authorized_staker.pubkey(),
|
||||||
@ -779,7 +779,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||||||
{
|
{
|
||||||
// Deactivate baseline stake
|
// Deactivate baseline stake
|
||||||
delegate_stake_transactions.push((
|
delegate_stake_transactions.push((
|
||||||
Transaction::new_unsigned(Message::new_with_payer(
|
Transaction::new_unsigned(Message::new(
|
||||||
&[stake_instruction::deactivate_stake(
|
&[stake_instruction::deactivate_stake(
|
||||||
&baseline_stake_address,
|
&baseline_stake_address,
|
||||||
&config.authorized_staker.pubkey(),
|
&config.authorized_staker.pubkey(),
|
||||||
@ -795,7 +795,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||||||
|
|
||||||
// Deactivate bonus stake
|
// Deactivate bonus stake
|
||||||
delegate_stake_transactions.push((
|
delegate_stake_transactions.push((
|
||||||
Transaction::new_unsigned(Message::new_with_payer(
|
Transaction::new_unsigned(Message::new(
|
||||||
&[stake_instruction::deactivate_stake(
|
&[stake_instruction::deactivate_stake(
|
||||||
&bonus_stake_address,
|
&bonus_stake_address,
|
||||||
&config.authorized_staker.pubkey(),
|
&config.authorized_staker.pubkey(),
|
||||||
|
@ -158,7 +158,7 @@ fn distribute_tokens(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let fee_payer_pubkey = args.fee_payer.pubkey();
|
let fee_payer_pubkey = args.fee_payer.pubkey();
|
||||||
let message = Message::new_with_payer(&instructions, Some(&fee_payer_pubkey));
|
let message = Message::new(&instructions, Some(&fee_payer_pubkey));
|
||||||
match client.send_message(message, &signers) {
|
match client.send_message(message, &signers) {
|
||||||
Ok((transaction, last_valid_slot)) => {
|
Ok((transaction, last_valid_slot)) => {
|
||||||
db::set_transaction_info(
|
db::set_transaction_info(
|
||||||
@ -508,7 +508,7 @@ pub fn test_process_distribute_stake_with_client<C: Client>(client: C, sender_ke
|
|||||||
&lockup,
|
&lockup,
|
||||||
sol_to_lamports(3000.0),
|
sol_to_lamports(3000.0),
|
||||||
);
|
);
|
||||||
let message = Message::new(&instructions);
|
let message = Message::new(&instructions, Some(&sender_keypair.pubkey()));
|
||||||
let signers = [&sender_keypair, &stake_account_keypair];
|
let signers = [&sender_keypair, &stake_account_keypair];
|
||||||
thin_client.send_message(message, &signers).unwrap();
|
thin_client.send_message(message, &signers).unwrap();
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ impl<'a> ThinClient<'a> {
|
|||||||
) -> Result<(Transaction, u64)> {
|
) -> Result<(Transaction, u64)> {
|
||||||
let create_instruction =
|
let create_instruction =
|
||||||
system_instruction::transfer(&sender_keypair.pubkey(), &to_pubkey, lamports);
|
system_instruction::transfer(&sender_keypair.pubkey(), &to_pubkey, lamports);
|
||||||
let message = Message::new(&[create_instruction]);
|
let message = Message::new(&[create_instruction], Some(&sender_keypair.pubkey()));
|
||||||
self.send_message(message, &[sender_keypair])
|
self.send_message(message, &[sender_keypair])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user