Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
b2b31b25
Commit
b2b31b25
authored
Aug 16, 2019
by
Francisco Giordano
Committed by
Nicolás Venturo
Aug 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove unstructured storage from GSNContext (#1881)
parent
2b3aa0d2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
24 deletions
+10
-24
GSNContext.sol
contracts/GSN/GSNContext.sol
+6
-20
GSNRecipient.sol
contracts/GSN/GSNRecipient.sol
+2
-2
GSNContextMock.sol
contracts/mocks/GSNContextMock.sol
+2
-2
No files found.
contracts/GSN/GSNContext.sol
View file @
b2b31b25
...
...
@@ -11,36 +11,22 @@ import "./Context.sol";
* recipient contract: end users should use `GSNRecipient` instead.
*/
contract GSNContext is Context {
// We use a random storage slot to allow proxy contracts to enable GSN support in an upgrade without changing their
// storage layout. This value is calculated as: keccak256('gsn.relayhub.address'), minus 1.
bytes32 private constant RELAY_HUB_ADDRESS_STORAGE_SLOT = 0x06b7792c761dcc05af1761f0315ce8b01ac39c16cc934eb0b2f7a8e71414f262;
address internal _relayHub = 0xD216153c06E857cD7f72665E0aF1d7D82172F494;
event RelayHubChanged(address indexed oldRelayHub, address indexed newRelayHub);
constructor() internal {
_upgradeRelayHub(0xD216153c06E857cD7f72665E0aF1d7D82172F494);
}
function _getRelayHub() internal view returns (address relayHub) {
bytes32 slot = RELAY_HUB_ADDRESS_STORAGE_SLOT;
// solhint-disable-next-line no-inline-assembly
assembly {
relayHub := sload(slot)
}
// solhint-disable-previous-line no-empty-blocks
}
function _upgradeRelayHub(address newRelayHub) internal {
address currentRelayHub = _
getRelayHub()
;
address currentRelayHub = _
relayHub
;
require(newRelayHub != address(0), "GSNContext: new RelayHub is the zero address");
require(newRelayHub != currentRelayHub, "GSNContext: new RelayHub is the current one");
emit RelayHubChanged(currentRelayHub, newRelayHub);
bytes32 slot = RELAY_HUB_ADDRESS_STORAGE_SLOT;
// solhint-disable-next-line no-inline-assembly
assembly {
sstore(slot, newRelayHub)
}
_relayHub = newRelayHub;
}
// Overrides for Context's functions: when called from RelayHub, sender and
...
...
@@ -49,7 +35,7 @@ contract GSNContext is Context {
// when handling said data.
function _msgSender() internal view returns (address) {
if (msg.sender != _
getRelayHub()
) {
if (msg.sender != _
relayHub
) {
return msg.sender;
} else {
return _getRelayedCallSender();
...
...
@@ -57,7 +43,7 @@ contract GSNContext is Context {
}
function _msgData() internal view returns (bytes memory) {
if (msg.sender != _
getRelayHub()
) {
if (msg.sender != _
relayHub
) {
return msg.data;
} else {
return _getRelayedCallData();
...
...
contracts/GSN/GSNRecipient.sol
View file @
b2b31b25
...
...
@@ -12,7 +12,7 @@ import "./IRelayHub.sol";
*/
contract GSNRecipient is IRelayRecipient, GSNContext, GSNBouncerBase {
function getHubAddr() public view returns (address) {
return _
getRelayHub()
;
return _
relayHub
;
}
// This function is view for future-proofing, it may require reading from
...
...
@@ -23,6 +23,6 @@ contract GSNRecipient is IRelayRecipient, GSNContext, GSNBouncerBase {
}
function _withdrawDeposits(uint256 amount, address payable payee) internal {
IRelayHub(_
getRelayHub()
).withdraw(amount, payee);
IRelayHub(_
relayHub
).withdraw(amount, payee);
}
}
contracts/mocks/GSNContextMock.sol
View file @
b2b31b25
...
...
@@ -7,7 +7,7 @@ import "../GSN/IRelayRecipient.sol";
// By inheriting from GSNContext, Context's internal functions are overridden automatically
contract GSNContextMock is ContextMock, GSNContext, IRelayRecipient {
function getHubAddr() public view returns (address) {
return _
getRelayHub()
;
return _
relayHub
;
}
function acceptRelayedCall(
...
...
@@ -37,7 +37,7 @@ contract GSNContextMock is ContextMock, GSNContext, IRelayRecipient {
}
function getRelayHub() public view returns (address) {
return _
getRelayHub()
;
return _
relayHub
;
}
function upgradeRelayHub(address newRelayHub) public {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment