Skip to content

Convenience accessors#120

Draft
WalquerX wants to merge 3 commits into
paritytech:mainfrom
WalquerX:convenience-accessors
Draft

Convenience accessors#120
WalquerX wants to merge 3 commits into
paritytech:mainfrom
WalquerX:convenience-accessors

Conversation

@WalquerX

@WalquerX WalquerX commented Jul 2, 2026

Copy link
Copy Markdown

Closes #103

Adds convenience accessors (caller, value, timestamp, block_number, chain_id) on the macro-generated contract struct, so contracts can call self.caller() instead of the three-line host buffer pattern. Also adds has_code(addr) as a default method on HostApi, wrapping code_size.

@WalquerX

WalquerX commented Jul 2, 2026

Copy link
Copy Markdown
Author

@re-gius Can you give it a check to this. Im not sure about the tests placement. Also, it seems currently there is not implementation on the mock to tests has_code(), how should I deal with that? I didnt touched the contract examples. The use of the accessors on them should be part of this PR?

@re-gius

re-gius commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

@re-gius Can you give it a check to this.

It looks like the initial design causes several undesired conflicts, so I came up with a slightly different design in #103 (comment)

Can we first agree on that and then change your implementation accordingly?

Also, it seems currently there is not implementation on the mock to tests has_code(), how should I deal with that?

You don't need to implement has_code on MockHost because it's a default method on HostApi (code_size(addr) > 0), so every host, including the mock, inherits it automatically via code_size. The gap is that MockHost::code_size currently returns a hardcoded 0 with no way to configure it, so has_code can only ever return false. To test the positive case, you should extend the mock with a small per-address code map + a builder setter, and have code_size read from it

I didnt touched the contract examples. The use of the accessors on them should be part of this PR?

Yes, once they work we should change the example contracts to show how to use them and for benchmarking too.

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

Successfully merging this pull request may close these issues.

Add convenience accessors

2 participants