Skip to content

Commit b92041b

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

File tree

2 files changed

+28
-31
lines changed
  • cmd
    • crates/soroban-test/tests/it/integration/ledger
    • soroban-cli/src/commands/ledger/entry

2 files changed

+28
-31
lines changed

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: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ 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::{
19+
Contract,
20+
ed25519::PublicKey as Ed25519PublicKey
21+
};
1822
use stellar_xdr::curr::{
1923
AccountId, AlphaNum12, AlphaNum4, AssetCode12, AssetCode4,
2024
ClaimableBalanceId::ClaimableBalanceIdTypeV0, ConfigSettingId, ContractDataDurability, Hash,
@@ -189,9 +193,28 @@ impl Cmd {
189193

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

0 commit comments

Comments
 (0)