[Solidity] 230802 study
1. Using Roles
- 더 decentralized oracle을 위해,
oracle과owner의 access 권한을 분리할 필요가 있다. 따라서owneraddress에서만 실행할 수 있는add,remove와 같은 함수를 명시하기 위해Roles를 써야 한다. Roles는 다음과 같이import한다import "openzeppelin-solidity/contracts/access/Roles.sol";
2. Using Constructor to Set the Owner
constructor는 contract가 deploy 될 때, 단 한번만 실행된다.
3. Setting Up New Oracles
4. The Logical NOT Operator
!로 negation하기
5. Removing an Oracle
add도,remove도_numOracles를require로 체크하면서 실행해야 한다.- 특히, 제거할 oracle이 없는데
remove를 실행하면 오류가 발생하기 때문에 더더욱 체크해야 한다.
- 특히, 제거할 oracle이 없는데
6. Keeping Track of Responses
struct는 다음과 같이 정의한다.-
struct myStruct { address callerAddress; uint256 keyNumber; }
-
- 위에서 정의한
struct는 다음과 같이 선언한다-
myStruct memory myInstance; myInstance = new myStruct(callerParam, numberParam);
-
7. Computing the ETH price
8. Computing the ETH price - cont’d
9. Using SafeMath
target.add(),target.sub()와 같은SafeMath를 써야 overflow를 방지할 수 있다