Ethereum 身份证明合同

Ethereum 身份证明合同,ethereum,solidity,Ethereum,Solidity,我正在为身份验证人员创建一份合同,我需要验证是否存在具有相同地址、电子邮件或电话号码的合同 例如: contract Person { //date of create uint public dateCreate; //name of person string public name; //variables to be validates string public email; string public phone; // constructor function Person

我正在为身份验证人员创建一份合同,我需要验证是否存在具有相同地址、电子邮件或电话号码的合同

例如:

contract Person {
//date of create
uint public dateCreate;

//name of person
string public name;

//variables to be validates
string public email;

string public phone;

// constructor
function Person(string _name, string _email, string _phone) public {
    name = _name;
    email = _email;
    phone = _phone;
    owner = msg.sender;
}
}
我可以选择将地址合同保存在带有关键电子邮件或电话的映射中

contract RegisterPerson {
  //save the contract address person using the key of the email
  mapping(bytes32=>address) public addressEmail;
}
有这个解决方案,但我相信它不是更好的,因为它的映射将是非常大的,合同昂贵


有人知道另一种解决方案吗?

您不应该像在这里尝试的那样使用契约来表示对象。它不仅成本非常高,因为契约部署通常比事务要昂贵得多,而且还不能保证唯一性

您应该使用
struct
来表示个人

contract PersonStorage {
  struct Person {
    uint dateCreate;
    string name;
    string email;
    string phone;
  }

  mapping(bytes32 => Person) persons;

  function addPerson(string _name, string _email, string _phone) public {
    Person memory person;

    person.name = _name;
    person.email = _email;
    person.phone = _phone;

    persons[keccak256(person.email)] = person;
  }
  ...
}
现在,您的合同是所有
人员的数据存储。您可以部署此版本,并将合同地址传递给需要访问它的任何合同。如果您需要允许多个业务逻辑契约使用它,或者如果您需要升级业务契约,您还可以将所有数据集中化


编辑-我应该注意,如果这是在它自己的合同中,您必须将
string
更改为
bytes32
。您不能在合同之间发送字符串。

好的,对象映射有限制吗?想象一下,合同可以储存100万人,我相信这是一个非常昂贵的价格。这还是比较便宜的。无论大小,映射的读写操作的成本相同。合约的总存储限制为2^256个插槽,每个插槽可容纳32个字节。Adam您知道映射中数据的容量(数量)是多少吗?我可以在地图中储存一百万人吗?是的,它可以在地图中储存一百万人。它可以存储地球上每个人的个人记录,然后是一些。