Skip to content

Commit

Permalink
[R4R] Improve indent (#27)
Browse files Browse the repository at this point in the history
* improve indent

* add additional improvements

* update genesis.json

* fix some other files

Co-authored-by: fudongbai <296179868@qq.com>
  • Loading branch information
2 people authored and HaoyangLiu committed Jul 3, 2020
1 parent 6c1edca commit 44420a6
Show file tree
Hide file tree
Showing 32 changed files with 379 additions and 379 deletions.
164 changes: 82 additions & 82 deletions contracts/BSCValidatorSet.sol

Large diffs are not rendered by default.

168 changes: 84 additions & 84 deletions contracts/BSCValidatorSet.template

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions contracts/CrossChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function encodePayload(uint8 packageType, uint256 relayFee, bytes memory msgByte
if (packageType == SYN_PACKAGE) {
address handlerContract = channelHandlerContractMap[channelIdLocal];
try IApplication(handlerContract).handleSynPackage(channelIdLocal, msgBytes) returns (bytes memory responsePayload) {
if(responsePayload.length!=0){
if (responsePayload.length!=0) {
sendPackage(channelSendSequenceMap[channelIdLocal], channelIdLocal, encodePayload(ACK_PACKAGE, 0, responsePayload));
channelSendSequenceMap[channelIdLocal] = channelSendSequenceMap[channelIdLocal] + 1;
}
Expand Down Expand Up @@ -243,7 +243,7 @@ function encodePayload(uint8 packageType, uint256 relayFee, bytes memory msgByte
previousTxHeight=block.number;
} else {
txCounter++;
if(txCounter>=batchSizeForOracle) {
if (txCounter>=batchSizeForOracle) {
oracleSequence++;
txCounter = 0;
}
Expand All @@ -260,11 +260,11 @@ function encodePayload(uint8 packageType, uint256 relayFee, bytes memory msgByte
}

function updateParam(string calldata key, bytes calldata value) onlyGov external override {
if (Memory.compareStrings(key, "batchSizeForOracle")){
if (Memory.compareStrings(key, "batchSizeForOracle")) {
uint256 newBatchSizeForOracle = BytesToTypes.bytesToUint256(32, value);
require(newBatchSizeForOracle <= 10000 && newBatchSizeForOracle >= 10, "the newBatchSizeForOracle should be in [10, 10000]");
batchSizeForOracle = newBatchSizeForOracle;
} else if (Memory.compareStrings(key, "addChannel")){
} else if (Memory.compareStrings(key, "addChannel")) {
bytes memory valueLocal = value;
require(valueLocal.length == 22, "length of value for addChannel should be 22, channelId:isFromSystem:handlerAddress");
uint8 channelId;
Expand Down
8 changes: 4 additions & 4 deletions contracts/CrossChain.template
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function encodePayload(uint8 packageType, uint256 relayFee, bytes memory msgByte
if (packageType == SYN_PACKAGE) {
address handlerContract = channelHandlerContractMap[channelIdLocal];
try IApplication(handlerContract).handleSynPackage(channelIdLocal, msgBytes) returns (bytes memory responsePayload) {
if(responsePayload.length!=0){
if (responsePayload.length!=0) {
sendPackage(channelSendSequenceMap[channelIdLocal], channelIdLocal, encodePayload(ACK_PACKAGE, 0, responsePayload));
channelSendSequenceMap[channelIdLocal] = channelSendSequenceMap[channelIdLocal] + 1;
}
Expand Down Expand Up @@ -244,7 +244,7 @@ function encodePayload(uint8 packageType, uint256 relayFee, bytes memory msgByte
previousTxHeight=block.number;
} else {
txCounter++;
if(txCounter>=batchSizeForOracle) {
if (txCounter>=batchSizeForOracle) {
oracleSequence++;
txCounter = 0;
}
Expand All @@ -261,11 +261,11 @@ function encodePayload(uint8 packageType, uint256 relayFee, bytes memory msgByte
}

function updateParam(string calldata key, bytes calldata value) onlyGov external override {
if (Memory.compareStrings(key, "batchSizeForOracle")){
if (Memory.compareStrings(key, "batchSizeForOracle")) {
uint256 newBatchSizeForOracle = BytesToTypes.bytesToUint256(32, value);
require(newBatchSizeForOracle <= 10000 && newBatchSizeForOracle >= 10, "the newBatchSizeForOracle should be in [10, 10000]");
batchSizeForOracle = newBatchSizeForOracle;
} else if (Memory.compareStrings(key, "addChannel")){
} else if (Memory.compareStrings(key, "addChannel")) {
bytes memory valueLocal = value;
require(valueLocal.length == 22, "length of value for addChannel should be 22, channelId:isFromSystem:handlerAddress");
uint8 channelId;
Expand Down
20 changes: 10 additions & 10 deletions contracts/GovHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ contract GovHub is System, IApplication{
address target;
}

function handleSynPackage(uint8, bytes calldata msgBytes) onlyCrossChainContract external override returns(bytes memory responsePayload){
function handleSynPackage(uint8, bytes calldata msgBytes) onlyCrossChainContract external override returns(bytes memory responsePayload) {
(ParamChangePackage memory proposal, bool success) = decodeSynPackage(msgBytes);
if(!success){
if (!success) {
return CmnPkg.encodeCommonAckPackage(ERROR_FAIL_DECODE);
}
uint32 resCode = notifyUpdates(proposal);
if(resCode == CODE_OK){
if (resCode == CODE_OK) {
return new bytes(0);
}else{
} else {
return CmnPkg.encodeCommonAckPackage(resCode);
}
}
Expand All @@ -52,11 +52,11 @@ contract GovHub is System, IApplication{

function notifyUpdates(ParamChangePackage memory proposal) internal returns(uint32) {

if (!isContract(proposal.target)){
if (!isContract(proposal.target)) {
emit failReasonWithStr("the target is not a contract");
return ERROR_TARGET_NOT_CONTRACT;
}
try IParamSubscriber(proposal.target).updateParam(proposal.key, proposal.value){
try IParamSubscriber(proposal.target).updateParam(proposal.key, proposal.value) {
}catch Error(string memory reason) {
emit failReasonWithStr(reason);
return ERROR_TARGET_CONTRACT_FAIL;
Expand All @@ -74,12 +74,12 @@ contract GovHub is System, IApplication{
RLPDecode.Iterator memory iter = msgBytes.toRLPItem().iterator();
bool success = false;
uint256 idx=0;
while(iter.hasNext()) {
if ( idx == 0 ) {
while (iter.hasNext()) {
if (idx == 0) {
pkg.key = string(iter.next().toBytes());
}else if (idx == 1) {
} else if (idx == 1) {
pkg.value = iter.next().toBytes();
}else if (idx == 2){
} else if (idx == 2) {
pkg.target = iter.next().toAddress();
success = true;
} else {
Expand Down
2 changes: 1 addition & 1 deletion contracts/MerkleProof.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.6.4;
import "./lib/Memory.sol";

library MerkleProof {
function validateMerkleProof(bytes32 appHash, string memory storeName, bytes memory key, bytes memory value, bytes memory proof )
function validateMerkleProof(bytes32 appHash, string memory storeName, bytes memory key, bytes memory value, bytes memory proof)
internal view returns (bool) {
if (appHash == bytes32(0)) {
return false;
Expand Down
8 changes: 4 additions & 4 deletions contracts/RelayerHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber{

/*********************** Param update ********************************/
function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov{
if (Memory.compareStrings(key,"requiredDeposit")){
if (Memory.compareStrings(key,"requiredDeposit")) {
require(value.length == 32, "length of requiredDeposit mismatch");
uint256 newRequiredDeposit = BytesToTypes.bytesToUint256(32, value);
require(newRequiredDeposit >= 1 && newRequiredDeposit <= 1e21, "the requiredDeposit out of range");
requiredDeposit = newRequiredDeposit;
}else if(Memory.compareStrings(key,"dues")){
} else if (Memory.compareStrings(key,"dues")) {
require(value.length == 32, "length of dues mismatch");
uint256 newDues = BytesToTypes.bytesToUint256(32, value);
require(newDues > 0 && newDues < requiredDeposit, "the dues out of range");
dues = newDues;
}else{
} else {
require(false, "unknown param");
}
emit paramChange(key, value);
}

function isRelayer(address sender) external override view returns (bool){
function isRelayer(address sender) external override view returns (bool) {
return relayersExistMap[sender];
}
}
30 changes: 15 additions & 15 deletions contracts/RelayerIncentivize.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber {
collectedRewardForHeaderRelayer = collectedRewardForHeaderRelayer.add(reward);
collectedRewardForTransferRelayer = collectedRewardForTransferRelayer.add(actualAmount).sub(reward);

if (headerRelayersSubmitCount[headerRelayerAddr]==0){
if (headerRelayersSubmitCount[headerRelayerAddr]==0) {
headerRelayerAddressRecord.push(headerRelayerAddr);
}
headerRelayersSubmitCount[headerRelayerAddr]++;

if (transferRelayersSubmitCount[packageRelayer]==0){
if (transferRelayersSubmitCount[packageRelayer]==0) {
transferRelayerAddressRecord.push(packageRelayer);
}
transferRelayersSubmitCount[packageRelayer]++;

if (countInRound==ROUND_SIZE){
if (countInRound==ROUND_SIZE) {
emit LogDistributeCollectedReward(roundSequence, collectedRewardForHeaderRelayer, collectedRewardForTransferRelayer);

distributeHeaderRelayerReward(packageRelayer);
Expand All @@ -103,7 +103,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber {
uint256 totalWeight=0;
address payable[] memory relayers = headerRelayerAddressRecord;
uint256[] memory relayerWeight = new uint256[](relayers.length);
for(uint256 index = 0; index < relayers.length; index++) {
for (uint256 index = 0; index < relayers.length; index++) {
address relayer = relayers[index];
uint256 weight = calculateHeaderRelayerWeight(headerRelayersSubmitCount[relayer]);
relayerWeight[index] = weight;
Expand All @@ -113,7 +113,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber {
uint256 callerReward = totalReward.mul(moleculeCallerCompensation).div(denominatorCallerCompensation);
totalReward = totalReward.sub(callerReward);
uint256 remainReward = totalReward;
for(uint256 index = 1; index < relayers.length; index++) {
for (uint256 index = 1; index < relayers.length; index++) {
uint256 reward = relayerWeight[index].mul(totalReward).div(totalWeight);
relayers[index].send(reward);
remainReward = remainReward.sub(reward);
Expand All @@ -122,7 +122,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber {
packageRelayer.send(callerReward);

collectedRewardForHeaderRelayer = 0;
for (uint256 index = 0; index < relayers.length; index++){
for (uint256 index = 0; index < relayers.length; index++) {
delete headerRelayersSubmitCount[relayers[index]];
}
delete headerRelayerAddressRecord;
Expand All @@ -134,7 +134,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber {
uint256 totalWeight=0;
address payable[] memory relayers = transferRelayerAddressRecord;
uint256[] memory relayerWeight = new uint256[](relayers.length);
for(uint256 index = 0; index < relayers.length; index++) {
for (uint256 index = 0; index < relayers.length; index++) {
address relayer = relayers[index];
uint256 weight = calculateTransferRelayerWeight(transferRelayersSubmitCount[relayer]);
relayerWeight[index] = weight;
Expand All @@ -144,7 +144,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber {
uint256 callerReward = totalReward.mul(moleculeCallerCompensation).div(denominatorCallerCompensation);
totalReward = totalReward.sub(callerReward);
uint256 remainReward = totalReward;
for(uint256 index = 1; index < relayers.length; index++) {
for (uint256 index = 1; index < relayers.length; index++) {
uint256 reward = relayerWeight[index].mul(totalReward).div(totalWeight);
relayers[index].send(reward);
remainReward = remainReward.sub(reward);
Expand All @@ -153,7 +153,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber {
packageRelayer.send(callerReward);

collectedRewardForTransferRelayer = 0;
for (uint256 index = 0; index < relayers.length; index++){
for (uint256 index = 0; index < relayers.length; index++) {
delete transferRelayersSubmitCount[relayers[index]];
}
delete transferRelayerAddressRecord;
Expand All @@ -164,7 +164,7 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber {
return count;
} else if (MAXIMUM_WEIGHT < count && count <= 2*MAXIMUM_WEIGHT) {
return MAXIMUM_WEIGHT;
} else if (2*MAXIMUM_WEIGHT < count && count <= (2*MAXIMUM_WEIGHT + 3*MAXIMUM_WEIGHT/4 )) {
} else if (2*MAXIMUM_WEIGHT < count && count <= (2*MAXIMUM_WEIGHT + 3*MAXIMUM_WEIGHT/4)) {
return 3*MAXIMUM_WEIGHT - count;
} else {
return count/4;
Expand All @@ -181,25 +181,25 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber {

function updateParam(string calldata key, bytes calldata value) override external onlyGov{
require(alreadyInit, "contract has not been initialized");
if (Memory.compareStrings(key,"moleculeHeaderRelayer")){
if (Memory.compareStrings(key,"moleculeHeaderRelayer")) {
require(value.length == 32, "length of moleculeHeaderRelayer mismatch");
uint256 newMoleculeHeaderRelayer = BytesToTypes.bytesToUint256(32, value);
moleculeHeaderRelayer = newMoleculeHeaderRelayer;
} else if (Memory.compareStrings(key,"denominatorHeaderRelayer")){
} else if (Memory.compareStrings(key,"denominatorHeaderRelayer")) {
require(value.length == 32, "length of rewardForValidatorSetChange mismatch");
uint256 newDenominatorHeaderRelayer = BytesToTypes.bytesToUint256(32, value);
require(newDenominatorHeaderRelayer != 0, "the newDenominatorHeaderRelayer must not be zero");
denominatorHeaderRelayer = newDenominatorHeaderRelayer;
}else if (Memory.compareStrings(key,"moleculeCallerCompensation")){
} else if (Memory.compareStrings(key,"moleculeCallerCompensation")) {
require(value.length == 32, "length of rewardForValidatorSetChange mismatch");
uint256 newMoleculeCallerCompensation = BytesToTypes.bytesToUint256(32, value);
moleculeCallerCompensation = newMoleculeCallerCompensation;
} else if (Memory.compareStrings(key,"denominatorCallerCompensation")){
} else if (Memory.compareStrings(key,"denominatorCallerCompensation")) {
require(value.length == 32, "length of rewardForValidatorSetChange mismatch");
uint256 newDenominatorCallerCompensation = BytesToTypes.bytesToUint256(32, value);
require(newDenominatorCallerCompensation != 0, "the newDenominatorCallerCompensation must not be zero");
denominatorCallerCompensation = newDenominatorCallerCompensation;
}else{
} else {
require(false, "unknown param");
}
emit paramChange(key, value);
Expand Down
Loading

0 comments on commit 44420a6

Please sign in to comment.