-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extension-dependent extension changes (#9)
- Loading branch information
Showing
7 changed files
with
75 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[default] | ||
[profile.default] | ||
libs = ['lib'] | ||
out = 'out' | ||
remappings = [] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// SPDX-License-Identifier: MIT | ||
// @author: thirdweb (https://github.com/thirdweb-dev/dynamic-contracts) | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "../BaseRouter.sol"; | ||
|
||
/** | ||
* This smart contract is an EXAMPLE, and is not meant for use in production. | ||
*/ | ||
contract ExtensionRegistry { | ||
|
||
address public immutable admin; | ||
mapping (address => bool) public isRegistered; | ||
|
||
constructor() { | ||
admin = msg.sender; | ||
} | ||
|
||
function setExtensionRegistered(address _extension, bool _isRegistered) external { | ||
require(msg.sender == admin, "ExtensionRegistry: Only admin can alter extension registry"); | ||
isRegistered[_extension] = _isRegistered; | ||
} | ||
} | ||
|
||
/** | ||
* This smart contract is an EXAMPLE, and is not meant for use in production. | ||
*/ | ||
contract RouterRegistryConstrained is BaseRouter { | ||
|
||
address public admin; | ||
ExtensionRegistry public registry; | ||
|
||
// @dev Cannot initialize with extensions before registry is set, so we pass empty array to base constructor. | ||
constructor(address _registry) BaseRouter(new Extension[](0)) { | ||
admin = msg.sender; | ||
registry = ExtensionRegistry(_registry); | ||
} | ||
|
||
// @dev Sets the admin address. | ||
function setAdmin(address _admin) external { | ||
require(msg.sender == admin, "RouterUpgradeable: Only admin can set a new admin"); | ||
admin = _admin; | ||
} | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
Overrides | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/// @dev Returns whether extensions can be set in the given execution context. | ||
function _canSetExtension(Extension memory _extension) internal view virtual override returns (bool) { | ||
return msg.sender == admin && registry.isRegistered(_extension.metadata.implementation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters