-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dapp.sol
88 lines (70 loc) · 2.67 KB
/
Dapp.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
pragma solidity >=0.5.0;
pragma experimental ABIEncoderV2;
import "./interfaces/IDappState.sol";
import "./DappLib.sol";
/*
VERY IMPORTANT SECURITY NOTE:
You will want to restrict some of your state contract functions so only authorized
contracts can call them. This can be achieved in four steps:
1) Include the "Access Control: Contract Access" feature block when creating your project.
This adds all the functionality to manage white-listing of external contracts in your
state contract.
2) Add the "requireContractAuthorized" function modifiers to those state contract functions
that should be restricted.
3) Deploy the contract that will be calling into the state contract (like this one, for example).
4) Call the "authorizeContract()" function in the state contract with the deployed address of the
calling contract. This adds the calling contract to a white-list. Thereafter, any calls to any
function in the state contract that use the "requireContractAuthorized" function modifier will
succeed only if the calling contract (or any caller for that matter) is white-listed.
*/
contract Dapp {
// Allow DappLib(SafeMath) functions to be called for all uint256 types
// (similar to "prototype" in Javascript)
using DappLib for uint256;
IDappState state;
// During deployment, the address of the contract that contains data (or "state")
// is provided as a constructor argument. The "state" variable can then call any
// function in the state contract that it is aware of (by way of IDappState).
constructor
(
address dappStateContract
)
public
{
state = IDappState(dappStateContract);
}
/**
* @dev Example function to demonstrate cross-contract READ call
*
*/
function getStateContractOwner()
external
view
returns(address)
{
return state.getContractOwner();
}
/**
* @dev Example function to demonstrate cross-contract WRITE call
*
*/
function incrementStateCounter
(
uint256 increment
)
external
{
return state.incrementCounter(increment);
}
/**
* @dev Another example function to demonstrate cross-contract WRITE call
*
*/
function getStateCounter()
external
view
returns(uint256)
{
return state.getCounter();
}
}