Skip to content

Commit

Permalink
fix: expire -> extend
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Oct 19, 2023
1 parent e58b044 commit 56365ae
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
22 changes: 11 additions & 11 deletions cmd/soroban-cli/src/commands/contract/extend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ use crate::{
wasm, Pwd,
};

const MAX_LEDGERS_TO_EXPIRE: u32 = 535_679;
const MAX_LEDGERS_TO_EXTEND: u32 = 535_679;

#[derive(Parser, Debug, Clone)]
#[group(skip)]
pub struct Cmd {
/// Number of ledgers to extend the entries
#[arg(long, required = true)]
pub ledgers_to_expire: u32,
pub ledgers_to_extend: u32,

/// Only print the new expiration ledger
#[arg(long)]
Expand Down Expand Up @@ -97,11 +97,11 @@ impl Cmd {
Ok(())
}

fn ledgers_to_expire(&self) -> u32 {
let res = u32::min(self.ledgers_to_expire, MAX_LEDGERS_TO_EXPIRE);
if res < self.ledgers_to_expire {
fn ledgers_to_extend(&self) -> u32 {
let res = u32::min(self.ledgers_to_extend, MAX_LEDGERS_TO_EXTEND);
if res < self.ledgers_to_extend {
tracing::warn!(
"Ledgers to expire is too large, using max value of {MAX_LEDGERS_TO_EXPIRE}"
"Ledgers to extend is too large, using max value of {MAX_LEDGERS_TO_EXTEND}"
);
}
res
Expand All @@ -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 extend_to = self.ledgers_to_expire();
let extend_to = self.ledgers_to_extend();

// Get the account sequence number
let public_strkey =
Expand Down Expand Up @@ -175,9 +175,9 @@ impl Cmd {

if operations[0].changes.is_empty() {
let entry = client.get_full_ledger_entries(&keys).await?;
let expire = entry.entries[0].live_until_ledger_seq;
if entry.latest_ledger + i64::from(extend_to) < i64::from(expire) {
return Ok(expire);
let extension = entry.entries[0].live_until_ledger_seq;
if entry.latest_ledger + i64::from(extend_to) < i64::from(extension) {
return Ok(extension);
}
}

Expand Down Expand Up @@ -220,7 +220,7 @@ impl Cmd {
if keys.contains(&new_k) {
// It must have an expiration since it's a contract data entry
let old_expiration = v.1.unwrap();
expiration_ledger_seq = Some(old_expiration + self.ledgers_to_expire);
expiration_ledger_seq = Some(old_expiration + self.ledgers_to_extend);
expiration_ledger_seq
} else {
new_e
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 @@ -124,7 +124,7 @@ impl Cmd {
},
config: self.config.clone(),
fee: self.fee.clone(),
ledgers_to_expire: None,
ledgers_to_extend: None,
}
.run_against_rpc_server()
.await?;
Expand Down
6 changes: 3 additions & 3 deletions cmd/soroban-cli/src/commands/contract/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Cmd {
pub key: key::Args,
/// Number of ledgers to extend the entry
#[arg(long)]
pub ledgers_to_expire: Option<u32>,
pub ledgers_to_extend: Option<u32>,
#[command(flatten)]
pub config: config::Args,
#[command(flatten)]
Expand Down Expand Up @@ -90,10 +90,10 @@ impl Cmd {
self.run_against_rpc_server().await?
};

if let Some(ledgers_to_expire) = self.ledgers_to_expire {
if let Some(ledgers_to_extend) = self.ledgers_to_extend {
extend::Cmd {
key: self.key.clone(),
ledgers_to_expire,
ledgers_to_extend,
config: self.config.clone(),
fee: self.fee.clone(),
expiration_ledger_only: false,
Expand Down
4 changes: 2 additions & 2 deletions cmd/soroban-rpc/internal/test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestCLIExtend(t *testing.T) {
extendOutput := runSuccessfulCLICmd(
t,
fmt.Sprintf(
"contract extend --id %s --key COUNTER --durability persistent --ledgers-to-expire 20",
"contract extend --id %s --key COUNTER --durability persistent --ledgers-to-extend 20",
strkeyContractID,
),
)
Expand Down Expand Up @@ -330,7 +330,7 @@ func extend(t *testing.T, contractId string, amount string, rest string) uint64
res := runSuccessfulCLICmd(
t,
fmt.Sprintf(
"contract extend --expiration-ledger-only --id=%s --durability persistent --ledgers-to-expire=%s %s",
"contract extend --expiration-ledger-only --id=%s --durability persistent --ledgers-to-extend=%s %s",
contractId,
amount,
rest,
Expand Down
6 changes: 3 additions & 3 deletions docs/soroban-cli-full-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ Extend the expiry ledger of a contract-data ledger entry.

If no keys are specified the contract itself is extended.

**Usage:** `soroban contract extend [OPTIONS] --ledgers-to-expire <LEDGERS_TO_EXPIRE> --durability <DURABILITY>`
**Usage:** `soroban contract extend [OPTIONS] --ledgers-to-extend <LEDGERS_TO_EXTEND> --durability <DURABILITY>`

###### **Options:**

* `--ledgers-to-expire <LEDGERS_TO_EXPIRE>` — Number of ledgers to extend the entries
* `--ledgers-to-extend <LEDGERS_TO_EXTEND>` — Number of ledgers to extend the entries
* `--expiration-ledger-only` — Only print the new expiration ledger
* `--id <CONTRACT_ID>` — Contract ID to which owns the data entries. If no keys provided the Contract's instance will be extended
* `--key <KEY>` — Storage key (symbols only)
Expand Down Expand Up @@ -472,7 +472,7 @@ If no keys are specificed the contract itself is restored.
- `temporary`:
Temporary

* `--ledgers-to-expire <LEDGERS_TO_EXPIRE>` — Number of ledgers to extend the entry
* `--ledgers-to-extend <LEDGERS_TO_EXTEND>` — Number of ledgers to extend the entry
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
* `--network <NETWORK>` — Name of network to use from config
Expand Down

0 comments on commit 56365ae

Please sign in to comment.