Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
contracts used in CouponDemoApp v2
Browse files Browse the repository at this point in the history
  • Loading branch information
vdg committed Jun 25, 2018
1 parent a7f3023 commit 43f5844
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
2 changes: 1 addition & 1 deletion contracts/Coupon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// TODO

pragma solidity ^0.4.12;
pragma solidity ^0.4.23;

contract Coupon {

Expand Down
62 changes: 62 additions & 0 deletions contracts/CouponDemoRegistry.sol
Original file line number Diff line number Diff line change
@@ -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];
}

}
5 changes: 2 additions & 3 deletions contracts/CouponExample.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
The Rouge Project - Blochain Coupon platform
Copyright (C) 2017 Valentin D. Guillois <[email protected]>
Copyright (C) 2017 Christophe Le Bars <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion contracts/CouponUserApprovalLib.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.4.12;

pragma solidity ^0.4.23;

library CouponUserApprovalLib {

Expand Down
14 changes: 14 additions & 0 deletions contracts/RegistryInterface.sol
Original file line number Diff line number Diff line change
@@ -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);

}
16 changes: 12 additions & 4 deletions contracts/StandardCoupon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,7 +26,10 @@
*/
pragma solidity ^0.4.12;

pragma solidity ^0.4.23;

import "./RegistryInterface.sol";

import "./Coupon.sol";

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 43f5844

Please sign in to comment.