Blockchain 优化合同天然气使用的最佳固化实践

Blockchain 优化合同天然气使用的最佳固化实践,blockchain,solidity,smartcontracts,web3,Blockchain,Solidity,Smartcontracts,Web3,我只是想知道我的Solidity合同的最佳设置是什么,以减少读取和写入数据结构的天然气成本,以及如何映射它们。对于这个契约,我跟踪一个用户结构,每个用户都有一个带有个人信息的UserIdCard结构。在UserIdCard下,可以有多个文档结构。这是我当前的数据结构: struct Document{ uint8 docId; bytes32 docType; bytes docData; } struct

我只是想知道我的Solidity合同的最佳设置是什么,以减少读取和写入数据结构的天然气成本,以及如何映射它们。对于这个契约,我跟踪一个用户结构,每个用户都有一个带有个人信息的UserIdCard结构。在UserIdCard下,可以有多个文档结构。这是我当前的数据结构:

   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集。这是否意味着我应该在User结构的外部或内部映射UserIdCard?我确信我的参考资料有很多错误,请让我知道如何改进