Skip to content

Commit bb8e1bf

Browse files
committed
Anchor already stores and checks whether an account is initialized
1 parent 945b4dc commit bb8e1bf

File tree

2 files changed

+0
-10
lines changed
  • examples/sol-anchor-contract

2 files changed

+0
-10
lines changed

examples/sol-anchor-contract/programs/example-sol-anchor-contract/src/lib.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ declare_id!("Fwn1fCmbjd8d95hxY9NUUr5Xa7D13khveMnmCUFdd3ah");
77

88
#[account]
99
pub struct AdminConfig {
10-
pub is_initialized: bool,
1110
pub loan_price_feed_id: Pubkey,
1211
pub collateral_price_feed_id: Pubkey,
1312
}
@@ -39,18 +38,11 @@ pub mod example_sol_anchor_contract {
3938
use super::*;
4039

4140
pub fn init(ctx: Context<InitRequest>, config: AdminConfig) -> Result<()> {
42-
if ctx.accounts.config.is_initialized {
43-
return Err(error!(ErrorCode::ReInitialize));
44-
}
4541
ctx.accounts.config.set_inner(config);
4642
Ok(())
4743
}
4844

4945
pub fn loan_to_value(ctx: Context<QueryRequest>, loan_qty: i64, collateral_qty: i64) -> Result<()> {
50-
if !ctx.accounts.config.is_initialized {
51-
return Err(error!(ErrorCode::UnInitialize));
52-
}
53-
5446
msg!("Loan quantity is {}.", loan_qty);
5547
msg!("Collateral quantity is {}.", collateral_qty);
5648

examples/sol-anchor-contract/scripts/invoke.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ try {
3232
it("Initialize the config.", async () => {
3333
let txSig = await program.rpc.init(
3434
{
35-
isInitialized: true,
3635
loanPriceFeedId: new anchor.web3.PublicKey(ethToUSD),
3736
collateralPriceFeedId: new anchor.web3.PublicKey(usdtToUSD),
3837
},
@@ -73,7 +72,6 @@ it("Prevent initialization of config without authority.", async () => {
7372
try {
7473
txSig = await program.rpc.init(
7574
{
76-
isInitialized: true,
7775
loanPriceFeedId: new anchor.web3.PublicKey(ethToUSD),
7876
collateralPriceFeedId: new anchor.web3.PublicKey(usdtToUSD),
7977
},

0 commit comments

Comments
 (0)