如何解决最佳合同实践,可优化合同气体的使用
我只是想知道对我的Solidity合同而言,最佳的设置是什么,以减少读取和写入数据结构的气体成本以及如何映射它们。对于此合同,我跟踪一个User结构,每个结构都有一个带有个人信息的UserIdCard结构。在UserIdCard下,可以有多个Document结构。这是我当前的数据结构:
struct Document{
uint8 docId;
bytes32 docType;
bytes docData;
}
struct UserIdCard{
uint8 age;
uint phoneNo;
bytes32 firstName;
bytes32 lastName;
bytes32 location;
document[] docs; //Would an array of docs be the best way to store?
mapping(uint => Document) docsId; //Or would it be better to save it as a mapped reference?
}
struct User{
uint userId; //Is UserId necessary here if we're mapping it outside the struct?
uint48 timeCreated;
bytes32 username;
Role role;
UserIdCard idCard; //Would this save a duplicate instance of UserIdCard in idCard?
mapping(uint => UserIdCard) idCardsId; //Or should I once again map it?
}
mapping(uint256 => User) userId;
mapping(address => User) userAddress;
这个想法是,userId将是用于引用UserIdCard的同一个uint,但是对于每个文档,它将具有自己的一组ID。这是否意味着我应该将UserIdCard映射到User结构的外部还是内部?我确定我的引用存在很多错误,请告诉我我该如何改进!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。