pragma solidity ^0.4.0; contract P2Pcontract { //Global Variables Borrower[] public borrowers; //An array that will hold all of our borrowers uint totalNumBorrowers; //Keep track of the total number of borrowers we have uint borrowerIdCounter; //Keep track of the borrowerIds --> increment everytime we add a new borrower //Mappings mapping (uint => address) public borrowerToOwner; //Lookup borrower address from their id mapping(address => uint) public BorrowerAddress2Id; //Lookup borrower id based on their address mapping (address => Borrower) public borrower; //take an address and get the Borrower struct mapping(address => uint[]) public loansBorrowerHasCreated; //address to list of loan_ids the borrower has created //Borrower Struct struct Borrower { address borrowerPublicKey; string firstName; string lastName; uint accountBalance; uint numLoans; uint borrowerId; bool EXISTS; } //Create a new borrower function createBorrower(string memory _firstName, string memory _lastName, uint _accountBalance) public { require(isBorrower(msg.sender) == false); //you can only have one borrower profile so we check if the msg.sender has already created one //If the borrower msg.sender does not exist then we create it :) Borrower memory b = Borrower(msg.sender, _firstName, _lastName, _accountBalance, 0, borrowerIdCounter, true); borrowerToOwner[borrowerIdCounter] = msg.sender; BorrowerAddress2Id[msg.sender] = borrowerIdCounter; borrower[msg.sender] = b; totalNumBorrowers++; borrowerIdCounter++; } function isBorrower(address account) public view returns (bool) {return borrower[account].EXISTS;} }
0.4.18