Skip to content

Commit

Permalink
storage: changed fork and drop to instance | contract: initialize set…
Browse files Browse the repository at this point in the history
…s last_fork to 0
  • Loading branch information
markuspluna committed Oct 24, 2023
1 parent f2f905d commit 7bb7fe6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 70 deletions.
2 changes: 1 addition & 1 deletion emitter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Emitter for EmitterContract {

storage::set_backstop(&e, &backstop);
storage::set_blend_id(&e, &blnd_token_id);
storage::set_last_fork(&e, e.ledger().sequence() - 777600); // We set the block 45 days in the past to allow for an immediate initial drop
storage::set_last_fork(&e, 0); // We set the block 45 days in the past to allow for an immediate initial drop
storage::set_drop_status(&e, false);
// TODO: Determine if setting the last distro time here is appropriate, since it means tokens immediately start being distributed
storage::set_last_distro_time(&e, &(e.ledger().timestamp() - 7 * 24 * 60 * 60));
Expand Down
45 changes: 0 additions & 45 deletions emitter/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,51 +359,6 @@ mod tests {
});
}

#[test]
#[should_panic(expected = "Error(Storage, MissingValue)")]
fn test_drop_no_status() {
let e = Env::default();
e.mock_all_auths_allowing_non_root_auth();

e.ledger().set(LedgerInfo {
timestamp: 12345,
protocol_version: 20,
sequence_number: 50,
network_id: Default::default(),
base_reserve: 10,
min_temp_entry_expiration: 10,
min_persistent_entry_expiration: 10,
max_entry_expiration: 2000000,
});

let bombadil = Address::random(&e);
let frodo = Address::random(&e);
let samwise = Address::random(&e);
let emitter = create_emitter(&e);
let (backstop, backstop_client) = create_backstop(&e);

let backstop_token = e.register_stellar_asset_contract(bombadil.clone());
let drop_list = map![
&e,
(frodo.clone(), 20_000_000 * SCALAR_7),
(samwise.clone(), 30_000_000 * SCALAR_7)
];

backstop_client.initialize(
&backstop_token,
&Address::random(&e),
&Address::random(&e),
&Address::random(&e),
&drop_list,
);

e.as_contract(&emitter, || {
storage::set_last_distro_time(&e, &1000);
storage::set_backstop(&e, &backstop);

execute_drop(&e);
});
}
#[test]
#[should_panic(expected = "Error(Contract, #40)")]
fn test_drop_bad_block() {
Expand Down
28 changes: 4 additions & 24 deletions emitter/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,8 @@ pub fn set_last_distro_time(e: &Env, last_distro: &u64) {
///
/// Returns true if the emitter has dropped
pub fn get_drop_status(e: &Env) -> bool {
e.storage().persistent().bump(
&EmitterDataKey::DropStatus,
LEDGER_THRESHOLD_SHARED,
LEDGER_BUMP_SHARED,
);
e.storage()
.persistent()
.instance()
.get(&EmitterDataKey::DropStatus)
.unwrap_optimized()
}
Expand All @@ -136,26 +131,16 @@ pub fn get_drop_status(e: &Env) -> bool {
/// * `new_status` - new drop status
pub fn set_drop_status(e: &Env, new_status: bool) {
e.storage()
.persistent()
.instance()
.set::<EmitterDataKey, bool>(&EmitterDataKey::DropStatus, &new_status);
e.storage().persistent().bump(
&EmitterDataKey::DropStatus,
LEDGER_THRESHOLD_SHARED,
LEDGER_BUMP_SHARED,
);
}

/// Get the last block an emission fork was executed
///
/// Returns true if the emitter has dropped
pub fn get_last_fork(e: &Env) -> u32 {
e.storage().persistent().bump(
&EmitterDataKey::DropStatus,
LEDGER_THRESHOLD_SHARED,
LEDGER_BUMP_SHARED,
);
e.storage()
.persistent()
.instance()
.get(&EmitterDataKey::LastFork)
.unwrap_optimized()
}
Expand All @@ -166,11 +151,6 @@ pub fn get_last_fork(e: &Env) -> u32 {
/// * `new_status` - new drop status
pub fn set_last_fork(e: &Env, block: u32) {
e.storage()
.persistent()
.instance()
.set::<EmitterDataKey, u32>(&EmitterDataKey::LastFork, &block);
e.storage().persistent().bump(
&EmitterDataKey::LastFork,
LEDGER_THRESHOLD_SHARED,
LEDGER_BUMP_SHARED,
);
}

0 comments on commit 7bb7fe6

Please sign in to comment.