Transaction format changes toward Credit-Only accounts (#4386)
* Add num_readonly_accounts slice * Impl programs in account_keys * Emulate current account-loading functionality using program-account_keys (breaks exchange_program_api tests) * Fix test * Add temporary exchange faucet id * Update chacha golden * Split num_credit_only_accounts into separate fields * Improve readability * Move message field constants into Message * Add MessageHeader struct and fixup comments
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
|
||||
use crate::exchange_instruction::*;
|
||||
use crate::exchange_state::*;
|
||||
use crate::id;
|
||||
use crate::faucet_id;
|
||||
use log::*;
|
||||
use solana_metrics::inc_new_counter_info;
|
||||
use solana_sdk::account::KeyedAccount;
|
||||
@ -192,7 +192,7 @@ impl ExchangeProcessor {
|
||||
let mut to_account =
|
||||
Self::deserialize_account(&keyed_accounts[TO_ACCOUNT_INDEX].account.data)?;
|
||||
|
||||
if &id() == keyed_accounts[FROM_ACCOUNT_INDEX].unsigned_key() {
|
||||
if &faucet_id() == keyed_accounts[FROM_ACCOUNT_INDEX].unsigned_key() {
|
||||
to_account.tokens[token] += tokens;
|
||||
} else {
|
||||
let state: ExchangeState =
|
||||
@ -460,7 +460,7 @@ pub fn process_instruction(
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::exchange_instruction;
|
||||
use crate::{exchange_instruction, id};
|
||||
use solana_runtime::bank::Bank;
|
||||
use solana_runtime::bank_client::BankClient;
|
||||
use solana_sdk::client::SyncClient;
|
||||
@ -588,8 +588,13 @@ mod test {
|
||||
}
|
||||
|
||||
fn transfer(client: &BankClient, owner: &Keypair, to: &Pubkey, token: Token, tokens: u64) {
|
||||
let instruction =
|
||||
exchange_instruction::transfer_request(&owner.pubkey(), to, &id(), token, tokens);
|
||||
let instruction = exchange_instruction::transfer_request(
|
||||
&owner.pubkey(),
|
||||
to,
|
||||
&faucet_id(),
|
||||
token,
|
||||
tokens,
|
||||
);
|
||||
client
|
||||
.send_instruction(owner, instruction)
|
||||
.expect(&format!("{}:{}", line!(), file!()));
|
||||
@ -664,8 +669,13 @@ mod test {
|
||||
|
||||
let new = create_token_account(&client, &owner);
|
||||
|
||||
let instruction =
|
||||
exchange_instruction::transfer_request(&owner.pubkey(), &new, &id(), Token::A, 42);
|
||||
let instruction = exchange_instruction::transfer_request(
|
||||
&owner.pubkey(),
|
||||
&new,
|
||||
&faucet_id(),
|
||||
Token::A,
|
||||
42,
|
||||
);
|
||||
client
|
||||
.send_instruction(&owner, instruction)
|
||||
.expect(&format!("{}:{}", line!(), file!()));
|
||||
|
@ -11,3 +11,22 @@ pub const EXCHANGE_PROGRAM_ID: [u8; 32] = [
|
||||
];
|
||||
|
||||
solana_sdk::solana_program_id!(EXCHANGE_PROGRAM_ID);
|
||||
|
||||
pub const EXCHANGE_FAUCET_ID: [u8; 32] = [
|
||||
3, 147, 111, 103, 210, 47, 23, 11, 176, 29, 147, 89, 237, 155, 21, 62, 107, 105, 157, 1, 98,
|
||||
204, 206, 211, 54, 212, 79, 15, 160, 0, 0, 0,
|
||||
];
|
||||
|
||||
pub fn faucet_id() -> solana_sdk::pubkey::Pubkey {
|
||||
solana_sdk::pubkey::Pubkey::new(&EXCHANGE_FAUCET_ID)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn exchange_faucet_id() {
|
||||
let ids = [("ExchangeFaucet11111111111111111111111111111", faucet_id())];
|
||||
assert!(ids.iter().all(|(name, id)| *name == id.to_string()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user