Skip to content

Commit 55253c4

Browse files
committed
account-data/steel - improve readability
1 parent e27f4ef commit 55253c4

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

basics/account-data/steel/program/src/lib.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ pub fn process_instruction(
1010
accounts: &[AccountInfo],
1111
data: &[u8],
1212
) -> ProgramResult {
13-
// Parse data into address info.
13+
// Parse data into AddressInfo.
14+
//
1415
let address_info_data = bytemuck::try_from_bytes::<AddressInfo>(data)
1516
.or(Err(ProgramError::InvalidInstructionData))?;
1617

@@ -26,13 +27,15 @@ pub fn process_instruction(
2627
let rent = Rent::get()?;
2728
let space = 8 + std::mem::size_of::<AddressInfo>();
2829

30+
// create the account
31+
//
2932
solana_program::program::invoke(
3033
&solana_program::system_instruction::create_account(
3134
payer.key,
3235
address_info_account.key,
33-
rent.minimum_balance(space),
34-
space as u64,
35-
program_id,
36+
rent.minimum_balance(space), // lamports
37+
space as u64, // space
38+
program_id, // program id
3639
),
3740
&[
3841
payer.clone(),
@@ -41,9 +44,16 @@ pub fn process_instruction(
4144
],
4245
)?;
4346

47+
// parse the account to AddressInfo
48+
//
4449
let address_info = address_info_account.as_account_mut::<AddressInfo>(program_id)?;
4550

46-
*address_info = *address_info_data;
51+
// set the account data
52+
//
53+
address_info.name = address_info_data.name;
54+
address_info.house_number = address_info_data.house_number;
55+
address_info.street = address_info_data.street;
56+
address_info.city = address_info_data.city;
4757

4858
Ok(())
4959
}

basics/account-data/steel/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"types": ["mocha", "chai"],
3+
"types": ["mocha", "chai", "node"],
44
"typeRoots": ["./node_modules/@types"],
55
"lib": ["es2015"],
66
"module": "commonjs",

0 commit comments

Comments
 (0)