darkfi_deployooor_contract/client/
deploy_v1.rs

1/* This file is part of DarkFi (https://dark.fi)
2 *
3 * Copyright (C) 2020-2025 Dyne.org foundation
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18
19use darkfi::{ClientFailed, Result};
20use darkfi_sdk::{crypto::Keypair, deploy::DeployParamsV1};
21use log::{debug, error};
22
23use crate::error::DeployError;
24
25pub struct DeployCallDebris {
26    pub params: DeployParamsV1,
27}
28
29/// Struct holding necessary information to build a `Deployooor::DeployV1` contract call.
30pub struct DeployCallBuilder {
31    /// Contract deploy keypair
32    pub deploy_keypair: Keypair,
33    /// WASM bincode to deploy
34    pub wasm_bincode: Vec<u8>,
35    /// Serialized deployment payload instruction
36    pub deploy_ix: Vec<u8>,
37}
38
39impl DeployCallBuilder {
40    pub fn build(&self) -> Result<DeployCallDebris> {
41        debug!(target: "contract::deployooor::client::deploy", "Building Deployooor::DeployV1 contract call");
42        if self.wasm_bincode.is_empty() {
43            error!(target: "contract::deployooor::client::deploy", "Provided WASM bincode is empty");
44            return Err(ClientFailed::VerifyError(DeployError::WasmBincodeInvalid.to_string()).into())
45        }
46
47        let params = DeployParamsV1 {
48            wasm_bincode: self.wasm_bincode.clone(),
49            public_key: self.deploy_keypair.public,
50            ix: self.deploy_ix.clone(),
51        };
52
53        let debris = DeployCallDebris { params };
54
55        Ok(debris)
56    }
57}