def _sign_create_validator(transaction_dict, private_key): """ Sign a create validator transaction See sign_staking_transaction for details """ # preliminary steps if transaction_dict['directive'] != Directive.CreateValidator: raise TypeError('Only CreateValidator is supported by _sign_create_or_edit_validator') # first common step account, sanitized_transaction = _get_account_and_transaction(transaction_dict, private_key) # encode the stakeMsg description = [ sanitized_transaction.pop('name'), sanitized_transaction.pop('identity'), sanitized_transaction.pop('website'), sanitized_transaction.pop('security-contact'), sanitized_transaction.pop('details'), ] commission = apply_formatter_to_array( hexstr_if_str(to_int), # formatter [ _convert_staking_percentage_to_number(sanitized_transaction.pop('rate')), _convert_staking_percentage_to_number(sanitized_transaction.pop('max-rate')), _convert_staking_percentage_to_number(sanitized_transaction.pop('max-change-rate')), ] ) commission = [ [element] for element in commission ] bls_keys = apply_formatter_to_array( hexstr_if_str(to_bytes), # formatter sanitized_transaction.pop('bls-public-keys') ) sanitized_transaction['stakeMsg'] = \ apply_formatters_to_sequence( [ hexstr_if_str(to_bytes), # address identity, # description identity, # commission rates hexstr_if_str(to_int), # min self delegation (in ONE), decimals are silently dropped hexstr_if_str(to_int), # max total delegation (in ONE), decimals are silently dropped identity, # bls public keys hexstr_if_str(to_int), # amount (the Hexlify in the SDK drops the decimals, which is what we will do too) ], [ convert_one_to_hex(sanitized_transaction.pop('validatorAddress')), description, commission, math.floor(sanitized_transaction.pop('min-self-delegation')), # Decimal floors it correctly math.floor(sanitized_transaction.pop('max-total-delegation')), bls_keys, math.floor(sanitized_transaction.pop('amount')), ] ) return _sign_transaction_generic(account, sanitized_transaction, CreateValidator)
class NewBlockHashes(BaseCommand[Tuple[NewBlockHash, ...]]): protocol_command_id = 1 serialization_codec: RLPCodec[Tuple[NewBlockHash, ...]] = RLPCodec( sedes=NEW_BLOCK_HASHES_STRUCTURE, process_inbound_payload_fn=apply_formatter_to_array( lambda args: NewBlockHash(*args)), )
def _prepare_selector_collision_msg(duplicates): dup_sel = valmap(apply_formatter_to_array(abi_to_signature), duplicates) joined_funcs = valmap(lambda funcs: ', '.join(funcs), dup_sel) func_sel_msg_list = [ funcs + ' have selector ' + sel for sel, funcs in joined_funcs.items() ] return ' and\n'.join(func_sel_msg_list)
class NewBlockHashes(BaseCommand[Tuple[NewBlockHash, ...]]): protocol_command_id = 1 serialization_codec: RLPCodec[Tuple[NewBlockHash, ...]] = RLPCodec( sedes=sedes.CountableList( sedes.List([hash_sedes, sedes.big_endian_int])), process_inbound_payload_fn=apply_formatter_to_array( lambda args: NewBlockHash(*args)), )
class GetContractCodes(BaseCommand[GetContractCodesPayload]): protocol_command_id = 10 serialization_codec = RLPCodec( sedes=GET_CONTRACT_CODES_STRUCTURE, process_inbound_payload_fn=compose( lambda args: GetContractCodesPayload(*args), apply_formatter_at_index( apply_formatter_to_array( lambda args: ContractCodeRequest(*args)), 1, ), ), )
def apply_list_to_array_formatter(formatter: Any) -> Callable[..., Any]: return to_list(apply_formatter_to_array(formatter))
} transaction_pool_content_formatter = apply_formatters_to_dict( TRANSACTION_POOL_CONTENT_FORMATTERS) TRANSACTION_POOL_INSPECT_FORMATTERS = { 'pending': curried.keymap(to_ascii_if_bytes), 'queued': curried.keymap(to_ascii_if_bytes), } transaction_pool_inspect_formatter = apply_formatters_to_dict( TRANSACTION_POOL_INSPECT_FORMATTERS) FEE_HISTORY_FORMATTERS = { 'baseFeePerGas': apply_formatter_to_array(to_integer_if_hex), 'gasUsedRatio': apply_formatter_if(is_not_null, apply_formatter_to_array(float)), 'oldestBlock': to_integer_if_hex, 'reward': apply_formatter_if( is_not_null, apply_formatter_to_array(apply_formatter_to_array(to_integer_if_hex))), } fee_history_formatter = apply_formatters_to_dict(FEE_HISTORY_FORMATTERS) STORAGE_PROOF_FORMATTERS = { 'key': HexBytes, 'value': HexBytes,
def locate(self, node: Node, key: bytes) -> Tuple[Node, ...]: payload = node_to_rpc(node) + (encode_hex(key),) return apply_formatter_to_array( # type: ignore node_from_rpc, self.web3.manager.request_blocking(RPC.alexandria_locate, payload), )
"gasLimit": normalize_int, "gasPrice": normalize_int, "nonce": normalize_int, "secretKey": normalize_bytes, "to": normalize_to_address, "value": normalize_int, }) normalize_transaction = cast(TransactionNormalizer, dict_options_normalizer([ normalize_main_transaction, ])) normalize_main_transaction_group = dict_normalizer({ "data": apply_formatter_to_array(normalize_bytes), "gasLimit": apply_formatter_to_array(normalize_int), "gasPrice": normalize_int, "nonce": normalize_int, "secretKey": normalize_bytes, "to": normalize_to_address, "value": apply_formatter_to_array(normalize_int), }) normalize_transaction_group = cast(TransactionNormalizer, dict_options_normalizer([ normalize_main_transaction_group, ])) normalize_execution = dict_normalizer({
def test_apply_formatter_to_array(formatter, value, expected): assert eth_utils.apply_formatter_to_array(formatter, value) == expected mapper = apply_formatter_to_array(formatter) assert mapper(value) == expected
encode_hex, "storage": storage_formatter, }) state_item_formatter: Callable[[List[Any]], List[Any]] state_item_formatter = apply_formatters_to_sequence( [to_checksum_address, account_state_formatter]) state_formatter = curried.itemmap(state_item_formatter) transaction_group_formatter = apply_formatters_to_dict({ # all transaction types "to": to_checksum_address, "data": apply_formatter_to_array(encode_hex), "gasLimit": apply_formatter_to_array(to_hex), "gasPrice": to_hex, "nonce": to_hex, "secretKey": encode_hex, "value": apply_formatter_to_array(to_hex), }) execution_formatter = apply_formatters_to_dict({ "address": to_checksum_address, "origin": to_checksum_address,
"gasPrice": normalize_int, "nonce": normalize_int, "secretKey": normalize_bytes, "to": normalize_to_address, "value": normalize_int, }) normalize_transaction = cast( TransactionNormalizer, dict_options_normalizer([ normalize_main_transaction, ])) normalize_main_transaction_group = dict_normalizer({ "data": apply_formatter_to_array(normalize_bytes), "gasLimit": apply_formatter_to_array(normalize_int), "gasPrice": normalize_int, "nonce": normalize_int, "secretKey": normalize_bytes, "to": normalize_to_address, "value": apply_formatter_to_array(normalize_int), }) normalize_transaction_group = cast(
def apply_list_to_array_formatter(formatter): return to_list(apply_formatter_to_array(formatter))
LEGACY_TRANSACTION_FORMATTERS, LEGACY_TRANSACTION_VALID_VALUES, is_int_or_prefixed_hexstr, is_rpc_structured_access_list, ) TYPED_TRANSACTION_FORMATTERS = merge( LEGACY_TRANSACTION_FORMATTERS, { 'chainId': hexstr_if_str(to_int), 'type': hexstr_if_str(to_int), 'accessList': apply_formatter_to_array( apply_formatters_to_dict( { "address": apply_one_of_formatters(( (is_string, hexstr_if_str(to_bytes)), (is_bytes, identity), )), "storageKeys": apply_formatter_to_array(hexstr_if_str(to_int)) } ), ), 'maxPriorityFeePerGas': hexstr_if_str(to_int), 'maxFeePerGas': hexstr_if_str(to_int), }, ) # Define typed transaction common sedes. # [[{20 bytes}, [{32 bytes}...]]...], where ... means “zero or more of the thing to the left”. access_list_sede_type = CountableList( List([ Binary.fixed_length(20, allow_empty=False),
TRANSACTION_POOL_CONTENT_FORMATTERS ) TRANSACTION_POOL_INSPECT_FORMATTERS = { 'pending': curried.keymap(to_ascii_if_bytes), 'queued': curried.keymap(to_ascii_if_bytes), } transaction_pool_inspect_formatter = apply_formatters_to_dict( TRANSACTION_POOL_INSPECT_FORMATTERS ) FEE_HISTORY_FORMATTERS = { 'baseFeePerGas': apply_formatter_to_array(to_integer_if_hex), 'gasUsedRatio': apply_formatter_if(is_not_null, apply_formatter_to_array(float)), 'oldestBlock': to_integer_if_hex, 'reward': apply_formatter_if(is_not_null, apply_formatter_to_array( apply_formatter_to_array(to_integer_if_hex))), } fee_history_formatter = apply_formatters_to_dict(FEE_HISTORY_FORMATTERS) STORAGE_PROOF_FORMATTERS = { 'key': HexBytes, 'value': HexBytes, 'proof': apply_list_to_array_formatter(HexBytes), } ACCOUNT_PROOF_FORMATTERS = {