-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Chen Kai <281165273grape@gmail.com>
- Loading branch information
Showing
19 changed files
with
1,123 additions
and
713 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
hildr-utilities/src/main/java/io/optimism/utilities/derive/stages/RawSpanBatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package io.optimism.utilities.derive.stages; | ||
|
||
public record RawSpanBatch(SpanBatchPrefix spanbatchPrefix, SpanBatchPayload spanbatchPayload) {} | ||
// package io.optimism.utilities.derive.stages; | ||
// | ||
// public record RawSpanBatch(SpanBatchPrefix spanbatchPrefix, SpanBatchPayload spanbatchPayload) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 50 additions & 39 deletions
89
...tilities/src/main/java/io/optimism/utilities/derive/stages/SpanBatchAccessListTxData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,68 @@ | ||
package io.optimism.utilities.derive.stages; | ||
|
||
import java.math.BigInteger; | ||
import java.util.ArrayList; | ||
import static org.hyperledger.besu.ethereum.core.encoding.AccessListTransactionEncoder.writeAccessList; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import org.web3j.crypto.AccessListObject; | ||
import org.web3j.crypto.transaction.type.TransactionType; | ||
import org.web3j.rlp.RlpEncoder; | ||
import org.web3j.rlp.RlpList; | ||
import org.web3j.rlp.RlpString; | ||
import org.web3j.rlp.RlpType; | ||
import java.util.Optional; | ||
import org.apache.tuweni.bytes.Bytes; | ||
import org.hyperledger.besu.datatypes.AccessListEntry; | ||
import org.hyperledger.besu.datatypes.Address; | ||
import org.hyperledger.besu.datatypes.TransactionType; | ||
import org.hyperledger.besu.datatypes.Wei; | ||
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; | ||
import org.hyperledger.besu.ethereum.rlp.RLPInput; | ||
|
||
/** | ||
* EIP-2930. | ||
* The type SpanBatchAccessListTxData. | ||
* | ||
* @author grapebaba | ||
* @since 0.2.4 | ||
*/ | ||
public record SpanBatchAccessListTxData( | ||
BigInteger value, BigInteger gasPrice, String data, List<AccessListObject> accessList) | ||
public record SpanBatchAccessListTxData(Wei value, Wei gasPrice, Bytes data, List<AccessListEntry> accessList) | ||
implements SpanBatchTxData { | ||
|
||
@Override | ||
public byte txType() { | ||
return TransactionType.EIP2930.getRlpType(); | ||
public TransactionType txType() { | ||
return TransactionType.ACCESS_LIST; | ||
} | ||
|
||
/** | ||
* Encode byte [ ]. | ||
* | ||
* @return the byte [ ] | ||
*/ | ||
public byte[] encode() { | ||
List<RlpType> rlpList = new ArrayList<>(); | ||
for (AccessListObject access : accessList) { | ||
rlpList.add(RlpString.create(access.getAddress())); | ||
rlpList.add(new RlpList( | ||
access.getStorageKeys().stream().map(RlpString::create).collect(Collectors.toList()))); | ||
} | ||
return RlpEncoder.encode(new RlpList( | ||
RlpString.create(value()), | ||
RlpString.create(gasPrice()), | ||
RlpString.create(data()), | ||
new RlpList(rlpList))); | ||
BytesValueRLPOutput out = new BytesValueRLPOutput(); | ||
out.writeByte(txType().getEthSerializedType()); | ||
out.startList(); | ||
out.writeUInt256Scalar(value()); | ||
out.writeUInt256Scalar(gasPrice()); | ||
out.writeBytes(data()); | ||
writeAccessList(out, Optional.ofNullable(accessList())); | ||
out.endList(); | ||
return out.encoded().toArrayUnsafe(); | ||
} | ||
|
||
public static SpanBatchAccessListTxData decode(RlpList rlp) { | ||
BigInteger value = ((RlpString) rlp.getValues().get(0)).asPositiveBigInteger(); | ||
BigInteger gasPrice = ((RlpString) rlp.getValues().get(1)).asPositiveBigInteger(); | ||
String data = ((RlpString) rlp.getValues().get(2)).asString(); | ||
List<AccessListObject> accessObjList = new ArrayList<>(); | ||
((RlpList) rlp.getValues().get(3)).getValues().forEach(rlpType -> { | ||
RlpList rlpList = (RlpList) rlpType; | ||
String address = ((RlpString) rlpList.getValues().get(0)).asString(); | ||
List<String> storageKeys = ((RlpList) rlpList.getValues().get(1)) | ||
.getValues().stream() | ||
.map(stKey -> ((RlpString) stKey).asString()) | ||
.collect(Collectors.toList()); | ||
accessObjList.add(new AccessListObject(address, storageKeys)); | ||
/** | ||
* Decode span batch access list tx data. | ||
* | ||
* @param input the input | ||
* @return the span batch access list tx data | ||
*/ | ||
public static SpanBatchAccessListTxData decode(RLPInput input) { | ||
input.enterList(); | ||
Wei value = Wei.of(input.readUInt256Scalar()); | ||
Wei gasPrice = Wei.of(input.readUInt256Scalar()); | ||
Bytes data = input.readBytes(); | ||
List<AccessListEntry> accessList = input.readList(accessListEntryRLPInput -> { | ||
accessListEntryRLPInput.enterList(); | ||
final AccessListEntry accessListEntry = new AccessListEntry( | ||
Address.wrap(accessListEntryRLPInput.readBytes()), | ||
accessListEntryRLPInput.readList(RLPInput::readBytes32)); | ||
accessListEntryRLPInput.leaveList(); | ||
return accessListEntry; | ||
}); | ||
return new SpanBatchAccessListTxData(value, gasPrice, data, accessObjList); | ||
input.leaveList(); | ||
return new SpanBatchAccessListTxData(value, gasPrice, data, accessList); | ||
} | ||
} |
95 changes: 56 additions & 39 deletions
95
...tilities/src/main/java/io/optimism/utilities/derive/stages/SpanBatchDynamicFeeTxData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,71 @@ | ||
package io.optimism.utilities.derive.stages; | ||
|
||
import java.math.BigInteger; | ||
import java.util.ArrayList; | ||
import static org.hyperledger.besu.ethereum.core.encoding.AccessListTransactionEncoder.writeAccessList; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import org.web3j.crypto.AccessListObject; | ||
import org.web3j.crypto.transaction.type.TransactionType; | ||
import org.web3j.rlp.RlpEncoder; | ||
import org.web3j.rlp.RlpList; | ||
import org.web3j.rlp.RlpString; | ||
import org.web3j.rlp.RlpType; | ||
import java.util.Optional; | ||
import org.apache.tuweni.bytes.Bytes; | ||
import org.hyperledger.besu.datatypes.AccessListEntry; | ||
import org.hyperledger.besu.datatypes.Address; | ||
import org.hyperledger.besu.datatypes.TransactionType; | ||
import org.hyperledger.besu.datatypes.Wei; | ||
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; | ||
import org.hyperledger.besu.ethereum.rlp.RLPInput; | ||
|
||
/** | ||
* The type SpanBatchDynamicFeeTxData. | ||
* | ||
* @author grapebaba | ||
* @since 0.2.4 | ||
*/ | ||
public record SpanBatchDynamicFeeTxData( | ||
BigInteger value, BigInteger gasTipCap, BigInteger gasFeeCap, String data, List<AccessListObject> accessList) | ||
Wei value, Wei gasTipCap, Wei gasFeeCap, Bytes data, List<AccessListEntry> accessList) | ||
implements SpanBatchTxData { | ||
@Override | ||
public byte txType() { | ||
return TransactionType.EIP1559.getRlpType(); | ||
public TransactionType txType() { | ||
return TransactionType.EIP1559; | ||
} | ||
|
||
/** | ||
* Encode byte [ ]. | ||
* | ||
* @return the byte [ ] | ||
*/ | ||
public byte[] encode() { | ||
List<RlpType> rlpList = new ArrayList<>(); | ||
for (AccessListObject access : accessList) { | ||
rlpList.add(RlpString.create(access.getAddress())); | ||
rlpList.add(new RlpList( | ||
access.getStorageKeys().stream().map(RlpString::create).collect(Collectors.toList()))); | ||
} | ||
return RlpEncoder.encode(new RlpList( | ||
RlpString.create(value()), | ||
RlpString.create(gasTipCap()), | ||
RlpString.create(gasFeeCap()), | ||
RlpString.create(data()), | ||
new RlpList(rlpList))); | ||
BytesValueRLPOutput out = new BytesValueRLPOutput(); | ||
out.writeByte(txType().getEthSerializedType()); | ||
out.startList(); | ||
out.writeUInt256Scalar(value()); | ||
out.writeUInt256Scalar(gasTipCap()); | ||
out.writeUInt256Scalar(gasFeeCap()); | ||
out.writeBytes(data()); | ||
writeAccessList(out, Optional.ofNullable(accessList())); | ||
out.endList(); | ||
return out.encoded().toArrayUnsafe(); | ||
} | ||
|
||
public static SpanBatchDynamicFeeTxData decode(RlpList rlp) { | ||
BigInteger value = ((RlpString) rlp.getValues().get(0)).asPositiveBigInteger(); | ||
BigInteger gasTipCap = ((RlpString) rlp.getValues().get(1)).asPositiveBigInteger(); | ||
BigInteger gasFeeCap = ((RlpString) rlp.getValues().get(2)).asPositiveBigInteger(); | ||
String data = ((RlpString) rlp.getValues().get(2)).asString(); | ||
List<AccessListObject> accessObjList = new ArrayList<>(); | ||
((RlpList) rlp.getValues().get(3)).getValues().forEach(rlpType -> { | ||
RlpList rlpList = (RlpList) rlpType; | ||
String address = ((RlpString) rlpList.getValues().get(0)).asString(); | ||
List<String> storageKeys = ((RlpList) rlpList.getValues().get(1)) | ||
.getValues().stream() | ||
.map(stKey -> ((RlpString) stKey).asString()) | ||
.collect(Collectors.toList()); | ||
accessObjList.add(new AccessListObject(address, storageKeys)); | ||
/** | ||
* Decode span batch dynamic fee tx data. | ||
* | ||
* @param input the input | ||
* @return the span batch dynamic fee tx data | ||
*/ | ||
public static SpanBatchDynamicFeeTxData decode(RLPInput input) { | ||
input.enterList(); | ||
Wei value = Wei.of(input.readUInt256Scalar()); | ||
Wei gasTipCap = Wei.of(input.readUInt256Scalar()); | ||
Wei gasFeeCap = Wei.of(input.readUInt256Scalar()); | ||
Bytes data = input.readBytes(); | ||
List<AccessListEntry> accessList = input.readList(accessListEntryRLPInput -> { | ||
accessListEntryRLPInput.enterList(); | ||
final AccessListEntry accessListEntry = new AccessListEntry( | ||
Address.wrap(accessListEntryRLPInput.readBytes()), | ||
accessListEntryRLPInput.readList(RLPInput::readBytes32)); | ||
accessListEntryRLPInput.leaveList(); | ||
return accessListEntry; | ||
}); | ||
return new SpanBatchDynamicFeeTxData(value, gasTipCap, gasFeeCap, data, accessObjList); | ||
|
||
input.leaveList(); | ||
return new SpanBatchDynamicFeeTxData(value, gasTipCap, gasFeeCap, data, accessList); | ||
} | ||
} |
67 changes: 54 additions & 13 deletions
67
hildr-utilities/src/main/java/io/optimism/utilities/derive/stages/SpanBatchLegacyTxData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,67 @@ | ||
/* | ||
* Copyright 2023 q315xia@163.com | ||
* | ||
* 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. | ||
*/ | ||
|
||
package io.optimism.utilities.derive.stages; | ||
|
||
import java.math.BigInteger; | ||
import org.web3j.rlp.RlpEncoder; | ||
import org.web3j.rlp.RlpList; | ||
import org.web3j.rlp.RlpString; | ||
import org.apache.tuweni.bytes.Bytes; | ||
import org.hyperledger.besu.datatypes.TransactionType; | ||
import org.hyperledger.besu.datatypes.Wei; | ||
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; | ||
import org.hyperledger.besu.ethereum.rlp.RLPInput; | ||
|
||
public record SpanBatchLegacyTxData(BigInteger value, BigInteger gasPrice, String data) implements SpanBatchTxData { | ||
/** | ||
* The type SpanBatchLegacyTxData. | ||
* | ||
* @author zhouop0 | ||
* @since 0.2.4 | ||
*/ | ||
public record SpanBatchLegacyTxData(Wei value, Wei gasPrice, Bytes data) implements SpanBatchTxData { | ||
|
||
@Override | ||
public byte txType() { | ||
return 0x00; | ||
public TransactionType txType() { | ||
return TransactionType.FRONTIER; | ||
} | ||
|
||
/** | ||
* Encode span batch legacy tx data. | ||
* | ||
* @return the span batch legacy tx data | ||
*/ | ||
public byte[] encode() { | ||
return RlpEncoder.encode( | ||
new RlpList(RlpString.create(value()), RlpString.create(gasPrice()), RlpString.create(data()))); | ||
BytesValueRLPOutput out = new BytesValueRLPOutput(); | ||
out.startList(); | ||
out.writeUInt256Scalar(value()); | ||
out.writeUInt256Scalar(gasPrice()); | ||
out.writeBytes(data()); | ||
out.endList(); | ||
return out.encoded().toArrayUnsafe(); | ||
} | ||
|
||
public static SpanBatchLegacyTxData decode(RlpList rlp) { | ||
BigInteger value = ((RlpString) rlp.getValues().get(0)).asPositiveBigInteger(); | ||
BigInteger gasPrice = ((RlpString) rlp.getValues().get(1)).asPositiveBigInteger(); | ||
String data = ((RlpString) rlp.getValues().get(2)).asString(); | ||
/** | ||
* Decode span batch legacy tx data. | ||
* | ||
* @param input the rlp | ||
* @return the span batch legacy tx data | ||
*/ | ||
public static SpanBatchLegacyTxData decode(RLPInput input) { | ||
input.enterList(); | ||
Wei value = Wei.of(input.readUInt256Scalar()); | ||
Wei gasPrice = Wei.of(input.readUInt256Scalar()); | ||
Bytes data = input.readBytes(); | ||
input.leaveList(); | ||
return new SpanBatchLegacyTxData(value, gasPrice, data); | ||
} | ||
} |
14 changes: 7 additions & 7 deletions
14
hildr-utilities/src/main/java/io/optimism/utilities/derive/stages/SpanBatchPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package io.optimism.utilities.derive.stages; | ||
|
||
import java.math.BigInteger; | ||
import java.util.List; | ||
|
||
public record SpanBatchPayload( | ||
BigInteger blockCount, BigInteger originBits, List<BigInteger> blockTxCounts, SpanBatchTxs txs) {} | ||
// package io.optimism.utilities.derive.stages; | ||
// | ||
// import java.math.BigInteger; | ||
// import java.util.List; | ||
// | ||
// public record SpanBatchPayload( | ||
// BigInteger blockCount, BigInteger originBits, List<BigInteger> blockTxCounts, SpanBatchTxs txs) {} |
Oops, something went wrong.