-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement an endpoint+script to deploy contracts
- Loading branch information
1 parent
9602c50
commit b706578
Showing
13 changed files
with
308 additions
and
19 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
.direnv | ||
result* | ||
/target | ||
/wasm/target | ||
/wasm/**/target | ||
.envrc.local | ||
infra/wallet | ||
.vscode/* | ||
|
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,6 +1,6 @@ | ||
{ | ||
"rust-analyzer.linkedProjects": [ | ||
"Cargo.toml", | ||
"wasm/Cargo.toml" | ||
"wasm/simple-tx/Cargo.toml" | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,15 @@ | ||
[package] | ||
name = "firefly-cardano-deploy-contract" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
anyhow = "1" | ||
clap = { version = "4", features = ["derive"] } | ||
hex = "0.4" | ||
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] } | ||
serde = { version = "1", features = ["derive"] } | ||
tokio = { version = "1", features = ["full"] } | ||
uuid = { version = "1", features = ["v4"] } | ||
wat = "1" | ||
wit-component = "0.220" |
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,53 @@ | ||
use anyhow::{bail, Result}; | ||
use reqwest::{Client, Response}; | ||
use serde::Serialize; | ||
use uuid::Uuid; | ||
|
||
pub struct FireflyCardanoClient { | ||
client: Client, | ||
base_url: String, | ||
} | ||
|
||
impl FireflyCardanoClient { | ||
pub fn new(base_url: &str) -> Self { | ||
Self { | ||
client: Client::new(), | ||
base_url: base_url.to_string(), | ||
} | ||
} | ||
|
||
pub async fn deploy_contract(&self, name: &str, contract: &str) -> Result<()> { | ||
let url = format!("{}/contracts/deploy", self.base_url); | ||
let req = DeployContractRequest { | ||
id: Uuid::new_v4().to_string(), | ||
contract: contract.to_string(), | ||
definition: ABIContract { | ||
name: name.to_string(), | ||
}, | ||
}; | ||
let res = self.client.post(url).json(&req).send().await?; | ||
Self::extract_error(res).await?; | ||
Ok(()) | ||
} | ||
|
||
async fn extract_error(res: Response) -> Result<Response> { | ||
if !res.status().is_success() { | ||
let default_msg = res.status().to_string(); | ||
let message = res.text().await.unwrap_or(default_msg); | ||
bail!("request failed: {}", message); | ||
} | ||
Ok(res) | ||
} | ||
} | ||
|
||
#[derive(Serialize)] | ||
struct DeployContractRequest { | ||
pub id: String, | ||
pub contract: String, | ||
pub definition: ABIContract, | ||
} | ||
|
||
#[derive(Serialize)] | ||
struct ABIContract { | ||
pub name: String, | ||
} |
Oops, something went wrong.