mirror of https://github.com/hyperledger/besu
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>pull/7871/head
parent
ef9d1ab38e
commit
64b53b4745
@ -1,41 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright contributors to Hyperledger Besu. |
|
||||||
* |
|
||||||
* 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; |
|
||||||
|
|
||||||
/** |
|
||||||
* Enum representing the context in which a transaction is being encoded. This context is used to |
|
||||||
* determine the appropriate encoding strategy for a transaction. |
|
||||||
* |
|
||||||
* <p>The context can be one of the following: |
|
||||||
* |
|
||||||
* <ul> |
|
||||||
* <li>{@link #BLOCK_BODY}: The transaction is part of a block body. This context is used when |
|
||||||
* encoding transactions for inclusion in a block. |
|
||||||
* <li>{@link #POOLED_TRANSACTION}: The transaction is part of a transaction pool. This context is |
|
||||||
* used when encoding transactions that are currently in the transaction pool, waiting to be |
|
||||||
* included in a block. It is also used when encoding transactions for RPC calls related to |
|
||||||
* the transaction pool. |
|
||||||
* </ul> |
|
||||||
*/ |
|
||||||
public enum EncodingContext { |
|
||||||
/** Represents the context where the transaction is part of a block body. */ |
|
||||||
BLOCK_BODY, |
|
||||||
|
|
||||||
/** |
|
||||||
* Represents the context where the transaction is part of a transaction pool. This context is |
|
||||||
* also used when encoding transactions for RPC calls related to the transaction pool. |
|
||||||
*/ |
|
||||||
POOLED_TRANSACTION, |
|
||||||
} |
|
@ -0,0 +1,36 @@ |
|||||||
|
package org.hyperledger.besu.ethereum.core.encoding; |
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull; |
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting; |
||||||
|
import com.google.common.collect.ImmutableMap; |
||||||
|
import org.hyperledger.besu.datatypes.TransactionType; |
||||||
|
|
||||||
|
public class PooledTransactionDecoder extends TransactionDecoder{ |
||||||
|
|
||||||
|
private static final ImmutableMap<TransactionType, TransactionDecoder.Decoder> POOLED_TRANSACTION_DECODERS = |
||||||
|
ImmutableMap.of( |
||||||
|
TransactionType.ACCESS_LIST, |
||||||
|
AccessListTransactionDecoder::decode, |
||||||
|
TransactionType.EIP1559, |
||||||
|
EIP1559TransactionDecoder::decode, |
||||||
|
TransactionType.BLOB, |
||||||
|
BlobPooledTransactionDecoder::decode , |
||||||
|
TransactionType.DELEGATE_CODE, |
||||||
|
CodeDelegationTransactionDecoder::decode); |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the decoder for a given transaction type |
||||||
|
* |
||||||
|
* @param transactionType the transaction type |
||||||
|
* @return the decoder |
||||||
|
*/ |
||||||
|
@VisibleForTesting |
||||||
|
protected static TransactionDecoder.Decoder getDecoder( |
||||||
|
final TransactionType transactionType) { |
||||||
|
return checkNotNull( |
||||||
|
POOLED_TRANSACTION_DECODERS.get(transactionType), |
||||||
|
"Developer Error. A supported transaction type %s has no associated decoding logic", |
||||||
|
transactionType); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,49 @@ |
|||||||
|
/* |
||||||
|
* Copyright ConsenSys AG. |
||||||
|
* |
||||||
|
* 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 static com.google.common.base.Preconditions.checkNotNull; |
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting; |
||||||
|
import com.google.common.collect.ImmutableMap; |
||||||
|
import org.apache.tuweni.bytes.Bytes; |
||||||
|
import org.hyperledger.besu.datatypes.TransactionType; |
||||||
|
import org.hyperledger.besu.ethereum.core.Transaction; |
||||||
|
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; |
||||||
|
import org.hyperledger.besu.ethereum.rlp.RLP; |
||||||
|
import org.hyperledger.besu.ethereum.rlp.RLPOutput; |
||||||
|
|
||||||
|
public class PooledTransactionEncoder extends TransactionEncoder { |
||||||
|
|
||||||
|
private static final ImmutableMap<TransactionType, Encoder> POOLED_TRANSACTION_ENCODERS = |
||||||
|
ImmutableMap.of( |
||||||
|
TransactionType.ACCESS_LIST, |
||||||
|
AccessListTransactionEncoder::encode, |
||||||
|
TransactionType.EIP1559, |
||||||
|
EIP1559TransactionEncoder::encode, |
||||||
|
TransactionType.BLOB, |
||||||
|
BlobPooledTransactionEncoder::encode, |
||||||
|
TransactionType.DELEGATE_CODE, |
||||||
|
CodeDelegationEncoder::encode); |
||||||
|
|
||||||
|
@VisibleForTesting |
||||||
|
protected static Encoder getEncoder( |
||||||
|
final TransactionType transactionType) { |
||||||
|
return checkNotNull( |
||||||
|
POOLED_TRANSACTION_ENCODERS.get(transactionType), |
||||||
|
"Developer Error. A supported transaction type %s has no associated encoding logic", |
||||||
|
transactionType); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue