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

Introduce the ability to implement 3rd-party contract extensions. #1041

Closed
ruseinov opened this issue Jun 30, 2023 · 2 comments
Closed

Introduce the ability to implement 3rd-party contract extensions. #1041

ruseinov opened this issue Jun 30, 2023 · 2 comments

Comments

@ruseinov
Copy link
Collaborator

ruseinov commented Jun 30, 2023

A continuation of #422.

This should give an ability to wrap the functionality of an existing contract. Perhaps in a form of decorator, that needs to be discussed further to be properly fleshed-out. Perhaps some R&D is in order to figure out the most flexible and easy-to-use way.

Some context:

  1. Removing boilerplate from token_standards #422 (comment)
  2. An example from aforementioned issue:
#[near_bindgen::extensions]
impl Contract {
    // the user has to repeat the signature here specifcally for near_bindgen.
    // this is the bit we hardcode-away for known contracts
    fn ft_transfer(&mut self, receiver_id: ValidAccountId, amount: U128, memo: Option<String>); // note semicolon
} 

It's important to understand what's to be achieved by this, here are some questions/thoughts:

  1. Do we want to wrap some of the existing methods effectively overriding bingdgen definitions generated for the original contract?
  2. Do we want to allow providing additional methods for the Contract? I'm guessing not, because that would eliminate the point of extending it in the first place. If yes - how, why?
@frol
Copy link
Collaborator

frol commented Jul 5, 2023

Do we want to wrap some of the existing methods effectively overriding bingdgen definitions generated for the original contract?

@ruseinov Could you, please, elaborate more here? I don't understand the problem here.

Do we want to allow providing additional methods for the Contract? I'm guessing not, because that would eliminate the point of extending it in the first place. If yes - how, why?

I am not sure if I understand you correctly here, but let me try to provide some hopefully relevant context.

Here is the code which is totally valid:

#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize)]
struct MyContract {}

#[near_bindgen]
impl MyContract {
    pub fn my_fn_one(&self) {}
}

#[near_bindgen]
impl MyContract {
    pub fn my_fn_in_other_impl_block(&self) {}
}

trait SomeNearStandardTrait {
    fn standard_fn(&self) {}
}

#[near_bindgen]
impl SomeNearStandardTrait for MyContract {
    fn standard_fn(&self) {}
}

All three functions will be exposed (#[no_mangle] export "C") by near-sdk-rs. It already works in near-sdk-rs just fine, so I believe it already supports extensions, right?

@ruseinov
Copy link
Collaborator Author

ruseinov commented Jul 7, 2023

TBH those old comments about extensions were a bit confusing, so I'm no longer sure what was the intention there. I suggest we close this and revisit as necessary.

@ruseinov ruseinov closed this as completed Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants