Skip to content

Commit

Permalink
fix(CLI): update xdr and bump -> extend
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Oct 18, 2023
1 parent 2d13040 commit 431ff25
Show file tree
Hide file tree
Showing 22 changed files with 90 additions and 94 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ path = "cmd/soroban-cli"
version = "20.0.0-rc1"
git = "https://github.com/stellar/rs-stellar-xdr"
rev = "9c97e4fa909a0b6455547a4f4a95800696b2a69a"
default-features = false
default-features = true

[workspace.dependencies]
base64 = "0.21.2"
Expand Down
4 changes: 2 additions & 2 deletions cmd/crates/soroban-spec-json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::{fs, io};
pub mod types;

use sha2::{Digest, Sha256};
use stellar_xdr::ScSpecEntry;

use stellar_xdr::curr::ScSpecEntry;
use types::Entry;

use soroban_spec::read::{from_wasm, FromWasmError};
Expand All @@ -16,7 +16,7 @@ pub enum GenerateFromFileError {
#[error("sha256 does not match, expected: {expected}")]
VerifySha256 { expected: String },
#[error("parsing contract spec: {0}")]
Parse(stellar_xdr::Error),
Parse(stellar_xdr::curr::Error),
#[error("getting contract spec: {0}")]
GetSpec(FromWasmError),
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/crates/soroban-spec-json/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::Serialize;
use stellar_xdr::{
use stellar_xdr::curr::{
ScSpecEntry, ScSpecFunctionInputV0, ScSpecTypeDef, ScSpecUdtEnumCaseV0,
ScSpecUdtErrorEnumCaseV0, ScSpecUdtStructFieldV0, ScSpecUdtUnionCaseV0,
};
Expand Down
30 changes: 13 additions & 17 deletions cmd/crates/soroban-spec-tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::str::FromStr;

use itertools::Itertools;
use serde_json::{json, Value};
use stellar_xdr::{
use stellar_xdr::curr::{
AccountId, BytesM, ContractExecutable, Error as XdrError, Hash, Int128Parts, Int256Parts,
PublicKey, ScAddress, ScBytes, ScContractInstance, ScMap, ScMapEntry, ScNonceKey, ScSpecEntry,
ScSpecFunctionV0, ScSpecTypeDef as ScType, ScSpecTypeMap, ScSpecTypeOption, ScSpecTypeResult,
Expand Down Expand Up @@ -1025,9 +1025,9 @@ pub fn to_json(v: &ScVal) -> Result<Value, Error> {
..
}) => json!({ "hash": hash }),
ScVal::ContractInstance(ScContractInstance {
executable: ContractExecutable::Token,
executable: ContractExecutable::StellarAsset,
..
}) => json!({"token": true}),
}) => json!({"SAC": true}),
ScVal::LedgerKeyNonce(ScNonceKey { nonce }) => {
Value::Number(serde_json::Number::from(*nonce))
}
Expand Down Expand Up @@ -1175,11 +1175,10 @@ impl Spec {
.iter()
.map(|f| {
Some(match f {
stellar_xdr::ScSpecUdtUnionCaseV0::VoidV0(ScSpecUdtUnionCaseVoidV0 {
name,
..
}) => name.to_string_lossy(),
stellar_xdr::ScSpecUdtUnionCaseV0::TupleV0(ScSpecUdtUnionCaseTupleV0 {
ScSpecUdtUnionCaseV0::VoidV0(ScSpecUdtUnionCaseVoidV0 { name, .. }) => {
name.to_string_lossy()
}
ScSpecUdtUnionCaseV0::TupleV0(ScSpecUdtUnionCaseTupleV0 {
name,
type_,
..
Expand Down Expand Up @@ -1331,14 +1330,11 @@ impl Spec {
.cases
.iter()
.map(|case| match case {
stellar_xdr::ScSpecUdtUnionCaseV0::VoidV0(ScSpecUdtUnionCaseVoidV0 {
name,
..
}) => Some(format!("\"{}\"", name.to_string_lossy())),
stellar_xdr::ScSpecUdtUnionCaseV0::TupleV0(ScSpecUdtUnionCaseTupleV0 {
name,
type_,
..
ScSpecUdtUnionCaseV0::VoidV0(ScSpecUdtUnionCaseVoidV0 { name, .. }) => {
Some(format!("\"{}\"", name.to_string_lossy()))
}
ScSpecUdtUnionCaseV0::TupleV0(ScSpecUdtUnionCaseTupleV0 {
name, type_, ..
}) => {
if type_.len() == 1 {
let single = self.example(&type_[0])?;
Expand All @@ -1362,7 +1358,7 @@ impl Spec {
mod tests {
use super::*;

use stellar_xdr::ScSpecTypeBytesN;
use stellar_xdr::curr::ScSpecTypeBytesN;

#[test]
fn from_json_primitives_bytesn() {
Expand Down
13 changes: 5 additions & 8 deletions cmd/crates/soroban-spec-tools/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
io::{self, Cursor},
};

use stellar_xdr::{
use stellar_xdr::curr::{
DepthLimitedRead, ReadXdr, ScEnvMetaEntry, ScMetaEntry, ScMetaV0, ScSpecEntry,
ScSpecFunctionV0, ScSpecUdtEnumV0, ScSpecUdtErrorEnumV0, ScSpecUdtStructV0, ScSpecUdtUnionV0,
StringM,
Expand Down Expand Up @@ -33,7 +33,7 @@ pub enum Error {
error: wasmparser::BinaryReaderError,
},
#[error("xdr processing error: {0}")]
Xdr(#[from] stellar_xdr::Error),
Xdr(#[from] stellar_xdr::curr::Error),

#[error(transparent)]
Parser(#[from] wasmparser::BinaryReaderError),
Expand Down Expand Up @@ -62,8 +62,7 @@ impl ContractSpec {
env_meta_base64 = Some(base64.encode(env_meta));
let cursor = Cursor::new(env_meta);
let mut depth_limit_read = DepthLimitedRead::new(cursor, 100);
ScEnvMetaEntry::read_xdr_iter(&mut depth_limit_read)
.collect::<Result<Vec<_>, stellar_xdr::Error>>()?
ScEnvMetaEntry::read_xdr_iter(&mut depth_limit_read).collect::<Result<Vec<_>, _>>()?
} else {
vec![]
};
Expand All @@ -73,8 +72,7 @@ impl ContractSpec {
meta_base64 = Some(base64.encode(meta));
let cursor = Cursor::new(meta);
let mut depth_limit_read = DepthLimitedRead::new(cursor, 100);
ScMetaEntry::read_xdr_iter(&mut depth_limit_read)
.collect::<Result<Vec<_>, stellar_xdr::Error>>()?
ScMetaEntry::read_xdr_iter(&mut depth_limit_read).collect::<Result<Vec<_>, _>>()?
} else {
vec![]
};
Expand All @@ -84,8 +82,7 @@ impl ContractSpec {
spec_base64 = Some(base64.encode(spec));
let cursor = Cursor::new(spec);
let mut depth_limit_read = DepthLimitedRead::new(cursor, 100);
ScSpecEntry::read_xdr_iter(&mut depth_limit_read)
.collect::<Result<Vec<_>, stellar_xdr::Error>>()?
ScSpecEntry::read_xdr_iter(&mut depth_limit_read).collect::<Result<Vec<_>, _>>()?
} else {
vec![]
};
Expand Down
2 changes: 1 addition & 1 deletion cmd/crates/soroban-spec-typescript/src/boilerplate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
io::Write,
path::{Path, PathBuf},
};
use stellar_xdr::ScSpecEntry;
use stellar_xdr::curr::ScSpecEntry;

use super::generate;

Expand Down
4 changes: 2 additions & 2 deletions cmd/crates/soroban-spec-typescript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::types::Type;
use heck::ToLowerCamelCase;
use itertools::Itertools;
use sha2::{Digest, Sha256};
use stellar_xdr::{ScSpecEntry, WriteXdr};
use stellar_xdr::curr::{ScSpecEntry, WriteXdr};

use types::Entry;

Expand All @@ -27,7 +27,7 @@ pub enum GenerateFromFileError {
#[error("sha256 does not match, expected: {expected}")]
VerifySha256 { expected: String },
#[error("parsing contract spec: {0}")]
Parse(stellar_xdr::Error),
Parse(stellar_xdr::curr::Error),
#[error("getting contract spec: {0}")]
GetSpec(FromWasmError),
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/crates/soroban-spec-typescript/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::Serialize;
use stellar_xdr::{
use stellar_xdr::curr::{
ScSpecEntry, ScSpecFunctionInputV0, ScSpecTypeDef, ScSpecUdtEnumCaseV0,
ScSpecUdtErrorEnumCaseV0, ScSpecUdtStructFieldV0, ScSpecUdtStructV0, ScSpecUdtUnionCaseV0,
};
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl Cmd {
&mut state.ledger_entries,
contract_id,
wasm_hash.0,
state.min_persistent_entry_expiration,
state.min_persistent_entry_ttl,
);
self.config.set_state(&state)?;
Ok(stellar_strkey::Contract(contract_id).to_string())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use std::{fmt::Debug, path::Path, str::FromStr};

use clap::{command, Parser};
use soroban_env_host::xdr::{
BumpFootprintExpirationOp, Error as XdrError, ExpirationEntry, ExtensionPoint, LedgerEntry,
LedgerEntryChange, LedgerEntryData, LedgerFootprint, Memo, MuxedAccount, Operation,
OperationBody, Preconditions, SequenceNumber, SorobanResources, SorobanTransactionData,
Transaction, TransactionExt, TransactionMeta, TransactionMetaV3, Uint256,
Error as XdrError, ExtendFootprintTtlOp, ExtensionPoint, LedgerEntry, LedgerEntryChange,
LedgerEntryData, LedgerFootprint, Memo, MuxedAccount, Operation, OperationBody, Preconditions,
SequenceNumber, SorobanResources, SorobanTransactionData, Transaction, TransactionExt,
TransactionMeta, TransactionMetaV3, TtlEntry, Uint256,
};

use crate::{
Expand Down Expand Up @@ -114,7 +114,7 @@ impl Cmd {
let network = &self.config.get_network()?;
let client = Client::new(&network.rpc_url)?;
let key = self.config.key_pair()?;
let ledgers_to_expire = self.ledgers_to_expire();
let extend_to = self.ledgers_to_expire();

// Get the account sequence number
let public_strkey =
Expand All @@ -130,9 +130,9 @@ impl Cmd {
memo: Memo::None,
operations: vec![Operation {
source_account: None,
body: OperationBody::BumpFootprintExpiration(BumpFootprintExpirationOp {
body: OperationBody::ExtendFootprintTtl(ExtendFootprintTtlOp {
ext: ExtensionPoint::V0,
ledgers_to_expire,
extend_to,
}),
}]
.try_into()?,
Expand All @@ -147,7 +147,7 @@ impl Cmd {
read_bytes: 0,
write_bytes: 0,
},
refundable_fee: 0,
resource_fee: 0,
}),
};

Expand All @@ -161,13 +161,13 @@ impl Cmd {
tracing::info!("Events:\n {events:#?}");
}

// The transaction from core will succeed regardless of whether it actually found & bumped
// The transaction from core will succeed regardless of whether it actually found & extended
// the entry, so we have to inspect the result meta to tell if it worked or not.
let TransactionMeta::V3(TransactionMetaV3 { operations, .. }) = meta else {
return Err(Error::LedgerEntryNotFound);
};

// Simply check if there is exactly one entry here. We only support bumping a single
// Simply check if there is exactly one entry here. We only support extending a single
// entry via this command (which we should fix separately, but).
if operations.len() == 0 {
return Err(Error::LedgerEntryNotFound);
Expand All @@ -176,7 +176,7 @@ impl Cmd {
if operations[0].changes.is_empty() {
let entry = client.get_full_ledger_entries(&keys).await?;
let expire = entry.entries[0].expiration_ledger_seq;
if entry.latest_ledger + i64::from(ledgers_to_expire) < i64::from(expire) {
if entry.latest_ledger + i64::from(extend_to) < i64::from(expire) {
return Ok(expire);
}
}
Expand All @@ -186,13 +186,13 @@ impl Cmd {
LedgerEntryChange::State(_),
LedgerEntryChange::Updated(LedgerEntry {
data:
LedgerEntryData::Expiration(ExpirationEntry {
expiration_ledger_seq,
LedgerEntryData::Ttl(TtlEntry {
live_until_ledger_seq,
..
}),
..
}),
) => Ok(*expiration_ledger_seq),
) => Ok(*live_until_ledger_seq),
_ => Err(Error::LedgerEntryNotFound),
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ pub fn get_contract_wasm_from_storage(
Err(FromWasmError::NotFound)
}
}
ContractExecutable::Token => todo!(),
ContractExecutable::StellarAsset => todo!(),
},
_ => Err(FromWasmError::NotFound),
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Cmd {
let wasm_hash = utils::add_contract_code_to_ledger_entries(
&mut state.ledger_entries,
contract,
state.min_persistent_entry_expiration,
state.min_persistent_entry_ttl,
)?;

self.config.set_state(&state)?;
Expand Down
20 changes: 11 additions & 9 deletions cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{fmt::Debug, fs, io, rc::Rc};
use clap::{arg, command, value_parser, Parser};
use ed25519_dalek::SigningKey;
use heck::ToKebabCase;
use soroban_env_host::e2e_invoke::{get_ledger_changes, ExpirationEntryMap};
use soroban_env_host::e2e_invoke::{get_ledger_changes, TtlEntryMap};
use soroban_env_host::xdr::ReadXdr;
use soroban_env_host::{
budget::Budget,
Expand Down Expand Up @@ -435,16 +435,18 @@ impl Cmd {
log_budget(&budget);
}

let ledger_changes =
get_ledger_changes(&budget, &storage, &state, ExpirationEntryMap::new())?;
let mut expiration_ledger_bumps: HashMap<LedgerKey, u32> = HashMap::new();
let ledger_changes = get_ledger_changes(&budget, &storage, &state, TtlEntryMap::new())?;
let mut expiration_ledger_extensions: HashMap<LedgerKey, u32> = HashMap::new();
for ledger_entry_change in ledger_changes {
if let Some(exp_change) = ledger_entry_change.expiration_change {
if let Some(exp_change) = ledger_entry_change.ttl_change {
let key = xdr::LedgerKey::from_xdr(ledger_entry_change.encoded_key)?;
expiration_ledger_bumps.insert(key, exp_change.new_expiration_ledger);
expiration_ledger_extensions.insert(key, exp_change.new_live_until_ledger);
}
}
utils::bump_ledger_entry_expirations(&mut state.ledger_entries, &expiration_ledger_bumps);
utils::extend_ledger_entry_expirations(
&mut state.ledger_entries,
&expiration_ledger_extensions,
);

self.config.set_state(&state)?;
if !events.0.is_empty() {
Expand All @@ -463,15 +465,15 @@ impl Cmd {
let wasm_hash = utils::add_contract_code_to_ledger_entries(
&mut state.ledger_entries,
contract,
state.min_persistent_entry_expiration,
state.min_persistent_entry_ttl,
)
.map_err(Error::CannotAddContractToLedgerEntries)?
.0;
utils::add_contract_to_ledger_entries(
&mut state.ledger_entries,
*contract_id,
wasm_hash,
state.min_persistent_entry_expiration,
state.min_persistent_entry_ttl,
);
}
Ok(())
Expand Down
10 changes: 5 additions & 5 deletions cmd/soroban-cli/src/commands/contract/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod bindings;
pub mod build;
pub mod bump;
pub mod deploy;
pub mod extend;
pub mod fetch;
pub mod inspect;
pub mod install;
Expand All @@ -22,8 +22,8 @@ pub enum Cmd {

/// Extend the expiry ledger of a contract-data ledger entry.
///
/// If no keys are specified the contract itself is bumped.
Bump(bump::Cmd),
/// If no keys are specified the contract itself is extended.
Extend(extend::Cmd),

/// Deploy a contract
Deploy(deploy::Cmd),
Expand Down Expand Up @@ -68,7 +68,7 @@ pub enum Error {
Build(#[from] build::Error),

#[error(transparent)]
Bump(#[from] bump::Error),
Extend(#[from] extend::Error),

#[error(transparent)]
Deploy(#[from] deploy::Error),
Expand Down Expand Up @@ -100,7 +100,7 @@ impl Cmd {
match &self {
Cmd::Bindings(bindings) => bindings.run().await?,
Cmd::Build(build) => build.run()?,
Cmd::Bump(bump) => bump.run().await?,
Cmd::Extend(extend) => extend.run().await?,
Cmd::Deploy(deploy) => deploy.run().await?,
Cmd::Inspect(inspect) => inspect.run()?,
Cmd::Install(install) => install.run().await?,
Expand Down
Loading

0 comments on commit 431ff25

Please sign in to comment.