Rename Account.program_id to Account.owner
This commit is contained in:
parent
7d05cc8c5d
commit
522876c808
@ -110,7 +110,7 @@ fn serialize_parameters(keyed_accounts: &mut [KeyedAccount], data: &[u8]) -> Vec
|
|||||||
v.write_u64::<LittleEndian>(info.account.userdata.len() as u64)
|
v.write_u64::<LittleEndian>(info.account.userdata.len() as u64)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
v.write_all(&info.account.userdata).unwrap();
|
v.write_all(&info.account.userdata).unwrap();
|
||||||
v.write_all(info.account.program_id.as_ref()).unwrap();
|
v.write_all(info.account.owner.as_ref()).unwrap();
|
||||||
}
|
}
|
||||||
v.write_u64::<LittleEndian>(data.len() as u64).unwrap();
|
v.write_u64::<LittleEndian>(data.len() as u64).unwrap();
|
||||||
v.write_all(data).unwrap();
|
v.write_all(data).unwrap();
|
||||||
@ -131,7 +131,7 @@ fn deserialize_parameters(keyed_accounts: &mut [KeyedAccount], buffer: &[u8]) {
|
|||||||
info.account.userdata.clone_from_slice(&buffer[start..end]);
|
info.account.userdata.clone_from_slice(&buffer[start..end]);
|
||||||
|
|
||||||
start += info.account.userdata.len() // skip userdata
|
start += info.account.userdata.len() // skip userdata
|
||||||
+ mem::size_of::<Pubkey>(); // skip program_id
|
+ mem::size_of::<Pubkey>(); // skip owner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ mod tests {
|
|||||||
|
|
||||||
let alice_pubkey = Pubkey::default();
|
let alice_pubkey = Pubkey::default();
|
||||||
let bob_pubkey = Pubkey::default();
|
let bob_pubkey = Pubkey::default();
|
||||||
let program_id = Pubkey::default();
|
let owner = Pubkey::default();
|
||||||
|
|
||||||
let mut accounts = [
|
let mut accounts = [
|
||||||
(
|
(
|
||||||
@ -164,13 +164,13 @@ mod tests {
|
|||||||
Account {
|
Account {
|
||||||
tokens: 1,
|
tokens: 1,
|
||||||
userdata,
|
userdata,
|
||||||
program_id,
|
owner,
|
||||||
executable: true,
|
executable: true,
|
||||||
loader: Pubkey::default(),
|
loader: Pubkey::default(),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
(alice_pubkey, Account::new(100, 0, program_id)),
|
(alice_pubkey, Account::new(100, 0, owner)),
|
||||||
(bob_pubkey, Account::new(1, 0, program_id)),
|
(bob_pubkey, Account::new(1, 0, owner)),
|
||||||
];
|
];
|
||||||
let data = serialize(&10u64).unwrap();
|
let data = serialize(&10u64).unwrap();
|
||||||
process(&mut create_keyed_accounts(&mut accounts), &data);
|
process(&mut create_keyed_accounts(&mut accounts), &data);
|
||||||
@ -198,19 +198,19 @@ mod tests {
|
|||||||
accounts[3].userdata = serialize({a=1, b=2, c=3}, nil, "s")
|
accounts[3].userdata = serialize({a=1, b=2, c=3}, nil, "s")
|
||||||
"#.as_bytes()
|
"#.as_bytes()
|
||||||
.to_vec();
|
.to_vec();
|
||||||
let program_id = Pubkey::default();
|
let owner = Pubkey::default();
|
||||||
let program_account = Account {
|
let program_account = Account {
|
||||||
tokens: 1,
|
tokens: 1,
|
||||||
userdata,
|
userdata,
|
||||||
program_id,
|
owner,
|
||||||
executable: true,
|
executable: true,
|
||||||
loader: Pubkey::default(),
|
loader: Pubkey::default(),
|
||||||
};
|
};
|
||||||
let alice_account = Account::new(100, 0, program_id);
|
let alice_account = Account::new(100, 0, owner);
|
||||||
let serialize_account = Account {
|
let serialize_account = Account {
|
||||||
tokens: 100,
|
tokens: 100,
|
||||||
userdata: read_test_file("serialize.lua"),
|
userdata: read_test_file("serialize.lua"),
|
||||||
program_id,
|
owner,
|
||||||
executable: false,
|
executable: false,
|
||||||
loader: Pubkey::default(),
|
loader: Pubkey::default(),
|
||||||
};
|
};
|
||||||
@ -218,7 +218,7 @@ mod tests {
|
|||||||
(Pubkey::default(), program_account),
|
(Pubkey::default(), program_account),
|
||||||
(Pubkey::default(), alice_account),
|
(Pubkey::default(), alice_account),
|
||||||
(Pubkey::default(), serialize_account),
|
(Pubkey::default(), serialize_account),
|
||||||
(Pubkey::default(), Account::new(1, 0, program_id)),
|
(Pubkey::default(), Account::new(1, 0, owner)),
|
||||||
];
|
];
|
||||||
let mut keyed_accounts = create_keyed_accounts(&mut accounts);
|
let mut keyed_accounts = create_keyed_accounts(&mut accounts);
|
||||||
process(&mut keyed_accounts, &[]);
|
process(&mut keyed_accounts, &[]);
|
||||||
@ -231,7 +231,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_lua_multisig() {
|
fn test_lua_multisig() {
|
||||||
let program_id = Pubkey::default();
|
let owner = Pubkey::default();
|
||||||
|
|
||||||
let alice_pubkey = Pubkey::new(&[0; 32]);
|
let alice_pubkey = Pubkey::new(&[0; 32]);
|
||||||
let serialize_pubkey = Pubkey::new(&[1; 32]);
|
let serialize_pubkey = Pubkey::new(&[1; 32]);
|
||||||
@ -244,7 +244,7 @@ mod tests {
|
|||||||
let program_account = Account {
|
let program_account = Account {
|
||||||
tokens: 1,
|
tokens: 1,
|
||||||
userdata: read_test_file("multisig.lua"),
|
userdata: read_test_file("multisig.lua"),
|
||||||
program_id,
|
owner,
|
||||||
executable: true,
|
executable: true,
|
||||||
loader: Pubkey::default(),
|
loader: Pubkey::default(),
|
||||||
};
|
};
|
||||||
@ -252,7 +252,7 @@ mod tests {
|
|||||||
let alice_account = Account {
|
let alice_account = Account {
|
||||||
tokens: 100,
|
tokens: 100,
|
||||||
userdata: Vec::new(),
|
userdata: Vec::new(),
|
||||||
program_id,
|
owner,
|
||||||
executable: true,
|
executable: true,
|
||||||
loader: Pubkey::default(),
|
loader: Pubkey::default(),
|
||||||
};
|
};
|
||||||
@ -260,7 +260,7 @@ mod tests {
|
|||||||
let serialize_account = Account {
|
let serialize_account = Account {
|
||||||
tokens: 100,
|
tokens: 100,
|
||||||
userdata: read_test_file("serialize.lua"),
|
userdata: read_test_file("serialize.lua"),
|
||||||
program_id,
|
owner,
|
||||||
executable: true,
|
executable: true,
|
||||||
loader: Pubkey::default(),
|
loader: Pubkey::default(),
|
||||||
};
|
};
|
||||||
@ -269,8 +269,8 @@ mod tests {
|
|||||||
(Pubkey::default(), program_account), // Account holding the program
|
(Pubkey::default(), program_account), // Account holding the program
|
||||||
(alice_pubkey, alice_account), // The payer
|
(alice_pubkey, alice_account), // The payer
|
||||||
(serialize_pubkey, serialize_account), // Where the serialize library is stored.
|
(serialize_pubkey, serialize_account), // Where the serialize library is stored.
|
||||||
(state_pubkey, Account::new(1, 0, program_id)), // Where program state is stored.
|
(state_pubkey, Account::new(1, 0, owner)), // Where program state is stored.
|
||||||
(bob_pubkey, Account::new(1, 0, program_id)), // The payee once M signatures are collected.
|
(bob_pubkey, Account::new(1, 0, owner)), // The payee once M signatures are collected.
|
||||||
];
|
];
|
||||||
let mut keyed_accounts = create_keyed_accounts(&mut accounts);
|
let mut keyed_accounts = create_keyed_accounts(&mut accounts);
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ pub struct Account {
|
|||||||
/// A transaction can write to its userdata
|
/// A transaction can write to its userdata
|
||||||
pub userdata: Vec<u8>,
|
pub userdata: Vec<u8>,
|
||||||
/// contract id this contract belongs to
|
/// contract id this contract belongs to
|
||||||
pub program_id: Pubkey,
|
pub owner: Pubkey,
|
||||||
|
|
||||||
/// this account contains a program (and is strictly read-only)
|
/// this account contains a program (and is strictly read-only)
|
||||||
pub executable: bool,
|
pub executable: bool,
|
||||||
@ -20,12 +20,12 @@ pub struct Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Account {
|
impl Account {
|
||||||
// TODO do we want to add executable and leader_program_id even though they should always be false/default?
|
// TODO do we want to add executable and leader_owner even though they should always be false/default?
|
||||||
pub fn new(tokens: u64, space: usize, program_id: Pubkey) -> Account {
|
pub fn new(tokens: u64, space: usize, owner: Pubkey) -> Account {
|
||||||
Account {
|
Account {
|
||||||
tokens,
|
tokens,
|
||||||
userdata: vec![0u8; space],
|
userdata: vec![0u8; space],
|
||||||
program_id,
|
owner,
|
||||||
executable: false,
|
executable: false,
|
||||||
loader: Pubkey::default(),
|
loader: Pubkey::default(),
|
||||||
}
|
}
|
||||||
|
12
src/bank.rs
12
src/bank.rs
@ -726,11 +726,11 @@ impl Bank {
|
|||||||
// Verify the transaction
|
// Verify the transaction
|
||||||
|
|
||||||
// Make sure that program_id is still the same or this was just assigned by the system call contract
|
// Make sure that program_id is still the same or this was just assigned by the system call contract
|
||||||
if *pre_program_id != account.program_id && !SystemProgram::check_id(&program_id) {
|
if *pre_program_id != account.owner && !SystemProgram::check_id(&program_id) {
|
||||||
return Err(BankError::ModifiedContractId(instruction_index as u8));
|
return Err(BankError::ModifiedContractId(instruction_index as u8));
|
||||||
}
|
}
|
||||||
// For accounts unassigned to the contract, the individual balance of each accounts cannot decrease.
|
// For accounts unassigned to the contract, the individual balance of each accounts cannot decrease.
|
||||||
if *program_id != account.program_id && pre_tokens > account.tokens {
|
if *program_id != account.owner && pre_tokens > account.tokens {
|
||||||
return Err(BankError::ExternalAccountTokenSpend(
|
return Err(BankError::ExternalAccountTokenSpend(
|
||||||
instruction_index as u8,
|
instruction_index as u8,
|
||||||
));
|
));
|
||||||
@ -771,7 +771,7 @@ impl Bank {
|
|||||||
let pre_total: u64 = program_accounts.iter().map(|a| a.tokens).sum();
|
let pre_total: u64 = program_accounts.iter().map(|a| a.tokens).sum();
|
||||||
let pre_data: Vec<_> = program_accounts
|
let pre_data: Vec<_> = program_accounts
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.map(|a| (a.program_id, a.tokens))
|
.map(|a| (a.owner, a.tokens))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Call the contract method
|
// Call the contract method
|
||||||
@ -1299,9 +1299,9 @@ impl Bank {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_balance(account: &Account) -> u64 {
|
pub fn read_balance(account: &Account) -> u64 {
|
||||||
if SystemProgram::check_id(&account.program_id) {
|
if SystemProgram::check_id(&account.owner) {
|
||||||
SystemProgram::get_balance(account)
|
SystemProgram::get_balance(account)
|
||||||
} else if BudgetState::check_id(&account.program_id) {
|
} else if BudgetState::check_id(&account.owner) {
|
||||||
BudgetState::get_balance(account)
|
BudgetState::get_balance(account)
|
||||||
} else {
|
} else {
|
||||||
account.tokens
|
account.tokens
|
||||||
@ -2025,7 +2025,7 @@ mod tests {
|
|||||||
let string = transport_receiver.poll();
|
let string = transport_receiver.poll();
|
||||||
assert!(string.is_ok());
|
assert!(string.is_ok());
|
||||||
if let Async::Ready(Some(response)) = string.unwrap() {
|
if let Async::Ready(Some(response)) = string.unwrap() {
|
||||||
let expected = format!(r#"{{"jsonrpc":"2.0","method":"accountNotification","params":{{"result":{{"executable":false,"loader":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"program_id":[129,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tokens":1,"userdata":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},"subscription":0}}}}"#);
|
let expected = format!(r#"{{"jsonrpc":"2.0","method":"accountNotification","params":{{"result":{{"executable":false,"loader":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"owner":[129,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tokens":1,"userdata":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},"subscription":0}}}}"#);
|
||||||
assert_eq!(expected, response);
|
assert_eq!(expected, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ pub fn id() -> Pubkey {
|
|||||||
pub fn account() -> Account {
|
pub fn account() -> Account {
|
||||||
Account {
|
Account {
|
||||||
tokens: 0,
|
tokens: 0,
|
||||||
program_id: id(),
|
owner: id(),
|
||||||
userdata: BPF_LOADER_NAME.as_bytes().to_vec(),
|
userdata: BPF_LOADER_NAME.as_bytes().to_vec(),
|
||||||
executable: true,
|
executable: true,
|
||||||
loader: native_loader::id(),
|
loader: native_loader::id(),
|
||||||
|
@ -46,7 +46,7 @@ impl ComputeLeaderFinalityService {
|
|||||||
.filter_map(|account| {
|
.filter_map(|account| {
|
||||||
// Filter out any accounts that don't belong to the VoteProgram
|
// Filter out any accounts that don't belong to the VoteProgram
|
||||||
// by returning None
|
// by returning None
|
||||||
if VoteProgram::check_id(&account.program_id) {
|
if VoteProgram::check_id(&account.owner) {
|
||||||
if let Ok(vote_state) = VoteProgram::deserialize(&account.userdata) {
|
if let Ok(vote_state) = VoteProgram::deserialize(&account.userdata) {
|
||||||
let validator_stake = bank.get_stake(&vote_state.node_id);
|
let validator_stake = bank.get_stake(&vote_state.node_id);
|
||||||
total_stake += validator_stake;
|
total_stake += validator_stake;
|
||||||
|
@ -121,7 +121,7 @@ Returns all information associated with the account of provided Pubkey
|
|||||||
The result field will be a JSON object with the following sub fields:
|
The result field will be a JSON object with the following sub fields:
|
||||||
|
|
||||||
* `tokens`, number of tokens assigned to this account, as a signed 64-bit integer
|
* `tokens`, number of tokens assigned to this account, as a signed 64-bit integer
|
||||||
* `program_id`, array of 32 bytes representing the program this account has been assigned to
|
* `owner`, array of 32 bytes representing the program this account has been assigned to
|
||||||
* `userdata`, array of bytes representing any userdata associated with the account
|
* `userdata`, array of bytes representing any userdata associated with the account
|
||||||
* `executable`, boolean indicating if the account contains a program (and is strictly read-only)
|
* `executable`, boolean indicating if the account contains a program (and is strictly read-only)
|
||||||
* `loader`, array of 32 bytes representing the loader for this program (if `executable`), otherwise all
|
* `loader`, array of 32 bytes representing the loader for this program (if `executable`), otherwise all
|
||||||
@ -132,7 +132,7 @@ The result field will be a JSON object with the following sub fields:
|
|||||||
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id":1, "method":"getAccountInfo", "params":["2gVkYWexTHR5Hb2aLeQN3tnngvWzisFKXDUPrgMHpdST"]}' http://localhost:8899
|
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id":1, "method":"getAccountInfo", "params":["2gVkYWexTHR5Hb2aLeQN3tnngvWzisFKXDUPrgMHpdST"]}' http://localhost:8899
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
{"jsonrpc":"2.0","result":{"executable":false,"loader":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"program_id":[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tokens":1,"userdata":[3,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,20,0,0,0,0,0,0,0,50,48,53,48,45,48,49,45,48,49,84,48,48,58,48,48,58,48,48,90,252,10,7,28,246,140,88,177,98,82,10,227,89,81,18,30,194,101,199,16,11,73,133,20,246,62,114,39,20,113,189,32,50,0,0,0,0,0,0,0,247,15,36,102,167,83,225,42,133,127,82,34,36,224,207,130,109,230,224,188,163,33,213,13,5,117,211,251,65,159,197,51,0,0,0,0,0,0]},"id":1}
|
{"jsonrpc":"2.0","result":{"executable":false,"loader":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"owner":[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tokens":1,"userdata":[3,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,20,0,0,0,0,0,0,0,50,48,53,48,45,48,49,45,48,49,84,48,48,58,48,48,58,48,48,90,252,10,7,28,246,140,88,177,98,82,10,227,89,81,18,30,194,101,199,16,11,73,133,20,246,62,114,39,20,113,189,32,50,0,0,0,0,0,0,0,247,15,36,102,167,83,225,42,133,127,82,34,36,224,207,130,109,230,224,188,163,33,213,13,5,117,211,251,65,159,197,51,0,0,0,0,0,0]},"id":1}
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -271,7 +271,7 @@ Subscribe to an account to receive notifications when the userdata for a given a
|
|||||||
|
|
||||||
##### Notification Format:
|
##### Notification Format:
|
||||||
```bash
|
```bash
|
||||||
{"jsonrpc": "2.0","method": "accountNotification", "params": {"result": {"executable":false,"loader":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"program_id":[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tokens":1,"userdata":[3,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,20,0,0,0,0,0,0,0,50,48,53,48,45,48,49,45,48,49,84,48,48,58,48,48,58,48,48,90,252,10,7,28,246,140,88,177,98,82,10,227,89,81,18,30,194,101,199,16,11,73,133,20,246,62,114,39,20,113,189,32,50,0,0,0,0,0,0,0,247,15,36,102,167,83,225,42,133,127,82,34,36,224,207,130,109,230,224,188,163,33,213,13,5,117,211,251,65,159,197,51,0,0,0,0,0,0]},"subscription":0}}
|
{"jsonrpc": "2.0","method": "accountNotification", "params": {"result": {"executable":false,"loader":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"owner":[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tokens":1,"userdata":[3,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,20,0,0,0,0,0,0,0,50,48,53,48,45,48,49,45,48,49,84,48,48,58,48,48,58,48,48,90,252,10,7,28,246,140,88,177,98,82,10,227,89,81,18,30,194,101,199,16,11,73,133,20,246,62,114,39,20,113,189,32,50,0,0,0,0,0,0,0,247,15,36,102,167,83,225,42,133,127,82,34,36,224,207,130,109,230,224,188,163,33,213,13,5,117,211,251,65,159,197,51,0,0,0,0,0,0]},"subscription":0}}
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -294,7 +294,7 @@ impl LeaderScheduler {
|
|||||||
.accounts
|
.accounts
|
||||||
.values()
|
.values()
|
||||||
.filter_map(|account| {
|
.filter_map(|account| {
|
||||||
if VoteProgram::check_id(&account.program_id) {
|
if VoteProgram::check_id(&account.owner) {
|
||||||
if let Ok(vote_state) = VoteProgram::deserialize(&account.userdata) {
|
if let Ok(vote_state) = VoteProgram::deserialize(&account.userdata) {
|
||||||
return vote_state
|
return vote_state
|
||||||
.votes
|
.votes
|
||||||
|
@ -484,7 +484,7 @@ mod tests {
|
|||||||
let expected = r#"{
|
let expected = r#"{
|
||||||
"jsonrpc":"2.0",
|
"jsonrpc":"2.0",
|
||||||
"result":{
|
"result":{
|
||||||
"program_id": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
|
"owner": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
|
||||||
"tokens": 20,
|
"tokens": 20,
|
||||||
"userdata": [],
|
"userdata": [],
|
||||||
"executable": false,
|
"executable": false,
|
||||||
|
@ -485,7 +485,7 @@ mod tests {
|
|||||||
"method": "accountNotification",
|
"method": "accountNotification",
|
||||||
"params": {
|
"params": {
|
||||||
"result": {
|
"result": {
|
||||||
"program_id": budget_program_id,
|
"owner": budget_program_id,
|
||||||
"tokens": 1,
|
"tokens": 1,
|
||||||
"userdata": expected_userdata,
|
"userdata": expected_userdata,
|
||||||
"executable": executable,
|
"executable": executable,
|
||||||
@ -526,7 +526,7 @@ mod tests {
|
|||||||
"method": "accountNotification",
|
"method": "accountNotification",
|
||||||
"params": {
|
"params": {
|
||||||
"result": {
|
"result": {
|
||||||
"program_id": budget_program_id,
|
"owner": budget_program_id,
|
||||||
"tokens": 51,
|
"tokens": 51,
|
||||||
"userdata": expected_userdata,
|
"userdata": expected_userdata,
|
||||||
"executable": executable,
|
"executable": executable,
|
||||||
@ -565,7 +565,7 @@ mod tests {
|
|||||||
"method": "accountNotification",
|
"method": "accountNotification",
|
||||||
"params": {
|
"params": {
|
||||||
"result": {
|
"result": {
|
||||||
"program_id": budget_program_id,
|
"owner": budget_program_id,
|
||||||
"tokens": 1,
|
"tokens": 1,
|
||||||
"userdata": expected_userdata,
|
"userdata": expected_userdata,
|
||||||
"executable": executable,
|
"executable": executable,
|
||||||
|
@ -73,14 +73,13 @@ impl SystemProgram {
|
|||||||
space,
|
space,
|
||||||
program_id,
|
program_id,
|
||||||
} => {
|
} => {
|
||||||
if !Self::check_id(&accounts[0].program_id) {
|
if !Self::check_id(&accounts[0].owner) {
|
||||||
info!("Invalid account[0] program_id");
|
info!("Invalid account[0] owner");
|
||||||
Err(Error::InvalidArgument)?;
|
Err(Error::InvalidArgument)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if space > 0
|
if space > 0
|
||||||
&& (!accounts[1].userdata.is_empty()
|
&& (!accounts[1].userdata.is_empty() || !Self::check_id(&accounts[1].owner))
|
||||||
|| !Self::check_id(&accounts[1].program_id))
|
|
||||||
{
|
{
|
||||||
info!("Invalid account[1]");
|
info!("Invalid account[1]");
|
||||||
Err(Error::InvalidArgument)?;
|
Err(Error::InvalidArgument)?;
|
||||||
@ -91,16 +90,16 @@ impl SystemProgram {
|
|||||||
}
|
}
|
||||||
accounts[0].tokens -= tokens;
|
accounts[0].tokens -= tokens;
|
||||||
accounts[1].tokens += tokens;
|
accounts[1].tokens += tokens;
|
||||||
accounts[1].program_id = program_id;
|
accounts[1].owner = program_id;
|
||||||
accounts[1].userdata = vec![0; space as usize];
|
accounts[1].userdata = vec![0; space as usize];
|
||||||
accounts[1].executable = false;
|
accounts[1].executable = false;
|
||||||
accounts[1].loader = Pubkey::default();
|
accounts[1].loader = Pubkey::default();
|
||||||
}
|
}
|
||||||
SystemProgram::Assign { program_id } => {
|
SystemProgram::Assign { program_id } => {
|
||||||
if !Self::check_id(&accounts[0].program_id) {
|
if !Self::check_id(&accounts[0].owner) {
|
||||||
Err(Error::AssignOfUnownedAccount)?;
|
Err(Error::AssignOfUnownedAccount)?;
|
||||||
}
|
}
|
||||||
accounts[0].program_id = program_id;
|
accounts[0].owner = program_id;
|
||||||
}
|
}
|
||||||
SystemProgram::Move { tokens } => {
|
SystemProgram::Move { tokens } => {
|
||||||
//bank should be verifying correctness
|
//bank should be verifying correctness
|
||||||
@ -112,12 +111,11 @@ impl SystemProgram {
|
|||||||
accounts[1].tokens += tokens;
|
accounts[1].tokens += tokens;
|
||||||
}
|
}
|
||||||
SystemProgram::Spawn => {
|
SystemProgram::Spawn => {
|
||||||
if !accounts[0].executable || accounts[0].loader != Pubkey::default()
|
if !accounts[0].executable || accounts[0].loader != Pubkey::default() {
|
||||||
{
|
|
||||||
Err(Error::AccountNotFinalized)?;
|
Err(Error::AccountNotFinalized)?;
|
||||||
}
|
}
|
||||||
accounts[0].loader = accounts[0].program_id;
|
accounts[0].loader = accounts[0].owner;
|
||||||
accounts[0].program_id = tx.account_keys[0];
|
accounts[0].owner = tx.account_keys[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -171,7 +169,7 @@ mod test {
|
|||||||
let to = Keypair::new();
|
let to = Keypair::new();
|
||||||
let mut accounts = vec![Account::default(), Account::default()];
|
let mut accounts = vec![Account::default(), Account::default()];
|
||||||
accounts[0].tokens = 1;
|
accounts[0].tokens = 1;
|
||||||
accounts[0].program_id = from.pubkey();
|
accounts[0].owner = from.pubkey();
|
||||||
let tx = Transaction::system_new(&from, to.pubkey(), 1, Hash::default());
|
let tx = Transaction::system_new(&from, to.pubkey(), 1, Hash::default());
|
||||||
if let Ok(()) = process_transaction(&tx, &mut accounts) {
|
if let Ok(()) = process_transaction(&tx, &mut accounts) {
|
||||||
panic!("Account not owned by SystemProgram");
|
panic!("Account not owned by SystemProgram");
|
||||||
@ -189,14 +187,14 @@ mod test {
|
|||||||
process_transaction(&tx, &mut accounts).unwrap();
|
process_transaction(&tx, &mut accounts).unwrap();
|
||||||
assert!(accounts[0].userdata.is_empty());
|
assert!(accounts[0].userdata.is_empty());
|
||||||
assert_eq!(accounts[1].userdata.len(), 1);
|
assert_eq!(accounts[1].userdata.len(), 1);
|
||||||
assert_eq!(accounts[1].program_id, to.pubkey());
|
assert_eq!(accounts[1].owner, to.pubkey());
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_allocate_wrong_dest_program() {
|
fn test_create_allocate_wrong_dest_program() {
|
||||||
let from = Keypair::new();
|
let from = Keypair::new();
|
||||||
let to = Keypair::new();
|
let to = Keypair::new();
|
||||||
let mut accounts = vec![Account::default(), Account::default()];
|
let mut accounts = vec![Account::default(), Account::default()];
|
||||||
accounts[1].program_id = to.pubkey();
|
accounts[1].owner = to.pubkey();
|
||||||
let tx = Transaction::system_create(
|
let tx = Transaction::system_create(
|
||||||
&from,
|
&from,
|
||||||
to.pubkey(),
|
to.pubkey(),
|
||||||
@ -214,7 +212,7 @@ mod test {
|
|||||||
let from = Keypair::new();
|
let from = Keypair::new();
|
||||||
let to = Keypair::new();
|
let to = Keypair::new();
|
||||||
let mut accounts = vec![Account::default(), Account::default()];
|
let mut accounts = vec![Account::default(), Account::default()];
|
||||||
accounts[0].program_id = to.pubkey();
|
accounts[0].owner = to.pubkey();
|
||||||
let tx = Transaction::system_create(
|
let tx = Transaction::system_create(
|
||||||
&from,
|
&from,
|
||||||
to.pubkey(),
|
to.pubkey(),
|
||||||
@ -252,7 +250,7 @@ mod test {
|
|||||||
let mut accounts = vec![Account::default()];
|
let mut accounts = vec![Account::default()];
|
||||||
let tx = Transaction::system_assign(&from, Hash::default(), program.pubkey(), 0);
|
let tx = Transaction::system_assign(&from, Hash::default(), program.pubkey(), 0);
|
||||||
process_transaction(&tx, &mut accounts).unwrap();
|
process_transaction(&tx, &mut accounts).unwrap();
|
||||||
assert_eq!(accounts[0].program_id, program.pubkey());
|
assert_eq!(accounts[0].owner, program.pubkey());
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_move() {
|
fn test_move() {
|
||||||
|
@ -16,7 +16,7 @@ pub fn id() -> Pubkey {
|
|||||||
pub fn account() -> Account {
|
pub fn account() -> Account {
|
||||||
Account {
|
Account {
|
||||||
tokens: 0,
|
tokens: 0,
|
||||||
program_id: id(),
|
owner: id(),
|
||||||
userdata: ERC20_NAME.as_bytes().to_vec(),
|
userdata: ERC20_NAME.as_bytes().to_vec(),
|
||||||
executable: true,
|
executable: true,
|
||||||
loader: native_loader::id(),
|
loader: native_loader::id(),
|
||||||
|
@ -105,7 +105,7 @@ impl VoteProgram {
|
|||||||
Ok(VoteInstruction::RegisterAccount) => {
|
Ok(VoteInstruction::RegisterAccount) => {
|
||||||
// TODO: a single validator could register multiple "vote accounts"
|
// TODO: a single validator could register multiple "vote accounts"
|
||||||
// which would clutter the "accounts" structure. See github issue 1654.
|
// which would clutter the "accounts" structure. See github issue 1654.
|
||||||
accounts[1].program_id = Self::id();
|
accounts[1].owner = Self::id();
|
||||||
|
|
||||||
let mut vote_state = VoteProgram {
|
let mut vote_state = VoteProgram {
|
||||||
votes: VecDeque::new(),
|
votes: VecDeque::new(),
|
||||||
@ -117,7 +117,7 @@ impl VoteProgram {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Ok(VoteInstruction::NewVote(vote)) => {
|
Ok(VoteInstruction::NewVote(vote)) => {
|
||||||
if !Self::check_id(&accounts[0].program_id) {
|
if !Self::check_id(&accounts[0].owner) {
|
||||||
error!("accounts[0] is not assigned to the VOTE_PROGRAM");
|
error!("accounts[0] is not assigned to the VOTE_PROGRAM");
|
||||||
Err(Error::InvalidArguments)?;
|
Err(Error::InvalidArguments)?;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user