-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Subscribe "Publish" and "Deploy" events when deploying smartdeploy (#46)
* feat: Create a 'publish' event feat: Add events module feat: Enhance events module, usage of IntoKey trait fix: Fix the "publish" event bug ResourceLimitExceeded: Must put the wasm_hash instead of the wasm_binary in the event data * feat: Subscribe to events automatically when deploying smartdeploy
- Loading branch information
1 parent
8467f6e
commit 64ff439
Showing
11 changed files
with
163 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
SOROBAN_NETWORK=testnet | ||
SOROBAN_ACCOUNT=default | ||
CONFIG_DIR=. | ||
SOROBAN_FEE=10000000 | ||
MERCURY_BACKEND_ENDPOINT=https://api.mercurydata.app:8443 | ||
MERCURY_JWT_TOKEN=request-access-to-mercury-team |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
/target/ | ||
.soroban | ||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use crate::{ | ||
metadata::ContractMetadata, | ||
version::{Update, Version}, | ||
}; | ||
use loam_sdk::soroban_sdk::{self, contracttype, Address, Env, IntoVal, String, Val}; | ||
use loam_sdk::IntoKey; | ||
|
||
#[contracttype] | ||
#[derive(IntoKey)] | ||
pub struct Publish { | ||
pub published_name: String, | ||
pub author: Address, | ||
pub hash: soroban_sdk::BytesN<32>, | ||
pub repo: ContractMetadata, | ||
pub kind: Update, | ||
} | ||
|
||
#[contracttype] | ||
#[derive(IntoKey)] | ||
pub struct Deploy { | ||
pub published_name: String, | ||
pub deployed_name: String, | ||
pub version: Version, | ||
pub deployer: Address, | ||
pub contract_id: Address, | ||
} | ||
|
||
pub trait EventPublishable { | ||
/// Publish an event on the blockchain | ||
fn publish_event(self, env: &Env); | ||
} | ||
|
||
impl<T> EventPublishable for T | ||
where | ||
T: soroban_sdk::IntoKey + IntoVal<Env, Val>, | ||
{ | ||
fn publish_event(self, env: &Env) { | ||
env.events().publish((T::into_key(),), self); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ use registry::{ | |
}; | ||
|
||
pub mod error; | ||
pub mod events; | ||
pub mod metadata; | ||
pub mod registry; | ||
pub mod util; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
# Load the .env variables | ||
if [ -f .env ]; then | ||
source .env | ||
else | ||
echo "The file .env doesn't exist" | ||
exit 1 | ||
fi | ||
|
||
# Subscribe to the "Publish" event | ||
# XDR built with JS: sorobanClient.xdr.ScVal.scvString("Publish").toXDR("base64") | ||
curl -X POST \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: Bearer $MERCURY_JWT_TOKEN" \ | ||
-d '{ | ||
"contract_id": "'"$1"'", | ||
"topic1": "AAAADgAAAAdQdWJsaXNoAA==" | ||
}' \ | ||
$MERCURY_BACKEND_ENDPOINT/event | ||
|
||
# Subscribe to the "Deploy" event | ||
# XDR built with JS: sorobanClient.xdr.ScVal.scvString("Deploy").toXDR("base64") | ||
curl -X POST \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: Bearer $MERCURY_JWT_TOKEN" \ | ||
-d '{ | ||
"contract_id": "'"$1"'", | ||
"topic1": "AAAADgAAAAZEZXBsb3kAAA==" | ||
}' \ | ||
$MERCURY_BACKEND_ENDPOINT/event | ||
|
||
echo "\n\nSuccessfully subscribed to the events" |