-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Adding support for EIP1559 Private Transactions #1980
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
Changes from 4 commits
6b6f97b
bbd4847
d47d0a5
cf25d0e
b71b19f
3cfcc7a
c254a72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,28 +13,26 @@ | |
package org.web3j.protocol.eea.crypto; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.web3j.crypto.Credentials; | ||
import org.web3j.crypto.Sign; | ||
import org.web3j.crypto.TransactionEncoder; | ||
import org.web3j.protocol.eea.crypto.transaction.type.RawPrivateTransaction; | ||
import org.web3j.rlp.RlpEncoder; | ||
import org.web3j.rlp.RlpList; | ||
import org.web3j.rlp.RlpString; | ||
import org.web3j.rlp.RlpType; | ||
import org.web3j.utils.Base64String; | ||
|
||
/** Create signed RLP encoded private transaction. */ | ||
public class PrivateTransactionEncoder { | ||
|
||
public static byte[] signMessage( | ||
final RawPrivateTransaction rawTransaction, final Credentials credentials) { | ||
final byte[] encodedTransaction = encode(rawTransaction); | ||
final RawPrivateTransaction privateTransaction, final Credentials credentials) { | ||
final byte[] encodedTransaction = encode(privateTransaction); | ||
final Sign.SignatureData signatureData = | ||
Sign.signMessage(encodedTransaction, credentials.getEcKeyPair()); | ||
|
||
return encode(rawTransaction, signatureData); | ||
return encode(privateTransaction, signatureData); | ||
} | ||
|
||
public static byte[] signMessage( | ||
|
@@ -61,35 +59,25 @@ public static byte[] encode(final RawPrivateTransaction rawTransaction, final lo | |
} | ||
|
||
private static byte[] encode( | ||
final RawPrivateTransaction rawTransaction, final Sign.SignatureData signatureData) { | ||
final List<RlpType> values = asRlpValues(rawTransaction, signatureData); | ||
final RawPrivateTransaction privateTransaction, | ||
final Sign.SignatureData signatureData) { | ||
// final List<RlpType> values = asRlpValues(rawTransaction, signatureData); | ||
final List<RlpType> values = privateTransaction.asRlpValues(signatureData); | ||
final RlpList rlpList = new RlpList(values); | ||
return RlpEncoder.encode(rlpList); | ||
byte[] encoded = RlpEncoder.encode(rlpList); | ||
|
||
if (privateTransaction.getTransactionType().isPrivateEip1559()) { | ||
return ByteBuffer.allocate(encoded.length + 1) | ||
.put(privateTransaction.getTransactionType().getRlpType()) | ||
.put(encoded) | ||
.array(); | ||
} | ||
return encoded; | ||
} | ||
|
||
private static byte[] longToBytes(long x) { | ||
ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); | ||
buffer.putLong(x); | ||
return buffer.array(); | ||
} | ||
|
||
public static List<RlpType> asRlpValues( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any issue with this being removed for backwards compatibility? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So every Tx type has its own different asRlpValues(), so it is being transferred from here. |
||
final RawPrivateTransaction privateTransaction, | ||
final Sign.SignatureData signatureData) { | ||
|
||
final List<RlpType> result = | ||
new ArrayList<>(TransactionEncoder.asRlpValues(privateTransaction, signatureData)); | ||
|
||
result.add(privateTransaction.getPrivateFrom().asRlp()); | ||
|
||
privateTransaction | ||
.getPrivateFor() | ||
.ifPresent(privateFor -> result.add(Base64String.unwrapListToRlp(privateFor))); | ||
|
||
privateTransaction.getPrivacyGroupId().map(Base64String::asRlp).ifPresent(result::add); | ||
|
||
result.add(RlpString.create(privateTransaction.getRestriction().getRestriction())); | ||
|
||
return result; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we talked about, I guess this package change will break backwards compatibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we can change the class path to original so that it doesn't break anything