diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/contracts/Coupon.sol b/contracts/Coupon.sol index c84050a..15a220e 100644 --- a/contracts/Coupon.sol +++ b/contracts/Coupon.sol @@ -2,7 +2,7 @@ // TODO -pragma solidity ^0.4.12; +pragma solidity ^0.4.23; contract Coupon { diff --git a/contracts/CouponDemoRegistry.sol b/contracts/CouponDemoRegistry.sol new file mode 100644 index 0000000..f7379fd --- /dev/null +++ b/contracts/CouponDemoRegistry.sol @@ -0,0 +1,62 @@ + +pragma solidity ^0.4.23; + +import "./RegistryInterface.sol"; + +contract CouponDemoRegistry is RegistryInterface { + + string public version = 'v0.2'; + + address owner; + + address[] issuers; + address[] all_campaigns; + + mapping (address => bool) public is_issuer; + mapping (address => bool) public is_campaign; + mapping (address => address[]) campaigns; + + modifier onlyBy(address _account) { + require(msg.sender == _account); + _; + } + + constructor() public { + owner = msg.sender; + } + + function add_campaign(address _a) public { + if (!is_issuer[msg.sender]) { + is_issuer[msg.sender] = true; + issuers.push(msg.sender); + } + all_campaigns.push(_a); + campaigns[msg.sender].push(_a); + is_campaign[_a] = true; + } + + function get_all_count() public view returns(uint count) { + return all_campaigns.length; + } + + function get_all_campaign(uint index) public view returns(address) { + return all_campaigns[index]; + } + + function get_count(address issuer) public view returns(uint count) { + return campaigns[issuer].length; + } + + function get_campaign(address issuer, uint index) public view returns(address) { + return campaigns[issuer][index]; + } + + function get_mycount() public view returns(uint count) { + return campaigns[msg.sender].length; + } + + function get_mycampaign(uint index) public view returns(address) { + return campaigns[msg.sender][index]; + } + +} diff --git a/contracts/CouponExample.sol b/contracts/CouponExample.sol index 8d0605f..99978ae 100644 --- a/contracts/CouponExample.sol +++ b/contracts/CouponExample.sol @@ -1,6 +1,7 @@ /* The Rouge Project - Blochain Coupon platform Copyright (C) 2017 Valentin D. Guillois + Copyright (C) 2017 Christophe Le Bars This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as @@ -17,15 +18,13 @@ *************************************************** - WARNING : EXPERIMENTAL and NON AUDITED code. - only use for tests purpose (on a testnet!) - */ import "./StandardCoupon.sol"; pragma solidity ^0.4.12; + contract CouponExample is StandardCoupon { string public name; diff --git a/contracts/CouponUserApprovalLib.sol b/contracts/CouponUserApprovalLib.sol index 9da027f..1bfa4cf 100644 --- a/contracts/CouponUserApprovalLib.sol +++ b/contracts/CouponUserApprovalLib.sol @@ -1,4 +1,5 @@ -pragma solidity ^0.4.12; + +pragma solidity ^0.4.23; library CouponUserApprovalLib { diff --git a/contracts/RegistryInterface.sol b/contracts/RegistryInterface.sol new file mode 100644 index 0000000..ecc1087 --- /dev/null +++ b/contracts/RegistryInterface.sol @@ -0,0 +1,14 @@ + +pragma solidity ^0.4.23; + +contract RegistryInterface { + + function add_campaign(address _a) public; + function get_all_count() public view returns(uint count); + function get_all_campaign(uint index) public view returns(address); + function get_count(address issuer) public view returns(uint count); + function get_campaign(address issuer, uint index) public view returns(address); + function get_mycount() public view returns(uint count); + function get_mycampaign(uint index) public view returns(address); + +} diff --git a/contracts/StandardCoupon.sol b/contracts/StandardCoupon.sol index 05fd0b1..cfc3f5d 100644 --- a/contracts/StandardCoupon.sol +++ b/contracts/StandardCoupon.sol @@ -17,8 +17,7 @@ *************************************************** - WARNING : EXPERIMENTAL and NON AUDITED code. - only use for tests purpose (on a testnet!) + WARNING : EXPERIMENTAL ALPHA code. This is main contract that encapsule the coupon workflow logic @@ -27,7 +26,10 @@ */ -pragma solidity ^0.4.12; + +pragma solidity ^0.4.23; + +import "./RegistryInterface.sol"; import "./Coupon.sol"; @@ -64,11 +66,17 @@ contract StandardCoupon is Coupon { address public creator; /* Creator is set up at the contract creation */ address public issuer; /* Issuer is now always same as creator */ + address constant registry = 0xdb331368bAb3492CF366Fdc8Eb83356B40838a55; + /* set up some parameters like expiration at issuance ? */ function issue() atState(States.Created) onlyBy(creator) { state = States.Issued; issuer = creator; + + RegistryInterface _reg = RegistryInterface(registry); + _reg.add_campaign(this); + } uint256 public totalCoupon; @@ -88,7 +96,7 @@ contract StandardCoupon is Coupon { function distributeCoupon(address _to) atState(States.Issued) private returns (bool success) { require(_to != issuer); /* SI_10 issuer is excluded for now to simplify tests */ - require(!hasCoupon(_to)); + require(!hasCoupon(_to)); /* only one coupon per address (but not user) */ if (totalFreeCoupon > 0) { totalFreeCoupon -= 1; totalAcquiredCoupon += 1;