Skip to content

Commit 1469168

Browse files
authored
Add NATIVE_TO_ETH_RATIO to missing methods (#2607)
* Add `NATIVE_TO_ETH_RATIO` to missing methods * Add `NATIVE_TO_ETH_RATIO` to missing methods
1 parent 2821151 commit 1469168

File tree

3 files changed

+63
-26
lines changed

3 files changed

+63
-26
lines changed

crates/ink/codegen/src/generator/metadata.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ impl Metadata<'_> {
369369
.block_number(#block_number)
370370
.chain_extension(#chain_extension)
371371
.max_event_topics(MAX_EVENT_TOPICS)
372+
.native_to_eth_ratio(NATIVE_TO_ETH_RATIO)
372373
.static_buffer_size(#buffer_size_const)
373374
.done()
374375
)

crates/metadata/src/specs.rs

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,8 @@ mod state {
659659
pub struct ChainExtension;
660660
/// Type state for the max number of topics specified in the environment.
661661
pub struct MaxEventTopics;
662+
/// Type state for the native to eth ratio specified in the environment.
663+
pub struct NativeToEthRatio;
662664
/// Type state for the size of the static buffer configured via environment variable.`
663665
pub struct BufferSize;
664666
}
@@ -1649,6 +1651,7 @@ where
16491651
Missing<state::BlockNumber>,
16501652
Missing<state::ChainExtension>,
16511653
Missing<state::MaxEventTopics>,
1654+
Missing<state::NativeToEthRatio>,
16521655
Missing<state::BufferSize>,
16531656
> {
16541657
EnvironmentSpecBuilder {
@@ -1661,18 +1664,18 @@ where
16611664
/// An environment specification builder.
16621665
#[allow(clippy::type_complexity)]
16631666
#[must_use]
1664-
pub struct EnvironmentSpecBuilder<F, A, B, H, T, BN, C, M, BS>
1667+
pub struct EnvironmentSpecBuilder<F, A, B, H, T, BN, C, M, NTER, BS>
16651668
where
16661669
F: Form,
16671670
TypeSpec<F>: Default,
16681671
EnvironmentSpec<F>: Default,
16691672
{
16701673
spec: EnvironmentSpec<F>,
1671-
marker: PhantomData<fn() -> (A, B, H, T, BN, C, M, BS)>,
1674+
marker: PhantomData<fn() -> (A, B, H, T, BN, C, M, NTER, BS)>,
16721675
}
16731676

1674-
impl<F, B, H, T, BN, C, M, BS>
1675-
EnvironmentSpecBuilder<F, Missing<state::AccountId>, B, H, T, BN, C, M, BS>
1677+
impl<F, B, H, T, BN, C, M, NTER, BS>
1678+
EnvironmentSpecBuilder<F, Missing<state::AccountId>, B, H, T, BN, C, M, NTER, BS>
16761679
where
16771680
F: Form,
16781681
TypeSpec<F>: Default,
@@ -1682,7 +1685,7 @@ where
16821685
pub fn account_id(
16831686
self,
16841687
account_id: TypeSpec<F>,
1685-
) -> EnvironmentSpecBuilder<F, state::AccountId, B, H, T, BN, C, M, BS> {
1688+
) -> EnvironmentSpecBuilder<F, state::AccountId, B, H, T, BN, C, M, NTER, BS> {
16861689
EnvironmentSpecBuilder {
16871690
spec: EnvironmentSpec {
16881691
account_id,
@@ -1693,8 +1696,8 @@ where
16931696
}
16941697
}
16951698

1696-
impl<F, A, H, T, BN, C, M, BS>
1697-
EnvironmentSpecBuilder<F, A, Missing<state::Balance>, H, T, BN, C, M, BS>
1699+
impl<F, A, H, T, BN, C, M, NTER, BS>
1700+
EnvironmentSpecBuilder<F, A, Missing<state::Balance>, H, T, BN, C, M, NTER, BS>
16981701
where
16991702
F: Form,
17001703
TypeSpec<F>: Default,
@@ -1704,7 +1707,7 @@ where
17041707
pub fn balance(
17051708
self,
17061709
balance: TypeSpec<F>,
1707-
) -> EnvironmentSpecBuilder<F, A, state::Balance, H, T, BN, C, M, BS> {
1710+
) -> EnvironmentSpecBuilder<F, A, state::Balance, H, T, BN, C, M, NTER, BS> {
17081711
EnvironmentSpecBuilder {
17091712
spec: EnvironmentSpec {
17101713
balance,
@@ -1715,8 +1718,8 @@ where
17151718
}
17161719
}
17171720

1718-
impl<F, A, B, T, BN, C, M, BS>
1719-
EnvironmentSpecBuilder<F, A, B, Missing<state::Hash>, T, BN, C, M, BS>
1721+
impl<F, A, B, T, BN, C, M, NTER, BS>
1722+
EnvironmentSpecBuilder<F, A, B, Missing<state::Hash>, T, BN, C, M, NTER, BS>
17201723
where
17211724
F: Form,
17221725
TypeSpec<F>: Default,
@@ -1726,16 +1729,16 @@ where
17261729
pub fn hash(
17271730
self,
17281731
hash: TypeSpec<F>,
1729-
) -> EnvironmentSpecBuilder<F, A, B, state::Hash, T, BN, C, M, BS> {
1732+
) -> EnvironmentSpecBuilder<F, A, B, state::Hash, T, BN, C, M, NTER, BS> {
17301733
EnvironmentSpecBuilder {
17311734
spec: EnvironmentSpec { hash, ..self.spec },
17321735
marker: PhantomData,
17331736
}
17341737
}
17351738
}
17361739

1737-
impl<F, A, B, H, BN, C, M, BS>
1738-
EnvironmentSpecBuilder<F, A, B, H, Missing<state::Timestamp>, BN, C, M, BS>
1740+
impl<F, A, B, H, BN, C, M, NTER, BS>
1741+
EnvironmentSpecBuilder<F, A, B, H, Missing<state::Timestamp>, BN, C, M, NTER, BS>
17391742
where
17401743
F: Form,
17411744
TypeSpec<F>: Default,
@@ -1745,7 +1748,7 @@ where
17451748
pub fn timestamp(
17461749
self,
17471750
timestamp: TypeSpec<F>,
1748-
) -> EnvironmentSpecBuilder<F, A, B, H, state::Timestamp, BN, C, M, BS> {
1751+
) -> EnvironmentSpecBuilder<F, A, B, H, state::Timestamp, BN, C, M, NTER, BS> {
17491752
EnvironmentSpecBuilder {
17501753
spec: EnvironmentSpec {
17511754
timestamp,
@@ -1756,8 +1759,8 @@ where
17561759
}
17571760
}
17581761

1759-
impl<F, A, B, H, T, C, M, BS>
1760-
EnvironmentSpecBuilder<F, A, B, H, T, Missing<state::BlockNumber>, C, M, BS>
1762+
impl<F, A, B, H, T, C, M, NTER, BS>
1763+
EnvironmentSpecBuilder<F, A, B, H, T, Missing<state::BlockNumber>, C, M, NTER, BS>
17611764
where
17621765
F: Form,
17631766
TypeSpec<F>: Default,
@@ -1767,7 +1770,7 @@ where
17671770
pub fn block_number(
17681771
self,
17691772
block_number: TypeSpec<F>,
1770-
) -> EnvironmentSpecBuilder<F, A, B, H, T, state::BlockNumber, C, M, BS> {
1773+
) -> EnvironmentSpecBuilder<F, A, B, H, T, state::BlockNumber, C, M, NTER, BS> {
17711774
EnvironmentSpecBuilder {
17721775
spec: EnvironmentSpec {
17731776
block_number,
@@ -1778,8 +1781,8 @@ where
17781781
}
17791782
}
17801783

1781-
impl<F, A, B, H, T, BN, M, BS>
1782-
EnvironmentSpecBuilder<F, A, B, H, T, BN, Missing<state::ChainExtension>, M, BS>
1784+
impl<F, A, B, H, T, BN, M, NTER, BS>
1785+
EnvironmentSpecBuilder<F, A, B, H, T, BN, Missing<state::ChainExtension>, M, NTER, BS>
17831786
where
17841787
F: Form,
17851788
TypeSpec<F>: Default,
@@ -1789,7 +1792,8 @@ where
17891792
pub fn chain_extension(
17901793
self,
17911794
chain_extension: TypeSpec<F>,
1792-
) -> EnvironmentSpecBuilder<F, A, B, H, T, BN, state::ChainExtension, M, BS> {
1795+
) -> EnvironmentSpecBuilder<F, A, B, H, T, BN, state::ChainExtension, M, NTER, BS>
1796+
{
17931797
EnvironmentSpecBuilder {
17941798
spec: EnvironmentSpec {
17951799
chain_extension,
@@ -1800,8 +1804,8 @@ where
18001804
}
18011805
}
18021806

1803-
impl<F, A, B, H, T, BN, C, BS>
1804-
EnvironmentSpecBuilder<F, A, B, H, T, BN, C, Missing<state::MaxEventTopics>, BS>
1807+
impl<F, A, B, H, T, BN, C, NTER, BS>
1808+
EnvironmentSpecBuilder<F, A, B, H, T, BN, C, Missing<state::MaxEventTopics>, NTER, BS>
18051809
where
18061810
F: Form,
18071811
TypeSpec<F>: Default,
@@ -1811,7 +1815,8 @@ where
18111815
pub fn max_event_topics(
18121816
self,
18131817
max_event_topics: usize,
1814-
) -> EnvironmentSpecBuilder<F, A, B, H, T, BN, C, state::MaxEventTopics, BS> {
1818+
) -> EnvironmentSpecBuilder<F, A, B, H, T, BN, C, state::MaxEventTopics, NTER, BS>
1819+
{
18151820
EnvironmentSpecBuilder {
18161821
spec: EnvironmentSpec {
18171822
max_event_topics,
@@ -1822,8 +1827,31 @@ where
18221827
}
18231828
}
18241829

1825-
impl<F, A, B, H, T, BN, C, M>
1826-
EnvironmentSpecBuilder<F, A, B, H, T, BN, C, M, Missing<state::BufferSize>>
1830+
impl<F, A, B, H, T, BN, C, M, BS>
1831+
EnvironmentSpecBuilder<F, A, B, H, T, BN, C, M, Missing<state::NativeToEthRatio>, BS>
1832+
where
1833+
F: Form,
1834+
TypeSpec<F>: Default,
1835+
EnvironmentSpec<F>: Default,
1836+
{
1837+
/// Sets the `NATIVE_TO_ETH_RATIO` value of the environment.
1838+
pub fn native_to_eth_ratio(
1839+
self,
1840+
native_to_eth_ratio: u32,
1841+
) -> EnvironmentSpecBuilder<F, A, B, H, T, BN, C, M, state::NativeToEthRatio, BS>
1842+
{
1843+
EnvironmentSpecBuilder {
1844+
spec: EnvironmentSpec {
1845+
native_to_eth_ratio,
1846+
..self.spec
1847+
},
1848+
marker: PhantomData,
1849+
}
1850+
}
1851+
}
1852+
1853+
impl<F, A, B, H, T, BN, C, M, NTER>
1854+
EnvironmentSpecBuilder<F, A, B, H, T, BN, C, M, NTER, Missing<state::BufferSize>>
18271855
where
18281856
F: Form,
18291857
TypeSpec<F>: Default,
@@ -1833,7 +1861,7 @@ where
18331861
pub fn static_buffer_size(
18341862
self,
18351863
static_buffer_size: usize,
1836-
) -> EnvironmentSpecBuilder<F, A, B, H, T, BN, C, M, state::BufferSize> {
1864+
) -> EnvironmentSpecBuilder<F, A, B, H, T, BN, C, M, NTER, state::BufferSize> {
18371865
EnvironmentSpecBuilder {
18381866
spec: EnvironmentSpec {
18391867
static_buffer_size,
@@ -1854,6 +1882,7 @@ impl<F>
18541882
state::BlockNumber,
18551883
state::ChainExtension,
18561884
state::MaxEventTopics,
1885+
state::NativeToEthRatio,
18571886
state::BufferSize,
18581887
>
18591888
where

crates/metadata/src/tests.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ fn spec_contract_only_one_default_constructor_allowed() {
189189
fn spec_contract_event_definition_exceeds_environment_topics_limit() {
190190
const MAX_EVENT_TOPICS: usize = 2;
191191
const BUFFER_SIZE: usize = 1 << 14;
192+
const NATIVE_TO_ETH_RATIO: u32 = 100000000;
192193

193194
ContractSpec::new()
194195
.constructors(vec![ConstructorSpec::from_label("new")
@@ -278,6 +279,7 @@ fn spec_contract_event_definition_exceeds_environment_topics_limit() {
278279
.block_number(TypeSpec::of_type::<u128>())
279280
.chain_extension(TypeSpec::of_type::<()>())
280281
.max_event_topics(MAX_EVENT_TOPICS)
282+
.native_to_eth_ratio(NATIVE_TO_ETH_RATIO)
281283
.static_buffer_size(BUFFER_SIZE)
282284
.done(),
283285
)
@@ -291,6 +293,7 @@ fn spec_contract_event_definition_exceeds_environment_topics_limit() {
291293
fn spec_contract_event_definition_signature_topic_collision() {
292294
const SIGNATURE_TOPIC: Option<[u8; 32]> = Some([42u8; 32]);
293295
const BUFFER_SIZE: usize = 1 << 14;
296+
const NATIVE_TO_ETH_RATIO: u32 = 100000000;
294297

295298
ContractSpec::new()
296299
.constructors(vec![ConstructorSpec::from_label("new")
@@ -353,6 +356,7 @@ fn spec_contract_event_definition_signature_topic_collision() {
353356
.block_number(TypeSpec::of_type::<u128>())
354357
.chain_extension(TypeSpec::of_type::<()>())
355358
.max_event_topics(2)
359+
.native_to_eth_ratio(NATIVE_TO_ETH_RATIO)
356360
.static_buffer_size(BUFFER_SIZE)
357361
.done(),
358362
)
@@ -371,6 +375,7 @@ fn spec_contract_json() {
371375
type BlockNumber = u128;
372376
type ChainExtension = NoChainExtension;
373377
const MAX_EVENT_TOPICS: usize = 4;
378+
const NATIVE_TO_ETH_RATIO: u32 = 100000000;
374379
const BUFFER_SIZE: usize = 1 << 14;
375380

376381
// given
@@ -488,6 +493,7 @@ fn spec_contract_json() {
488493
),
489494
))
490495
.max_event_topics(MAX_EVENT_TOPICS)
496+
.native_to_eth_ratio(NATIVE_TO_ETH_RATIO)
491497
.static_buffer_size(BUFFER_SIZE)
492498
.done(),
493499
)
@@ -819,6 +825,7 @@ fn environment_spec() -> EnvironmentSpec<PortableForm> {
819825
.chain_extension(Default::default())
820826
.max_event_topics(4)
821827
.static_buffer_size(16384)
828+
.native_to_eth_ratio(100_000_000)
822829
.done()
823830
}
824831

0 commit comments

Comments
 (0)