Пример #1
0
 def _get_deposit(self, deposit_count: int, deposit_index: int) -> Deposit:
     """
     Return `Deposit` according to `deposit_count` and `deposit_index`.
     It should include the deposit data at the `deposit_index`, and the merkle proof of
     the corresponding merkle tree made from deposit data of size `deposit_count`.
     """
     if deposit_index >= deposit_count:
         raise Eth1MonitorValidationError(
             "`deposit_index` should be smaller than `deposit_count`: "
             f"deposit_index={deposit_index}, deposit_count={deposit_count}"
         )
     len_deposit_data = self.total_deposit_count
     if deposit_count <= 0 or deposit_count > len_deposit_data:
         raise Eth1MonitorValidationError(
             f"invalid `deposit_count`: deposit_count={deposit_count}")
     if deposit_index < 0 or deposit_index >= len_deposit_data:
         raise Eth1MonitorValidationError(
             f"invalid `deposit_index`: deposit_index={deposit_index}")
     deposit_data_in_range = self._db.get_deposit_data_range(
         0, deposit_count)
     tree, root = make_deposit_tree_and_root(deposit_data_in_range)
     return Deposit.create(
         proof=make_deposit_proof(deposit_data_in_range, tree, root,
                                  deposit_index),
         data=self._db.get_deposit_data(deposit_index),
     )
Пример #2
0
def create_mock_deposits_and_root(
    pubkeys: Sequence[BLSPubkey],
    keymap: Dict[BLSPubkey, int],
    config: Eth2Config,
    withdrawal_credentials: Sequence[Hash32] = None,
    leaves: Sequence[Hash32] = None,
) -> Tuple[Tuple[Deposit, ...], Hash32]:
    """
    Creates as many new deposits as there are keys in ``pubkeys``.

    Optionally provide corresponding ``withdrawal_credentials`` to include those.

    Optionally provide the prefix in the sequence of leaves leading up to the
    new deposits made by this function to get the correct updated root. If ``leaves`` is
    empty, this function simulates the genesis deposit tree calculation.
    """
    if not withdrawal_credentials:
        withdrawal_credentials = tuple(
            Hash32(b"\x22" * 32) for _ in range(len(pubkeys)))
    else:
        assert len(withdrawal_credentials) == len(pubkeys)
    if not leaves:
        leaves = tuple()

    deposit_datas = tuple()  # type: Tuple[DepositData, ...]
    for key, credentials in zip(pubkeys, withdrawal_credentials):
        privkey = keymap[key]
        deposit_data = create_mock_deposit_data(
            config=config,
            pubkey=key,
            privkey=privkey,
            withdrawal_credentials=credentials,
        )
        deposit_datas += (deposit_data, )

    deposits: Tuple[Deposit, ...] = tuple()
    for index, data in enumerate(deposit_datas):
        deposit_datas_at_count = deposit_datas[:index + 1]
        tree, root = make_deposit_tree_and_root(deposit_datas_at_count)
        proof = make_deposit_proof(deposit_datas_at_count, tree, root, index)

        deposit = Deposit.create(proof=proof, data=data)
        deposits += (deposit, )

    if len(deposit_datas) > 0:
        return deposits, root
    else:
        return tuple(), ZERO_HASH32
Пример #3
0
def create_deposit(deposit_data: DepositData, tree: MerkleTree, index: int,
                   leaf_count: int) -> Deposit:
    proof = create_deposit_proof(tree, index, leaf_count)
    return Deposit.create(proof=proof, data=deposit_data)
Пример #4
0
def test_defaults(sample_deposit_params):
    deposit = Deposit.create(**sample_deposit_params)

    assert deposit.data == sample_deposit_params["data"]