Skip to content

Commit

Permalink
enable and disable channel through governance
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoyangLiu committed Jun 24, 2020
1 parent 6f548e1 commit 470257e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
18 changes: 18 additions & 0 deletions contracts/CrossChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ contract CrossChain is System, ICrossChain, IParamSubscriber{
event unexpectedRevertInPackageHandler(address indexed contractAddr, string reason);
event unexpectedFailureAssertionInPackageHandler(address indexed contractAddr, bytes lowLevelData);
event paramChange(string key, bytes value);
event enableOrDisableChannel(uint8 indexed channelId, bool isEnable);
event addChannel(uint8 indexed channelId, address indexed contractAddr);

modifier sequenceInOrder(uint64 _sequence, uint8 _channelID) {
Expand Down Expand Up @@ -287,6 +288,23 @@ function encodePayload(uint8 packageType, uint256 relayFee, bytes memory msgByte
registeredContractMap[handlerContract] = true;
isRelayRewardFromSystemReward[channelId] = (isRewardFromSystem == 0x0);
emit addChannel(channelId, handlerContract);
} else if (Memory.compareStrings(key, "enableOrDisableChannel")) {
bytes memory valueLocal = value;
require(valueLocal.length == 2, "length of value for enableOrDisableChannel should be 2, channelId:isEnable");

uint8 channelId;
assembly {
channelId := mload(add(valueLocal, 1))
}
uint8 status;
assembly {
status := mload(add(valueLocal, 2))
}
bool isEnable = (status == 1);

address handlerContract = channelHandlerContractMap[channelId];
registeredContractMap[handlerContract] = isEnable;
emit enableOrDisableChannel(channelId, isEnable);
} else {
require(false, "unknown param");
}
Expand Down
18 changes: 18 additions & 0 deletions contracts/CrossChain.template
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ contract CrossChain is System, ICrossChain, IParamSubscriber{
event unexpectedRevertInPackageHandler(address indexed contractAddr, string reason);
event unexpectedFailureAssertionInPackageHandler(address indexed contractAddr, bytes lowLevelData);
event paramChange(string key, bytes value);
event enableOrDisableChannel(uint8 indexed channelId, bool isEnable);
event addChannel(uint8 indexed channelId, address indexed contractAddr);

modifier sequenceInOrder(uint64 _sequence, uint8 _channelID) {
Expand Down Expand Up @@ -288,6 +289,23 @@ function encodePayload(uint8 packageType, uint256 relayFee, bytes memory msgByte
registeredContractMap[handlerContract] = true;
isRelayRewardFromSystemReward[channelId] = (isRewardFromSystem == 0x0);
emit addChannel(channelId, handlerContract);
} else if (Memory.compareStrings(key, "enableOrDisableChannel")) {
bytes memory valueLocal = value;
require(valueLocal.length == 2, "length of value for enableOrDisableChannel should be 2, channelId:isEnable");

uint8 channelId;
assembly {
channelId := mload(add(valueLocal, 1))
}
uint8 status;
assembly {
status := mload(add(valueLocal, 2))
}
bool isEnable = (status == 1);

address handlerContract = channelHandlerContractMap[channelId];
registeredContractMap[handlerContract] = isEnable;
emit enableOrDisableChannel(channelId, isEnable);
} else {
require(false, "unknown param");
}
Expand Down
Loading

0 comments on commit 470257e

Please sign in to comment.