-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Account.sol
52 lines (44 loc) · 1.63 KB
/
Account.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
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.7;
/// @title Example contract instance to be reconstituted by `Host`
/// @author S0AndS0
contract Account {
address public owner;
string public name;
/* -------------------------------------------------------------------- */
///
constructor(address _owner, string memory _name) {
owner = _owner;
name = _name;
}
/* -------------------------------------------------------------------- */
/// @notice Require message sender to be an instance owner
/// @param _caller {string} Function name that implements this modifier
modifier onlyOwner(string memory _caller) {
string memory _message = string(
abi.encodePacked(
"Account.",
_caller,
": message sender not an owner"
)
);
require(msg.sender == owner, _message);
_;
}
/* -------------------------------------------------------------------- */
/// @notice Update `Account.name`
/// @param _new_name **{string}** Name to assign to `Account.name`
/// @custom:throws **{Error}** `"Account.changeName: message sender not an owner"`
function changeName(string memory _new_name)
public
onlyOwner("changeName")
{
name = _new_name;
}
/// @notice Update `Account.owner`
/// @param _new_owner **{address}** Address to assign to `Account.owner`
/// @custom:throws **{Error}** `"Account.changeOwner: message sender not an owner"`
function changeOwner(address _new_owner) public onlyOwner("changeOwner") {
owner = _new_owner;
}
}