use-ink / ink

Polkadot's ink! to write smart contracts.
https://use.ink
Apache License 2.0
1.35k stars 428 forks source link

Enable referencing chain extension methods from separate file #1719

Open cmichi opened 1 year ago

cmichi commented 1 year ago

Escalated from this StackExchange question.

It could be that this issue is solved "automatically" with https://github.com/paritytech/ink/issues/259, but I'm not sure.

Description

We should make it possible to reference a chain extension method in a separate file.

For example, it should be possible to modify our rand-extension example in roughly the following way.

The following is only pseudo-code to explain what should be possible in the big picture. The API and types have to be figured out by whoever implements this ticket. The code does not work at this time.

(1) Add mod utils; to rand-extension/lib.rs.

(2) The fn update in lib.rs should be modified:

-            let new_random = self.env().extension().fetch_random(subject)?;
+            let new_random = crate::utils::new_random(&self.env().extension(), subject);

(3) Create a file utils.rs:

pub fn new_random(rand_extension_instance: &FetchRandomInstance, subject: [u8; 32]) -> [u8; 32]
where
{
    rand_extension_instance.fetch_random(subject).unwrap()
}
xgreenx commented 1 year ago

On the way to solving the https://github.com/paritytech/ink/issues/259, we need to solve this problem=) I created a separate task to track it https://github.com/paritytech/ink/issues/1722