如何将结构转换为智能合约的数组?
我将写一份有关患者病历的智能合同。我有一个例子。但是所有存储在结构中的数据。我想使用时间序列数据。据知道,我必须使用一系列结构,但是我不知道该怎么做?
你能帮我吗?
contract MedicalHistory {
enum Gender {
Male,
Female
}
uint _patientCount = 0;
struct Patient {
string name;
uint16 age;
//max of uint16 is 4096
//if we use uint8 the max is uint8
string telephone;
string homeAddress;
uint64 birthday; //unix time
string disease; //disease can be enum
uint256 createdAt; // save all history
Gender gender;
}
mapping(uint => Patient) _patients;
function Register(
string memory name,
uint16 age,
string memory telephone,
string memory homeAddress,
uint64 birthday,
string memory disease,
// uint256 createdAt,
Gender gender
}
}
这是我智能合约中的代码段。如何将结构转换为数组?
I will write a smart contract about patient medical records. And I have an example for this. But all data stored in struct. I want to use time-series data. As far as know, I have to use array of struct, but I don't know how can i do that?
Can you help me please?
contract MedicalHistory {
enum Gender {
Male,
Female
}
uint _patientCount = 0;
struct Patient {
string name;
uint16 age;
//max of uint16 is 4096
//if we use uint8 the max is uint8
string telephone;
string homeAddress;
uint64 birthday; //unix time
string disease; //disease can be enum
uint256 createdAt; // save all history
Gender gender;
}
mapping(uint => Patient) _patients;
function Register(
string memory name,
uint16 age,
string memory telephone,
string memory homeAddress,
uint64 birthday,
string memory disease,
// uint256 createdAt,
Gender gender
}
}
This is the code snippet from my smart contract.. How can I convert struct to array?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以
.push()
到存储数组中,有效地添加新项目。我简化了代码示例,以便更容易地看到实际的数组操作:
请注意,如果您使用的是以太坊等公共网络,则所有存储的数据都是可检索的,即使它存储在非
公共网络中 属性通过查询合约存储槽位来实现。有关代码示例,请参阅此答案。因此,除非这只是一个学术练习,否则我真的不建议在区块链上存储健康和其他敏感数据。
You can
.push()
into a storage array, effectively adding new item.I simplified the code example just so it's easier to see the actual array manipulation:
Please note that if you're using a public network such as Ethereum, all stored data is retrievable even though it's stored in a non-
public
property by querying the contract storage slots. See this answer for a code example. So unless this is just an academic exercise, I really don't recommend storing health and other sensitive data on the blockchain.