-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
797 additions
and
696 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
from __future__ import annotations | ||
|
||
from typing import ClassVar | ||
|
||
from pydantic import AliasChoices, Field | ||
from typing_extensions import Self | ||
|
||
from common.ethereum.bin_str import EthBinStrField, EthBinStr | ||
from common.ethereum.hash import EthAddressField, EthHash32Field, EthAddress, EthTxHash | ||
from common.jsonrpc.api import BaseJsonRpcModel | ||
from common.neon.transaction_model import NeonTxModel | ||
from common.neon_rpc.api import EmulNeonCallModel | ||
from common.utils.pydantic import HexUIntField | ||
|
||
|
||
class RpcAccessItemModel(BaseJsonRpcModel): | ||
address: EthAddressField | ||
storageKeys: list[EthHash32Field] | ||
|
||
|
||
class RpcEthTxRequest(BaseJsonRpcModel): | ||
txType: HexUIntField = Field(default=0, validation_alias="type") | ||
fromAddress: EthAddressField = Field( | ||
default=EthAddress.default(), | ||
validation_alias=AliasChoices("from", "fromAddress"), | ||
) | ||
toAddress: EthAddressField = Field( | ||
default=EthAddress.default(), | ||
validation_alias=AliasChoices("to", "toAddress"), | ||
) | ||
data: EthBinStrField = Field( | ||
default=EthBinStr.default(), | ||
validation_alias=AliasChoices("data", "input"), | ||
) | ||
value: HexUIntField = Field(default=0) | ||
nonce: HexUIntField = Field(default=0) | ||
|
||
gas: HexUIntField = Field(default=2**64) | ||
gasPrice: HexUIntField = Field(default=2**64) | ||
maxFeePerGas: HexUIntField = Field(default=2**64) | ||
maxPriorityFeePerGas: HexUIntField = Field(default=2**64) | ||
|
||
accessList: list[RpcAccessItemModel] = Field(default_factory=list) | ||
chainId: HexUIntField = Field(default=0) | ||
|
||
_default: ClassVar[RpcEthTxRequest | None] = None | ||
|
||
@classmethod | ||
def default(cls) -> Self: | ||
if not cls._default: | ||
cls._default = cls( | ||
fromAddress=EthAddress.default(), | ||
toAddress=EthAddress.default(), | ||
data=EthBinStr.default(), | ||
) | ||
return cls._default | ||
|
||
def to_emulation_call(self, chain_id: int) -> EmulNeonCallModel: | ||
return EmulNeonCallModel( | ||
from_address=self.fromAddress, | ||
to_address=self.toAddress, | ||
value=self.value, | ||
data=self.data.to_bytes(), | ||
gas_limit=self.gas, | ||
gas_price=self.gasPrice, | ||
chain_id=chain_id | ||
) | ||
|
||
def to_neon_tx(self) -> NeonTxModel: | ||
return NeonTxModel( | ||
tx_type=self.txType, | ||
neon_tx_hash=EthTxHash.default(), | ||
from_address=self.fromAddress, | ||
to_address=self.toAddress, | ||
contract=EthAddress.default(), | ||
nonce=self.nonce, | ||
gas_price=self.gasPrice, | ||
gas_limit=self.gas, | ||
value=self.value, | ||
call_data=self.data, | ||
v=0, | ||
r=0, | ||
s=0, | ||
) |
Oops, something went wrong.