Skip to content

Commit 26e3d38

Browse files
Glebelizabethengelman
authored andcommitted
clippy
1 parent 0f2e01e commit 26e3d38

File tree

2 files changed

+181
-91
lines changed

2 files changed

+181
-91
lines changed

FULL_HELP_DOCS.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Anything after the `--` double dash (the "slop") is parsed as arguments to the c
5656
* `cache` — Cache for transactions and contract specs
5757
* `version` — Print version information
5858
* `plugin` — The subcommand for CLI plugins
59+
* `ledger` — Fetch ledger information
5960

6061
###### **Options:**
6162

@@ -2693,3 +2694,79 @@ List installed plugins
26932694

26942695

26952696

2697+
## `stellar ledger`
2698+
2699+
Fetch ledger information
2700+
2701+
**Usage:** `stellar ledger <COMMAND>`
2702+
2703+
###### **Subcommands:**
2704+
2705+
* `entry` — Work with ledger entries
2706+
2707+
2708+
2709+
## `stellar ledger entry`
2710+
2711+
Work with ledger entries
2712+
2713+
**Usage:** `stellar ledger entry <COMMAND>`
2714+
2715+
###### **Subcommands:**
2716+
2717+
* `get` — Get ledger entries. This command supports every type of ledger entries supported by the RPC. Read more about RPC command here: https://developers.stellar.org/docs/data/apis/rpc/api-reference/methods/getLedgerEntries#types-of-ledgerkeys
2718+
2719+
2720+
2721+
## `stellar ledger entry get`
2722+
2723+
Get ledger entries. This command supports every type of ledger entries supported by the RPC. Read more about RPC command here: https://developers.stellar.org/docs/data/apis/rpc/api-reference/methods/getLedgerEntries#types-of-ledgerkeys
2724+
2725+
**Usage:** `stellar ledger entry get [OPTIONS]`
2726+
2727+
###### **Options:**
2728+
2729+
* `--rpc-url <RPC_URL>` — RPC server endpoint
2730+
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
2731+
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
2732+
* `-n`, `--network <NETWORK>` — Name of network to use from config
2733+
* `--global` — Use global config
2734+
* `--config-dir <CONFIG_DIR>` — Location of config directory, default is "."
2735+
* `--account <ACCOUNT>` — Name of identity to lookup, default is test identity
2736+
* `--hd-path <HD_PATH>` — If identity is a seed phrase use this hd path, default is 0
2737+
* `--asset <ASSET>` — Assets to get trustline info for
2738+
* `--offer <OFFER>` — ID of an offer made on the Stellar DEX
2739+
* `--data-name <DATA_NAME>` — Fetch key-value data entries attached to an account (see manageDataOp)
2740+
* `--claimable-id <CLAIMABLE_ID>` — Claimable Balance id
2741+
* `--pool-id <POOL_ID>` — Liquidity pool id
2742+
* `--config-setting-id <CONFIG_SETTING_ID>` — Defines the currently active network configuration
2743+
* `--wasm-hash <WASM_HASH>` — Get WASM bytecode by hash
2744+
* `--ttl <TTL>` — Get the time-to-live of an associated contract data or code entry
2745+
* `--id <CONTRACT_ID>` — Contract id to fetch an info for
2746+
* `--durability <DURABILITY>` — Storage entry durability
2747+
2748+
Default value: `persistent`
2749+
2750+
Possible values:
2751+
- `persistent`:
2752+
Persistent
2753+
- `temporary`:
2754+
Temporary
2755+
2756+
* `--key <KEY>` — Storage key (symbols only)
2757+
* `--key-xdr <KEY_XDR>` — Storage key (base64-encoded XDR)
2758+
* `--output <OUTPUT>` — Format of the output
2759+
2760+
Default value: `original`
2761+
2762+
Possible values:
2763+
- `original`:
2764+
Original RPC output (containing XDRs)
2765+
- `json`:
2766+
JSON output of the ledger entry with parsed XDRs (one line, not formatted)
2767+
- `json-formatted`:
2768+
Formatted (multiline) JSON output of the ledger entry with parsed XDRs
2769+
2770+
2771+
2772+

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

Lines changed: 104 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use stellar_xdr::curr::{
2222
LedgerKeyLiquidityPool, LedgerKeyOffer, LedgerKeyTrustLine, LedgerKeyTtl, Limits, MuxedAccount,
2323
PoolId, PublicKey, ReadXdr, ScAddress, ScVal, String64, TrustLineAsset, Uint256,
2424
};
25+
use crate::config::network::Network;
2526

