|
|
@ -35,7 +35,6 @@ import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive; |
|
|
|
import tech.pegasys.pantheon.util.bytes.BytesValue; |
|
|
|
import tech.pegasys.pantheon.util.bytes.BytesValue; |
|
|
|
import tech.pegasys.pantheon.util.bytes.BytesValues; |
|
|
|
import tech.pegasys.pantheon.util.bytes.BytesValues; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Base64; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
@ -98,18 +97,18 @@ public class PrivateTransactionHandler { |
|
|
|
public String getPrivacyGroup(final String key, final PrivateTransaction privateTransaction) |
|
|
|
public String getPrivacyGroup(final String key, final PrivateTransaction privateTransaction) |
|
|
|
throws Exception { |
|
|
|
throws Exception { |
|
|
|
if (privateTransaction.getPrivacyGroupId().isPresent()) { |
|
|
|
if (privateTransaction.getPrivacyGroupId().isPresent()) { |
|
|
|
return privateTransaction.getPrivacyGroupId().get().toString(); |
|
|
|
return BytesValues.asBase64String(privateTransaction.getPrivacyGroupId().get()); |
|
|
|
} |
|
|
|
} |
|
|
|
final ReceiveRequest receiveRequest = |
|
|
|
final ReceiveRequest receiveRequest = |
|
|
|
new ReceiveRequest(key, BytesValues.asString(privateTransaction.getPrivateFrom().get())); |
|
|
|
new ReceiveRequest( |
|
|
|
|
|
|
|
key, BytesValues.asBase64String(privateTransaction.getPrivateFrom().get())); |
|
|
|
LOG.debug( |
|
|
|
LOG.debug( |
|
|
|
"Getting privacy group for {}", |
|
|
|
"Getting privacy group for {}", |
|
|
|
BytesValues.asString(privateTransaction.getPrivateFrom().get())); |
|
|
|
BytesValues.asBase64String(privateTransaction.getPrivateFrom().get())); |
|
|
|
final ReceiveResponse receiveResponse; |
|
|
|
final ReceiveResponse receiveResponse; |
|
|
|
try { |
|
|
|
try { |
|
|
|
receiveResponse = enclave.receive(receiveRequest); |
|
|
|
receiveResponse = enclave.receive(receiveRequest); |
|
|
|
return BytesValue.wrap(receiveResponse.getPrivacyGroupId().getBytes(Charsets.UTF_8)) |
|
|
|
return receiveResponse.getPrivacyGroupId(); |
|
|
|
.toString(); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
LOG.error("Failed to retrieve private transaction in enclave", e); |
|
|
|
LOG.error("Failed to retrieve private transaction in enclave", e); |
|
|
|
throw e; |
|
|
|
throw e; |
|
|
@ -159,33 +158,34 @@ public class PrivateTransactionHandler { |
|
|
|
private SendRequest createSendRequest(final PrivateTransaction privateTransaction) { |
|
|
|
private SendRequest createSendRequest(final PrivateTransaction privateTransaction) { |
|
|
|
final BytesValueRLPOutput bvrlp = new BytesValueRLPOutput(); |
|
|
|
final BytesValueRLPOutput bvrlp = new BytesValueRLPOutput(); |
|
|
|
privateTransaction.writeTo(bvrlp); |
|
|
|
privateTransaction.writeTo(bvrlp); |
|
|
|
|
|
|
|
final String payload = BytesValues.asBase64String(bvrlp.encoded()); |
|
|
|
|
|
|
|
|
|
|
|
if (privateTransaction.getPrivacyGroupId().isPresent()) { |
|
|
|
if (privateTransaction.getPrivacyGroupId().isPresent()) { |
|
|
|
return new SendRequestPantheon( |
|
|
|
return new SendRequestPantheon( |
|
|
|
Base64.getEncoder().encodeToString(bvrlp.encoded().extractArray()), |
|
|
|
payload, |
|
|
|
enclavePublicKey, |
|
|
|
enclavePublicKey, |
|
|
|
BytesValues.asString(privateTransaction.getPrivacyGroupId().get())); |
|
|
|
BytesValues.asBase64String(privateTransaction.getPrivacyGroupId().get())); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
final List<String> privateFor = |
|
|
|
final List<String> privateFor = |
|
|
|
privateTransaction.getPrivateFor().get().stream() |
|
|
|
privateTransaction.getPrivateFor().get().stream() |
|
|
|
.map(BytesValues::asString) |
|
|
|
.map(BytesValues::asBase64String) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
// FIXME: orion should accept empty privateFor
|
|
|
|
// FIXME: orion should accept empty privateFor
|
|
|
|
if (privateFor.isEmpty()) { |
|
|
|
if (privateFor.isEmpty()) { |
|
|
|
privateFor.add(BytesValues.asString(privateTransaction.getPrivateFrom().get())); |
|
|
|
privateFor.add(BytesValues.asBase64String(privateTransaction.getPrivateFrom().get())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new SendRequestLegacy( |
|
|
|
return new SendRequestLegacy( |
|
|
|
Base64.getEncoder().encodeToString(bvrlp.encoded().extractArray()), |
|
|
|
payload, |
|
|
|
BytesValues.asString(privateTransaction.getPrivateFrom().get()), |
|
|
|
BytesValues.asBase64String(privateTransaction.getPrivateFrom().get()), |
|
|
|
privateFor); |
|
|
|
privateFor); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public long getSenderNonce(final Address sender, final String privacyGroupId) { |
|
|
|
public long getSenderNonce(final Address sender, final String privacyGroupId) { |
|
|
|
return privateStateStorage |
|
|
|
return privateStateStorage |
|
|
|
.getPrivateAccountState(BytesValue.fromHexString(privacyGroupId)) |
|
|
|
.getPrivateAccountState(BytesValues.fromBase64(privacyGroupId)) |
|
|
|
.map( |
|
|
|
.map( |
|
|
|
lastRootHash -> |
|
|
|
lastRootHash -> |
|
|
|
privateWorldStateArchive |
|
|
|
privateWorldStateArchive |
|
|
|