Onchain contracts upgrade to solidity 0.6, make parameter names in contracts more consistent (#1354)

* upgrade to solidity 0.6
* make parameter names in contracts more consistent

Signed-off-by: Stefan Pingel <stefan.pingel@consensys.net>
pull/1358/head
Stefan Pingel 4 years ago committed by GitHub
parent eb3941976c
commit 2bfbeefc0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/group/OnChainGroupManagement.java
  2. 6
      privacy-contracts/src/main/java/org/hyperledger/besu/privacy/contracts/generated/DefaultOnChainPrivacyGroupManagementContract.java
  3. 8
      privacy-contracts/src/main/java/org/hyperledger/besu/privacy/contracts/generated/OnChainPrivacyGroupManagementInterface.java
  4. 6
      privacy-contracts/src/main/java/org/hyperledger/besu/privacy/contracts/generated/OnChainPrivacyGroupManagementProxy.java
  5. 45
      privacy-contracts/src/main/solidity/DefaultOnChainPrivacyGroupManagementContract.sol
  6. 20
      privacy-contracts/src/main/solidity/OnChainPrivacyGroupManagementInterface.sol
  7. 38
      privacy-contracts/src/main/solidity/OnChainPrivacyGroupManagementProxy.sol

@ -102,7 +102,7 @@ public class OnChainPrivacyGroupManagementInterface extends Contract {
super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider);
}
public RemoteFunctionCall<TransactionReceipt> addParticipants(List<byte[]> participants) {
public RemoteFunctionCall<TransactionReceipt> addParticipants(List<byte[]> publicEnclaveKeys) {
final Function function =
new Function(
FUNC_ADDPARTICIPANTS,
@ -110,7 +110,7 @@ public class OnChainPrivacyGroupManagementInterface extends Contract {
new org.web3j.abi.datatypes.DynamicArray<org.web3j.abi.datatypes.generated.Bytes32>(
org.web3j.abi.datatypes.generated.Bytes32.class,
org.web3j.abi.Utils.typeMap(
participants, org.web3j.abi.datatypes.generated.Bytes32.class))),
publicEnclaveKeys, org.web3j.abi.datatypes.generated.Bytes32.class))),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
@ -164,11 +164,11 @@ public class OnChainPrivacyGroupManagementInterface extends Contract {
return executeRemoteCallTransaction(function);
}
public RemoteFunctionCall<TransactionReceipt> removeParticipant(byte[] account) {
public RemoteFunctionCall<TransactionReceipt> removeParticipant(byte[] participant) {
final Function function =
new Function(
FUNC_REMOVEPARTICIPANT,
Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Bytes32(account)),
Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Bytes32(participant)),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}

