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

Allow for querying a specific contract's owner #312

Merged
merged 3 commits into from
Jan 15, 2024
Merged

Conversation

ureeves
Copy link
Member

@ureeves ureeves commented Jan 12, 2024

Currently it is only possible for contract's to query for their own owners. This PR makes it possible for contract's to query for any other contract's owner as well.

This is achieved by modifying the owner import to accept a pointer to a contract ID in the calling contract's memory. If the passed pointer is non-null, the host reads the contract ID from the contract's memory, otherwise it is assumed to be the calling contract's.

If the contract queried for exists, its owner is emplaced in the calling contract's argument buffer, and 1 is returned, otherwise 0 is returned.

@ureeves ureeves added team:Core Low Level Core Development Team (Rust) type:enhancement Issues concerning code or feature improvement (performance, refactoring, etc) type:feature implementing a new feature labels Jan 12, 2024
Eduardo Leegwater Simões and others added 2 commits January 12, 2024 15:53
The `owner` extern is modified to allow for querying the host for a
given contract's owner. Along the same lines the public `owner` function
is changed to accomodate this and a new `self_owner` function is added
to handle the case of querying for the calling contract's owner.

Co-authored-by: Milosz Muszynski <[email protected]>
The `read_owner` function is modified to use `uplink::self_owner`
instead of `uplink::owner` and a new function - `read_owner_of` - is
added to allow callers to query for a given contract's owner.

Co-authored-by: Milosz Muszynski <[email protected]>
@ureeves ureeves force-pushed the specific-contract-owner branch from e53b291 to ae60e88 Compare January 12, 2024 14:56
Copy link
Contributor

@fed-franz fed-franz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
pointed a typo (I think)

piecrust/tests/metadata.rs Outdated Show resolved Hide resolved
Copy link
Member

@moCello moCello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

The `owner` import is changed to accept a pointer to a contract ID. If
the pointer is null, it assumed that the calling contract is querying
for its owner, whereas if the pointer is not null, a contract ID is
presumed to exist at that address, and read from its memory.

The relevant owner is then emplaced in the contract's argument buffer,
if it exists, and 1 is returned. If the contract whose owner is asked
for does not exist, 0 is returned instead.

Co-authored-by: Milosz Muszynski <[email protected]>
@ureeves ureeves force-pushed the specific-contract-owner branch from ae60e88 to 6f55455 Compare January 15, 2024 11:06
@ureeves ureeves merged commit 3693632 into main Jan 15, 2024
6 checks passed
@ureeves ureeves deleted the specific-contract-owner branch January 15, 2024 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team:Core Low Level Core Development Team (Rust) type:enhancement Issues concerning code or feature improvement (performance, refactoring, etc) type:feature implementing a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants