Skip to content

Commit

Permalink
Merge pull request #1785 from multiversx/gateway-refactor-2
Browse files Browse the repository at this point in the history
VM query refactor
  • Loading branch information
andrei-marinica authored Oct 1, 2024
2 parents 7bf0592 + 78b8967 commit f6b0774
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use multiversx_sc_scenario::{
multiversx_sc::{abi::TypeAbiFrom, codec::TopDecodeMulti, types::ContractCall},
scenario_model::{ScQueryStep, TxResponse},
};
use multiversx_sdk_wbg::{data::vm::VmValueRequest, utils::base64_decode};
use multiversx_sdk_wbg::{data::vm::VMQueryInput, utils::base64_decode};

impl Interactor {
pub async fn sc_query<S>(&mut self, mut step: S) -> &mut Self
Expand All @@ -21,7 +21,7 @@ impl Interactor {

pub async fn perform_sc_query(&mut self, step: &mut ScQueryStep) {
let sc_address = address_h256_to_erdrs(&step.tx.to.to_address());
let req = VmValueRequest {
let req = VMQueryInput {
sc_address: sc_address.clone(),
func_name: step.tx.function.clone(),
args: step
Expand All @@ -30,8 +30,6 @@ impl Interactor {
.iter()
.map(|arg| hex::encode(&arg.value))
.collect(),
caller: sc_address,
value: "0".to_string(),
};
let result = self
.proxy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use multiversx_sc_scenario::{
multiversx_sc::{abi::TypeAbiFrom, codec::TopDecodeMulti, types::ContractCall},
scenario_model::{ScQueryStep, TxResponse},
};
use multiversx_sdk_reqwest::core::{data::vm::VmValueRequest, utils::base64_decode};
use multiversx_sdk_reqwest::core::{data::vm::VMQueryInput, utils::base64_decode};

impl Interactor {
pub async fn sc_query<S>(&mut self, mut step: S) -> &mut Self
Expand All @@ -21,7 +21,7 @@ impl Interactor {

pub async fn perform_sc_query(&mut self, step: &mut ScQueryStep) {
let sc_address = step.tx.to.to_address();
let req = VmValueRequest {
let req = VMQueryInput {
sc_address: sc_address.clone().into(),
func_name: step.tx.function.clone(),
args: step
Expand All @@ -30,8 +30,6 @@ impl Interactor {
.iter()
.map(|arg| hex::encode(&arg.value))
.collect(),
caller: sc_address.into(),
value: "0".to_string(),
};
let result = self
.proxy
Expand Down
4 changes: 1 addition & 3 deletions sdk/core/src/data/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ pub enum CallType {
// VmValueRequest defines the request struct for values available in a VM
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct VmValueRequest {
pub struct VMQueryInput {
pub sc_address: Address,
pub func_name: String,
pub caller: Address,
pub value: String,
pub args: Vec<String>,
}

Expand Down
6 changes: 3 additions & 3 deletions sdk/core/src/gateway/gateway_tx_vmquery.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::data::vm::{ResponseVmValue, VmValueRequest, VmValuesResponseData};
use crate::data::vm::{ResponseVmValue, VMQueryInput, VmValuesResponseData};
use anyhow::anyhow;

use super::{GatewayRequest, GatewayRequestType, VM_VALUES_ENDPOINT};

/// Executes a VM query.
pub struct VMQueryRequest<'a>(pub &'a VmValueRequest);
pub struct VMQueryRequest<'a>(pub &'a VMQueryInput);

impl<'a> GatewayRequest for VMQueryRequest<'a> {
type Payload = VmValueRequest;
type Payload = VMQueryInput;
type DecodedJson = ResponseVmValue;
type Result = VmValuesResponseData;

Expand Down
6 changes: 2 additions & 4 deletions sdk/reqwest/examples/vm_query.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use multiversx_sdk::data::{address::Address, vm::VmValueRequest};
use multiversx_sdk::data::{address::Address, vm::VMQueryInput};
use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY};

#[tokio::main]
Expand All @@ -8,12 +8,10 @@ async fn main() {
"erd1qqqqqqqqqqqqqpgq5dvvkmka7sujfsx7cfmygnx0n7luv8k0d8sskpqcec",
)
.unwrap();
let req = VmValueRequest {
let req = VMQueryInput {
sc_address: sc_address.clone(),
func_name: "empty".to_string(),
args: vec![],
caller: sc_address,
value: "0".to_string(),
};
let result = blockchain.execute_vmquery(&req).await;
println!("{result:#?}");
Expand Down
7 changes: 2 additions & 5 deletions sdk/reqwest/src/gateway/gateway_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use multiversx_sdk::{
transaction::{
ArgCreateTransaction, Transaction, TransactionOnNetwork, TxCostResponseData,
},
vm::{VmValueRequest, VmValuesResponseData},
vm::{VMQueryInput, VmValuesResponseData},
},
gateway::{
GetTxCost, GetTxInfo, GetTxProcessStatus, GetTxStatus, SendMultiTxRequest, SendTxRequest,
Expand Down Expand Up @@ -79,10 +79,7 @@ impl GatewayProxy {
}

// execute_vmquery retrieves data from existing SC trie through the use of a VM
pub async fn execute_vmquery(
&self,
vm_request: &VmValueRequest,
) -> Result<VmValuesResponseData> {
pub async fn execute_vmquery(&self, vm_request: &VMQueryInput) -> Result<VmValuesResponseData> {
self.request(VMQueryRequest(vm_request)).await
}
}
7 changes: 2 additions & 5 deletions sdk/wbg/src/gateway/gateway_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use multiversx_sdk::data::{
Transaction, TransactionInfo, TransactionOnNetwork, TransactionProcessStatus,
TransactionStatus, TxCostResponseData,
},
vm::{ResponseVmValue, VmValueRequest, VmValuesResponseData},
vm::{ResponseVmValue, VMQueryInput, VmValuesResponseData},
};

use super::GatewayProxy;
Expand Down Expand Up @@ -171,10 +171,7 @@ impl GatewayProxy {
}

// execute_vmquery retrieves data from existing SC trie through the use of a VM
pub async fn execute_vmquery(
&self,
vm_request: &VmValueRequest,
) -> Result<VmValuesResponseData> {
pub async fn execute_vmquery(&self, vm_request: &VMQueryInput) -> Result<VmValuesResponseData> {
let endpoint = self.get_endpoint(VM_VALUES_ENDPOINT);
let resp = Request::post(&endpoint)
.json(vm_request)?
Expand Down

0 comments on commit f6b0774

Please sign in to comment.