Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error message on system contract #1494

Merged
merged 10 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ path = "cmd/soroban-cli"

[workspace.dependencies.soroban-rpc]
package = "stellar-rpc-client"
version = "21.4.0"
version = "21.5.0"
path = "../rs-stellar-rpc-client" # TODO: replace with actual version

[workspace.dependencies.stellar-xdr]
version = "21.2.0"
Expand Down
20 changes: 19 additions & 1 deletion cmd/soroban-cli/src/commands/contract/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use soroban_env_host::{
use soroban_spec::read::FromWasmError;
use stellar_strkey::DecodeError;

use crate::commands::contract::fetch::Error::{ContractIsStellarAsset, UnexpectedContractToken};
use crate::commands::{global, NetworkRunnable};
use crate::config::{
self, locator,
Expand Down Expand Up @@ -88,6 +89,13 @@ pub enum Error {
Network(#[from] network::Error),
#[error("cannot create contract directory for {0:?}")]
CannotCreateContractDir(PathBuf),
#[error("unexpected contract data {0:?}")]
UnexpectedContractToken(ContractDataEntry),
#[error(
"cannot fetch wasm for contract because the contract is \
a network built-in asset contract that does not have a downloadable code binary"
)]
ContractIsStellarAsset(),
}

impl From<Infallible> for Error {
Expand Down Expand Up @@ -150,9 +158,19 @@ impl NetworkRunnable for Cmd {
client
.verify_network_passphrase(Some(&network.network_passphrase))
.await?;
Ok(client.get_remote_wasm(&contract_id).await?)
let data_entry = client.get_contract_data(&contract_id).await?;
if let ScVal::ContractInstance(contract) = &data_entry.val {
return match &contract.executable {
ContractExecutable::Wasm(hash) => {
Ok(client.get_remote_wasm_from_hash(&hash).await?)
Ifropc marked this conversation as resolved.
Show resolved Hide resolved
}
ContractExecutable::StellarAsset => Err(ContractIsStellarAsset()),
};
}
return Err(UnexpectedContractToken(data_entry));
}
}

pub fn get_contract_wasm_from_storage(
storage: &mut Storage,
contract_id: [u8; 32],
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/get_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub async fn get_remote_contract_spec(
if let Ok(entries) = data::read_spec(&hash_str) {
entries
} else {
let raw_wasm = client.get_remote_wasm_from_hash(hash).await?;
let raw_wasm = client.get_remote_wasm_from_hash(&hash).await?;
let res = contract_spec::Spec::new(&raw_wasm)?;
let res = res.spec;
if global_args.map_or(true, |a| !a.no_cache) {
Expand Down
Loading