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

how to use chain extensions to read/write runtime storage #640

Closed
galaio opened this issue Jan 23, 2021 · 16 comments
Closed

how to use chain extensions to read/write runtime storage #640

galaio opened this issue Jan 23, 2021 · 16 comments
Labels
C-question Further information is requested

Comments

@galaio
Copy link

galaio commented Jan 23, 2021

can give a example in ink/examples, and compile with cargo-contract

rel #592

@Robbepop
Copy link
Collaborator

An example is given in the docs here: https://paritytech.github.io/ink/ink_lang/attr.chain_extension.html#example-definition
Note that for chain extensions to work you also need to provide a definition on the runtime side.
The #[ink::chain_extension] marked traits acts as a bridge between runtime and smart contract.

@galaio
Copy link
Author

galaio commented Jan 24, 2021

An example is given in the docs here: https://paritytech.github.io/ink/ink_lang/attr.chain_extension.html#example-definition
Note that for chain extensions to work you also need to provide a definition on the runtime side.
The #[ink::chain_extension] marked traits acts as a bridge between runtime and smart contract.

when I compile, get error use-ink/cargo-contract#158

@ascjones
Copy link
Collaborator

As metntioned in that issue the TypeInfo derive is only for std #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]

@galaio
Copy link
Author

galaio commented Jan 25, 2021

As metntioned in that issue the TypeInfo derive is only for std #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]

but it will be compiled to wasm.... have another solution?

@kuleleyokn42
Copy link

I have met the same problem, waiting for a solution. Thanks.

@ascjones
Copy link
Collaborator

ascjones commented Jan 25, 2021

As metntioned in that issue the TypeInfo derive is only for std #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]

but it will be compiled to wasm.... have another solution?

The TypeInfo is only required for metadata generation which is done in std. So this should work if you apply it to all your types.

If you did require the TypeInfo for whatever reason in the wasm environment then you could just remove optional = true from the scale-info dependency in your Cargo.toml. I don't think this is necessary in your case.

@galaio
Copy link
Author

galaio commented Jan 25, 2021

optional = true

when compile, got

cargo +nightly contract build                     
ERROR: Error invoking `cargo metadata`

Caused by:
    failed to run `cargo metadata`: error: failed to parse manifest at `/Users/galaio/RustProjects/kylin-node/contracts/get_prices/Cargo.toml`
    
    Caused by:
      feature `std` includes `scale-info`, but `scale-info` is not an optional dependency
      A non-optional dependency of the same name is defined; consider adding `optional = true` to its definition.

It seems scale-info is neccessary;

@galaio
Copy link
Author

galaio commented Jan 25, 2021

An example is given in the docs here: https://paritytech.github.io/ink/ink_lang/attr.chain_extension.html#example-definition
Note that for chain extensions to work you also need to provide a definition on the runtime side.
The #[ink::chain_extension] marked traits acts as a bridge between runtime and smart contract.

can ink give some compilable and runable example, like the example in ink/examples, https://github.com/paritytech/ink/tree/master/examples

@Robbepop
Copy link
Collaborator

It seems scale-info is neccessary;

No the error tells you to remove scale-info from the Cargo.toml list of your std feature implications, that's all. ;)

can ink give some compilable and runable example, like the example in ink/examples, https://github.com/paritytech/ink/tree/master/examples

We will be providing an example in the future! :)

@galaio
Copy link
Author

galaio commented Jan 25, 2021

It seems scale-info is neccessary;

No the error tells you to remove scale-info from the Cargo.toml list of your std feature implications, that's all. ;)

can ink give some compilable and runable example, like the example in ink/examples, https://github.com/paritytech/ink/tree/master/examples

We will be providing an example in the future! :)

when?

@Robbepop
Copy link
Collaborator

Since the chain extension feature needs to be orchestrated between ink! and the contracts-pallet from Substrate we plan on delivering such an example and documentation with cross-concerns (not only for ink!) as soon as we ship the orchestrated release between contracts-pallet 3.0 and ink! 3.0 which is expected to happen in roughly 2 weeks without guarantee.

@galaio
Copy link
Author

galaio commented Feb 7, 2021

Since the chain extension feature needs to be orchestrated between ink! and the contracts-pallet from Substrate we plan on delivering such an example and documentation with cross-concerns (not only for ink!) as soon as we ship the orchestrated release between contracts-pallet 3.0 and ink! 3.0 which is expected to happen in roughly 2 weeks without guarantee.

hi, How's it going?

@Robbepop
Copy link
Collaborator

Robbepop commented Feb 7, 2021

@galaio
Copy link
Author

galaio commented Feb 7, 2021

https://github.com/paritytech/ink/tree/master/examples/rand-extension

what version of pallet contract?not found in substrate v2.0.1

@Robbepop
Copy link
Collaborator

Robbepop commented Feb 7, 2021

it uses ink! master and Substrate master.

@HCastano HCastano added the C-question Further information is requested label Jun 14, 2021
@HCastano
Copy link
Contributor

This seems pretty stale. @galaio feel free to re-open if you think this is unresolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants