From fb1689f4e054a59f0262a9941a5b2a35b296caed Mon Sep 17 00:00:00 2001 From: zfliex Date: Thu, 27 Apr 2023 11:00:29 +0800 Subject: [PATCH] fix: validator contract allows receiving core --- contracts/ValidatorSet.sol | 7 +++++++ contracts/ValidatorSet.template | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/contracts/ValidatorSet.sol b/contracts/ValidatorSet.sol index 011d4b4a..546c2703 100644 --- a/contracts/ValidatorSet.sol +++ b/contracts/ValidatorSet.sol @@ -63,6 +63,7 @@ contract ValidatorSet is IValidatorSet, System, IParamSubscriber { event validatorMisdemeanor(address indexed validator, uint256 amount); event validatorFelony(address indexed validator, uint256 amount); event paramChange(string key, bytes value); + event received(address indexed from, uint256 amount); /*********************** init **************************/ function init() external onlyNotInit { @@ -86,6 +87,12 @@ contract ValidatorSet is IValidatorSet, System, IParamSubscriber { return currentValidatorSetMap[addr] != 0; } + receive() external payable { + if (msg.value != 0) { + emit received(msg.sender, msg.value); + } + } + /// Add block reward on a validator /// @dev This method is called by the golang consensus engine every block /// @param valAddr The validator address diff --git a/contracts/ValidatorSet.template b/contracts/ValidatorSet.template index 6f3263ae..183349dd 100644 --- a/contracts/ValidatorSet.template +++ b/contracts/ValidatorSet.template @@ -63,6 +63,7 @@ contract ValidatorSet is IValidatorSet, System, IParamSubscriber { event validatorMisdemeanor(address indexed validator, uint256 amount); event validatorFelony(address indexed validator, uint256 amount); event paramChange(string key, bytes value); + event received(address indexed from, uint256 amount); /*********************** init **************************/ function init() external onlyNotInit { @@ -86,6 +87,12 @@ contract ValidatorSet is IValidatorSet, System, IParamSubscriber { return currentValidatorSetMap[addr] != 0; } + receive() external payable { + if (msg.value != 0) { + emit received(msg.sender, msg.value); + } + } + /// Add block reward on a validator /// @dev This method is called by the golang consensus engine every block /// @param valAddr The validator address