-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize vault and load it with 1029$
- Loading branch information
1 parent
caf69bc
commit c5c56f1
Showing
18 changed files
with
261 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
# Buld and deploy this program with ease using a single command | ||
# Run this script with "bash cicd.sh" or "./cicd.sh" | ||
# Note: Try running "chmod +x cicd.sh" if you face any issues. | ||
|
||
# Check if cargo is installed | ||
if ! command -v cargo &> /dev/null | ||
then | ||
echo "Cargo could not be found. Please install Rust." | ||
exit 1 | ||
fi | ||
|
||
# Check if solana CLI is installed | ||
if ! command -v solana &> /dev/null | ||
then | ||
echo "Solana CLI could not be found. Please install Solana." | ||
exit 1 | ||
fi | ||
|
||
|
||
# Build | ||
cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so | ||
|
||
# Deploy | ||
solana program deploy ./program/target/so/pda_rent_payer_program.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 25 additions & 10 deletions
35
basics/pda-rent-payer/steel/program/src/create_new_account.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,38 @@ | ||
use pda_rent_payer_api::prelude::*; | ||
use solana_program::msg; | ||
use steel::sysvar::rent::Rent; | ||
use steel::*; | ||
|
||
pub fn process_create_account(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult { | ||
// // Parse args. | ||
// let args = Add::try_from_bytes(data)?; | ||
// let amount = u64::from_le_bytes(args.amount); | ||
|
||
// Load and validate accounts. | ||
let [payer_info, new_account_info] = accounts else { | ||
pub fn process_create_account(accounts: &[AccountInfo<'_>]) -> ProgramResult { | ||
// Load accounts | ||
let [rent_vault_info, new_account_info, system_program] = accounts else { | ||
return Err(ProgramError::NotEnoughAccountKeys); | ||
}; | ||
|
||
// Validate accounts | ||
new_account_info.is_signer()?.is_empty()?.is_writable()?; | ||
payer_info | ||
rent_vault_info | ||
.is_writable()? | ||
.has_seeds(&[RENT_VAULT], &pda_rent_payer_api::ID)?; | ||
system_program.is_program(&system_program::ID)?; | ||
|
||
let vault_balance = rent_vault_info.lamports(); | ||
|
||
// Create new account by simply sending a | ||
msg!("Vault balance: {}", vault_balance); | ||
// First we get the lamports required for rent | ||
// assuming this account has no inner data | ||
let lamports_required_for_rent = (Rent::get()?).minimum_balance(0); | ||
|
||
if vault_balance < lamports_required_for_rent { | ||
return Err(ProgramError::InsufficientFunds); | ||
} | ||
|
||
// Then we create a new account by simply sending a | ||
// token amount to the new account. | ||
payer_info.send(100, new_account_info); | ||
rent_vault_info.send(lamports_required_for_rent, new_account_info); | ||
|
||
msg!("Created new account."); | ||
msg!("New account: {:?}", new_account_info.key); | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.