Skip to content

Commit 398d112

Browse files
Update ttl ledger entry option
1 parent 12e2d33 commit 398d112

2 files changed

Lines changed: 24 additions & 31 deletions

File tree

  • cmd
    • crates/soroban-test/tests/it/integration/ledger
    • soroban-cli/src/commands/ledger/entry

cmd/crates/soroban-test/tests/it/integration/ledger/entry.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -372,47 +372,21 @@ async fn ledger_entry_ttl() {
372372
)
373373
.await;
374374

375-
let storage_key = "COUNTER";
376-
let storage_key_xdr = ScVal::Symbol(storage_key.try_into().unwrap())
377-
.to_xdr_base64(Limits::none())
378-
.unwrap();
379-
println!("storage key: {}", storage_key_xdr);
380-
381-
// update contract storage
382-
sandbox
383-
.invoke_with_test(&["--id", &contract_id, "--", "inc"])
384-
.await
385-
.unwrap();
386-
387-
// get the data's TTL
375+
// get the contract's TTL
388376
let output = sandbox
389377
.new_assert_cmd("ledger")
390378
.arg("entry")
391379
.arg("fetch")
392380
.arg("--network")
393381
.arg("testnet")
394382
.arg("--ttl")
395-
.arg(storage_key_xdr)
383+
.arg(contract_id)
396384
.assert()
397385
.success()
398386
.stdout_as_str();
399387
let parsed_output: FullLedgerEntries =
400388
serde_json::from_str(&output).expect("Failed to parse JSON");
401389
assert!(!parsed_output.entries.is_empty());
402-
403-
// let parsed_key_xdr_output: FullLedgerEntries = serde_json::from_str(&key_xdr_output).expect("Failed to parse JSON");
404-
// assert!(!parsed_key_xdr_output.entries.is_empty());
405-
406-
// let expected_contract_data_key = expected_contract_ledger_key(&contract_id, storage_key).await;
407-
408-
// assert_eq!(parsed_key_output.entries[0].key, expected_contract_data_key);
409-
// assert!(matches!(parsed_key_output.entries[0].val, LedgerEntryData::ContractData{ .. }));
410-
411-
// assert_eq!(parsed_key_xdr_output.entries[0].key, expected_contract_data_key);
412-
// assert!(matches!(parsed_key_xdr_output.entries[0].val, LedgerEntryData::ContractData{ .. }));
413-
414-
// // the output should be the same regardless of key format
415-
// assert_eq!(parsed_key_output.entries, parsed_key_xdr_output.entries);
416390
}
417391

418392
// Helper Fns

cmd/soroban-cli/src/commands/ledger/entry/fetch.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ use crate::config::network::Network;
1212
use crate::rpc::{self};
1313
use crate::{config, xdr};
1414
use clap::{command, Parser};
15-
use hex::FromHexError;
15+
use hex::{FromHex, FromHexError};
1616
use soroban_spec_tools::utils::padded_hex_from_str;
17-
use stellar_strkey::ed25519::PublicKey as Ed25519PublicKey;
17+
use stellar_strkey::Strkey;
18+
use stellar_strkey::{ed25519::PublicKey as Ed25519PublicKey, Contract};
1819
use stellar_xdr::curr::{
1920
AccountId, AlphaNum12, AlphaNum4, AssetCode12, AssetCode4,
2021
ClaimableBalanceId::ClaimableBalanceIdTypeV0, ConfigSettingId, ContractDataDurability, Hash,
@@ -189,7 +190,25 @@ impl Cmd {
189190

190191
if let Some(ttl) = &self.ttl {
191192
for x in ttl {
192-
let hash = Hash(padded_hex_from_str(x, 32)?.try_into().unwrap());
193+
let bytes: [u8; 32] = if x.starts_with('C') && x.len() == 56 {
194+
// Contract ID (StrKey-encoded)
195+
if let stellar_strkey::Strkey::Contract(Contract(contract_id)) =
196+
Strkey::from_string(x).unwrap()
197+
{
198+
contract_id
199+
} else {
200+
//todo: handle this error
201+
panic!("Invalid StrKey type, expected Contract");
202+
}
203+
} else {
204+
// Hex-encoded 32-byte hash
205+
let clean = x.trim_start_matches("0x");
206+
// todo: handle this error
207+
let vec = Vec::from_hex(clean).unwrap();
208+
vec.try_into().unwrap()
209+
};
210+
211+
let hash = Hash(bytes);
193212
let key = LedgerKey::Ttl(LedgerKeyTtl { key_hash: hash });
194213
ledger_keys.push(key);
195214
}

0 commit comments

Comments
 (0)