Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions contracts/events/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ pub fn initialize(
) {
// Refuse double-init by checking the admin key in instance storage (the
// new home for admin/config per the 2026-06 audit).
if env
.storage()
.instance()
.has(&crate::types::DataKey::Admin)
{
if env.storage().instance().has(&crate::types::DataKey::Admin) {
panic_with_error!(env, Error::AlreadyInitialized);
}
if fee_bps > MAX_FEE_BPS {
Expand Down Expand Up @@ -360,8 +356,7 @@ pub fn migrate(env: &Env) -> Result<(), Error> {
// READS
// ============================================================
pub fn get_admin(env: &Env) -> Address {
storage::get_admin(env)
.unwrap_or_else(|_| panic_with_error!(env, Error::NotInitialized))
storage::get_admin(env).unwrap_or_else(|_| panic_with_error!(env, Error::NotInitialized))
}

pub fn get_fee_bps(env: &Env) -> u32 {
Expand All @@ -381,8 +376,7 @@ pub fn is_paused(env: &Env) -> bool {
}

pub fn get_version(env: &Env) -> String {
storage::get_version(env)
.unwrap_or_else(|| panic_with_error!(env, Error::NotInitialized))
storage::get_version(env).unwrap_or_else(|| panic_with_error!(env, Error::NotInitialized))
}

pub fn get_pending_upgrade(env: &Env) -> Option<PendingUpgrade> {
Expand Down
6 changes: 1 addition & 5 deletions contracts/events/src/bounty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ use crate::profile_client;
use crate::storage;
use crate::types::{EventRecord, EventStatus, Pillar, ReleaseKind};

pub fn validate_create(
_env: &Env,
record: &EventRecord,
_owner: &Address,
) -> Result<(), Error> {
pub fn validate_create(_env: &Env, record: &EventRecord, _owner: &Address) -> Result<(), Error> {
if !matches!(record.release_kind, ReleaseKind::Single) {
return Err(Error::InvalidReleaseKind);
}
Expand Down
6 changes: 1 addition & 5 deletions contracts/events/src/crowdfunding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ use soroban_sdk::{Address, Env};
use crate::errors::Error;
use crate::types::{EventRecord, ReleaseKind};

pub fn validate_create(
_env: &Env,
record: &EventRecord,
_owner: &Address,
) -> Result<(), Error> {
pub fn validate_create(_env: &Env, record: &EventRecord, _owner: &Address) -> Result<(), Error> {
// Multi(n) required.
match record.release_kind {
ReleaseKind::Multi(n) if n > 0 => {}
Expand Down
1 change: 0 additions & 1 deletion contracts/events/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ pub enum Error {
UpgradeProposalExpired = 68,
MigrationAlreadyApplied = 69,


// Pause
Paused = 70,

Expand Down
42 changes: 12 additions & 30 deletions contracts/events/src/event_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ const MIN_CONTRIBUTION_STROOPS: i128 = 100_000_000_i128; // 10 * 10^7
// ============================================================
// CREATE EVENT
// ============================================================
pub fn create_event(
env: &Env,
params: CreateEventParams,
op_id: BytesN<32>,
) -> Result<u64, Error> {
pub fn create_event(env: &Env, params: CreateEventParams, op_id: BytesN<32>) -> Result<u64, Error> {
admin::require_not_paused(env)?;
idempotency::require_unseen(env, &op_id)?;

Expand Down Expand Up @@ -109,7 +105,11 @@ pub fn create_event(
// Crowdfunding flips total_budget into a funding goal; escrow starts at 0
// and grows only via add_funds. Every other pillar deposits at create.
let is_crowdfunding = matches!(params.pillar, Pillar::Crowdfunding);
let initial_escrow: i128 = if is_crowdfunding { 0 } else { params.total_budget };
let initial_escrow: i128 = if is_crowdfunding {
0
} else {
params.total_budget
};

let provisional = EventRecord {
id: 0,
Expand Down Expand Up @@ -147,10 +147,7 @@ pub fn create_event(

// Assign id and persist.
let id = idempotency::next_event_id(env);
let record = EventRecord {
id,
..provisional
};
let record = EventRecord { id, ..provisional };
storage::set_event(env, id, &record);

// Crowdfunding: pre-seat the builder as the sole winner at position 1.
Expand Down Expand Up @@ -673,34 +670,19 @@ pub fn select_winners(

let earn_op =
idempotency::derive_child_indexed(env, &op_id, tag::EARN_CREDITS, sub_idx);
profile.earn_credits(
&spec.recipient,
&spec.credit_earn,
&reason_win,
&earn_op,
);
profile.earn_credits(&spec.recipient, &spec.credit_earn, &reason_win, &earn_op);

let rep_op =
idempotency::derive_child_indexed(env, &op_id, tag::BUMP_REP, sub_idx);
let rep_op = idempotency::derive_child_indexed(env, &op_id, tag::BUMP_REP, sub_idx);
profile.bump_reputation(
&spec.recipient,
&spec.reputation_bump,
&reason_win,
&rep_op,
);

let earnings_op = idempotency::derive_child_indexed(
env,
&op_id,
tag::REGISTER_EARNINGS,
sub_idx,
);
profile.register_earnings(
&spec.recipient,
&event.token,
&amount,
&earnings_op,
);
let earnings_op =
idempotency::derive_child_indexed(env, &op_id, tag::REGISTER_EARNINGS, sub_idx);
profile.register_earnings(&spec.recipient, &event.token, &amount, &earnings_op);

storage::append_winner(
env,
Expand Down
1 change: 0 additions & 1 deletion contracts/events/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,3 @@ pub struct Migrated {
pub from_version: String,
pub to_version: String,
}

9 changes: 2 additions & 7 deletions contracts/events/src/grant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ use crate::profile_client;
use crate::storage;
use crate::types::{EventRecord, EventStatus, Pillar, ReleaseKind, Winner};

pub fn validate_create(
_env: &Env,
record: &EventRecord,
_owner: &Address,
) -> Result<(), Error> {
pub fn validate_create(_env: &Env, record: &EventRecord, _owner: &Address) -> Result<(), Error> {
match record.release_kind {
ReleaseKind::Multi(n) if n > 0 => Ok(()),
_ => Err(Error::InvalidReleaseKind),
Expand Down Expand Up @@ -123,8 +119,7 @@ pub fn claim_milestone(
match w.milestone {
None => winner_position = Some(w.position),
Some(_) => {
already_claimed_for_recipient =
already_claimed_for_recipient.saturating_add(1);
already_claimed_for_recipient = already_claimed_for_recipient.saturating_add(1);
already_paid_to_recipient = already_paid_to_recipient.saturating_add(w.amount);
}
}
Expand Down
6 changes: 1 addition & 5 deletions contracts/events/src/hackathon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ use soroban_sdk::{Address, Env};
use crate::errors::Error;
use crate::types::{EventRecord, ReleaseKind};

pub fn validate_create(
_env: &Env,
record: &EventRecord,
_owner: &Address,
) -> Result<(), Error> {
pub fn validate_create(_env: &Env, record: &EventRecord, _owner: &Address) -> Result<(), Error> {
if !matches!(record.release_kind, ReleaseKind::Single) {
return Err(Error::InvalidReleaseKind);
}
Expand Down
7 changes: 1 addition & 6 deletions contracts/events/src/idempotency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,7 @@ pub fn derive_child(env: &Env, parent: &BytesN<32>, op_tag: u8) -> BytesN<32> {
/// Same as `derive_child` but also XORs a sub-index into the second byte, so
/// per-winner cross-contract calls within select_winners get unique op_ids
/// even when the same op_tag is reused across winners.
pub fn derive_child_indexed(
env: &Env,
parent: &BytesN<32>,
op_tag: u8,
sub_idx: u8,
) -> BytesN<32> {
pub fn derive_child_indexed(env: &Env, parent: &BytesN<32>, op_tag: u8, sub_idx: u8) -> BytesN<32> {
let mut payload = parent.to_array();
payload[0] ^= op_tag;
payload[1] ^= sub_idx;
Expand Down
24 changes: 8 additions & 16 deletions contracts/events/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,11 @@ impl EventsContract {
event_ops::get_event(&env, event_id)
}

pub fn get_submission(env: Env, event_id: u64, applicant: Address) -> Result<Submission, Error> {
pub fn get_submission(
env: Env,
event_id: u64,
applicant: Address,
) -> Result<Submission, Error> {
event_ops::get_submission(&env, event_id, applicant)
}

Expand All @@ -253,11 +257,7 @@ impl EventsContract {
event_ops::get_applicant_count(&env, event_id)
}

pub fn get_applicant_at(
env: Env,
event_id: u64,
idx: u32,
) -> Result<Option<Address>, Error> {
pub fn get_applicant_at(env: Env, event_id: u64, idx: u32) -> Result<Option<Address>, Error> {
event_ops::get_applicant_at(&env, event_id, idx)
}

Expand All @@ -269,11 +269,7 @@ impl EventsContract {
event_ops::get_winner_count(&env, event_id)
}

pub fn get_winner_at(
env: Env,
event_id: u64,
idx: u32,
) -> Result<Option<Winner>, Error> {
pub fn get_winner_at(env: Env, event_id: u64, idx: u32) -> Result<Option<Winner>, Error> {
event_ops::get_winner_at(&env, event_id, idx)
}

Expand All @@ -285,11 +281,7 @@ impl EventsContract {
event_ops::get_contributor_count(&env, event_id)
}

pub fn get_contributor_at(
env: Env,
event_id: u64,
idx: u32,
) -> Result<Option<Address>, Error> {
pub fn get_contributor_at(env: Env, event_id: u64, idx: u32) -> Result<Option<Address>, Error> {
event_ops::get_contributor_at(&env, event_id, idx)
}

Expand Down
8 changes: 1 addition & 7 deletions contracts/events/src/profile_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ pub trait ProfileInterface {
fn refund_credits(env: Env, user: Address, amount: u32, reason: Symbol, op_id: BytesN<32>);
fn bump_reputation(env: Env, user: Address, delta: u32, reason: Symbol, op_id: BytesN<32>);
fn slash_reputation(env: Env, user: Address, delta: u32, reason: Symbol, op_id: BytesN<32>);
fn register_earnings(
env: Env,
user: Address,
token: Address,
amount: i128,
op_id: BytesN<32>,
);
fn register_earnings(env: Env, user: Address, token: Address, amount: i128, op_id: BytesN<32>);
}

/// Helper to build a typed ProfileClient pointing at the currently-configured
Expand Down
Loading
Loading