-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpgradeable.rb
37 lines (25 loc) · 1.06 KB
/
Upgradeable.rb
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
pragma :rubidity, "1.0.0"
contract :Upgradeable, abstract: true do
address :public, :upgradeAdmin
event :ContractUpgraded, { oldHash: :bytes32, newHash: :bytes32 }
event :UpgradeAdminChanged, { newUpgradeAdmin: :address }
constructor(upgradeAdmin: :address) {
s.upgradeAdmin = upgradeAdmin
}
function :setUpgradeAdmin, { newUpgradeAdmin: :address }, :public do
require(msg.sender == s.upgradeAdmin, "NOT_AUTHORIZED")
s.upgradeAdmin = newUpgradeAdmin
emit :UpgradeAdminChanged, newUpgradeAdmin: newUpgradeAdmin
end
function :upgradeAndCall, { newHash: :bytes32, migrationCalldata: :string }, :public do
upgrade(newHash: newHash)
(success, data) = address(this).call(migrationCalldata)
require(success, "Migration failed")
end
function :upgrade, { newHash: :bytes32 }, :public do
currentHash = esc.getImplementationHash
require(msg.sender == s.upgradeAdmin, "NOT_AUTHORIZED")
esc.upgradeContract(newHash)
emit :ContractUpgraded, oldHash: currentHash, newHash: newHash
end
end