Skip to content

Commit

Permalink
Runtime API calls (#91)
Browse files Browse the repository at this point in the history
* Added runtime API calls to registry

* Added EthereumRuntimeRPCApi Runtime Calls

* Add checks to generate_type_decomposition()
Implemented generate_type_decomposition() for Set
Simplified type reg test
  • Loading branch information
arjanz authored Nov 24, 2022
1 parent 5a28f0d commit dabd829
Show file tree
Hide file tree
Showing 10 changed files with 1,737 additions and 53 deletions.
13 changes: 8 additions & 5 deletions docs/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h1 class="title">Module <code>scalecodec.base</code></h1>

def __init__(self, config_id=None, ss58_format=None, only_primitives_on_init=False, implements_scale_info=False):
self.config_id = config_id
self.type_registry = {&#39;types&#39;: {}}
self.type_registry = {&#39;types&#39;: {}, &#39;runtime_api&#39;: {}}
self.__initial_state = False
self.clear_type_registry()
self.active_spec_version_id = None
Expand Down Expand Up @@ -206,7 +206,7 @@ <h1 class="title">Module <code>scalecodec.base</code></h1>
def clear_type_registry(self):

if not self.__initial_state:
self.type_registry = {&#39;types&#39;: {}}
self.type_registry = {&#39;types&#39;: {}, &#39;runtime_api&#39;: {}}

# Class names that contains &#39;&lt;&#39; are excluded because of a side effect that is introduced in
# get_decoder_class: &#34;Create dynamic class for Part1&lt;Part2&gt; based on Part1 and set class variable Part2 as
Expand Down Expand Up @@ -301,6 +301,7 @@ <h1 class="title">Module <code>scalecodec.base</code></h1>
self.chain_id = type_registry.get(&#39;chain_id&#39;)

self.type_registry[&#39;versioning&#39;] = type_registry.get(&#39;versioning&#39;)
self.type_registry[&#39;runtime_api&#39;].update(type_registry.get(&#39;runtime_api&#39;, {}))
self.type_registry[&#39;runtime_upgrades&#39;] = type_registry.get(&#39;runtime_upgrades&#39;)

# Update types
Expand Down Expand Up @@ -945,7 +946,7 @@ <h3>Inherited members</h3>

def __init__(self, config_id=None, ss58_format=None, only_primitives_on_init=False, implements_scale_info=False):
self.config_id = config_id
self.type_registry = {&#39;types&#39;: {}}
self.type_registry = {&#39;types&#39;: {}, &#39;runtime_api&#39;: {}}
self.__initial_state = False
self.clear_type_registry()
self.active_spec_version_id = None
Expand Down Expand Up @@ -1075,7 +1076,7 @@ <h3>Inherited members</h3>
def clear_type_registry(self):

if not self.__initial_state:
self.type_registry = {&#39;types&#39;: {}}
self.type_registry = {&#39;types&#39;: {}, &#39;runtime_api&#39;: {}}

# Class names that contains &#39;&lt;&#39; are excluded because of a side effect that is introduced in
# get_decoder_class: &#34;Create dynamic class for Part1&lt;Part2&gt; based on Part1 and set class variable Part2 as
Expand Down Expand Up @@ -1170,6 +1171,7 @@ <h3>Inherited members</h3>
self.chain_id = type_registry.get(&#39;chain_id&#39;)

self.type_registry[&#39;versioning&#39;] = type_registry.get(&#39;versioning&#39;)
self.type_registry[&#39;runtime_api&#39;].update(type_registry.get(&#39;runtime_api&#39;, {}))
self.type_registry[&#39;runtime_upgrades&#39;] = type_registry.get(&#39;runtime_upgrades&#39;)

# Update types
Expand Down Expand Up @@ -1527,7 +1529,7 @@ <h3>Methods</h3>
<pre><code class="python">def clear_type_registry(self):

if not self.__initial_state:
self.type_registry = {&#39;types&#39;: {}}
self.type_registry = {&#39;types&#39;: {}, &#39;runtime_api&#39;: {}}

# Class names that contains &#39;&lt;&#39; are excluded because of a side effect that is introduced in
# get_decoder_class: &#34;Create dynamic class for Part1&lt;Part2&gt; based on Part1 and set class variable Part2 as
Expand Down Expand Up @@ -1972,6 +1974,7 @@ <h2 id="returns">Returns</h2></div>
self.chain_id = type_registry.get(&#39;chain_id&#39;)

self.type_registry[&#39;versioning&#39;] = type_registry.get(&#39;versioning&#39;)
self.type_registry[&#39;runtime_api&#39;].update(type_registry.get(&#39;runtime_api&#39;, {}))
self.type_registry[&#39;runtime_upgrades&#39;] = type_registry.get(&#39;runtime_upgrades&#39;)

# Update types
Expand Down
178 changes: 176 additions & 2 deletions docs/types.html
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,10 @@ <h1 class="title">Module <code>scalecodec.types</code></h1>

return data + value.to_bytes(length=byte_length, byteorder=&#39;little&#39;)

@classmethod
def generate_type_decomposition(cls, _recursion_level: int = 0):
return &#39;BitVec&#39;


class GenericAddress(ScaleType):

Expand Down Expand Up @@ -1092,6 +1096,7 @@ <h1 class="title">Module <code>scalecodec.types</code></h1>
def generate_type_decomposition(cls, _recursion_level: int = 0):
return cls.__name__.lower()


class AccountIdAddress(GenericAddress):

def process(self):
Expand Down Expand Up @@ -2591,6 +2596,24 @@ <h1 class="title">Module <code>scalecodec.types</code></h1>
return param_info


class GenericRuntimeCallDefinition(Struct):

def get_param_info(self) -&gt; list:
&#34;&#34;&#34;
Return a type decomposition how to format parameters for current storage function

Returns
-------
list
&#34;&#34;&#34;
param_info = []
for param in self.value[&#39;params&#39;]:
scale_type = self.runtime_config.create_scale_object(param[&#39;type&#39;])
param_info.append(scale_type.generate_type_decomposition())

return param_info


class GenericEventMetadata(Struct):

@property
Expand Down Expand Up @@ -2753,6 +2776,10 @@ <h1 class="title">Module <code>scalecodec.types</code></h1>

return data

@classmethod
def generate_type_decomposition(cls, _recursion_level: int = 0):
return &#39;Extrinsic&#39;


class Extrinsic(GenericExtrinsic):
pass
Expand Down Expand Up @@ -3377,7 +3404,11 @@ <h2 id="parameters">Parameters</h2>

byte_length = math.ceil(value.bit_length() / 8)

return data + value.to_bytes(length=byte_length, byteorder=&#39;little&#39;)</code></pre>
return data + value.to_bytes(length=byte_length, byteorder=&#39;little&#39;)

@classmethod
def generate_type_decomposition(cls, _recursion_level: int = 0):
return &#39;BitVec&#39;</code></pre>
</details>
<h3>Ancestors</h3>
<ul class="hlist">
Expand All @@ -3392,6 +3423,23 @@ <h3>Class variables</h3>
<div class="desc"></div>
</dd>
</dl>
<h3>Static methods</h3>
<dl>
<dt id="scalecodec.types.BitVec.generate_type_decomposition"><code class="name flex">
<span>def <span class="ident">generate_type_decomposition</span></span>(<span>)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@classmethod
def generate_type_decomposition(cls, _recursion_level: int = 0):
return &#39;BitVec&#39;</code></pre>
</details>
</dd>
</dl>
<h3>Methods</h3>
<dl>
<dt id="scalecodec.types.BitVec.process"><code class="name flex">
Expand Down Expand Up @@ -7792,7 +7840,11 @@ <h2 id="parameters">Parameters</h2>

self.value_object[&#39;extrinsic_length&#39;] = length_obj

return data</code></pre>
return data

@classmethod
def generate_type_decomposition(cls, _recursion_level: int = 0):
return &#39;Extrinsic&#39;</code></pre>
</details>
<h3>Ancestors</h3>
<ul class="hlist">
Expand All @@ -7811,6 +7863,23 @@ <h3>Class variables</h3>
<div class="desc"></div>
</dd>
</dl>
<h3>Static methods</h3>
<dl>
<dt id="scalecodec.types.GenericExtrinsic.generate_type_decomposition"><code class="name flex">
<span>def <span class="ident">generate_type_decomposition</span></span>(<span>)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@classmethod
def generate_type_decomposition(cls, _recursion_level: int = 0):
return &#39;Extrinsic&#39;</code></pre>
</details>
</dd>
</dl>
<h3>Instance variables</h3>
<dl>
<dt id="scalecodec.types.GenericExtrinsic.extrinsic_hash"><code class="name">var <span class="ident">extrinsic_hash</span></code></dt>
Expand Down Expand Up @@ -9732,6 +9801,101 @@ <h3>Inherited members</h3>
</li>
</ul>
</dd>
<dt id="scalecodec.types.GenericRuntimeCallDefinition"><code class="flex name class">
<span>class <span class="ident">GenericRuntimeCallDefinition</span></span>
<span>(</span><span>data=None, type_mapping=None, **kwargs)</span>
</code></dt>
<dd>
<div class="desc"><p>Helper class that provides a standard way to create an ABC using
inheritance.</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>data</code></strong> :&ensp;<code>ScaleBytes</code></dt>
<dd>&nbsp;</dd>
<dt><strong><code>sub_type</code></strong> :&ensp;<code>str</code></dt>
<dd>&nbsp;</dd>
<dt><strong><code>metadata</code></strong> :&ensp;<code>VersionedMetadata</code></dt>
<dd>&nbsp;</dd>
<dt><strong><code>runtime_config</code></strong> :&ensp;<code>RuntimeConfigurationObject</code></dt>
<dd>&nbsp;</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class GenericRuntimeCallDefinition(Struct):

def get_param_info(self) -&gt; list:
&#34;&#34;&#34;
Return a type decomposition how to format parameters for current storage function

Returns
-------
list
&#34;&#34;&#34;
param_info = []
for param in self.value[&#39;params&#39;]:
scale_type = self.runtime_config.create_scale_object(param[&#39;type&#39;])
param_info.append(scale_type.generate_type_decomposition())

return param_info</code></pre>
</details>
<h3>Ancestors</h3>
<ul class="hlist">
<li><a title="scalecodec.types.Struct" href="#scalecodec.types.Struct">Struct</a></li>
<li><a title="scalecodec.base.ScaleType" href="base.html#scalecodec.base.ScaleType">ScaleType</a></li>
<li><a title="scalecodec.base.ScaleDecoder" href="base.html#scalecodec.base.ScaleDecoder">ScaleDecoder</a></li>
<li>abc.ABC</li>
</ul>
<h3>Class variables</h3>
<dl>
<dt id="scalecodec.types.GenericRuntimeCallDefinition.scale_info_type"><code class="name">var <span class="ident">scale_info_type</span> : <a title="scalecodec.types.GenericRegistryType" href="#scalecodec.types.GenericRegistryType">GenericRegistryType</a></code></dt>
<dd>
<div class="desc"></div>
</dd>
</dl>
<h3>Methods</h3>
<dl>
<dt id="scalecodec.types.GenericRuntimeCallDefinition.get_param_info"><code class="name flex">
<span>def <span class="ident">get_param_info</span></span>(<span>self) ‑> list</span>
</code></dt>
<dd>
<div class="desc"><p>Return a type decomposition how to format parameters for current storage function</p>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>list</code></dt>
<dd>&nbsp;</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def get_param_info(self) -&gt; list:
&#34;&#34;&#34;
Return a type decomposition how to format parameters for current storage function

Returns
-------
list
&#34;&#34;&#34;
param_info = []
for param in self.value[&#39;params&#39;]:
scale_type = self.runtime_config.create_scale_object(param[&#39;type&#39;])
param_info.append(scale_type.generate_type_decomposition())

return param_info</code></pre>
</details>
</dd>
</dl>
<h3>Inherited members</h3>
<ul class="hlist">
<li><code><b><a title="scalecodec.types.Struct" href="#scalecodec.types.Struct">Struct</a></b></code>:
<ul class="hlist">
<li><code><a title="scalecodec.types.Struct.get_decoder_class" href="base.html#scalecodec.base.ScaleDecoder.get_decoder_class">get_decoder_class</a></code></li>
</ul>
</li>
</ul>
</dd>
<dt id="scalecodec.types.GenericScaleInfoEvent"><code class="flex name class">
<span>class <span class="ident">GenericScaleInfoEvent</span></span>
<span>(</span><span>*args, **kwargs)</span>
Expand Down Expand Up @@ -14178,6 +14342,7 @@ <h3>Subclasses</h3>
<li><a title="scalecodec.types.GenericPalletMetadata" href="#scalecodec.types.GenericPalletMetadata">GenericPalletMetadata</a></li>
<li><a title="scalecodec.types.GenericPreRuntime" href="#scalecodec.types.GenericPreRuntime">GenericPreRuntime</a></li>
<li><a title="scalecodec.types.GenericRegistryType" href="#scalecodec.types.GenericRegistryType">GenericRegistryType</a></li>
<li><a title="scalecodec.types.GenericRuntimeCallDefinition" href="#scalecodec.types.GenericRuntimeCallDefinition">GenericRuntimeCallDefinition</a></li>
<li><a title="scalecodec.types.GenericSeal" href="#scalecodec.types.GenericSeal">GenericSeal</a></li>
<li><a title="scalecodec.types.GenericSealV0" href="#scalecodec.types.GenericSealV0">GenericSealV0</a></li>
<li><a title="scalecodec.types.GenericStorageEntryMetadata" href="#scalecodec.types.GenericStorageEntryMetadata">GenericStorageEntryMetadata</a></li>
Expand Down Expand Up @@ -15589,6 +15754,7 @@ <h4><code><a title="scalecodec.types.BTreeSet" href="#scalecodec.types.BTreeSet"
<li>
<h4><code><a title="scalecodec.types.BitVec" href="#scalecodec.types.BitVec">BitVec</a></code></h4>
<ul class="">
<li><code><a title="scalecodec.types.BitVec.generate_type_decomposition" href="#scalecodec.types.BitVec.generate_type_decomposition">generate_type_decomposition</a></code></li>
<li><code><a title="scalecodec.types.BitVec.process" href="#scalecodec.types.BitVec.process">process</a></code></li>
<li><code><a title="scalecodec.types.BitVec.process_encode" href="#scalecodec.types.BitVec.process_encode">process_encode</a></code></li>
<li><code><a title="scalecodec.types.BitVec.scale_info_type" href="#scalecodec.types.BitVec.scale_info_type">scale_info_type</a></code></li>
Expand Down Expand Up @@ -15858,6 +16024,7 @@ <h4><code><a title="scalecodec.types.GenericEventRecord" href="#scalecodec.types
<h4><code><a title="scalecodec.types.GenericExtrinsic" href="#scalecodec.types.GenericExtrinsic">GenericExtrinsic</a></code></h4>
<ul class="">
<li><code><a title="scalecodec.types.GenericExtrinsic.extrinsic_hash" href="#scalecodec.types.GenericExtrinsic.extrinsic_hash">extrinsic_hash</a></code></li>
<li><code><a title="scalecodec.types.GenericExtrinsic.generate_type_decomposition" href="#scalecodec.types.GenericExtrinsic.generate_type_decomposition">generate_type_decomposition</a></code></li>
<li><code><a title="scalecodec.types.GenericExtrinsic.process" href="#scalecodec.types.GenericExtrinsic.process">process</a></code></li>
<li><code><a title="scalecodec.types.GenericExtrinsic.process_encode" href="#scalecodec.types.GenericExtrinsic.process_encode">process_encode</a></code></li>
<li><code><a title="scalecodec.types.GenericExtrinsic.scale_info_type" href="#scalecodec.types.GenericExtrinsic.scale_info_type">scale_info_type</a></code></li>
Expand Down Expand Up @@ -15977,6 +16144,13 @@ <h4><code><a title="scalecodec.types.GenericRegistryType" href="#scalecodec.type
</ul>
</li>
<li>
<h4><code><a title="scalecodec.types.GenericRuntimeCallDefinition" href="#scalecodec.types.GenericRuntimeCallDefinition">GenericRuntimeCallDefinition</a></code></h4>
<ul class="">
<li><code><a title="scalecodec.types.GenericRuntimeCallDefinition.get_param_info" href="#scalecodec.types.GenericRuntimeCallDefinition.get_param_info">get_param_info</a></code></li>
<li><code><a title="scalecodec.types.GenericRuntimeCallDefinition.scale_info_type" href="#scalecodec.types.GenericRuntimeCallDefinition.scale_info_type">scale_info_type</a></code></li>
</ul>
</li>
<li>
<h4><code><a title="scalecodec.types.GenericScaleInfoEvent" href="#scalecodec.types.GenericScaleInfoEvent">GenericScaleInfoEvent</a></code></h4>
<ul class="">
<li><code><a title="scalecodec.types.GenericScaleInfoEvent.process" href="#scalecodec.types.GenericScaleInfoEvent.process">process</a></code></li>
Expand Down
Loading

0 comments on commit dabd829

Please sign in to comment.