Blockchain Identity Example "Passport Contract" Version 2

So in this example, on top of just information, i want to be saving the Users Picture just like the passport.
I should be able to retrieve this picture and be able to view it.
Given that there is no specific Datatype for image. i Will be using a "Base64" string of the image.
In order to see an example of this Image to String of Base64: Use this https://www.base64-image.de

 Following is some Sample Outputs and images size
Filesize:8.21 KB
Encoded:10.95 KB
Width:170 px
Height:86 px

Filesize:53.60 KB
Encoded:71.47 KB
Width:511 px
Height:511 px

From the samples. The bigger the image, the more KB of size, and more Ether needs to be spent.
Assuming i stick to a 72x72 image
Filesize:6.68 KB
Encoded:8.91 KB
Width:72 px
Height:72 px

which works fine to be saved in the block-chain for the period of the passport Validity.

The new code is added in Bold

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;
        //only if photo exists
        string Photo;
    }
    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);
    }
    function addPhoto(string _passnum, string _base64) public onlyBy(creator){
        bytes32 hash = sha256(_passnum);
        AllCountryPassport[hash].Photo = _base64;
    }
    function getPhoto(string _passnum) public constant returns (string)
    {
        bytes32 hash = sha256(_passnum);
        return AllCountryPassport[hash].Photo;
    }
    //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