Skip to content

Instantly share code, notes, and snippets.

@franz101
Created May 2, 2018 14:33
Show Gist options
  • Save franz101/ebce79b73ad88ca6554e549327f4bd4c to your computer and use it in GitHub Desktop.
Save franz101/ebce79b73ad88ca6554e549327f4bd4c to your computer and use it in GitHub Desktop.
Stromanbieter Beispiel
pragma solidity ^0.4.15;
contract City {
address public owner; // owner of the contract
struct User { // User structure
uint id;
address taker;
string name;
uint monatskosten;
string anbieter;
string status;
}
uint totalLoan=0; // count of total loans
mapping(address => User) users; // mapping address to loan
// constructor executed when deploying the contract into network
// `msg.sender` is the account creating this contract.
constructor() public payable {
owner = msg.sender;
}
// transaction to request Loan
function requestLoan(string username, uint monatskosten, string anbieter) public {
users[msg.sender] = User(totalLoan, msg.sender, username, monatskosten, anbieter, "Requested"); // add Loan object to mapping
totalLoan++;
}
// get loan details
function getLoan(address addr) public constant returns(uint, string, uint, string, string) {
User memory u = users[addr];
return (u.id, u.name, u.monatskosten, u.anbieter, u.status);
}
// transaction to approve Loan based on key address
function approveLoan(address addr) public {
require(msg.sender == owner);
User storage user = users[addr];
user.status="Accepted";
//users[addr].status="Accepted";
addr.transfer(users[addr].monatskosten);
}
// reject
function rejectLoan(address addr) public {
require(msg.sender == owner);
User storage user = users[addr];
user.status="Rejected";
}
// get Balance
function getBalance() public constant returns(uint){
return address(this).balance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment