Blockchain Identity Example "Passport Contract"

So the basics
The 1 MB size limit per Block is for the Bitcoin's blockchain. In Ethereum, there is theoretically no limit for the block size. However, blockchain is not meant for data storage and storing large documents will be very expensive.

pragma solidity ^0.4.0;

contract passportAresh{
    //Declare a struct similar to C++ 
    struct Passport{
        string givenName;
        string middleName;
        string surname;
        string passportType;
        string countryCode;
        string passportNumber;
        string dateBirth;
        string nationality;
        string gender;
        string placeBirth;
        string dateIssue;
        string dateExpire;
    }
    address creator; 
    mapping (bytes32 => Passport) AllCountryPassport;
    
    //modifier
    modifier onlyBy(address _account)
    {
        require(msg.sender == _account);
        // Do not forget the "_;"! It will
        // be replaced by the actual function
        // body when the modifier is used.
        _;
    }
    function passportAresh() public {
        creator = msg.sender;
    }
    function addPassport(string _firstname, string _lastname,
                        string _middlename, string _passtype, string _countrycode,
                        string _passno, string _datebirth, string _nationality,
                        string _gender, string _placebirth, string _dateissue,
                        string _dateexpire) public onlyBy(creator)
    {
      bytes32 hash = sha256(_passno);
      AllCountryPassport[hash] = Passport(_firstname,_middlename,
                                        _lastname, _passtype,_countrycode,_passno,_datebirth,
                                        _nationality,_gender,_placebirth,_dateissue,_dateexpire);  
    }
    
    function getPassportBasic(string _passnum) public view onlyBy(creator) returns (string _firstname, string _lastname,
                        string _middlename, string _passtype, string _countrycode,
                        string _passno) 
    {
        
        bytes32 hash = sha256(_passnum);
        return (AllCountryPassport[hash].givenName, AllCountryPassport[hash].surname,
                AllCountryPassport[hash].middleName,AllCountryPassport[hash].passportType,
                AllCountryPassport[hash].countryCode,AllCountryPassport[hash].passportNumber);
    }
    function getPassportAdvance(string _passnum) public view onlyBy(creator) returns (
                        string _passno, string _datebirth, string _nationality,
                        string _gender, string _placebirth, string _dateissue,
                        string _dateexpire)
    {
        bytes32 hash = sha256(_passnum);
        return (AllCountryPassport[hash].passportNumber,
                AllCountryPassport[hash].dateBirth,AllCountryPassport[hash].nationality,
                AllCountryPassport[hash].gender,AllCountryPassport[hash].placeBirth,
                AllCountryPassport[hash].dateIssue,AllCountryPassport[hash].dateExpire);
    }
    
    //verify if person is of legal age (Bar/Club)
    function isLegalAge(string _passnum) public constant returns (string)
    {
        bytes32 hash = sha256(_passnum);
        return AllCountryPassport[hash].dateBirth;
    }
}

Comments

Popular posts from this blog

Solidity Hash of Structs (Testing hash uniqueness)

Is Making the Crypto Space Legally Compliant Paving the Road to Mass (Blockchain) Adoption?

Parity installation on Ubuntu Virtual Machine