Repository: paritytech/ink
Pull request #302 (2019-12-24 08:06:01)

[core] Constrain invoke_runtime parameter
As discussed in #297. Use the same constraint `Into<<Self as EnvTypes>::Call>` as in the first [env/api.rs#L84](https://github.com/paritytech/ink/blob/master/core/src/env/api.rs#L84).

This is also a prerequisite to exposing the `invoke_runtime` method as will be done from https://github.com/paritytech/ink-types-node-runtime/pull/7



codecov-io: # [Codecov](https://codecov.io/gh/paritytech/ink/pull/302?src=pr&el=h1) Report
> Merging [#302](https://codecov.io/gh/paritytech/ink/pull/302?src=pr&el=desc) into [master](https://codecov.io/gh/paritytech/ink/commit/8bcf3813c7341d12ad0e12b6fc4db8c5e2e3cb2f?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/paritytech/ink/pull/302/graphs/tree.svg?width=650&token=tYyVaCZb7o&height=150&src=pr)](https://codecov.io/gh/paritytech/ink/pull/302?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master     #302   +/-   ##
=======================================
  Coverage   52.81%   52.81%           
=======================================
  Files          59       59           
  Lines        3859     3859           
=======================================
  Hits         2038     2038           
  Misses       1821     1821
```


| [Impacted Files](https://codecov.io/gh/paritytech/ink/pull/302?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [core/src/env2/test/accessor.rs](https://codecov.io/gh/paritytech/ink/pull/302/diff?src=pr&el=tree#diff-Y29yZS9zcmMvZW52Mi90ZXN0L2FjY2Vzc29yLnJz) | `0% <ø> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/paritytech/ink/pull/302?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/paritytech/ink/pull/302?src=pr&el=footer). Last update [8bcf381...ac1bd49](https://codecov.io/gh/paritytech/ink/pull/302?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

jaybutera: @Robbepop If this looks good can we push it through? Just trying to finish for my own use :smile: 

Patch:
diff --git a/core/src/env2/srml/impls.rs b/core/src/env2/srml/impls.rs
index 4e1d507d8f..8e73b2758c 100644
--- a/core/src/env2/srml/impls.rs
+++ b/core/src/env2/srml/impls.rs
@@ -349,10 +349,9 @@ where
         ext::deposit_event(topics, data);
     }
 
-    fn invoke_runtime<O, V>(buffer: &mut O, call_data: &V)
+    fn invoke_runtime<O>(buffer: &mut O, call_data: &<Self as EnvTypes>::Call)
     where
         O: scale::Output + AsRef<[u8]> + Reset,
-        V: scale::Encode,
     {
         buffer.reset();
         call_data.encode_to(buffer);
diff --git a/core/src/env2/traits.rs b/core/src/env2/traits.rs
index c6467216dd..a737b957b6 100644
--- a/core/src/env2/traits.rs
+++ b/core/src/env2/traits.rs
@@ -147,10 +147,9 @@ pub trait Env:
         Event: Topics<Self> + scale::Encode;
 
     /// Invokes a runtime dispatchable function with the given call data.
-    fn invoke_runtime<O, V>(buffer: &mut O, call_data: &V)
+    fn invoke_runtime<O>(buffer: &mut O, call_data: &<Self as EnvTypes>::Call)
     where
-        O: scale::Output + AsRef<[u8]> + Reset,
-        V: scale::Encode;
+        O: scale::Output + AsRef<[u8]> + Reset;
 
     /// Restores the contract to the given address.
     ///


Test patch:
diff --git a/core/src/env2/test/accessor.rs b/core/src/env2/test/accessor.rs
index ece95acadc..2e9d867fa7 100644
--- a/core/src/env2/test/accessor.rs
+++ b/core/src/env2/test/accessor.rs
@@ -65,6 +65,7 @@ use crate::{
     },
     storage::Key,
 };
+use scale::Encode;
 
 thread_local! {
     /// The single thread-local test environment instance.
@@ -420,10 +421,9 @@ where
         })
     }
 
-    fn invoke_runtime<O, V>(_buffer: &mut O, call_data: &V)
+    fn invoke_runtime<O>(_buffer: &mut O, call_data: &<Self as EnvTypes>::Call)
     where
         O: scale::Output + AsRef<[u8]> + Reset,
-        V: scale::Encode,
     {
         // With the off-chain test environment we have no means
         // to emit an event on the chain since there is no chain.