From f11b0acc59a6b15f0243055757cbc0d5b0703fda Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Fri, 16 Feb 2024 20:54:20 -0500 Subject: [PATCH] fix: don't install contract if it is already installed --- cmd/soroban-cli/src/commands/contract/install.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/soroban-cli/src/commands/contract/install.rs b/cmd/soroban-cli/src/commands/contract/install.rs index 8e15f201e5..783007d849 100644 --- a/cmd/soroban-cli/src/commands/contract/install.rs +++ b/cmd/soroban-cli/src/commands/contract/install.rs @@ -4,6 +4,7 @@ use std::num::ParseIntError; use clap::{command, Parser}; use soroban_env_host::xdr::{ + self, Error as XdrError, Hash, HostFunction, InvokeHostFunctionOp, Memo, MuxedAccount, Operation, OperationBody, Preconditions, ScMetaEntry, ScMetaV0, SequenceNumber, Transaction, TransactionExt, TransactionResult, TransactionResultResult, Uint256, VecM, @@ -117,6 +118,13 @@ impl NetworkRunnable for Cmd { let (tx_without_preflight, hash) = build_install_contract_code_tx(&contract, sequence + 1, self.fee.fee, &key)?; + + + let code_key = xdr::LedgerKey::ContractCode(xdr::LedgerKeyContractCode { hash: hash.clone() }); + let contract_data = client.get_ledger_entries(&[code_key]).await?; + if !contract_data.entries.unwrap_or_default().is_empty() { + return Ok(hash); + } // Currently internal errors are not returned if the contract code is expired if let Some(TransactionResult {