Support nonced transactions in the CLI (#7624)
* Support nonced transactions in the CLI * Update nonce.rs
This commit is contained in:
@ -49,3 +49,25 @@ pub fn transfer(
|
||||
let instructions = vec![transfer_instruction];
|
||||
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash)
|
||||
}
|
||||
|
||||
/// Create and sign new nonced system_instruction::Transfer transaction
|
||||
pub fn nonced_transfer(
|
||||
from_keypair: &Keypair,
|
||||
to: &Pubkey,
|
||||
lamports: u64,
|
||||
nonce_account: &Pubkey,
|
||||
nonce_authority: &Keypair,
|
||||
nonce_hash: Hash,
|
||||
) -> Transaction {
|
||||
let from_pubkey = from_keypair.pubkey();
|
||||
let transfer_instruction = system_instruction::transfer(&from_pubkey, to, lamports);
|
||||
let instructions = vec![transfer_instruction];
|
||||
Transaction::new_signed_with_nonce(
|
||||
instructions,
|
||||
Some(&from_pubkey),
|
||||
&[from_keypair, nonce_authority],
|
||||
nonce_account,
|
||||
&nonce_authority.pubkey(),
|
||||
nonce_hash,
|
||||
)
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
use crate::hash::Hash;
|
||||
use crate::instruction::{CompiledInstruction, Instruction, InstructionError};
|
||||
use crate::message::Message;
|
||||
use crate::nonce_instruction;
|
||||
use crate::pubkey::Pubkey;
|
||||
use crate::short_vec;
|
||||
use crate::signature::{KeypairUtil, Signature};
|
||||
@ -94,6 +95,19 @@ impl Transaction {
|
||||
Self::new(signing_keypairs, message, recent_blockhash)
|
||||
}
|
||||
|
||||
pub fn new_signed_with_nonce<T: KeypairUtil>(
|
||||
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 = nonce_instruction::nonce(&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: Vec<Instruction>) -> Self {
|
||||
let message = Message::new(instructions);
|
||||
Self::new_unsigned(message)
|
||||
|
Reference in New Issue
Block a user