这份合约包括创建物品、租用物品、支付押金租金返还押金等功能。这个需求其实很简单,很适合学习和参考。合约并非原创,感谢我的师兄对本合约的帮助!如果有语法还不清楚的朋友请参看solidity官方文档。
代码更新于2018.5.8 14:52分
pragma solidity ^0.4.4;
struct Renter{
address addr;//renter's address
uint since;//from which time?
}
struct Object{
address creator;//the owner of obj
string name;// name of obj
uint priceDaily;//price of each day
uint deposit;//deposits of the obj
Renter renter;//who rent the obj
bool rented;//if rented?
string detail;//another infomation
}
struct Namekey{
uint[] keys;//storage the name's keys
}
uint[] private ids; //to return the ids of obj
uint public numObjects;
mapping(uint => Object) private objects;
mapping(string => Namekey) private nameToKeys;
address public owner;
event NewObject(uint objID,address creator);
modifier objectInRange(uint objID) {//modify function
if (objID >= numObjects)
throw;
_;
}
modifier onlyOwner(){
if(msg.sender != owner){
throw;
}
_;
}
function myShare() {
owner = msg.sen