Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb7d6c8

Browse files
committed
runtime: Rename instance and borrow_instance
1 parent 71db400 commit bb7d6c8

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

runtime/wasm/src/module/mod.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ impl WasmInstanceHandle {
5757
value: &serde_json::Value,
5858
user_data: &store::Value,
5959
) -> Result<BlockState, anyhow::Error> {
60-
let value = self.instance().asc_new(value);
61-
let user_data = self.instance().asc_new(user_data);
60+
let value = self.instance_mut().asc_new(value);
61+
let user_data = self.instance_mut().asc_new(user_data);
6262

6363
// Invoke the callback
6464
let func = self
@@ -86,7 +86,7 @@ impl WasmInstanceHandle {
8686
// Decide on the destination type using the mapping
8787
// api version provided in the subgraph manifest
8888
let event = if self.instance().ctx.host_exports.api_version >= Version::new(0, 0, 2) {
89-
self.instance()
89+
self.instance_mut()
9090
.asc_new::<AscEthereumEvent<AscEthereumTransaction_0_0_2>, _>(&EthereumEventData {
9191
block: EthereumBlockData::from(block.as_ref()),
9292
transaction: EthereumTransactionData::from(transaction.deref()),
@@ -98,7 +98,7 @@ impl WasmInstanceHandle {
9898
})
9999
.erase()
100100
} else {
101-
self.instance()
101+
self.instance_mut()
102102
.asc_new::<AscEthereumEvent<AscEthereumTransaction>, _>(&EthereumEventData {
103103
block: EthereumBlockData::from(block.as_ref()),
104104
transaction: EthereumTransactionData::from(transaction.deref()),
@@ -135,11 +135,13 @@ impl WasmInstanceHandle {
135135
outputs,
136136
};
137137
let arg = if self.instance().ctx.host_exports.api_version >= Version::new(0, 0, 3) {
138-
self.instance()
138+
self.instance_mut()
139139
.asc_new::<AscEthereumCall_0_0_3, _>(&call)
140140
.erase()
141141
} else {
142-
self.instance().asc_new::<AscEthereumCall, _>(&call).erase()
142+
self.instance_mut()
143+
.asc_new::<AscEthereumCall, _>(&call)
144+
.erase()
143145
};
144146

145147
self.invoke_handler(handler_name, arg)?;
@@ -154,23 +156,22 @@ impl WasmInstanceHandle {
154156
let block = EthereumBlockData::from(self.instance().ctx.block.as_ref());
155157

156158
// Prepare an EthereumBlock for the WASM runtime
157-
let arg = self.instance().asc_new(&block);
159+
let arg = self.instance_mut().asc_new(&block);
158160

159161
self.invoke_handler(handler_name, arg)?;
160162

161163
Ok(self.take_instance().ctx.state)
162164
}
163165

164-
pub(crate) fn instance(&mut self) -> RefMut<'_, WasmInstance> {
166+
pub(crate) fn instance_mut(&mut self) -> RefMut<'_, WasmInstance> {
165167
RefMut::map(self.instance.borrow_mut(), |i| i.as_mut().unwrap())
166168
}
167169

168170
pub(crate) fn take_instance(&mut self) -> WasmInstance {
169171
self.instance.borrow_mut().take().unwrap()
170172
}
171173

172-
#[cfg(test)]
173-
pub(crate) fn borrow_instance(&self) -> std::cell::Ref<'_, WasmInstance> {
174+
pub(crate) fn instance(&self) -> std::cell::Ref<'_, WasmInstance> {
174175
std::cell::Ref::map(self.instance.borrow(), |i| i.as_ref().unwrap())
175176
}
176177

runtime/wasm/src/module/test.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn mock_context(
171171

172172
impl WasmInstanceHandle {
173173
fn get_func(&self, name: &str) -> wasmtime::Func {
174-
self.borrow_instance().instance.get_func(name).unwrap()
174+
self.instance().instance.get_func(name).unwrap()
175175
}
176176

177177
fn invoke_export<C, R>(&self, f: &str, arg: AscPtr<C>) -> AscPtr<R> {
@@ -210,11 +210,11 @@ impl WasmInstanceHandle {
210210

211211
impl AscHeap for WasmInstanceHandle {
212212
fn raw_new(&mut self, bytes: &[u8]) -> u32 {
213-
self.instance().raw_new(bytes)
213+
self.instance_mut().raw_new(bytes)
214214
}
215215

216216
fn get(&self, offset: u32, size: u32) -> Vec<u8> {
217-
self.borrow_instance().get(offset, size)
217+
self.instance().get(offset, size)
218218
}
219219
}
220220

@@ -328,8 +328,8 @@ async fn ipfs_map() {
328328
} else {
329329
ipfs.add(Cursor::new(json_string)).await.unwrap().hash
330330
};
331-
let value = module.instance().asc_new(&hash);
332-
let user_data = module.instance().asc_new(USER_DATA);
331+
let value = module.instance_mut().asc_new(&hash);
332+
let user_data = module.instance_mut().asc_new(USER_DATA);
333333

334334
// Invoke the callback
335335
let func = module
@@ -416,7 +416,7 @@ async fn ipfs_map() {
416416
async fn ipfs_fail() {
417417
let mut module = test_module("ipfsFail", mock_data_source("wasm_test/ipfs_cat.wasm"));
418418

419-
let hash = module.instance().asc_new("invalid hash");
419+
let hash = module.instance_mut().asc_new("invalid hash");
420420
assert!(module
421421
.invoke_export::<_, AscString>("ipfsCat", hash,)
422422
.is_null());
@@ -662,7 +662,7 @@ async fn entity_store() {
662662

663663
// We need to empty the cache for the next test
664664
let cache = std::mem::replace(
665-
&mut module.instance().ctx.state.entity_cache,
665+
&mut module.instance_mut().ctx.state.entity_cache,
666666
EntityCache::new(store.clone()),
667667
);
668668
let mut mods = cache

0 commit comments

Comments
 (0)