system_instruction_processor updates (#6448)

* zero lamport account creation

* whack create_user_account, take 2

* target->to

* ..

* ..

* update chacha golden

* update chacha golden

* ..

* ..
This commit is contained in:
Rob Walker
2019-10-19 18:23:27 -07:00
committed by GitHub
parent 74ee88d9bc
commit e2c316d2d0
28 changed files with 377 additions and 255 deletions

View File

@ -8,7 +8,6 @@ use num_derive::{FromPrimitive, ToPrimitive};
pub enum SystemError {
AccountAlreadyInUse,
ResultWithNegativeLamports,
SourceNotSystemAccount,
InvalidProgramId,
InvalidAccountId,
}
@ -70,10 +69,17 @@ pub fn create_account(
)
}
/// Create and sign a transaction to create a system account
pub fn create_user_account(from_pubkey: &Pubkey, to_pubkey: &Pubkey, lamports: u64) -> Instruction {
let program_id = system_program::id();
create_account(from_pubkey, to_pubkey, lamports, 0, &program_id)
/// transfer with to as credit-debit
pub fn transfer_now(from_pubkey: &Pubkey, to_pubkey: &Pubkey, lamports: u64) -> Instruction {
let account_metas = vec![
AccountMeta::new(*from_pubkey, true),
AccountMeta::new(*to_pubkey, false),
];
Instruction::new(
system_program::id(),
&SystemInstruction::Transfer { lamports },
account_metas,
)
}
pub fn assign(from_pubkey: &Pubkey, program_id: &Pubkey) -> Instruction {

View File

@ -1,11 +1,12 @@
//! The `system_transaction` module provides functionality for creating system transactions.
use crate::hash::Hash;
use crate::pubkey::Pubkey;
use crate::signature::{Keypair, KeypairUtil};
use crate::system_instruction;
use crate::system_program;
use crate::transaction::Transaction;
use crate::{
hash::Hash,
pubkey::Pubkey,
signature::{Keypair, KeypairUtil},
system_instruction,
transaction::Transaction,
};
/// Create and sign new SystemInstruction::CreateAccount transaction
pub fn create_account(
@ -23,15 +24,17 @@ pub fn create_account(
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash)
}
/// Create and sign a transaction to create a system account
pub fn create_user_account(
/// Create and sign new system_instruction::Transfer transaction, but don't use a CO "to"
pub fn transfer_now(
from_keypair: &Keypair,
to: &Pubkey,
lamports: u64,
recent_blockhash: Hash,
) -> Transaction {
let program_id = system_program::id();
create_account(from_keypair, to, recent_blockhash, lamports, 0, &program_id)
let from_pubkey = from_keypair.pubkey();
let transfer_instruction = system_instruction::transfer_now(&from_pubkey, to, lamports);
let instructions = vec![transfer_instruction];
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash)
}
/// Create and sign new system_instruction::Assign transaction