Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented priv_getLogs #686

Merged
merged 7 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.web3j.crypto.Credentials;
import org.web3j.protocol.besu.Besu;
import org.web3j.tx.BesuPrivateTransactionManager;
import org.web3j.tx.LegacyPrivateTransactionManager;
import org.web3j.tx.PrivateTransactionManager;
import org.web3j.tx.gas.BesuPrivacyGasProvider;
Expand All @@ -38,6 +39,7 @@ public class CallPrivateSmartContractFunction implements Transaction<String> {
private final long chainId;
private final Base64String privateFrom;
private final List<Base64String> privateFor;
private final Base64String privacyGroupId;

public CallPrivateSmartContractFunction(
final String contractAddress,
Expand All @@ -46,22 +48,65 @@ public CallPrivateSmartContractFunction(
final long chainId,
final String privateFrom,
final List<String> privateFor) {
this(
contractAddress,
encodedFunction,
transactionSigningKey,
chainId,
privateFrom,
privateFor,
null);
}

public CallPrivateSmartContractFunction(
final String contractAddress,
final String encodedFunction,
final String transactionSigningKey,
final long chainId,
final String privateFrom,
final String privacyGroupId) {
this(
contractAddress,
encodedFunction,
transactionSigningKey,
chainId,
privateFrom,
null,
privacyGroupId);
}

private CallPrivateSmartContractFunction(
final String contractAddress,
final String encodedFunction,
final String transactionSigningKey,
final long chainId,
final String privateFrom,
final List<String> privateFor,
final String privacyGroupId) {

this.contractAddress = contractAddress;
this.encodedFunction = encodedFunction;
this.senderCredentials = Credentials.create(transactionSigningKey);
this.chainId = chainId;
this.privateFrom = Base64String.wrap(privateFrom);
this.privateFor = Base64String.wrapList(privateFor);
this.privateFor = privateFor != null ? Base64String.wrapList(privateFor) : null;
this.privacyGroupId = privacyGroupId != null ? Base64String.wrap(privacyGroupId) : null;
}

@Override
public String execute(final NodeRequests node) {
final Besu besu = node.privacy().getBesuClient();

final PrivateTransactionManager privateTransactionManager =
new LegacyPrivateTransactionManager(
besu, GAS_PROVIDER, senderCredentials, chainId, privateFrom, privateFor);
PrivateTransactionManager privateTransactionManager;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can be final

if (privacyGroupId != null) {
privateTransactionManager =
new BesuPrivateTransactionManager(
besu, GAS_PROVIDER, senderCredentials, chainId, privateFrom, privacyGroupId);
} else {
privateTransactionManager =
new LegacyPrivateTransactionManager(
besu, GAS_PROVIDER, senderCredentials, chainId, privateFrom, privateFor);
}

try {
return privateTransactionManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ public CallPrivateSmartContractFunction callSmartContract(
contractAddress, encodedFunction, transactionSigningKey, chainId, privateFrom, privateFor);
}

public CallPrivateSmartContractFunction callSmartContract(
final String contractAddress,
final String encodedFunction,
final String transactionSigningKey,
final long chainId,
final String privateFrom,
final String privacyGroupId) {
return new CallPrivateSmartContractFunction(
contractAddress,
encodedFunction,
transactionSigningKey,
chainId,
privateFrom,
privacyGroupId);
}

public <T extends Contract> LoadPrivateSmartContractTransaction<T> loadSmartContract(
final String contractAddress,
final Class<T> clazz,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyNode;
import org.hyperledger.besu.tests.acceptance.dsl.privacy.condition.PrivGetTransactionReceiptTransaction;
import org.hyperledger.besu.tests.acceptance.dsl.privacy.util.LogFilterJsonParameter;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.EeaSendRawTransactionTransaction;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivCallTransaction;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivGetCodeTransaction;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivGetLogsTransaction;

import java.util.List;

Expand Down Expand Up @@ -75,6 +77,11 @@ public PrivGetCodeTransaction privGetCode(
return new PrivGetCodeTransaction(privacyGroupId, contractAddress, blockParameter);
}

public PrivGetLogsTransaction privGetLogs(
final String privacyGroupId, final LogFilterJsonParameter filterParameter) {
return new PrivGetLogsTransaction(privacyGroupId, filterParameter);
}

public RemoveFromOnChainPrivacyGroupTransaction removeFromPrivacyGroup(
final String privacyGroupId, final PrivacyNode remover, final PrivacyNode nodeToRemove) {
return new RemoveFromOnChainPrivacyGroupTransaction(privacyGroupId, remover, nodeToRemove);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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
*/
package org.hyperledger.besu.tests.acceptance.dsl.privacy.util;

import java.util.List;

public class LogFilterJsonParameter {

private final String fromBlock;
private final String toBlock;
private final List<String> addresses;
private final List<List<String>> topics;
private final String blockhash;

public LogFilterJsonParameter(
final String fromBlock,
final String toBlock,
final List<String> addresses,
final List<List<String>> topics,
final String blockhash) {
this.fromBlock = fromBlock;
this.toBlock = toBlock;
this.addresses = addresses;
this.topics = topics;
this.blockhash = blockhash;
}

public String getFromBlock() {
return fromBlock;
}

public String getToBlock() {
return toBlock;
}

public List<String> getAddresses() {
return addresses;
}

public List<List<String>> getTopics() {
return topics;
}

public String getBlockhash() {
return blockhash;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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
*/
package org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy;

import static org.assertj.core.api.Assertions.assertThat;

import org.hyperledger.besu.tests.acceptance.dsl.privacy.util.LogFilterJsonParameter;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction;

import java.io.IOException;

import org.web3j.protocol.core.methods.response.EthLog;

public class PrivGetLogsTransaction implements Transaction<EthLog> {

private final String privacyGroupId;
private final LogFilterJsonParameter filterParameter;

public PrivGetLogsTransaction(
final String privacyGroupId, final LogFilterJsonParameter filterParameter) {
this.privacyGroupId = privacyGroupId;
this.filterParameter = filterParameter;
}

@Override
public EthLog execute(final NodeRequests node) {
try {
final EthLog response = node.privacy().privGetLogs(privacyGroupId, filterParameter).send();

assertThat(response).as("check response is not null").isNotNull();
assertThat(response.getResult()).as("check result in response isn't null").isNotNull();

return response;
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.hyperledger.besu.ethereum.privacy.group.OnChainGroupManagement;
import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyNode;
import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivateTransactionGroupResponse;
import org.hyperledger.besu.tests.acceptance.dsl.privacy.util.LogFilterJsonParameter;

import java.io.IOException;
import java.math.BigInteger;
Expand All @@ -39,14 +40,14 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.tuweni.bytes.Bytes;
import org.web3j.abi.datatypes.Type;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3jService;
import org.web3j.protocol.besu.Besu;
import org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt;
import org.web3j.protocol.core.Request;
import org.web3j.protocol.core.Response;
import org.web3j.protocol.core.methods.response.EthCall;
import org.web3j.protocol.core.methods.response.EthLog;
import org.web3j.protocol.eea.crypto.PrivateTransactionEncoder;
import org.web3j.protocol.eea.crypto.RawPrivateTransaction;
import org.web3j.protocol.exceptions.TransactionException;
Expand Down Expand Up @@ -387,6 +388,13 @@ public Request<?, EthCall> privCall(
EthCall.class);
}

public Request<?, EthLog> privGetLogs(
final String privacyGroupId, final LogFilterJsonParameter filterParameter) {

return new Request<>(
"priv_getLogs", Arrays.asList(privacyGroupId, filterParameter), web3jService, EthLog.class);
}

public static class PrivxFindPrivacyGroupResponse extends Response<List<OnChainPrivacyGroup>> {

public List<OnChainPrivacyGroup> getGroups() {
Expand Down
Loading