Skip to content

Commit

Permalink
upgreable app
Browse files Browse the repository at this point in the history
  • Loading branch information
hujw77 committed Mar 12, 2024
1 parent 9931c57 commit b643aec
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/user/Application.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pragma solidity 0.8.17;
pragma solidity ^0.8.17;

import "../Common.sol";
import "../interfaces/IORMP.sol";

// https://eips.ethereum.org/EIPS/eip-5164
Expand Down
78 changes: 78 additions & 0 deletions src/user/UpgradeableApplication.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// This file is part of Darwinia.
// Copyright (C) 2018-2023 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pragma solidity ^0.8.17;

import "../interfaces/IORMP.sol";

// https://eips.ethereum.org/EIPS/eip-5164
abstract contract UpgradeableApplication {
address public sender;
address public recver;

event SetSender(address ormp);
event SetRecver(address ormp);

constructor(address ormp) {
sender = ormp;
recver = ormp;
}

function _setSender(address ormp) internal virtual {
sender = ormp;
emit SetSender(ormp);
}

function _setRecver(address ormp) internal virtual {
recver = ormp;
emit SetRecver(ormp);
}

function _setSenderConfig(address oracle, address relayer) internal virtual {
IORMP(sender).setAppConfig(oracle, relayer);
}

function _setRecverConfig(address oracle, address relayer) internal virtual {
IORMP(recver).setAppConfig(oracle, relayer);
}

modifier onlyORMP() {
require(recver == msg.sender, "!ormp");
_;
}

function _messageId() internal pure returns (bytes32 _msgDataMessageId) {
require(msg.data.length >= 84, "!messageId");
assembly {
_msgDataMessageId := calldataload(sub(calldatasize(), 84))
}
}

function _fromChainId() internal pure returns (uint256 _msgDataFromChainId) {
require(msg.data.length >= 52, "!fromChainId");
assembly {
_msgDataFromChainId := calldataload(sub(calldatasize(), 52))
}
}

function _xmsgSender() internal pure returns (address payable _from) {
require(msg.data.length >= 20, "!xmsgSender");
assembly {
_from := shr(96, calldataload(sub(calldatasize(), 20)))
}
}
}

0 comments on commit b643aec

Please sign in to comment.