[PRIV] Generate Private Contract Address (#1004)

* Create a new PrivateContractAddress generation

* Remove resolveAccountFromPublicState

* Change method sign to BytesValue

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Vinicius Stevam 6 years ago committed by Lucas Saldanha
parent 6c1e0b2d0c
commit 7b9e491774
  1. 22
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/Address.java
  2. 18
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionProcessor.java

@ -129,6 +129,28 @@ public class Address extends DelegatingBytesValue {
})));
}
/**
* Address of the created private contract.
*
* @param senderAddress the address of the transaction sender.
* @param nonce the nonce of this transaction.
* @param privacyGroupId hash of participants list ordered from Enclave response.
* @return The generated address of the created private contract.
*/
public static Address privateContractAddress(
final Address senderAddress, final long nonce, final BytesValue privacyGroupId) {
return Address.extract(
Hash.hash(
RLP.encode(
out -> {
out.startList();
out.writeBytesValue(senderAddress);
out.writeLongScalar(nonce);
out.writeBytesValue(privacyGroupId);
out.endList();
})));
}
@Override
public Address copy() {
final BytesValue copiedStorage = wrapped.copy();

@ -154,7 +154,7 @@ public class PrivateTransactionProcessor {
final MutableAccount sender =
maybePrivateSender != null
? maybePrivateSender
: resolveAccountFromPublicState(publicWorldState, privateWorldState, senderAddress);
: privateWorldState.createAccount(senderAddress, 0, Wei.ZERO);
final long previousNonce = sender.incrementNonce();
LOG.trace(
@ -166,8 +166,8 @@ public class PrivateTransactionProcessor {
final MessageFrame initialFrame;
final Deque<MessageFrame> messageFrameStack = new ArrayDeque<>();
if (transaction.isContractCreation()) {
final Address contractAddress =
Address.contractAddress(senderAddress, sender.getNonce() - 1L);
final Address privateContractAddress =
Address.privateContractAddress(senderAddress, sender.getNonce() - 1L, BytesValue.EMPTY);
initialFrame =
MessageFrame.builder()
@ -175,9 +175,9 @@ public class PrivateTransactionProcessor {
.messageFrameStack(messageFrameStack)
.blockchain(blockchain)
.worldState(privateWorldState.updater())
.address(contractAddress)
.address(privateContractAddress)
.originator(senderAddress)
.contract(contractAddress)
.contract(privateContractAddress)
.initialGas(Gas.MAX_VALUE)
.gasPrice(transaction.getGasPrice())
.inputData(BytesValue.EMPTY)
@ -239,14 +239,6 @@ public class PrivateTransactionProcessor {
}
}
private MutableAccount resolveAccountFromPublicState(
final WorldUpdater publicWorldState,
final WorldUpdater privateWorldState,
final Address senderAddress) {
final MutableAccount publicSender = publicWorldState.getOrCreate(senderAddress);
return privateWorldState.createAccount(senderAddress, publicSender.getNonce(), Wei.ZERO);
}
private static void clearEmptyAccounts(final WorldUpdater worldState) {
worldState.getTouchedAccounts().stream()
.filter(Account::isEmpty)

Loading…
Cancel
Save