Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow reupload of wasm if extension is v0 #1309

Merged
merged 4 commits into from
May 2, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions cmd/soroban-cli/src/commands/contract/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ 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,
self, ContractCodeEntryExt, Error as XdrError, Hash, HostFunction, InvokeHostFunctionOp,
LedgerEntryData, Limits, Memo, MuxedAccount, Operation, OperationBody, Preconditions, ReadXdr,
ScMetaEntry, ScMetaV0, SequenceNumber, Transaction, TransactionExt, TransactionResult,
TransactionResultResult, Uint256, VecM,
};

use super::restore;
Expand Down Expand Up @@ -122,8 +123,24 @@ impl NetworkRunnable for Cmd {
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);
if let Some(entries) = contract_data.entries {
sisuresh marked this conversation as resolved.
Show resolved Hide resolved
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(hash);
}
}
_ => {
tracing::warn!("Entry retrieved should be of type ContractCode");
}
}
}
}

let txn = client
Expand Down
Loading