From 470bd463bd96b3df2162923b8b44ab8e6b0e9e60 Mon Sep 17 00:00:00 2001 From: kayagokalp Date: Fri, 4 Aug 2023 13:58:05 +0300 Subject: [PATCH 1/6] feat: write deployment artifacts to out folder --- forc-plugins/forc-client/src/op/deploy.rs | 63 ++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/forc-plugins/forc-client/src/op/deploy.rs b/forc-plugins/forc-client/src/op/deploy.rs index 035c81212aa..0e86021a8d1 100644 --- a/forc-plugins/forc-client/src/op/deploy.rs +++ b/forc-plugins/forc-client/src/op/deploy.rs @@ -8,14 +8,20 @@ use crate::{ use anyhow::{bail, Context, Result}; use forc_pkg::{self as pkg, PackageManifestFile}; use forc_tx::Gas; +use forc_util::default_output_directory; use fuel_core_client::client::types::TransactionStatus; use fuel_core_client::client::FuelClient; +use fuel_crypto::fuel_types::ChainId; use fuel_tx::{Output, Salt, TransactionBuilder}; use fuel_vm::prelude::*; use futures::FutureExt; use pkg::BuiltPackage; +use serde::{Deserialize, Serialize}; use std::time::Duration; -use std::{collections::BTreeMap, path::PathBuf}; +use std::{ + collections::BTreeMap, + path::{Path, PathBuf}, +}; use sway_core::language::parsed::TreeType; use sway_core::BuildTarget; use tracing::info; @@ -25,6 +31,38 @@ pub struct DeployedContract { pub id: fuel_tx::ContractId, } +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeploymentArtifact { + transaction_id: Bytes32, + salt: Salt, + network_endpoint: String, + chain_id: ChainId, + contract_id: ContractId, + deployment_size: usize, + deployed_block_id: String, +} + +impl DeploymentArtifact { + pub fn to_file( + &self, + output_dir: &Path, + pkg_name: &str, + contract_id: ContractId, + ) -> Result<()> { + if !output_dir.exists() { + std::fs::create_dir_all(output_dir)?; + } + + let deployment_artifact_json = format!("{pkg_name}-deployment-0x{contract_id}"); + let deployments_path = output_dir + .join(deployment_artifact_json) + .with_extension("json"); + let deployments_file = std::fs::File::create(deployments_path)?; + serde_json::to_writer_pretty(&deployments_file, &self)?; + Ok(()) + } +} + type ContractSaltMap = BTreeMap; /// Takes the contract member salt inputs passed via the --salt option, validates them against @@ -241,6 +279,7 @@ pub async fn deploy_pkg( .await?; let tx = Transaction::from(tx); + let chain_id = client.chain_info().await?.consensus_parameters.chain_id; let deployment_request = client.submit_and_await_commit(&tx).map(|res| match res { Ok(logs) => match logs { @@ -254,6 +293,28 @@ pub async fn deploy_pkg( info!("\nNetwork: {node_url}"); info!("Contract ID: 0x{contract_id}"); info!("Deployed in block {}", &block_id); + + // Create a deployment articact. + let deployment_size = bytecode.len(); + let deployment_artifact = DeploymentArtifact { + transaction_id: tx.id(&chain_id), + salt, + network_endpoint: node_url.to_string(), + chain_id, + contract_id, + deployment_size, + deployed_block_id: block_id, + }; + + let output_dir = command + .pkg + .output_directory + .as_ref() + .map(PathBuf::from) + .unwrap_or_else(|| default_output_directory(manifest.dir())) + .join("deployments"); + deployment_artifact.to_file(&output_dir, pkg_name, contract_id)?; + Ok(contract_id) } e => { From 82a47f50af40646f58102647943758bf668d6859 Mon Sep 17 00:00:00 2001 From: kayagokalp Date: Fri, 4 Aug 2023 15:03:30 +0300 Subject: [PATCH 2/6] feat: serialize deployment artifacts with 0x prefixed --- forc-plugins/forc-client/src/op/deploy.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/forc-plugins/forc-client/src/op/deploy.rs b/forc-plugins/forc-client/src/op/deploy.rs index 0e86021a8d1..c9b453e1319 100644 --- a/forc-plugins/forc-client/src/op/deploy.rs +++ b/forc-plugins/forc-client/src/op/deploy.rs @@ -33,15 +33,16 @@ pub struct DeployedContract { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct DeploymentArtifact { - transaction_id: Bytes32, - salt: Salt, + transaction_id: String, + salt: String, network_endpoint: String, chain_id: ChainId, - contract_id: ContractId, + contract_id: String, deployment_size: usize, deployed_block_id: String, } + impl DeploymentArtifact { pub fn to_file( &self, @@ -297,11 +298,11 @@ pub async fn deploy_pkg( // Create a deployment articact. let deployment_size = bytecode.len(); let deployment_artifact = DeploymentArtifact { - transaction_id: tx.id(&chain_id), - salt, + transaction_id: format!("0x{}", tx.id(&chain_id)), + salt: format!("0x{}", salt), network_endpoint: node_url.to_string(), chain_id, - contract_id, + contract_id: format!("0x{}", contract_id), deployment_size, deployed_block_id: block_id, }; From 122b7f4e7f3753838f446ed5c7566e4cd18a3b06 Mon Sep 17 00:00:00 2001 From: kayagokalp Date: Fri, 4 Aug 2023 15:05:47 +0300 Subject: [PATCH 3/6] chore: fmt --- forc-plugins/forc-client/src/op/deploy.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/forc-plugins/forc-client/src/op/deploy.rs b/forc-plugins/forc-client/src/op/deploy.rs index c9b453e1319..92b4054cf8b 100644 --- a/forc-plugins/forc-client/src/op/deploy.rs +++ b/forc-plugins/forc-client/src/op/deploy.rs @@ -42,7 +42,6 @@ pub struct DeploymentArtifact { deployed_block_id: String, } - impl DeploymentArtifact { pub fn to_file( &self, From 37b9e28a07fd4ad046e162f7ae5e681060d4743e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaya=20G=C3=B6kalp?= Date: Mon, 7 Aug 2023 13:19:05 +0300 Subject: [PATCH 4/6] fix: typo Co-authored-by: Joshua Batty --- forc-plugins/forc-client/src/op/deploy.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forc-plugins/forc-client/src/op/deploy.rs b/forc-plugins/forc-client/src/op/deploy.rs index 92b4054cf8b..52b985cf2d0 100644 --- a/forc-plugins/forc-client/src/op/deploy.rs +++ b/forc-plugins/forc-client/src/op/deploy.rs @@ -294,7 +294,7 @@ pub async fn deploy_pkg( info!("Contract ID: 0x{contract_id}"); info!("Deployed in block {}", &block_id); - // Create a deployment articact. + // Create a deployment artifact. let deployment_size = bytecode.len(); let deployment_artifact = DeploymentArtifact { transaction_id: format!("0x{}", tx.id(&chain_id)), From cd9228e2ce2b91937d80fbcbfa51ca2a1a9aa4da Mon Sep 17 00:00:00 2001 From: kayagokalp Date: Tue, 15 Aug 2023 19:18:06 +0300 Subject: [PATCH 5/6] docs: add docs with artifact example --- docs/book/src/forc/plugins/forc_client/index.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/book/src/forc/plugins/forc_client/index.md b/docs/book/src/forc/plugins/forc_client/index.md index 93c826fe308..82d670e58b8 100644 --- a/docs/book/src/forc/plugins/forc_client/index.md +++ b/docs/book/src/forc/plugins/forc_client/index.md @@ -63,3 +63,19 @@ Also the default value of the "gas price" parameter is 0 for both `forc-deploy` ```sh forc-deploy --node-url https://beta-3.fuel.network/graphql --gas-price 1 ``` + +## Deployment Artifacts + +forc-deploy stores deployment details in 'out/deployments' folder in project root directory for each deployment. An example deployment artifact can be seen below: + +```json +{ + "transaction_id": "0xec27bb7a4c8a3b8af98070666cf4e6ea22ca4b9950a0862334a1830520012f5d", + "salt": "0x9e35d1d5ef5724f29e649a3465033f5397d3ebb973c40a1d76bb35c253f0dec7", + "network_endpoint": "http://127.0.0.1:4000", + "chain_id": 0, + "contract_id": "0x767eeaa7af2621e637f9785552620e175d4422b17d4cf0d76335c38808608a7b", + "deployment_size": 68, + "deployed_block_id": "0x915c6f372252be6bc54bd70df6362dae9bf750ba652bf5582d9b31c7023ca6cf" +} +``` From ffc14855ce52e626bce11b0059a2af4668280852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaya=20G=C3=B6kalp?= Date: Wed, 16 Aug 2023 12:41:29 +0300 Subject: [PATCH 6/6] Update docs/book/src/forc/plugins/forc_client/index.md Co-authored-by: Joshua Batty --- docs/book/src/forc/plugins/forc_client/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/book/src/forc/plugins/forc_client/index.md b/docs/book/src/forc/plugins/forc_client/index.md index 82d670e58b8..72c04941d02 100644 --- a/docs/book/src/forc/plugins/forc_client/index.md +++ b/docs/book/src/forc/plugins/forc_client/index.md @@ -66,7 +66,7 @@ forc-deploy --node-url https://beta-3.fuel.network/graphql --gas-price 1 ## Deployment Artifacts -forc-deploy stores deployment details in 'out/deployments' folder in project root directory for each deployment. An example deployment artifact can be seen below: +forc-deploy saves the details of each deployment in the `out/deployments` folder within the project's root directory. Below is an example of a deployment artifact: ```json {