forked from hyperledger/besu
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:add op deposit tx encode/decode.
Signed-off-by: Chen Kai <281165273grape@gmail.com>
- Loading branch information
Showing
12 changed files
with
231 additions
and
13 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
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
44 changes: 44 additions & 0 deletions
44
...n/java/org/hyperledger/besu/ethereum/core/encoding/OptimismDepositTransactionDecoder.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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright optimism-java. | ||
* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.ethereum.core.encoding; | ||
|
||
import org.hyperledger.besu.datatypes.Address; | ||
import org.hyperledger.besu.datatypes.Hash; | ||
import org.hyperledger.besu.datatypes.TransactionType; | ||
import org.hyperledger.besu.datatypes.Wei; | ||
import org.hyperledger.besu.ethereum.core.Transaction; | ||
import org.hyperledger.besu.ethereum.rlp.RLPInput; | ||
|
||
import java.math.BigInteger; | ||
|
||
public class OptimismDepositTransactionDecoder { | ||
|
||
public static Transaction decode(final RLPInput input) { | ||
input.enterList(); | ||
final Transaction.Builder builder = | ||
Transaction.builder() | ||
.type(TransactionType.OPTIMISM_DEPOSIT) | ||
.sourceHash(Hash.wrap(input.readBytes32())) | ||
.sender(Address.wrap(input.readBytes())) | ||
.to(input.readBytes(v -> v.isEmpty() ? null : Address.wrap(v))) | ||
.mint(Wei.of(input.readUInt256Scalar())) | ||
.value(Wei.of(input.readUInt256Scalar())) | ||
.gasLimit(input.readLongScalar()) | ||
.isSystemTx(input.readBigIntegerScalar().compareTo(BigInteger.ONE) == 0) | ||
.payload(input.readBytes()); | ||
input.leaveList(); | ||
return builder.build(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...n/java/org/hyperledger/besu/ethereum/core/encoding/OptimismDepositTransactionEncoder.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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright optimism-java. | ||
* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.ethereum.core.encoding; | ||
|
||
import org.hyperledger.besu.datatypes.Wei; | ||
import org.hyperledger.besu.ethereum.core.Transaction; | ||
import org.hyperledger.besu.ethereum.rlp.RLPOutput; | ||
|
||
import java.math.BigInteger; | ||
|
||
import org.apache.tuweni.bytes.Bytes; | ||
|
||
public class OptimismDepositTransactionEncoder { | ||
|
||
public static void encode(final Transaction transaction, final RLPOutput out) { | ||
out.startList(); | ||
out.writeBytes(transaction.getSourceHash().orElseThrow()); | ||
out.writeBytes(transaction.getSender()); | ||
out.writeBytes(transaction.getTo().map(Bytes::copy).orElse(Bytes.EMPTY)); | ||
out.writeUInt256Scalar(transaction.getMint().orElse(Wei.ZERO)); | ||
out.writeUInt256Scalar(transaction.getValue() != null ? transaction.getValue() : Wei.ZERO); | ||
out.writeLongScalar(transaction.getGasLimit()); | ||
out.writeBigIntegerScalar( | ||
transaction.getIsSystemTx().map(b -> b ? BigInteger.ONE : BigInteger.ZERO).orElseThrow()); | ||
out.writeBytes(transaction.getPayload() != null ? transaction.getPayload() : Bytes.EMPTY); | ||
out.endList(); | ||
} | ||
} |
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
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
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
Oops, something went wrong.