-
Notifications
You must be signed in to change notification settings - Fork 20
/
ValidationModule.sol
65 lines (55 loc) · 1.75 KB
/
ValidationModule.sol
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//SPDX-License-Identifier: MPL-2.0
pragma solidity ^0.8.17;
import "../../openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol";
import "../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import "../interfaces/IRuleEngine.sol";
/**
* @dev Validation module.
*
* Useful for to restrict and validate transfers
*/
abstract contract ValidationModule is Initializable, ContextUpgradeable {
/**
* @dev Emitted when a rule engine is set.
*/
event RuleEngineSet(address indexed newRuleEngine);
IRuleEngine public ruleEngine;
/**
* @dev Initializes the contract with rule engine.
*/
function __Validation_init(IRuleEngine ruleEngine_) internal onlyInitializing {
__Context_init_unchained();
__Validation_init_unchained(ruleEngine_);
}
function __Validation_init_unchained(IRuleEngine ruleEngine_)
internal
onlyInitializing
{
if (address(ruleEngine_) != address(0)) {
ruleEngine = ruleEngine_;
emit RuleEngineSet(address(ruleEngine));
}
}
function _validateTransfer(
address from,
address to,
uint256 amount
) internal view returns (bool) {
return ruleEngine.validateTransfer(from, to, amount);
}
function _messageForTransferRestriction(uint8 restrictionCode)
internal
view
returns (string memory)
{
return ruleEngine.messageForTransferRestriction(restrictionCode);
}
function _detectTransferRestriction(
address from,
address to,
uint256 amount
) internal view returns (uint8) {
return ruleEngine.detectTransferRestriction(from, to, amount);
}
uint256[50] private __gap;
}