essential_deploy_contract/
lib.rs

1use essential_rest_client::EssentialClient;
2use essential_types::{
3    contract::{Contract, SignedContract},
4    ContentAddress,
5};
6
7/// Deploy a contract to the server.
8/// The signed contract is expected to be a JSON serialized `SignedContract`.
9pub async fn deploy_signed_bytes(
10    addr: String,
11    signed_predicates: Vec<u8>,
12) -> anyhow::Result<ContentAddress> {
13    let signed_predicates: SignedContract = serde_json::from_slice(&signed_predicates)?;
14    deploy_signed(addr, signed_predicates).await
15}
16
17/// Sign and deploy a unsigned contract to the server.
18/// The unsigned contract is expected to be a JSON serialized `Contract`.
19pub async fn deploy_bytes(
20    addr: String,
21    account_name: &str,
22    wallet: &mut essential_wallet::Wallet,
23    contract: Vec<u8>,
24) -> anyhow::Result<ContentAddress> {
25    let contract: Contract = serde_json::from_slice(&contract)?;
26    sign_and_deploy(addr, account_name, wallet, contract).await
27}
28
29/// Deploy a signed contract to the server.
30pub async fn deploy_signed(
31    addr: String,
32    signed_predicates: SignedContract,
33) -> anyhow::Result<ContentAddress> {
34    let client = EssentialClient::new(addr)?;
35    client.deploy_contract(signed_predicates).await
36}
37
38/// Sign and deploy a unsigned contract to the server.
39pub async fn sign_and_deploy(
40    addr: String,
41    account_name: &str,
42    wallet: &mut essential_wallet::Wallet,
43    contract: Contract,
44) -> anyhow::Result<ContentAddress> {
45    let signed_predicates = wallet.sign_contract(contract, account_name)?;
46    deploy_signed(addr, signed_predicates).await
47}