From 9874db76102969f1aeca436441cc50e09989741f Mon Sep 17 00:00:00 2001 From: Gleb Date: Fri, 26 Jul 2024 19:05:18 -0700 Subject: [PATCH 1/5] Cleanup wasm fetch methods --- .gitignore | 2 ++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/lib.rs | 20 ++------------------ 4 files changed, 6 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 7af275d4..076949bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ target/ .soroban/ +.idea +.vscode diff --git a/Cargo.lock b/Cargo.lock index cf9450b0..c2fa77c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1079,7 +1079,7 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "stellar-rpc-client" -version = "21.4.0" +version = "21.5.0" dependencies = [ "clap", "hex", diff --git a/Cargo.toml b/Cargo.toml index 958d73be..c12a61ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ repository = "https://github.com/stellar/soroban-rpc" authors = ["Stellar Development Foundation "] license = "Apache-2.0" readme = "README.md" -version = "21.4.0" +version = "21.5.0" edition = "2021" rust-version = "1.74.0" autobins = false diff --git a/src/lib.rs b/src/lib.rs index a8133afb..760f99c0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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), @@ -1065,23 +1065,7 @@ impl Client { /// /// # Errors - pub async fn get_remote_wasm(&self, contract_id: &[u8; 32]) -> Result, 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, Error> { + pub async fn get_remote_wasm_from_hash(&self, hash: &Hash) -> Result, 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(); From 6470c85aad8a35f17e39a502746ff363b1e7e8d8 Mon Sep 17 00:00:00 2001 From: Gleb Date: Mon, 29 Jul 2024 10:50:35 -0700 Subject: [PATCH 2/5] Fix comments --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/lib.rs | 21 ++++++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c2fa77c6..cf9450b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1079,7 +1079,7 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "stellar-rpc-client" -version = "21.5.0" +version = "21.4.0" dependencies = [ "clap", "hex", diff --git a/Cargo.toml b/Cargo.toml index c12a61ae..958d73be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ repository = "https://github.com/stellar/soroban-rpc" authors = ["Stellar Development Foundation "] license = "Apache-2.0" readme = "README.md" -version = "21.5.0" +version = "21.4.0" edition = "2021" rust-version = "1.74.0" autobins = false diff --git a/src/lib.rs b/src/lib.rs index 760f99c0..2b2547d9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -95,6 +95,7 @@ pub enum Error { #[error("unexpected contract instance type: {0:?}")] UnexpectedContractInstance(xdr::ScVal), #[error("unexpected contract code got token {0:?}")] + #[deprecated(note = "To be removed in future versions")] UnexpectedToken(ContractDataEntry), #[error("Fee was too large {0}")] LargeFee(u64), @@ -1065,7 +1066,25 @@ impl Client { /// /// # Errors - pub async fn get_remote_wasm_from_hash(&self, hash: &Hash) -> Result, Error> { + #[deprecated(note = "To be removed in future versions, use get_ledger_entries()")] + pub async fn get_remote_wasm(&self, contract_id: &[u8; 32]) -> Result, 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 + #[deprecated(note = "To be removed in future versions, use get_ledger_entries()")] + pub async fn get_remote_wasm_from_hash(&self, hash: Hash) -> Result, 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(); From 495001a0118802fa807714c3ef25f5893bc6a0bb Mon Sep 17 00:00:00 2001 From: Gleb Date: Mon, 29 Jul 2024 13:08:19 -0700 Subject: [PATCH 3/5] fmt --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2b2547d9..0bbc5de9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1071,10 +1071,10 @@ impl Client { match self.get_contract_data(contract_id).await? { xdr::ContractDataEntry { val: - xdr::ScVal::ContractInstance(xdr::ScContractInstance { - executable: xdr::ContractExecutable::Wasm(hash), - .. - }), + xdr::ScVal::ContractInstance(xdr::ScContractInstance { + executable: xdr::ContractExecutable::Wasm(hash), + .. + }), .. } => self.get_remote_wasm_from_hash(hash).await, scval => Err(Error::UnexpectedToken(scval)), From 90e2dbc5e2b86421baa60efafe4f8dca1c4aa43d Mon Sep 17 00:00:00 2001 From: Gleb Date: Mon, 29 Jul 2024 13:27:17 -0700 Subject: [PATCH 4/5] Fix deprecation warnings --- Makefile | 3 +++ src/lib.rs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Makefile b/Makefile index f0f7c092..dcdc1034 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,9 @@ all: check build test export RUSTFLAGS=-Dwarnings -Dclippy::all -Dclippy::pedantic build: + cargo build + +check: cargo clippy --all-targets test: diff --git a/src/lib.rs b/src/lib.rs index 0bbc5de9..875e9b7e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,6 +45,7 @@ pub type LogEvents = fn( pub type LogResources = fn(resources: &SorobanResources) -> (); #[derive(thiserror::Error, Debug)] +#[allow(deprecated)] pub enum Error { #[error(transparent)] InvalidAddress(#[from] stellar_strkey::DecodeError), @@ -634,6 +635,7 @@ pub struct Client { http_client: Arc, } +#[allow(deprecated)] impl Client { /// /// # Errors From 22f15cf75d2fee33eca9d80480e727ec0f6322cd Mon Sep 17 00:00:00 2001 From: Gleb Date: Mon, 29 Jul 2024 13:36:56 -0700 Subject: [PATCH 5/5] Add comment --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 875e9b7e..86f721cc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,7 +45,7 @@ pub type LogEvents = fn( pub type LogResources = fn(resources: &SorobanResources) -> (); #[derive(thiserror::Error, Debug)] -#[allow(deprecated)] +#[allow(deprecated)] // Can be removed once Error enum doesn't have any code marked deprecated inside pub enum Error { #[error(transparent)] InvalidAddress(#[from] stellar_strkey::DecodeError), @@ -635,7 +635,7 @@ pub struct Client { http_client: Arc, } -#[allow(deprecated)] +#[allow(deprecated)] // Can be removed once Client doesn't have any code marked deprecated inside impl Client { /// /// # Errors