forked from hyperledger/besu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[4844] Add encodingContext to TransactionEncoder and TransactionDecod…
…er (hyperledger#5820) * Add decode type to TransactionDecoder * Refactoring TransactionDecoder * Invert methods order * Use Transaction encoder instead of writeTo * Move enter and leave list to inner method as pr suggestion * Size calculation should use opaque bytes instead of rlp --------- Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net> Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
- Loading branch information
Showing
28 changed files
with
920 additions
and
411 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
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
74 changes: 74 additions & 0 deletions
74
...c/main/java/org/hyperledger/besu/ethereum/core/encoding/AccessListTransactionDecoder.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,74 @@ | ||
/* | ||
* Copyright Hyperledger Besu Contributors. | ||
* | ||
* 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.crypto.SignatureAlgorithm; | ||
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; | ||
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.core.Transaction; | ||
import org.hyperledger.besu.ethereum.rlp.RLPInput; | ||
|
||
import java.math.BigInteger; | ||
import java.util.function.Supplier; | ||
|
||
import com.google.common.base.Suppliers; | ||
|
||
class AccessListTransactionDecoder { | ||
private static final Supplier<SignatureAlgorithm> SIGNATURE_ALGORITHM = | ||
Suppliers.memoize(SignatureAlgorithmFactory::getInstance); | ||
|
||
public static Transaction decode(final RLPInput rlpInput) { | ||
rlpInput.enterList(); | ||
final Transaction.Builder preSignatureTransactionBuilder = | ||
Transaction.builder() | ||
.type(TransactionType.ACCESS_LIST) | ||
.chainId(BigInteger.valueOf(rlpInput.readLongScalar())) | ||
.nonce(rlpInput.readLongScalar()) | ||
.gasPrice(Wei.of(rlpInput.readUInt256Scalar())) | ||
.gasLimit(rlpInput.readLongScalar()) | ||
.to( | ||
rlpInput.readBytes( | ||
addressBytes -> addressBytes.size() == 0 ? null : Address.wrap(addressBytes))) | ||
.value(Wei.of(rlpInput.readUInt256Scalar())) | ||
.payload(rlpInput.readBytes()) | ||
.accessList( | ||
rlpInput.readList( | ||
accessListEntryRLPInput -> { | ||
accessListEntryRLPInput.enterList(); | ||
final AccessListEntry accessListEntry = | ||
new AccessListEntry( | ||
Address.wrap(accessListEntryRLPInput.readBytes()), | ||
accessListEntryRLPInput.readList(RLPInput::readBytes32)); | ||
accessListEntryRLPInput.leaveList(); | ||
return accessListEntry; | ||
})); | ||
final byte recId = (byte) rlpInput.readIntScalar(); | ||
final Transaction transaction = | ||
preSignatureTransactionBuilder | ||
.signature( | ||
SIGNATURE_ALGORITHM | ||
.get() | ||
.createSignature( | ||
rlpInput.readUInt256Scalar().toUnsignedBigInteger(), | ||
rlpInput.readUInt256Scalar().toUnsignedBigInteger(), | ||
recId)) | ||
.build(); | ||
rlpInput.leaveList(); | ||
return transaction; | ||
} | ||
} |
Oops, something went wrong.