-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inheritance.sol
46 lines (34 loc) · 936 Bytes
/
Inheritance.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Ownable {
address owner;
modifier isOwner() {
require(msg.sender == owner, "Owner only can access secret.");
_;
}
constructor() {
owner = msg.sender;
}
}
contract SecretVault {
string secret;
constructor(string memory _sec) {
secret = _sec;
}
function getSecret() public view returns (string memory) {
return secret;
}
}
// inhering the Ownable contract using 'is' keyword.
contract MyContract is Ownable {
address public secretvault;
constructor(string memory _sec) {
SecretVault sec = new SecretVault(_sec);
secretvault = address(sec);
// Importing the states/props from the parent contract.
super;
}
function getSecret() public view isOwner returns (string memory) {
return SecretVault(secretvault).getSecret();
}
}