2627
#[derive(Parser, Debug, Clone)]
2728
#[group(skip)]
@@ -139,55 +140,95 @@ impl Cmd {
139140
let client = network.rpc_client()?;
140141
let mut ledger_keys = vec![];
141142

142-
if let Some(contract_id) = &self.contract_id {
143-
let contract_id =
144-
contract_id.resolve_contract_id(&self.locator, &network.network_passphrase)?;
143+
self.insert_contract_keys(&network, &mut ledger_keys)?;
145144

146-
let contract_address_arg = ScAddress::Contract(Hash(contract_id.0));
145+
self.insert_accpount_keys(&mut ledger_keys)?;
147146

148-
if let Some(keys) = &self.key {
149-
for key in keys {
150-
let key = LedgerKey::ContractData(LedgerKeyContractData {
151-
contract: contract_address_arg.clone(),
152-
key: soroban_spec_tools::from_string_primitive(
153-
key,
154-
&xdr::ScSpecTypeDef::Symbol,
155-
)?,
156-
durability: ContractDataDurability::Persistent,
157-
});
147+
if let Some(claimable_id) = &self.claimable_id {
148+
for x in claimable_id {
149+
let hash = Hash(padded_hex_from_str(x, 32)?.try_into().unwrap());
150+
let key = LedgerKey::ClaimableBalance(LedgerKeyClaimableBalance {
151+
balance_id: ClaimableBalanceIdTypeV0(hash),
152+
});
153+
ledger_keys.push(key);
154+
}
155+
}
158156

159-
ledger_keys.push(key);
160-
}
157+
if let Some(pool_id) = &self.pool_id {
158+
for x in pool_id {
159+
let hash = Hash(padded_hex_from_str(x, 32)?.try_into().unwrap());
160+
let key = LedgerKey::LiquidityPool(LedgerKeyLiquidityPool {
161+
liquidity_pool_id: PoolId(hash),
162+
});
163+
ledger_keys.push(key);
161164
}
165+
}
162166

163-
if let Some(keys) = &self.key_xdr {
164-
for key in keys {
165-
let key = LedgerKey::ContractData(LedgerKeyContractData {
166-
contract: contract_address_arg.clone(),
167-
key: ScVal::from_xdr_base64(key, Limits::none())?,
168-
durability: ContractDataDurability::Persistent,
169-
});
167+
if let Some(wasm_hash) = &self.wasm_hash {
168+
for wasm_hash in wasm_hash {
169+
let hash = Hash(
170+
soroban_spec_tools::utils::contract_id_from_str(wasm_hash)
171+
.map_err(|_| InvalidHash(wasm_hash.clone()))?,
172+
);
173+
let key = LedgerKey::ContractCode(LedgerKeyContractCode { hash });
174+
ledger_keys.push(key);
175+
}
176+
}
170177

171-
ledger_keys.push(key);
172-
}
178+
if let Some(config_setting_id) = &self.config_setting_id {
179+
for x in config_setting_id {
180+
let key = LedgerKey::ConfigSetting(LedgerKeyConfigSetting {
181+
config_setting_id: ConfigSettingId::try_from(*x)
182+
.map_err(|_| InvalidConfigId(*x))?,
183+
});
184+
ledger_keys.push(key);
185+
}
186+
}
187+
188+
if let Some(ttl) = &self.ttl {
189+
for x in ttl {
190+
let hash = Hash(padded_hex_from_str(x, 32)?.try_into().unwrap());
191+
let key = LedgerKey::Ttl(LedgerKeyTtl { key_hash: hash });
192+
ledger_keys.push(key);
193+
}
194+
}
195+
196+
if ledger_keys.is_empty() {
197+
return Err(EmptyKeys);
198+
}
199+
200+
match self.output {
201+
OutputFormat::Original => {
202+
let resp = client.get_ledger_entries(&ledger_keys).await?;
203+
println!("{}", serde_json::to_string(&resp)?);
204+
}
205+
OutputFormat::Json => {
206+
let resp = client.get_full_ledger_entries(&ledger_keys).await?;
207+
println!("{}", serde_json::to_string(&resp)?);
208+
}
209+
OutputFormat::JsonFormatted => {
210+
let resp = client.get_full_ledger_entries(&ledger_keys).await?;
211+
println!("{}", serde_json::to_string_pretty(&resp)?);
173212
}
174-
} else if self.key.is_some() || self.key_xdr.is_some() {
175-
return Err(ContractRequired);
176213
}
177214

215+
Ok(())
216+
}
217+
218+
fn insert_accpount_keys(&self, ledger_keys: &mut Vec<LedgerKey>) -> Result<(), Error> {
178219
if let Some(acc) = &self.account {
179220
let acc = self.muxed_account(acc)?;
180221

181222
if let Some(asset) = &self.asset {
182223
for asset in asset {
183-
let asset = if asset.to_ascii_uppercase() == "XLM" {
224+
let asset = if asset.eq_ignore_ascii_case("XLM") {
184225
TrustLineAsset::Native
185-
} else if asset.contains(":") {
186-
let mut parts = asset.split(":");
226+
} else if asset.contains(':') {
227+
let mut parts = asset.split(':');
187228
let code = parts.next().ok_or(InvalidAsset(asset.clone()))?;
188229
let issuer = parts.next().ok_or(InvalidAsset(asset.clone()))?;
189-
if !parts.next().is_none() {
190-
Err(InvalidAsset(asset.clone()))?
230+
if parts.next().is_some() {
231+
Err(InvalidAsset(asset.clone()))?;
191232
}
192233
let source_bytes = Ed25519PublicKey::from_string(issuer).unwrap().0;
193234
let issuer =
@@ -249,75 +290,47 @@ impl Cmd {
249290
return Err(AccountRequired);
250291
}
251292

252-
if let Some(claimable_id) = &self.claimable_id {
253-
for x in claimable_id {
254-
let hash = Hash(padded_hex_from_str(x, 32)?.try_into().unwrap());
255-
let key = LedgerKey::ClaimableBalance(LedgerKeyClaimableBalance {
256-
balance_id: ClaimableBalanceIdTypeV0(hash),
257-
});
258-
ledger_keys.push(key);
259-
}
260-
}
293+
Ok(())
294+
}
261295

262-
if let Some(pool_id) = &self.pool_id {
263-
for x in pool_id {
264-
let hash = Hash(padded_hex_from_str(x, 32)?.try_into().unwrap());
265-
let key = LedgerKey::LiquidityPool(LedgerKeyLiquidityPool {
266-
liquidity_pool_id: PoolId(hash),
267-
});
268-
ledger_keys.push(key);
269-
}
270-
}
296+
fn insert_contract_keys(&self, network: &Network, ledger_keys: &mut Vec<LedgerKey>) -> Result<(), Error> {
297+
if let Some(contract_id) = &self.contract_id {
298+
let contract_id =
299+
contract_id.resolve_contract_id(&self.locator, &network.network_passphrase)?;
271300

272-
if let Some(wasm_hash) = &self.wasm_hash {
273-
for wasm_hash in wasm_hash {
274-
let hash = Hash(
275-
soroban_spec_tools::utils::contract_id_from_str(wasm_hash)
276-
.map_err(|_| InvalidHash(wasm_hash.clone()))?,
277-
);
278-
let key = LedgerKey::ContractCode(LedgerKeyContractCode { hash });
279-
ledger_keys.push(key);
280-
}
281-
}
301+
let contract_address_arg = ScAddress::Contract(Hash(contract_id.0));
282302

283-
if let Some(config_setting_id) = &self.config_setting_id {
284-
for x in config_setting_id {
285-
let key = LedgerKey::ConfigSetting(LedgerKeyConfigSetting {
286-
config_setting_id: ConfigSettingId::try_from(*x)
287-
.map_err(|_| InvalidConfigId(*x))?,
288-
});
289-
ledger_keys.push(key);
290-
}
291-
}
303+
if let Some(keys) = &self.key {
304+
for key in keys {
305+
let key = LedgerKey::ContractData(LedgerKeyContractData {
306+
contract: contract_address_arg.clone(),
307+
key: soroban_spec_tools::from_string_primitive(
308+
key,
309+
&xdr::ScSpecTypeDef::Symbol,
310+
)?,
311+
durability: ContractDataDurability::Persistent,
312+
});
292313

293-
if let Some(ttl) = &self.ttl {
294-
for x in ttl {
295-
let hash = Hash(padded_hex_from_str(x, 32)?.try_into().unwrap());
296-
let key = LedgerKey::Ttl(LedgerKeyTtl { key_hash: hash });
297-
ledger_keys.push(key);
314+
ledger_keys.push(key);
315+
}
298316
}
299-
}
300317

301-
if ledger_keys.is_empty() {
302-
return Err(EmptyKeys);
303-
}
318+
if let Some(keys) = &self.key_xdr {
319+
for key in keys {
320+
let key = LedgerKey::ContractData(LedgerKeyContractData {
321+
contract: contract_address_arg.clone(),
322+
key: ScVal::from_xdr_base64(key, Limits::none())?,
323+
durability: ContractDataDurability::Persistent,
324+
});
304325

305-
match self.output {
306-
OutputFormat::Original => {
307-
let resp = client.get_ledger_entries(&ledger_keys).await?;
308-
println!("{}", serde_json::to_string(&resp)?);
309-
}
310-
OutputFormat::Json => {
311-
let resp = client.get_full_ledger_entries(&ledger_keys).await?;
312-
println!("{}", serde_json::to_string(&resp)?);
313-
}
314-
OutputFormat::JsonFormatted => {
315-
let resp = client.get_full_ledger_entries(&ledger_keys).await?;
316-
println!("{}", serde_json::to_string_pretty(&resp)?);
326+
ledger_keys.push(key);
327+
}
317328
}
329+
} else if self.key.is_some() || self.key_xdr.is_some() {
330+
return Err(ContractRequired);
318331
}
319332

320-
return Ok(());
333+
Ok(())
321334
}
322335

323336
fn muxed_account(&self, account: &str) -> Result<MuxedAccount, Error> {

0 commit comments

Comments
 (0)