Skip to content

Commit

Permalink
Cleanup wasm fetch methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifropc committed Jul 27, 2024
1 parent 1e4a1a3 commit 9874db7
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
target/
.soroban/
.idea
.vscode
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repository = "https://github.com/stellar/soroban-rpc"
authors = ["Stellar Development Foundation <[email protected]>"]
license = "Apache-2.0"
readme = "README.md"
version = "21.4.0"
version = "21.5.0"
edition = "2021"
rust-version = "1.74.0"
autobins = false
Expand Down
20 changes: 2 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub enum Error {
UnexpectedContractCodeDataType(LedgerEntryData),
#[error("unexpected contract instance type: {0:?}")]
UnexpectedContractInstance(xdr::ScVal),
#[error("unexpected contract code got token")]
#[error("unexpected contract code got token {0:?}")]
UnexpectedToken(ContractDataEntry),
#[error("Fee was too large {0}")]
LargeFee(u64),
Expand Down Expand Up @@ -1065,23 +1065,7 @@ impl Client {

///
/// # Errors
pub async fn get_remote_wasm(&self, contract_id: &[u8; 32]) -> Result<Vec<u8>, Error> {
match self.get_contract_data(contract_id).await? {
xdr::ContractDataEntry {
val:
xdr::ScVal::ContractInstance(xdr::ScContractInstance {
executable: xdr::ContractExecutable::Wasm(hash),
..
}),
..
} => self.get_remote_wasm_from_hash(hash).await,
scval => Err(Error::UnexpectedToken(scval)),
}
}

///
/// # Errors
pub async fn get_remote_wasm_from_hash(&self, hash: xdr::Hash) -> Result<Vec<u8>, Error> {
pub async fn get_remote_wasm_from_hash(&self, hash: &Hash) -> Result<Vec<u8>, Error> {
let code_key = LedgerKey::ContractCode(xdr::LedgerKeyContractCode { hash: hash.clone() });
let contract_data = self.get_ledger_entries(&[code_key]).await?;
let entries = contract_data.entries.unwrap_or_default();
Expand Down

0 comments on commit 9874db7

Please sign in to comment.