Skip to content

Commit 9ca3f60

Browse files
Change the argument of handle_query. (#4585)
## Motivation The `call_application` and `instantiate` are taking a reference, but in contrast to those functions the `handle_query`` is taking a value which is immediate serialized. There is no reason for that. ## Proposal Make the change of having `handle_query` take a reference. Also change `create_data_blob`. ## Test Plan The CI. ## Release Plan This is definitely breaking the smart contracts, though not the validator code. ## Links None.
1 parent abd85fe commit 9ca3f60

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed

examples/create-and-call/src/contract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Contract for CreateAndCallContract {
7575
// Step 3: Call the service. It should return the value before
7676
// the initialization of this contract and thus zero.
7777
let counter_request = CounterRequest::Query;
78-
let value = self.runtime.query_service(application_id, counter_request);
78+
let value = self.runtime.query_service(application_id, &counter_request);
7979
assert_eq!(value, 0);
8080

8181
// Step 4: Call the contract with counter increment operation

examples/ethereum-tracker/src/contract.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl EthereumTrackerContract {
8282
let request = async_graphql::Request::new("query { readInitialEvent }");
8383

8484
let application_id = self.runtime.application_id();
85-
let response = self.runtime.query_service(application_id, request);
85+
let response = self.runtime.query_service(application_id, &request);
8686

8787
let async_graphql::Value::Object(data_object) = response.data else {
8888
panic!("Unexpected response from `readInitialEvent`: {response:#?}");
@@ -115,7 +115,7 @@ impl EthereumTrackerContract {
115115
));
116116

117117
let application_id = self.runtime.application_id();
118-
let response = self.runtime.query_service(application_id, request);
118+
let response = self.runtime.query_service(application_id, &request);
119119

120120
let async_graphql::Value::Object(data_object) = response.data else {
121121
panic!("Unexpected response from `readTransferEvents`: {response:#?}");

examples/how-to/perform-http-requests/src/contract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl Contract {
8484
let application_id = self.runtime.application_id();
8585
let request = async_graphql::Request::new("query { performHttpRequest }");
8686

87-
let graphql_response = self.runtime.query_service(application_id, request);
87+
let graphql_response = self.runtime.query_service(application_id, &request);
8888

8989
let async_graphql::Value::Object(graphql_response_data) = graphql_response.data else {
9090
panic!("Unexpected response from service: {graphql_response:#?}");

examples/meta-counter/src/contract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl Contract for MetaCounterContract {
7474
let counter_id = self.counter_id();
7575
let _ = self
7676
.runtime
77-
.query_service(counter_id, "query { value }".into());
77+
.query_service(counter_id, &"query { value }".into());
7878
}
7979
message.send_to(recipient_id);
8080
}

examples/publish-read-data-blob/src/contract.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl Contract for PublishReadDataBlobContract {
3939
async fn execute_operation(&mut self, operation: Operation) {
4040
match operation {
4141
Operation::CreateDataBlob(data) => {
42-
self.runtime.create_data_blob(data);
42+
self.runtime.create_data_blob(&data);
4343
}
4444
Operation::ReadDataBlob(hash, expected_data) => {
4545
let data = self.runtime.read_data_blob(hash);
@@ -49,7 +49,7 @@ impl Contract for PublishReadDataBlobContract {
4949
);
5050
}
5151
Operation::CreateAndReadDataBlob(data) => {
52-
let hash: DataBlobHash = self.runtime.create_data_blob(data.clone());
52+
let hash: DataBlobHash = self.runtime.create_data_blob(&data);
5353
let data_read = self.runtime.read_data_blob(hash);
5454
assert_eq!(data_read, data);
5555
}

linera-sdk/src/contract/runtime.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,9 @@ where
305305
pub fn query_service<A: ServiceAbi + Send>(
306306
&mut self,
307307
application_id: ApplicationId<A>,
308-
query: A::Query,
308+
query: &A::Query,
309309
) -> A::QueryResponse {
310-
let query = serde_json::to_vec(&query).expect("Failed to serialize service query");
310+
let query = serde_json::to_vec(query).expect("Failed to serialize service query");
311311
let response = contract_wit::query_service(application_id.forget_abi().into(), &query);
312312
serde_json::from_slice(&response).expect("Failed to deserialize service response")
313313
}
@@ -375,8 +375,8 @@ where
375375
}
376376

377377
/// Creates a new data blob and returns its hash.
378-
pub fn create_data_blob(&mut self, bytes: Vec<u8>) -> DataBlobHash {
379-
let hash = contract_wit::create_data_blob(&bytes);
378+
pub fn create_data_blob(&mut self, bytes: &[u8]) -> DataBlobHash {
379+
let hash = contract_wit::create_data_blob(bytes);
380380
hash.into()
381381
}
382382

linera-sdk/src/contract/test_runtime.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -803,15 +803,15 @@ where
803803
}
804804

805805
/// Creates a new data blob and returns its hash.
806-
pub fn create_data_blob(&mut self, bytes: Vec<u8>) -> DataBlobHash {
806+
pub fn create_data_blob(&mut self, bytes: &[u8]) -> DataBlobHash {
807807
let ExpectedCreateDataBlobCall {
808808
bytes: expected_bytes,
809809
blob_id,
810810
} = self
811811
.expected_create_data_blob_calls
812812
.pop_front()
813813
.expect("Unexpected create_data_blob call");
814-
assert_eq!(bytes, expected_bytes);
814+
assert_eq!(bytes, &expected_bytes);
815815
DataBlobHash(blob_id.hash)
816816
}
817817

@@ -946,13 +946,13 @@ where
946946
pub fn query_service<A: ServiceAbi + Send>(
947947
&mut self,
948948
application_id: ApplicationId<A>,
949-
query: A::Query,
949+
query: &A::Query,
950950
) -> A::QueryResponse {
951951
let maybe_query = self.expected_service_queries.pop_front();
952952
let (expected_id, expected_query, response) =
953953
maybe_query.expect("Unexpected service query");
954954
assert_eq!(application_id.forget_abi(), expected_id);
955-
let query = serde_json::to_string(&query).expect("Failed to serialize query");
955+
let query = serde_json::to_string(query).expect("Failed to serialize query");
956956
assert_eq!(query, expected_query);
957957
serde_json::from_str(&response).expect("Failed to deserialize response")
958958
}

0 commit comments

Comments
 (0)