Skip to content

Commit aa358eb

Browse files
committed
Test commit
1 parent 7e637a3 commit aa358eb

File tree

127 files changed

+4618
-5910
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+4618
-5910
lines changed

.config/cargo_spellcheck.dic

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ defragmentation
3838
deploy
3939
dereferencing
4040
deserialize/S
41+
deserialization
4142
dispatchable/S
4243
encodable
4344
evaluable

crates/engine/src/ext.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl Engine {
229229

230230
/// Writes the encoded value into the storage at the given key.
231231
/// Returns the size of the previously stored value at the key if any.
232-
pub fn set_storage(&mut self, key: &[u8; 32], encoded_value: &[u8]) -> Option<u32> {
232+
pub fn set_storage(&mut self, key: &[u8], encoded_value: &[u8]) -> Option<u32> {
233233
let callee = self.get_callee();
234234
let account_id = AccountId::from_bytes(&callee[..]);
235235

@@ -243,7 +243,7 @@ impl Engine {
243243
}
244244

245245
/// Returns the decoded contract storage at the key if any.
246-
pub fn get_storage(&mut self, key: &[u8; 32], output: &mut &mut [u8]) -> Result {
246+
pub fn get_storage(&mut self, key: &[u8], output: &mut &mut [u8]) -> Result {
247247
let callee = self.get_callee();
248248
let account_id = AccountId::from_bytes(&callee[..]);
249249

@@ -258,7 +258,7 @@ impl Engine {
258258
}
259259

260260
/// Returns the size of the value stored in the contract storage at the key if any.
261-
pub fn contains_storage(&mut self, key: &[u8; 32]) -> Option<u32> {
261+
pub fn contains_storage(&mut self, key: &[u8]) -> Option<u32> {
262262
let callee = self.get_callee();
263263
let account_id = AccountId::from_bytes(&callee[..]);
264264

@@ -269,14 +269,16 @@ impl Engine {
269269
}
270270

271271
/// Removes the storage entries at the given key.
272-
pub fn clear_storage(&mut self, key: &[u8; 32]) {
272+
pub fn clear_storage(&mut self, key: &[u8]) -> Option<u32> {
273273
let callee = self.get_callee();
274274
let account_id = AccountId::from_bytes(&callee[..]);
275275
self.debug_info.inc_writes(account_id.clone());
276276
let _ = self
277277
.debug_info
278278
.remove_cell_for_account(account_id, key.to_vec());
279-
let _ = self.database.remove_contract_storage(&callee, key);
279+
self.database
280+
.remove_contract_storage(&callee, key)
281+
.map(|val| val.len() as u32)
280282
}
281283

282284
/// Remove the calling account and transfer remaining balance.

crates/env/src/api.rs

+21-15
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use crate::{
3939
Environment,
4040
Result,
4141
};
42-
use ink_primitives::Key;
4342

4443
/// Returns the address of the caller of the executed contract.
4544
///
@@ -183,49 +182,56 @@ where
183182
})
184183
}
185184

186-
/// Writes the value to the contract storage under the given key and returns
187-
/// the size of pre-existing value at the specified key if any.
185+
/// Writes the value to the contract storage under the given storage key and returns the size
186+
/// of pre-existing value if any.
188187
///
189188
/// # Panics
190189
///
191190
/// - If the encode length of value exceeds the configured maximum value length of a storage entry.
192-
pub fn set_contract_storage<V>(key: &Key, value: &V) -> Option<u32>
191+
pub fn set_contract_storage<K, V>(key: &K, value: &V) -> Option<u32>
193192
where
193+
K: scale::Encode,
194194
V: scale::Encode,
195195
{
196196
<EnvInstance as OnInstance>::on_instance(|instance| {
197-
EnvBackend::set_contract_storage::<V>(instance, key, value)
197+
EnvBackend::set_contract_storage::<K, V>(instance, key, value)
198198
})
199199
}
200200

201-
/// Returns the value stored under the given key in the contract's storage if any.
201+
/// Returns the value stored under the given storage key in the contract's storage if any.
202202
///
203203
/// # Errors
204204
///
205205
/// - If the decoding of the typed value failed (`KeyNotFound`)
206-
pub fn get_contract_storage<R>(key: &Key) -> Result<Option<R>>
206+
pub fn get_contract_storage<K, R>(key: &K) -> Result<Option<R>>
207207
where
208+
K: scale::Encode,
208209
R: scale::Decode,
209210
{
210211
<EnvInstance as OnInstance>::on_instance(|instance| {
211-
EnvBackend::get_contract_storage::<R>(instance, key)
212+
EnvBackend::get_contract_storage::<K, R>(instance, key)
212213
})
213214
}
214215

215-
/// Checks whether there is a value stored under the given key in
216-
/// the contract's storage.
216+
/// Checks whether there is a value stored under the given storage key in the contract's storage.
217217
///
218218
/// If a value is stored under the specified key, the size of the value is returned.
219-
pub fn contract_storage_contains(key: &Key) -> Option<u32> {
219+
pub fn contains_contract_storage<K>(key: &K) -> Option<u32>
220+
where
221+
K: scale::Encode,
222+
{
220223
<EnvInstance as OnInstance>::on_instance(|instance| {
221-
EnvBackend::contract_storage_contains(instance, key)
224+
EnvBackend::contains_contract_storage::<K>(instance, key)
222225
})
223226
}
224227

225-
/// Clears the contract's storage key entry.
226-
pub fn clear_contract_storage(key: &Key) {
228+
/// Clears the contract's storage entry under the given storage key.
229+
pub fn clear_contract_storage<K>(key: &K) -> Option<u32>
230+
where
231+
K: scale::Encode,
232+
{
227233
<EnvInstance as OnInstance>::on_instance(|instance| {
228-
EnvBackend::clear_contract_storage(instance, key)
234+
EnvBackend::clear_contract_storage::<K>(instance, key)
229235
})
230236
}
231237

crates/env/src/backend.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use crate::{
2727
Environment,
2828
Result,
2929
};
30-
use ink_primitives::Key;
3130

3231
/// The flags to indicate further information about the end of a contract execution.
3332
#[derive(Default)]
@@ -162,26 +161,33 @@ impl CallFlags {
162161

163162
/// Environmental contract functionality that does not require `Environment`.
164163
pub trait EnvBackend {
165-
/// Writes the value to the contract storage under the given key and returns
166-
/// the size of the pre-existing value at the specified key if any.
167-
fn set_contract_storage<V>(&mut self, key: &Key, value: &V) -> Option<u32>
164+
/// Writes the value to the contract storage under the given storage key.
165+
///
166+
/// Returns the size of the pre-existing value at the specified key if any.
167+
fn set_contract_storage<K, V>(&mut self, key: &K, value: &V) -> Option<u32>
168168
where
169+
K: scale::Encode,
169170
V: scale::Encode;
170171

171-
/// Returns the value stored under the given key in the contract's storage if any.
172+
/// Returns the value stored under the given storage key in the contract's storage if any.
172173
///
173174
/// # Errors
174175
///
175176
/// - If the decoding of the typed value failed
176-
fn get_contract_storage<R>(&mut self, key: &Key) -> Result<Option<R>>
177+
fn get_contract_storage<K, R>(&mut self, key: &K) -> Result<Option<R>>
177178
where
179+
K: scale::Encode,
178180
R: scale::Decode;
179181

180-
/// Returns the size of a value stored under the specified key is returned if any.
181-
fn contract_storage_contains(&mut self, key: &Key) -> Option<u32>;
182+
/// Returns the size of a value stored under the given storage key is returned if any.
183+
fn contains_contract_storage<K>(&mut self, key: &K) -> Option<u32>
184+
where
185+
K: scale::Encode;
182186

183-
/// Clears the contract's storage key entry.
184-
fn clear_contract_storage(&mut self, key: &Key);
187+
/// Clears the contract's storage key entry under the given storage key.
188+
fn clear_contract_storage<K>(&mut self, key: &K) -> Option<u32>
189+
where
190+
K: scale::Encode;
185191

186192
/// Returns the execution input to the executed contract and decodes it as `T`.
187193
///

crates/env/src/engine/off_chain/impls.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ use ink_engine::{
4444
ext,
4545
ext::Engine,
4646
};
47-
use ink_primitives::Key;
4847

4948
/// The capacity of the static buffer.
5049
/// This is the same size as the ink! on-chain environment. We chose to use the same size
@@ -184,20 +183,22 @@ impl EnvInstance {
184183
}
185184

186185
impl EnvBackend for EnvInstance {
187-
fn set_contract_storage<V>(&mut self, key: &Key, value: &V) -> Option<u32>
186+
fn set_contract_storage<K, V>(&mut self, key: &K, value: &V) -> Option<u32>
188187
where
188+
K: scale::Encode,
189189
V: scale::Encode,
190190
{
191191
let v = scale::Encode::encode(value);
192-
self.engine.set_storage(key.as_ref(), &v[..])
192+
self.engine.set_storage(&key.encode(), &v[..])
193193
}
194194

195-
fn get_contract_storage<R>(&mut self, key: &Key) -> Result<Option<R>>
195+
fn get_contract_storage<K, R>(&mut self, key: &K) -> Result<Option<R>>
196196
where
197+
K: scale::Encode,
197198
R: scale::Decode,
198199
{
199200
let mut output: [u8; 9600] = [0; 9600];
200-
match self.engine.get_storage(key.as_ref(), &mut &mut output[..]) {
201+
match self.engine.get_storage(&key.encode(), &mut &mut output[..]) {
201202
Ok(_) => (),
202203
Err(ext::Error::KeyNotFound) => return Ok(None),
203204
Err(_) => panic!("encountered unexpected error"),
@@ -206,12 +207,18 @@ impl EnvBackend for EnvInstance {
206207
Ok(Some(decoded))
207208
}
208209

209-
fn contract_storage_contains(&mut self, key: &Key) -> Option<u32> {
210-
self.engine.contains_storage(key.as_ref())
210+
fn contains_contract_storage<K>(&mut self, key: &K) -> Option<u32>
211+
where
212+
K: scale::Encode,
213+
{
214+
self.engine.contains_storage(&key.encode())
211215
}
212216

213-
fn clear_contract_storage(&mut self, key: &Key) {
214-
self.engine.clear_storage(key.as_ref())
217+
fn clear_contract_storage<K>(&mut self, key: &K) -> Option<u32>
218+
where
219+
K: scale::Encode,
220+
{
221+
self.engine.clear_storage(&key.encode())
215222
}
216223

217224
fn decode_input<T>(&mut self) -> Result<T>

crates/env/src/engine/on_chain/buffer.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ impl StaticBuffer {
3333
impl core::ops::Index<core::ops::RangeFull> for StaticBuffer {
3434
type Output = [u8];
3535

36+
#[inline(always)]
3637
fn index(&self, index: core::ops::RangeFull) -> &Self::Output {
3738
core::ops::Index::index(&self.buffer[..], index)
3839
}
3940
}
4041

4142
impl core::ops::IndexMut<core::ops::RangeFull> for StaticBuffer {
43+
#[inline(always)]
4244
fn index_mut(&mut self, index: core::ops::RangeFull) -> &mut Self::Output {
4345
core::ops::IndexMut::index_mut(&mut self.buffer[..], index)
4446
}
@@ -47,7 +49,7 @@ impl core::ops::IndexMut<core::ops::RangeFull> for StaticBuffer {
4749
/// Utility to allow for non-heap allocating encoding into a static buffer.
4850
///
4951
/// Required by `ScopedBuffer` internals.
50-
struct EncodeScope<'a> {
52+
pub struct EncodeScope<'a> {
5153
buffer: &'a mut [u8],
5254
len: usize,
5355
}
@@ -154,6 +156,7 @@ impl<'a> ScopedBuffer<'a> {
154156

155157
/// Encode the given value into the scoped buffer and return the sub slice
156158
/// containing all the encoded bytes.
159+
#[inline(always)]
157160
pub fn take_encoded<T>(&mut self, value: &T) -> &'a mut [u8]
158161
where
159162
T: scale::Encode,
@@ -172,6 +175,7 @@ impl<'a> ScopedBuffer<'a> {
172175
/// Does not return the buffer immediately so that other values can be appended
173176
/// afterwards. The [`take_appended`] method shall be used to return the buffer
174177
/// that includes all appended encodings as a single buffer.
178+
#[inline(always)]
175179
pub fn append_encoded<T>(&mut self, value: &T)
176180
where
177181
T: scale::Encode,

0 commit comments

Comments
 (0)