pragma solidity ^0.4.0; contract P2Pcontract { //Global Variables Borrower[] 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 Investor[] investors; //An array that will hold all of our investors uint totalNumInvestors; //Keep track of the total number of investors that we have uint investorIdCounter; //Helps create the investorId so that we can keep track of them //Mappings mapping (uint => address) borrowerToOwner; //Lookup borrower address from their id mapping(address => uint) BorrowerAddress2Id; //Lookup borrower id based on their address mapping (address => Borrower) borrower; //take an address and get the Borrower struct mapping (uint => address) investorToOwner; // take an id from our investors arrray and get the address of the investor mapping (address => uint) InvestorAddress2Id; //Lookup investor id based on their address mapping (address => Investor) investor; //take an address and get the investor struct //Borrower Struct struct Borrower { address borrowerPublicKey; string firstName; string lastName; uint accountBalance; uint numLoans; uint borrowerId; bool EXISTS; } //Investor Struct struct Investor { address investorPublicKey; string firstName; string lastName; uint accountBalance; uint numInvestments; uint investorId; bool EXISTS; } //Create a new borrower function createBorrower(address b_add, 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(b_add, _firstName, _lastName, _accountBalance, 0, borrowerIdCounter, true); borrowerToOwner[borrowerIdCounter] = msg.sender; BorrowerAddress2Id[msg.sender] = borrowerIdCounter; borrower[msg.sender] = b; totalNumBorrowers++; borrowerIdCounter++; } //Create a new Investor function createInvestor(address i_add, string memory _firstName, string memory _lastName, uint _accountBalance) public { //require(isInvestor(msg.sender) == false); //You can only have one investor profile //If the investor does not exist we will create them :) Investor memory i = Investor(i_add, _firstName, _lastName, _accountBalance, 0, investorIdCounter, true); investorToOwner[investorIdCounter] = msg.sender; InvestorAddress2Id[msg.sender] = investorIdCounter; investor[msg.sender] = i; totalNumInvestors++; investorIdCounter++; } function isBorrower(address account) public view returns (bool) {return borrower[account].EXISTS;} function isInvestor(address account) public view returns (bool) {return investor[account].EXISTS;} function getNumBorrowers() public view returns (uint) { return totalNumBorrowers;} function getNumInvestors() public view returns (uint) { return totalNumInvestors;} }
0.4.18