Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide environmental types (Balance, Gas, AccountId, ..) #4

Closed
Robbepop opened this issue Dec 20, 2018 · 3 comments
Closed

Provide environmental types (Balance, Gas, AccountId, ..) #4

Robbepop opened this issue Dec 20, 2018 · 3 comments
Labels
A-ink_storage [ink_storage] Work Item B-design Designing a new component, interface or functionality.

Comments

@Robbepop
Copy link
Collaborator

Environmental Types

Currently pdsl_core does not provide environmental types, for example what type an address has.

Having this information is very important for contract writers.
However, there are certain limitations and problems connected with making those environmental type definitions generic and chain agnostic.

We do want this information as part of psdl_core or similar.

This issue is about finding a proper, user friendly, efficient and possibly chain agnostic design for this feature.

Design 1: Bound to Environment

An implemention of pdsl_core::env::Env could be required to provide this information.
For this the Env trait should be extended for those type definitions or require an implementation of another trait that provides them.

We use this issue also to track which type definitions we initially want to provide for users.

The downside to this approach is that making the types bound to an environment implementation would restrict pDSL to be used only from certain predefined environments. This should be sufficient as a start, since we could for example provide an environment for testing purposes, for SRML contracts on substrate, for pwasm and for ewasm just to name a few.

@Robbepop Robbepop added B-design Designing a new component, interface or functionality. A-ink_storage [ink_storage] Work Item labels Dec 21, 2018
@Robbepop Robbepop changed the title [pdsl_core] Provide environmental types (Balance, Gas, AccountId, ..) Provide environmental types (Balance, Gas, AccountId, ..) Dec 21, 2018
@Robbepop
Copy link
Collaborator Author

Robbepop commented Jan 4, 2019

The currently proposed design is to introduce another trait EnvTypes that only consist of the types for the environment, e.g.:

trait EnvTypes {
    type Address;
    type Gas;
    type Balance;
}

A possible implementation could then be:

struct SmrlEnv;

impl EnvTypes for SrmlEnv {
    type Address = [u8; 32];
    type Gas = u64,
    type Balance = u64;
}

Then we could add the trait impl requirement to Env:

trait Env: EnvTypes { ... }

@Robbepop
Copy link
Collaborator Author

Commit b84fe87 adds initial environmental types.

These are structured in the following way:
The base pdsl_core::env::Env trait received a new trait bound pdsl_core::env::EnvTypes.
The new trait pdsl_core::env::EnvTypes is a trait with all useful environmental types.

Next there is a new srml module that replaces the former SrmlEnv definition.

In this we have some new definitions.
Mainly there is now srml::Address, srml::Balance that refer to their default type as can be used in SRML contracts. Note that it is possible to change those types fundamentally if you write your own runtime module.
That's why there is a generic SrmlEnv<T> environment that is generic over some T: EnvTypes.
If you want to use the default SRML types you can use DefaultSrmlEnv.
However, if you intend to use your own types based on the SRML contracts module you need to create another environment struct, i.e. MyTypes that implements EnvTypes and make another type alias for type MyEnv = SrmlEnv<MyTypes>.

Since c89eb2d the Subpeep example project is making use of these new environmental types and since b8b92ca there is another initial implementation of an example project of a very basic ERC-20 token based on the pDSL.

@ascjones
Copy link
Collaborator

Closed by #108

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ink_storage [ink_storage] Work Item B-design Designing a new component, interface or functionality.
Projects
None yet
Development

No branches or pull requests

2 participants