Skip to content

Commit

Permalink
fix a bug with how sim only works with install
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed May 9, 2024
1 parent 622d09c commit 457a54b
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions cmd/soroban-cli/src/commands/contract/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,28 +132,33 @@ impl NetworkRunnable for Cmd {
if self.fee.build_only {
return Ok(TxnResult::Txn(tx_without_preflight));
}
let code_key =
xdr::LedgerKey::ContractCode(xdr::LedgerKeyContractCode { hash: hash.clone() });
let contract_data = client.get_ledger_entries(&[code_key]).await?;
// Skip install if the contract is already installed, and the contract has an extension version that isn't V0.
// In protocol 21 extension V1 was added that stores additional information about a contract making execution
// of the contract cheaper. So if folks want to reinstall we should let them which is why the install will still
// go ahead if the contract has a V0 extension.
if let Some(entries) = contract_data.entries {
if let Some(entry_result) = entries.first() {
let entry: LedgerEntryData =
LedgerEntryData::from_xdr_base64(&entry_result.xdr, Limits::none())?;
// Don't check whether the contract is already installed when the user
// has requested to perform simulation only and is hoping to get a
// transaction back.
if !self.fee.sim_only {
let code_key =
xdr::LedgerKey::ContractCode(xdr::LedgerKeyContractCode { hash: hash.clone() });
let contract_data = client.get_ledger_entries(&[code_key]).await?;
// Skip install if the contract is already installed, and the contract has an extension version that isn't V0.
// In protocol 21 extension V1 was added that stores additional information about a contract making execution
// of the contract cheaper. So if folks want to reinstall we should let them which is why the install will still
// go ahead if the contract has a V0 extension.
if let Some(entries) = contract_data.entries {
if let Some(entry_result) = entries.first() {
let entry: LedgerEntryData =
LedgerEntryData::from_xdr_base64(&entry_result.xdr, Limits::none())?;

match &entry {
LedgerEntryData::ContractCode(code) => {
// Skip reupload if this isn't V0 because V1 extension already
// exists.
if code.ext.ne(&ContractCodeEntryExt::V0) {
return Ok(TxnResult::Res(hash));
match &entry {
LedgerEntryData::ContractCode(code) => {
// Skip reupload if this isn't V0 because V1 extension already
// exists.
if code.ext.ne(&ContractCodeEntryExt::V0) {
return Ok(TxnResult::Res(hash));
}
}
_ => {
tracing::warn!("Entry retrieved should be of type ContractCode");
}
}
_ => {
tracing::warn!("Entry retrieved should be of type ContractCode");
}
}
}
Expand Down

0 comments on commit 457a54b

Please sign in to comment.