|
|
@ -14,13 +14,13 @@ package tech.pegasys.pantheon.ethereum.mainnet.precompiles.privacy; |
|
|
|
|
|
|
|
|
|
|
|
import static java.nio.charset.StandardCharsets.UTF_8; |
|
|
|
import static java.nio.charset.StandardCharsets.UTF_8; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import tech.pegasys.pantheon.enclave.Enclave; |
|
|
|
|
|
|
|
import tech.pegasys.pantheon.enclave.types.ReceiveRequest; |
|
|
|
|
|
|
|
import tech.pegasys.pantheon.enclave.types.ReceiveResponse; |
|
|
|
import tech.pegasys.pantheon.ethereum.core.Gas; |
|
|
|
import tech.pegasys.pantheon.ethereum.core.Gas; |
|
|
|
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; |
|
|
|
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; |
|
|
|
import tech.pegasys.pantheon.ethereum.mainnet.AbstractPrecompiledContract; |
|
|
|
import tech.pegasys.pantheon.ethereum.mainnet.AbstractPrecompiledContract; |
|
|
|
import tech.pegasys.pantheon.ethereum.vm.GasCalculator; |
|
|
|
import tech.pegasys.pantheon.ethereum.vm.GasCalculator; |
|
|
|
import tech.pegasys.pantheon.orion.Orion; |
|
|
|
|
|
|
|
import tech.pegasys.pantheon.orion.types.ReceiveRequest; |
|
|
|
|
|
|
|
import tech.pegasys.pantheon.orion.types.ReceiveResponse; |
|
|
|
|
|
|
|
import tech.pegasys.pantheon.util.bytes.BytesValue; |
|
|
|
import tech.pegasys.pantheon.util.bytes.BytesValue; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
@ -29,21 +29,21 @@ import org.apache.logging.log4j.LogManager; |
|
|
|
import org.apache.logging.log4j.Logger; |
|
|
|
import org.apache.logging.log4j.Logger; |
|
|
|
|
|
|
|
|
|
|
|
public class PrivacyPrecompiledContract extends AbstractPrecompiledContract { |
|
|
|
public class PrivacyPrecompiledContract extends AbstractPrecompiledContract { |
|
|
|
private final Orion orion; |
|
|
|
private final Enclave enclave; |
|
|
|
private final String orionPublicKey; |
|
|
|
private final String enclavePublicKey; |
|
|
|
|
|
|
|
|
|
|
|
private static final Logger LOG = LogManager.getLogger(); |
|
|
|
private static final Logger LOG = LogManager.getLogger(); |
|
|
|
|
|
|
|
|
|
|
|
public PrivacyPrecompiledContract( |
|
|
|
public PrivacyPrecompiledContract( |
|
|
|
final GasCalculator gasCalculator, final PrivacyParameters privacyParameters) { |
|
|
|
final GasCalculator gasCalculator, final PrivacyParameters privacyParameters) { |
|
|
|
this(gasCalculator, privacyParameters.getPublicKey(), new Orion(privacyParameters.getUrl())); |
|
|
|
this(gasCalculator, privacyParameters.getPublicKey(), new Enclave(privacyParameters.getUrl())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PrivacyPrecompiledContract( |
|
|
|
PrivacyPrecompiledContract( |
|
|
|
final GasCalculator gasCalculator, final String publicKey, final Orion orion) { |
|
|
|
final GasCalculator gasCalculator, final String publicKey, final Enclave enclave) { |
|
|
|
super("Privacy", gasCalculator); |
|
|
|
super("Privacy", gasCalculator); |
|
|
|
this.orion = orion; |
|
|
|
this.enclave = enclave; |
|
|
|
this.orionPublicKey = publicKey; |
|
|
|
this.enclavePublicKey = publicKey; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -55,13 +55,13 @@ public class PrivacyPrecompiledContract extends AbstractPrecompiledContract { |
|
|
|
public BytesValue compute(final BytesValue input) { |
|
|
|
public BytesValue compute(final BytesValue input) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
String key = new String(input.extractArray(), UTF_8); |
|
|
|
String key = new String(input.extractArray(), UTF_8); |
|
|
|
ReceiveRequest receiveRequest = new ReceiveRequest(key, orionPublicKey); |
|
|
|
ReceiveRequest receiveRequest = new ReceiveRequest(key, enclavePublicKey); |
|
|
|
ReceiveResponse receiveResponse = orion.receive(receiveRequest); |
|
|
|
ReceiveResponse receiveResponse = enclave.receive(receiveRequest); |
|
|
|
LOG.info("Got the response as ", receiveResponse.getPayload()); |
|
|
|
LOG.info("Got the response as ", receiveResponse.getPayload()); |
|
|
|
return BytesValue.wrap(receiveResponse.getPayload()); |
|
|
|
return BytesValue.wrap(receiveResponse.getPayload()); |
|
|
|
// pass it to private tx processor
|
|
|
|
// pass it to private tx processor
|
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
LOG.fatal("Orion threw an unhandled exception.", e); |
|
|
|
LOG.fatal("Enclave threw an unhandled exception.", e); |
|
|
|
return BytesValue.EMPTY; |
|
|
|
return BytesValue.EMPTY; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|