Skip to content

Commit

Permalink
fix: check if change is contract code
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Jul 19, 2023
1 parent 2484305 commit a99a627
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 30 deletions.
40 changes: 22 additions & 18 deletions cmd/soroban-cli/src/commands/contract/bump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use std::{

use clap::{command, Parser};
use soroban_env_host::xdr::{
BumpFootprintExpirationOp, ContractDataEntry, ContractEntryBodyType, Error as XdrError,
ExtensionPoint, Hash, LedgerEntry, LedgerEntryChange, LedgerEntryData, LedgerFootprint,
LedgerKey, LedgerKeyContractData, Memo, MuxedAccount, Operation, OperationBody, Preconditions,
ReadXdr, ScAddress, ScSpecTypeDef, ScVal, SequenceNumber, SorobanResources,
SorobanTransactionData, Transaction, TransactionExt, TransactionMeta, TransactionMetaV3,
Uint256,
BumpFootprintExpirationOp, ContractCodeEntry, ContractDataEntry, ContractEntryBodyType,
Error as XdrError, ExtensionPoint, Hash, LedgerEntry, LedgerEntryChange, LedgerEntryData,
LedgerFootprint, LedgerKey, LedgerKeyContractData, Memo, MuxedAccount, Operation,
OperationBody, Preconditions, ReadXdr, ScAddress, ScSpecTypeDef, ScVal, SequenceNumber,
SorobanResources, SorobanTransactionData, Transaction, TransactionExt, TransactionMeta,
TransactionMetaV3, Uint256,
};
use stellar_strkey::DecodeError;

Expand Down Expand Up @@ -182,20 +182,24 @@ impl Cmd {
return Err(Error::LedgerEntryNotFound);
}

let (
LedgerEntryChange::State(_state),
LedgerEntryChange::Updated(LedgerEntry{
data: LedgerEntryData::ContractData(ContractDataEntry{
expiration_ledger_seq,
match (&operations[0].changes[0], &operations[0].changes[1]) {
(
LedgerEntryChange::State(_),
LedgerEntryChange::Updated(LedgerEntry {
data:
LedgerEntryData::ContractData(ContractDataEntry {
expiration_ledger_seq,
..
})
| LedgerEntryData::ContractCode(ContractCodeEntry {
expiration_ledger_seq,
..
}),
..
}),
..
})
) = (&operations[0].changes[0], &operations[0].changes[1]) else {
return Err(Error::LedgerEntryNotFound);
};

Ok(*expiration_ledger_seq)
) => Ok(*expiration_ledger_seq),
_ => Err(Error::LedgerEntryNotFound),
}
}

fn run_in_sandbox(&self) -> Result<u32, Error> {
Expand Down
33 changes: 21 additions & 12 deletions cmd/soroban-cli/src/commands/contract/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use std::{

use clap::{command, Parser};
use soroban_env_host::xdr::{
ContractDataDurability, ContractDataEntry, ContractEntryBodyType, Error as XdrError,
ExtensionPoint, Hash, LedgerEntry, LedgerEntryChange, LedgerEntryData, LedgerFootprint,
LedgerKey, LedgerKeyContractData, Memo, MuxedAccount, Operation, OperationBody, Preconditions,
ReadXdr, RestoreFootprintOp, ScAddress, ScSpecTypeDef, ScVal, SequenceNumber, SorobanResources,
SorobanTransactionData, Transaction, TransactionExt, TransactionMeta, TransactionMetaV3,
Uint256,
ContractCodeEntry, ContractDataDurability, ContractDataEntry, ContractEntryBodyType,
Error as XdrError, ExtensionPoint, Hash, LedgerEntry, LedgerEntryChange, LedgerEntryData,
LedgerFootprint, LedgerKey, LedgerKeyContractData, Memo, MuxedAccount, Operation,
OperationBody, Preconditions, ReadXdr, RestoreFootprintOp, ScAddress, ScSpecTypeDef, ScVal,
SequenceNumber, SorobanResources, SorobanTransactionData, Transaction, TransactionExt,
TransactionMeta, TransactionMetaV3, Uint256,
};
use stellar_strkey::DecodeError;

Expand Down Expand Up @@ -186,12 +186,21 @@ impl Cmd {
if operations[0].changes.len() != 1 {
return Err(Error::LedgerEntryNotFound);
}

let LedgerEntryChange::Created(LedgerEntry{ data: LedgerEntryData::ContractData(ContractDataEntry{expiration_ledger_seq, ..}), ..}) = &operations[0].changes[0] else {
return Err(Error::LedgerEntryNotFound);
};

Ok(*expiration_ledger_seq)
match operations[0].changes[0] {
LedgerEntryChange::Updated(LedgerEntry {
data:
LedgerEntryData::ContractData(ContractDataEntry {
expiration_ledger_seq,
..
})
| LedgerEntryData::ContractCode(ContractCodeEntry {
expiration_ledger_seq,
..
}),
..
}) => Ok(expiration_ledger_seq),
_ => Err(Error::LedgerEntryNotFound),
}
}

fn run_in_sandbox(&self) -> Result<u32, Error> {
Expand Down

0 comments on commit a99a627

Please sign in to comment.