Skip to content

Commit

Permalink
emit events for request updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lana-shanghai committed Dec 17, 2024
1 parent 071b525 commit a1d5fd7
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion packages/onchain/src/orderbook/orderbook.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,36 @@ mod Orderbook {
self.initializer(:strk_token, :relay_address);
}

#[event]
#[derive(Drop, starknet::Event)]
pub enum Event {
RequestCreated: RequestCreated,
RequestCanceled: RequestCanceled,
RequestLocked: RequestLocked,
RequestCompleted: RequestCompleted,
}

#[derive(Drop, starknet::Event)]
pub struct RequestCreated {
pub id: u32,
pub data: ByteArray,
}

#[derive(Drop, starknet::Event)]
pub struct RequestCanceled {
pub id: u32,
}

#[derive(Drop, starknet::Event)]
pub struct RequestLocked {
pub id: u32,
}

#[derive(Drop, starknet::Event)]
pub struct RequestCompleted {
pub id: u32,
}

#[abi(embed_v0)]
impl OrderbookImpl of super::IOrderbook<ContractState> {
/// Called by a user.
Expand Down Expand Up @@ -76,8 +106,9 @@ mod Orderbook {
);
}
let id = self.new_inscription_id.read();
self.inscriptions.write(id, (inscription_data, submitter_fee));
self.inscriptions.write(id, (inscription_data.clone(), submitter_fee));
self.inscription_statuses.write(id, Status::Open);
self.emit(RequestCreated { id: id, data: inscription_data });
id
}

Expand Down Expand Up @@ -122,6 +153,7 @@ mod Orderbook {
let (inscription_data, _) = self.inscriptions.read(inscription_id);
self.inscriptions.write(inscription_id, (inscription_data, 0));
self.inscription_statuses.write(inscription_id, Status::Canceled);
self.emit(RequestCanceled { id: inscription_id });
}

/// Called by a submitter. Multiple submitters are allowed to lock the
Expand Down Expand Up @@ -151,6 +183,7 @@ mod Orderbook {
submitters.write(submitter, submitter);

self.inscription_statuses.write(inscription_id, Status::Locked);
self.emit(RequestLocked { id: inscription_id });
}

/// Called by a submitter. The fee is transferred to the submitter if
Expand All @@ -174,6 +207,7 @@ mod Orderbook {
// TODO: assert that the witness data contains the requested inscription

self.inscription_statuses.write(inscription_id, Status::Closed);
self.emit(RequestCompleted { id: inscription_id });
}

/// Helper function that checks if the inscription has already been locked.
Expand Down

0 comments on commit a1d5fd7

Please sign in to comment.