Rename userdata to data (#3282)

* Rename userdata to data

Instead of saying "userdata", which is ambiguous and imprecise,
say "instruction data" or "account data".

Also, add `ProgramError::InvalidInstructionData`

Fixes #2761
This commit is contained in:
Greg Fitzgerald
2019-03-14 10:48:27 -06:00
committed by GitHub
parent de13082347
commit c1eec0290e
42 changed files with 245 additions and 254 deletions

View File

@@ -1,39 +1,36 @@
use crate::pubkey::Pubkey;
use std::{cmp, fmt};
/// An Account with userdata that is stored on chain
/// An Account with data that is stored on chain
#[repr(C)]
#[derive(Serialize, Deserialize, Clone, Default, Eq, PartialEq)]
pub struct Account {
/// lamports in the account
pub lamports: u64,
/// data held in this account
pub userdata: Vec<u8>,
pub data: Vec<u8>,
/// the program that owns this account. If executable, the program that loads this account.
pub owner: Pubkey,
/// this account's userdata contains a loaded program (and is now read-only)
/// this account's data contains a loaded program (and is now read-only)
pub executable: bool,
}
impl fmt::Debug for Account {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let userdata_len = cmp::min(64, self.userdata.len());
let userdata_str = if userdata_len > 0 {
format!(
" userdata: {}",
hex::encode(self.userdata[..userdata_len].to_vec())
)
let data_len = cmp::min(64, self.data.len());
let data_str = if data_len > 0 {
format!(" data: {}", hex::encode(self.data[..data_len].to_vec()))
} else {
"".to_string()
};
write!(
f,
"Account {{ lamports: {} userdata.len: {} owner: {} executable: {}{} }}",
"Account {{ lamports: {} data.len: {} owner: {} executable: {}{} }}",
self.lamports,
self.userdata.len(),
self.data.len(),
self.owner,
self.executable,
userdata_str,
data_str,
)
}
}
@@ -43,7 +40,7 @@ impl Account {
pub fn new(lamports: u64, space: usize, owner: &Pubkey) -> Account {
Account {
lamports,
userdata: vec![0u8; space],
data: vec![0u8; space],
owner: *owner,
executable: false,
}