Skip to content

Commit

Permalink
feat: Add a "Claim" event
Browse files Browse the repository at this point in the history
  • Loading branch information
asanson1404 committed Mar 27, 2024
1 parent 01cc586 commit 0afc98c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
8 changes: 8 additions & 0 deletions contracts/smartdeploy/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 10 additions & 2 deletions contracts/smartdeploy/src/registry/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(())
}

Expand Down
11 changes: 11 additions & 0 deletions subscribe_events.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 0afc98c

Please sign in to comment.