diff --git a/contracts/smartdeploy/src/events.rs b/contracts/smartdeploy/src/events.rs index 1198b99..f6bc57d 100644 --- a/contracts/smartdeploy/src/events.rs +++ b/contracts/smartdeploy/src/events.rs @@ -25,6 +25,14 @@ pub struct Deploy { pub contract_id: Address, } +#[contracttype] +#[derive(IntoKey)] +pub struct Claim { + pub deployed_name: String, + pub claimer: Address, + pub contract_id: Address, +} + pub trait EventPublishable { /// Publish an event on the blockchain fn publish_event(self, env: &Env); diff --git a/contracts/smartdeploy/src/registry/contract.rs b/contracts/smartdeploy/src/registry/contract.rs index d59208d..1033596 100644 --- a/contracts/smartdeploy/src/registry/contract.rs +++ b/contracts/smartdeploy/src/registry/contract.rs @@ -5,7 +5,7 @@ use loam_sdk::soroban_sdk::{ use crate::{ error::Error, - events::{Deploy, EventPublishable}, + events::{Deploy, Claim, EventPublishable}, registry::Publishable, util::{hash_string, MAX_BUMP}, version::Version, @@ -151,7 +151,15 @@ impl IsClaimable for ContractRegistry { if self.0.contains_key(deployed_name.clone()) { return Err(Error::AlreadyClaimed); } - self.0.set(deployed_name, ContractType::ContractByIdAndOwner(id, owner)); + self.0.set(deployed_name.clone(), ContractType::ContractByIdAndOwner(id.clone(), owner.clone())); + + // Publish a Claim event + Claim { + deployed_name, + claimer: owner, + contract_id: id, + } + .publish_event(env()); Ok(()) } diff --git a/subscribe_events.sh b/subscribe_events.sh index eeb91ff..dee9976 100755 --- a/subscribe_events.sh +++ b/subscribe_events.sh @@ -30,4 +30,15 @@ curl -X POST \ }' \ $MERCURY_BACKEND_ENDPOINT/event +# Subscribe to the "Claim" event +# XDR built with JS: sorobanClient.xdr.ScVal.scvString("Claim").toXDR("base64") +curl -X POST \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $MERCURY_JWT_TOKEN" \ + -d '{ + "contract_id": "'"$1"'", + "topic1": "AAAADgAAAAVDbGFpbQAAAA==" + }' \ + $MERCURY_BACKEND_ENDPOINT/event + echo "\n\nSuccessfully subscribed to the events" \ No newline at end of file