是否可以仅适用于合同所有者可用的结构的某些字段?

发布于 2025-01-22 12:33:29 字数 674 浏览 0 评论 0原文

例如,给定以下结构,我希望某些字段仅适用于合同所有者,

struct Participant{
    address participantAddress; // can be seen by anyone
    string team; // can be seen by anyone
    string personalDescription; // can be seen by anyone
    string secret // can be seen only by contract owner    
}
// Mapping each participant to an uint id
mapping(address=>Participant) public participantsMapping;

换句话说,检查参与者映射的人可以

从我所知道的 东西中看到除秘密的一个字段(只能由所有者看到) ,“私有”关键字不隐藏任何数据,它只是代码级规范符。

有功能的修饰符,但是它们也为结构中的字段工作吗? 如果没有,如何实现?

modifier onlyOwner() {
    require(msg.sender==ownerAddress,
    "Visible only by owner");
    _;
}

For example, given the following structure, I want some fields to be visible only for the contract owner

struct Participant{
    address participantAddress; // can be seen by anyone
    string team; // can be seen by anyone
    string personalDescription; // can be seen by anyone
    string secret // can be seen only by contract owner    
}
// Mapping each participant to an uint id
mapping(address=>Participant) public participantsMapping;

In other words, someone inspecting the participantsMapping can see all the fields EXCEPT the secret one (which can only be seen by owner)

From what I know, the "private" keyword doesn't hide any data, it's only a code-level specifier.

There are modifiers for function, but do they work for fields in a structure too? If not, how can it be achieved?

modifier onlyOwner() {
    require(msg.sender==ownerAddress,
    "Visible only by owner");
    _;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯淡〆 2025-01-29 12:33:29

否。在链上存储私人数据是不可能的。

可以加密数据,以便只有秘密钥匙的人才能访问它。请参阅 https://docs.metamask.io/guide/guide/rpc-api/rpc-api/rpc-api 。 .io/guide/rpc-api.html#加密例如用法。

No. Storing private data on-chain is impossible.

It's possible to encrypt the data, so that only the person with the secret key can access it. See https://docs.metamask.io/guide/rpc-api.html#example-4 and https://docs.metamask.io/guide/rpc-api.html#encrypting for example usage.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文