mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-17 08:56:45 +00:00
The deposit contract uses dynamic bytes for most of its event properties
https://github.com/ethereum/consensus-specs/blob/dev/solidity_deposit_contract/deposit_contract.sol#L19-L24
This commit is contained in:
parent
dae7b6aeea
commit
9381ad352f
@ -14,7 +14,7 @@ import
|
|||||||
chronos, json, metrics, chronicles/timings,
|
chronos, json, metrics, chronicles/timings,
|
||||||
web3, web3/ethtypes as web3Types, web3/ethhexstrings, web3/engine_api,
|
web3, web3/ethtypes as web3Types, web3/ethhexstrings, web3/engine_api,
|
||||||
eth/common/eth_types,
|
eth/common/eth_types,
|
||||||
eth/async_utils, stew/byteutils,
|
eth/async_utils, stew/[objects, byteutils],
|
||||||
# Local modules:
|
# Local modules:
|
||||||
../spec/[eth2_merkleization, forks, helpers],
|
../spec/[eth2_merkleization, forks, helpers],
|
||||||
../spec/datatypes/[base, merge],
|
../spec/datatypes/[base, merge],
|
||||||
@ -29,20 +29,26 @@ export
|
|||||||
logScope:
|
logScope:
|
||||||
topics = "eth1"
|
topics = "eth1"
|
||||||
|
|
||||||
|
type
|
||||||
|
PubKeyBytes = DynamicBytes[48, 48]
|
||||||
|
WithdrawalCredentialsBytes = DynamicBytes[32, 32]
|
||||||
|
SignatureBytes = DynamicBytes[96, 96]
|
||||||
|
Int64LeBytes = DynamicBytes[8, 8]
|
||||||
|
|
||||||
contract(DepositContract):
|
contract(DepositContract):
|
||||||
proc deposit(pubkey: Bytes48,
|
proc deposit(pubkey: PubKeyBytes,
|
||||||
withdrawalCredentials: Bytes32,
|
withdrawalCredentials: WithdrawalCredentialsBytes,
|
||||||
signature: Bytes96,
|
signature: SignatureBytes,
|
||||||
deposit_data_root: FixedBytes[32])
|
deposit_data_root: FixedBytes[32])
|
||||||
|
|
||||||
proc get_deposit_root(): FixedBytes[32]
|
proc get_deposit_root(): FixedBytes[32]
|
||||||
proc get_deposit_count(): Bytes8
|
proc get_deposit_count(): Int64LeBytes
|
||||||
|
|
||||||
proc DepositEvent(pubkey: Bytes48,
|
proc DepositEvent(pubkey: PubKeyBytes,
|
||||||
withdrawalCredentials: Bytes32,
|
withdrawalCredentials: WithdrawalCredentialsBytes,
|
||||||
amount: Bytes8,
|
amount: Int64LeBytes,
|
||||||
signature: Bytes96,
|
signature: SignatureBytes,
|
||||||
index: Bytes8) {.event.}
|
index: Int64LeBytes) {.event.}
|
||||||
|
|
||||||
const
|
const
|
||||||
web3Timeouts = 60.seconds
|
web3Timeouts = 60.seconds
|
||||||
@ -121,10 +127,12 @@ type
|
|||||||
DisconnectHandler* = proc () {.gcsafe, raises: [Defect].}
|
DisconnectHandler* = proc () {.gcsafe, raises: [Defect].}
|
||||||
|
|
||||||
DepositEventHandler* = proc (
|
DepositEventHandler* = proc (
|
||||||
pubkey: Bytes48,
|
pubkey: PubKeyBytes,
|
||||||
withdrawalCredentials: Bytes32,
|
withdrawalCredentials: WithdrawalCredentialsBytes,
|
||||||
amount: Bytes8,
|
amount: Int64LeBytes,
|
||||||
signature: Bytes96, merkleTreeIndex: Bytes8, j: JsonNode) {.gcsafe, raises: [Defect].}
|
signature: SignatureBytes,
|
||||||
|
merkleTreeIndex: Int64LeBytes,
|
||||||
|
j: JsonNode) {.gcsafe, raises: [Defect].}
|
||||||
|
|
||||||
BlockProposalEth1Data* = object
|
BlockProposalEth1Data* = object
|
||||||
vote*: Eth1Data
|
vote*: Eth1Data
|
||||||
@ -433,6 +441,9 @@ template readJsonField(j: JsonNode, fieldName: string, ValueType: type): untyped
|
|||||||
fromJson(j[fieldName], fieldName, res)
|
fromJson(j[fieldName], fieldName, res)
|
||||||
res
|
res
|
||||||
|
|
||||||
|
template init[N: static int](T: type DynamicBytes[N, N]): T =
|
||||||
|
T newSeq[byte](N)
|
||||||
|
|
||||||
proc depositEventsToBlocks(depositsList: JsonNode): seq[Eth1Block] {.
|
proc depositEventsToBlocks(depositsList: JsonNode): seq[Eth1Block] {.
|
||||||
raises: [Defect, CatchableError].} =
|
raises: [Defect, CatchableError].} =
|
||||||
if depositsList.kind != JArray:
|
if depositsList.kind != JArray:
|
||||||
@ -455,11 +466,11 @@ proc depositEventsToBlocks(depositsList: JsonNode): seq[Eth1Block] {.
|
|||||||
result.add lastEth1Block
|
result.add lastEth1Block
|
||||||
|
|
||||||
var
|
var
|
||||||
pubkey: Bytes48
|
pubkey = init PubKeyBytes
|
||||||
withdrawalCredentials: Bytes32
|
withdrawalCredentials = init WithdrawalCredentialsBytes
|
||||||
amount: Bytes8
|
amount = init Int64LeBytes
|
||||||
signature: Bytes96
|
signature = init SignatureBytes
|
||||||
index: Bytes8
|
index = init Int64LeBytes
|
||||||
|
|
||||||
var offset = 0
|
var offset = 0
|
||||||
offset += decode(logData, offset, pubkey)
|
offset += decode(logData, offset, pubkey)
|
||||||
@ -468,11 +479,18 @@ proc depositEventsToBlocks(depositsList: JsonNode): seq[Eth1Block] {.
|
|||||||
offset += decode(logData, offset, signature)
|
offset += decode(logData, offset, signature)
|
||||||
offset += decode(logData, offset, index)
|
offset += decode(logData, offset, index)
|
||||||
|
|
||||||
|
if pubkey.len != 48 or
|
||||||
|
withdrawalCredentials.len != 32 or
|
||||||
|
amount.len != 8 or
|
||||||
|
signature.len != 96 or
|
||||||
|
index.len != 8:
|
||||||
|
raise newException(CorruptDataProvider, "Web3 provider supplied invalid deposit logs")
|
||||||
|
|
||||||
lastEth1Block.deposits.add DepositData(
|
lastEth1Block.deposits.add DepositData(
|
||||||
pubkey: ValidatorPubKey.init(array[48, byte](pubkey)),
|
pubkey: ValidatorPubKey.init(pubkey.toArray),
|
||||||
withdrawal_credentials: Eth2Digest(data: array[32, byte](withdrawalCredentials)),
|
withdrawal_credentials: Eth2Digest(data: withdrawalCredentials.toArray),
|
||||||
amount: bytes_to_uint64(array[8, byte](amount)),
|
amount: bytes_to_uint64(amount.toArray),
|
||||||
signature: ValidatorSig.init(array[96, byte](signature)))
|
signature: ValidatorSig.init(signature.toArray))
|
||||||
|
|
||||||
proc fetchTimestamp(p: Web3DataProviderRef, blk: Eth1Block) {.async.} =
|
proc fetchTimestamp(p: Web3DataProviderRef, blk: Eth1Block) {.async.} =
|
||||||
let web3block = awaitWithRetries(
|
let web3block = awaitWithRetries(
|
||||||
|
2
vendor/nim-web3
vendored
2
vendor/nim-web3
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 74ae79499386e819262815c17587d319b9361aad
|
Subproject commit 9bf424a6eff44af00637b18b8cc887647e9b22c9
|
Loading…
x
Reference in New Issue
Block a user