-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathjames-squire.sol
51 lines (45 loc) · 1.89 KB
/
james-squire.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* A demonstration of how to use attestation in validating customers'
* purchase. The contract assumes the scenario of alcohol purchase
* from a vendor James Squire. The contract will be satisfied if the
* buyer can prove that his residential country is Australia and the
* buyer's age is above 18. It, however, allows the contract's owner
* to extend to allow consumers from other countries, and in the case
* the said country doesn't have an age restriction on drinking, for
* example China, the contract should only require a proof of
* residency in China.*/
import "../lib/AttestationFramework";
import "../lib/Authorisedattesters";
contract james-squire is AttestationFramework, Authorisedattesters
{
AttestationFramework attestationFramework;
Authorisedattesters authorisedattesters;
string[] ageExemptCountries;
constructor(
address attestationFrameworkAddress,
address authorisedattestersAddress,
string[] ageExemptAndAcceptedCountries
)
{
attestationFramework = new AttestationFramework(attestationFrameworkAddress);
authorisedattesters = new Authorisedattesters(authorisedattestersAddress);
ageExemptCountries = ageExemptAndAcceptedCountries;
}
//TODO range proof
function canPurchaseAlcohol(Attestation ageAttestation) public returns (bool)
{
require(attestationFramework.validateMerkle(ageAttestation));
bool isExempt = isAgeExemptAndAcceptedCountry(ageAttestation.value);
if(isExempt) return true;
//TODO probably need multiple branches?
//if(ageAttestation.age >= 18) return true;
return false;
}
function isAgeExemptAndAcceptedCountry(string country) public returns (bool)
{
for(uint i = 0; i < ageExemptAndAcceptedCountries.length; i++)
{
if(country == ageExemptAndAcceptedCountries[i]) return true;
}
return false;
}
}