-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdmin.sol
More file actions
44 lines (35 loc) · 1.08 KB
/
Copy pathAdmin.sol
File metadata and controls
44 lines (35 loc) · 1.08 KB
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IBank.sol";
contract Admin {
address public owner;
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_;
}
constructor() {
owner = msg.sender;
}
// 接收ETH
receive() external payable {}
// 转移管理员功能
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "New owner cannot be zero address");
owner = newOwner;
}
// 从IBank合约提取资金到Admin合约
function adminWithdraw(IBank bank) public onlyOwner {
bank.withdraw();
}
// 查询Admin合约余额
function getBalance() public view returns (uint256) {
return address(this).balance;
}
// Admin合约提现功能
function withdrawAdmin() public onlyOwner {
uint256 balance = address(this).balance;
require(balance > 0, "No balance to withdraw");
(bool success, ) = payable(owner).call{value: balance}("");
require(success, "Transfer failed");
}
}