是否可以仅适用于合同所有者可用的结构的某些字段?
例如,给定以下结构,我希望某些字段仅适用于合同所有者,
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
否。在链上存储私人数据是不可能的。
可以加密数据,以便只有秘密钥匙的人才能访问它。请参阅 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.