Skip to content

Commit 0afc98c

Browse files
committed
feat: Add a "Claim" event
1 parent 01cc586 commit 0afc98c

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

contracts/smartdeploy/src/events.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ pub struct Deploy {
2525
pub contract_id: Address,
2626
}
2727

28+
#[contracttype]
29+
#[derive(IntoKey)]
30+
pub struct Claim {
31+
pub deployed_name: String,
32+
pub claimer: Address,
33+
pub contract_id: Address,
34+
}
35+
2836
pub trait EventPublishable {
2937
/// Publish an event on the blockchain
3038
fn publish_event(self, env: &Env);

contracts/smartdeploy/src/registry/contract.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use loam_sdk::soroban_sdk::{
55

66
use crate::{
77
error::Error,
8-
events::{Deploy, EventPublishable},
8+
events::{Deploy, Claim, EventPublishable},
99
registry::Publishable,
1010
util::{hash_string, MAX_BUMP},
1111
version::Version,
@@ -151,7 +151,15 @@ impl IsClaimable for ContractRegistry {
151151
if self.0.contains_key(deployed_name.clone()) {
152152
return Err(Error::AlreadyClaimed);
153153
}
154-
self.0.set(deployed_name, ContractType::ContractByIdAndOwner(id, owner));
154+
self.0.set(deployed_name.clone(), ContractType::ContractByIdAndOwner(id.clone(), owner.clone()));
155+
156+
// Publish a Claim event
157+
Claim {
158+
deployed_name,
159+
claimer: owner,
160+
contract_id: id,
161+
}
162+
.publish_event(env());
155163
Ok(())
156164
}
157165

subscribe_events.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,15 @@ curl -X POST \
3030
}' \
3131
$MERCURY_BACKEND_ENDPOINT/event
3232

33+
# Subscribe to the "Claim" event
34+
# XDR built with JS: sorobanClient.xdr.ScVal.scvString("Claim").toXDR("base64")
35+
curl -X POST \
36+
-H "Content-Type: application/json" \
37+
-H "Authorization: Bearer $MERCURY_JWT_TOKEN" \
38+
-d '{
39+
"contract_id": "'"$1"'",
40+
"topic1": "AAAADgAAAAVDbGFpbQAAAA=="
41+
}' \
42+
$MERCURY_BACKEND_ENDPOINT/event
43+
3344
echo "\n\nSuccessfully subscribed to the events"

0 commit comments

Comments
 (0)