Skip to content

Commit f99d62b

Browse files
elizabethengelmanGlebjanewangleighmcculloch
authored
Add contract instance to ledger entry fetch (#2269)
### What this pr is based off of #2012 closes #2273 Updates the `ledger entry fetch` command to allow for returning the contract instance ledger entry by adding an `--instance` option which will include the contract instance ledger entry to the list of keys being fetched. `cargo run ledger entry fetch contract-data --contract hello-world --network local --instance` ### Why This way we are able to more easily fetch a contract wasm hash based on it's contract id/alias. ### Known limitations [TODO or N/A] --------- Co-authored-by: Gleb <gleb@stellar.org> Co-authored-by: Jane Wang <jane.wang@stellar.org> Co-authored-by: Leigh <351529+leighmcculloch@users.noreply.github.com>
1 parent 33f652b commit f99d62b

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ pub struct Cmd {
2424
pub durability: Durability,
2525

2626
/// Storage key (symbols only)
27-
#[arg(long = "key", required_unless_present = "key_xdr")]
27+
#[arg(long = "key", required_unless_present_any = vec!("key_xdr", "instance"))]
2828
pub key: Option<Vec<String>>,
2929

3030
/// Storage key (base64-encoded XDR)
31-
#[arg(long = "key-xdr", required_unless_present = "key")]
31+
#[arg(long = "key-xdr", required_unless_present_any = vec!("key", "instance"))]
3232
pub key_xdr: Option<Vec<String>>,
33+
34+
/// If the contract instance ledger entry should be included in the output
35+
#[arg(long = "instance", required_unless_present_any = vec!("key", "key_xdr"))]
36+
pub instance: bool,
3337
}
3438

3539
#[derive(thiserror::Error, Debug)]
@@ -57,6 +61,15 @@ impl Cmd {
5761
.contract
5862
.resolve_contract_id(&self.args.locator, &network.network_passphrase)?;
5963
let contract_address_arg = ScAddress::Contract(ContractId(Hash(contract_id.0)));
64+
if self.instance {
65+
let contract_instance_key = LedgerKey::ContractData(LedgerKeyContractData {
66+
contract: contract_address_arg.clone(),
67+
key: ScVal::LedgerKeyContractInstance,
68+
durability: ContractDataDurability::Persistent,
69+
});
70+
71+
ledger_keys.push(contract_instance_key);
72+
}
6073

6174
if let Some(keys) = &self.key {
6275
for key in keys {

0 commit comments

Comments
 (0)