@ -1,4 +1,18 @@
pragma solidity ^0.5.9;
/*
* Copyright ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
pragma solidity ^0.6.0;
import "./OnChainPrivacyGroupManagementInterface.sol";
contract DefaultOnChainPrivacyGroupManagementContract is OnChainPrivacyGroupManagementInterface {
@ -9,27 +23,27 @@ contract DefaultOnChainPrivacyGroupManagementContract is OnChainPrivacyGroupMana
bytes32[] private distributionList;
mapping(bytes32 => uint256) private distributionIndexOf;
function getVersion() external view returns (bytes32) {
function getVersion() external view override returns (bytes32) {
return _version;
}
function canExecute() external view returns (bool) {
function canExecute() external view override returns (bool) {
return _canExecute;
}
function lock() public {
function lock() public override {
require(_canExecute);
require(tx.origin == _owner, "Origin not the owner.");
_canExecute = false;
}
function unlock() public {
function unlock() public override {
require(!_canExecute);
require(tx.origin == _owner, "Origin not the owner.");
_canExecute = true;
}
function addParticipants(bytes32[] memory _publicEnclaveKeys) public returns (bool) {
function addParticipants(bytes32[] memory _publicEnclaveKeys) public override returns (bool) {
require(!_canExecute);
if (_owner == address(0x0)) {
// The account creating this group is set to be the owner
@ -42,19 +56,19 @@ contract DefaultOnChainPrivacyGroupManagementContract is OnChainPrivacyGroupMana
return result;
}
function removeParticipant(bytes32 _member) public returns (bool) {
function removeParticipant(bytes32 _participant) public override returns (bool) {
require(_canExecute);
require(tx.origin == _owner, "Origin not the owner.");
bool result = removeInternal(_member);
bool result = removeInternal(_participant);
updateVersion();
return result;
}
function getParticipants() public view returns (bytes32[] memory) {
function getParticipants() public view override returns (bytes32[] memory) {
return distributionList;
}
function canUpgrade() external returns (bool) {
function canUpgrade() external override returns (bool) {
return tx.origin == _owner;
}
@ -82,14 +96,15 @@ contract DefaultOnChainPrivacyGroupManagementContract is OnChainPrivacyGroupMana
function addParticipant(bytes32 _publicEnclaveKey) internal returns (bool) {
if (distributionIndexOf[_publicEnclaveKey] == 0) {
distributionIndexOf[_publicEnclaveKey] = distributionList.push(_publicEnclaveKey);
distributionList.push(_publicEnclaveKey);
distributionIndexOf[_publicEnclaveKey] = distributionList.length;
return true;
}
return false;
}
function removeInternal(bytes32 _member) internal returns (bool) {
uint256 index = distributionIndexOf[_member];
function removeInternal(bytes32 _participant) internal returns (bool) {
uint256 index = distributionIndexOf[_participant];
if (index > 0 && index <= distributionList.length) {
//move last address into index being vacated (unless we are dealing with last index)
if (index != distributionList.length) {
@ -97,8 +112,8 @@ contract DefaultOnChainPrivacyGroupManagementContract is OnChainPrivacyGroupMana
distributionList[index - 1] = lastPublicKey;
distributionIndexOf[lastPublicKey] = index;
}
distributionList.length -= 1;
distributionIndexOf[_member] = 0;
distributionList.pop();
distributionIndexOf[_participant] = 0;
return true;
}
return false;

@ -1,9 +1,23 @@
pragma solidity ^0.5.9;
/*
* Copyright ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
pragma solidity ^0.6.0;
interface OnChainPrivacyGroupManagementInterface {
function addParticipants(bytes32[] calldata participants) external returns (bool);
function addParticipants(bytes32[] calldata publicEnclaveKeys) external returns (bool);
function removeParticipant(bytes32 account) external returns (bool);
function removeParticipant(bytes32 participant) external returns (bool);
function getParticipants() external view returns (bytes32[] memory);

@ -1,6 +1,18 @@
pragma solidity ^0.5.12;
pragma solidity ^0.5.9;
/*
* Copyright ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
pragma solidity ^0.6.0;
import "./OnChainPrivacyGroupManagementInterface.sol";
contract OnChainPrivacyGroupManagementProxy is OnChainPrivacyGroupManagementInterface {
@ -15,46 +27,46 @@ contract OnChainPrivacyGroupManagementProxy is OnChainPrivacyGroupManagementInte
implementation = _newImp;
}
function addParticipants(bytes32[] memory _publicEnclaveKeys) public returns (bool) {
function addParticipants(bytes32[] memory _publicEnclaveKeys) public override returns (bool) {
OnChainPrivacyGroupManagementInterface privacyInterface = OnChainPrivacyGroupManagementInterface(implementation);
return privacyInterface.addParticipants(_publicEnclaveKeys);
}
function getParticipants() view public returns (bytes32[] memory) {
function getParticipants() view public override returns (bytes32[] memory) {
OnChainPrivacyGroupManagementInterface privacyInterface = OnChainPrivacyGroupManagementInterface(implementation);
return privacyInterface.getParticipants();
}
function removeParticipant(bytes32 _member) public returns (bool) {
function removeParticipant(bytes32 _participant) public override returns (bool) {
OnChainPrivacyGroupManagementInterface privacyInterface = OnChainPrivacyGroupManagementInterface(implementation);
bool result = privacyInterface.removeParticipant(_member);
bool result = privacyInterface.removeParticipant(_participant);
if (result) {
emit ParticipantRemoved(_member);
emit ParticipantRemoved(_participant);
}
return result;
}
function lock() public {
function lock() public override {
OnChainPrivacyGroupManagementInterface privacyInterface = OnChainPrivacyGroupManagementInterface(implementation);
return privacyInterface.lock();
}
function unlock() public {
function unlock() public override {
OnChainPrivacyGroupManagementInterface privacyInterface = OnChainPrivacyGroupManagementInterface(implementation);
return privacyInterface.unlock();
}
function canExecute() public view returns (bool) {
function canExecute() public view override returns (bool) {
OnChainPrivacyGroupManagementInterface privacyInterface = OnChainPrivacyGroupManagementInterface(implementation);
return privacyInterface.canExecute();
}
function getVersion() public view returns (bytes32) {
function getVersion() public view override returns (bytes32) {
OnChainPrivacyGroupManagementInterface privacyInterface = OnChainPrivacyGroupManagementInterface(implementation);
return privacyInterface.getVersion();
}
function canUpgrade() external returns (bool) {
function canUpgrade() external override returns (bool) {
OnChainPrivacyGroupManagementInterface privacyInterface = OnChainPrivacyGroupManagementInterface(implementation);
return privacyInterface.canUpgrade();
}

Loading…
Cancel
Save