本文整理汇总了Python中eth_utils.to_checksum_address方法的典型用法代码示例。如果您正苦于以下问题:Python eth_utils.to_checksum_address方法的具体用法?Python eth_utils.to_checksum_address怎么用?Python eth_utils.to_checksum_address使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eth_utils
的用法示例。
在下文中一共展示了eth_utils.to_checksum_address方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: exec_cmd_with_hash_param
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import to_checksum_address [as 别名]
def exec_cmd_with_hash_param(self, cmd, params):
"""
execute cmd with one hash param
"""
if cmd not in RPCConsole.functions["one_hash"]:
return
# check_param
common.check_param_num(params, 1, False)
# check contract address
if cmd == "getCode":
try:
if len(params) > 1:
raise ArgumentsError("{} must provide one param".format(cmd))
address = to_checksum_address(params[0])
self.exec_command(cmd, [address])
except Exception as e:
raise ArgumentsError("invalid address: {}, info: {}"
.format(params[0], e))
else:
if len(params) > 2:
raise ArgumentsError("{} must provide no more than one param".format(cmd))
# check hash
common.check_hash(params[0])
result = self.exec_command(cmd, [params[0]])
self.parse_tx_and_receipt(result, cmd, params)
示例2: match_state_dump_to_state_table
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import to_checksum_address [as 别名]
def match_state_dump_to_state_table(block_number):
current_session = get_current_session()
with open('tests/fixtures/balance/balance_{}.json'.format(block_number)) as data_file:
data = json.loads(data_file.read())
state = data['state']
with current_session.db_session_scope():
for address in state:
state_table_row = current_session.db_session.query(State).\
filter_by(address=to_checksum_address(address)).first()
assert state_table_row.balance == hex_to_integer(state[address]['balance'])
assert state_table_row.nonce == hex_to_integer(state[address]['nonce'])
if 'code' in state[address].keys():
assert state_table_row.code == "0x"+state[address]['code']
if state_table_row.storage is not None:
for storage in state_table_row.storage:
storage.storage = state[address]['storage'][storage.position]
示例3: add_block
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import to_checksum_address [as 别名]
def add_block(cls, block_data, iso_timestamp):
"""
Creates a new block object from data received from JSON-RPC call
eth_getBlockByNumber.
:param dict block_data: data received from the JSON RPC call
:param datetime iso_timestamp: timestamp when the block was mined
"""
block = cls(block_hash=to_hex(block_data['hash']),
parent_hash=to_hex(block_data['parentHash']),
difficulty=to_int(block_data['difficulty']),
block_number=to_int(block_data['number']),
gas_used=to_int(block_data['gasUsed']),
miner=to_checksum_address(block_data['miner']),
timestamp=iso_timestamp,
sha3uncles=to_hex(block_data['sha3Uncles']),
extra_data=to_hex(block_data['extraData']),
gas_limit=to_int(block_data['gasLimit']),
transaction_count=len(block_data['transactions']),
uncle_count=len(block_data['uncles']))
return block
示例4: add_uncle
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import to_checksum_address [as 别名]
def add_uncle(cls, uncle_data, block_number, iso_timestamp):
"""
Creates a new block object from data received from JSON-RPC call
eth_getUncleByBlockNumberAndIndex.
:param dict uncle_data: uncle data received from JSON RPC call
:param int block_number: block number where this uncle was included
:param datetime iso_timestamp: timestamp when the block was mined
"""
logger.debug('{}'.format(uncle_data['gasUsed']))
uncle = cls(uncle_hash=uncle_data['hash'],
uncle_blocknumber=hex_to_integer(uncle_data['number']), # 'uncle_blocknumber'
parent_hash=uncle_data['parentHash'], # parent_hash
difficulty=hex_to_integer(uncle_data['difficulty']), # 'difficulty
current_blocknumber=block_number, # current_blocknumber
gas_used=hex_to_integer(uncle_data['gasUsed']), # gas_used
miner=to_checksum_address(uncle_data['miner']), # miner
timestamp=iso_timestamp,
sha3uncles=uncle_data['sha3Uncles'], # SHA3uncles
extra_data=uncle_data['extraData'], # extra_data
gas_limit=hex_to_integer(uncle_data['gasLimit']))
return uncle
示例5: add_dao_hardfork_state_diff
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import to_checksum_address [as 别名]
def add_dao_hardfork_state_diff():
current_session = get_current_session()
with current_session.db_session_scope():
for dict_account in DAO_DRAIN_LIST:
state_diff = StateDiff.add_state_diff(
balance_diff=dict_account['balance_diff'],
nonce_diff=None,
code_from=None,
code_to=None,
address=to_checksum_address(dict_account['address']),
transaction_hash=None,
transaction_index=None,
block_number=MAINNET_DAO_BLOCK,
timestamp=MAINNET_DAO_TIMESTAMP,
state_diff_type='dao-fork')
current_session.db_session.add(state_diff)
示例6: upsert_monitor_request
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import to_checksum_address [as 别名]
def upsert_monitor_request(self, request: MonitorRequest) -> None:
self.upsert(
"monitor_request",
dict(
channel_identifier=hex256(request.channel_identifier),
token_network_address=to_checksum_address(request.token_network_address),
balance_hash=request.balance_hash,
nonce=hex256(request.nonce),
additional_hash=request.additional_hash,
closing_signature=to_hex(request.closing_signature),
non_closing_signature=to_hex(request.non_closing_signature),
reward_amount=hex256(request.reward_amount),
reward_proof_signature=to_hex(request.reward_proof_signature),
non_closing_signer=to_checksum_address(request.non_closing_signer),
),
)
示例7: upsert_channel
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import to_checksum_address [as 别名]
def upsert_channel(self, channel: Channel) -> None:
values = [
to_checksum_address(channel.token_network_address),
hex256(channel.identifier),
to_checksum_address(channel.participant1),
to_checksum_address(channel.participant2),
hex256(channel.settle_timeout),
channel.state,
hex256(channel.closing_block) if channel.closing_block else None,
channel.closing_participant,
encode_hex(channel.monitor_tx_hash) if channel.monitor_tx_hash else None,
encode_hex(channel.claim_tx_hash) if channel.claim_tx_hash else None,
]
if channel.update_status:
values += [
to_checksum_address(channel.update_status.update_sender_address),
hex256(channel.update_status.nonce),
]
else:
values += [None, None]
upsert_sql = "INSERT OR REPLACE INTO channel VALUES ({})".format(
", ".join("?" * len(values))
)
self.conn.execute(upsert_sql, values)
示例8: get
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import to_checksum_address [as 别名]
def get(self) -> Tuple[dict, int]:
info = {
"price_info": self.api.monitoring_service.context.min_reward,
"network_info": {
"chain_id": self.monitoring_service.chain_id,
"token_network_registry_address": to_checksum_address(
self.monitoring_service.context.ms_state.blockchain_state.token_network_registry_address # noqa
),
"user_deposit_address": to_checksum_address(
self.monitoring_service.context.user_deposit_contract.address
),
"service_token_address": to_checksum_address(self.service_token_address),
"confirmed_block": {
"number": self.monitoring_service.context.ms_state.blockchain_state.latest_committed_block # noqa
},
},
"version": self.version,
"contracts_version": self.contracts_version,
"operator": self.api.operator,
"message": self.api.info_message,
"UTC": datetime.utcnow().isoformat(),
}
return info, 200
示例9: get_capacity_updates
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import to_checksum_address [as 别名]
def get_capacity_updates(
self,
updating_participant: Address,
token_network_address: TokenNetworkAddress,
channel_id: int,
) -> Tuple[TokenAmount, TokenAmount]:
capacity_list = self.conn.execute(
"""
SELECT updating_capacity, other_capacity
FROM capacity_update WHERE updating_participant=?
AND token_network_address=?
AND channel_id=?
""",
[
to_checksum_address(updating_participant),
to_checksum_address(token_network_address),
hex256(channel_id),
],
)
try:
return next(capacity_list)
except StopIteration:
return TokenAmount(0), TokenAmount(0)
示例10: delete_channel
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import to_checksum_address [as 别名]
def delete_channel(
self, token_network_address: TokenNetworkAddress, channel_id: ChannelID
) -> bool:
""" Tries to delete a channel from the database
Args:
token_network_address: The address of the token network of the channel
channel_id: The id of the channel
Returns: `True` if the channel was deleted, `False` if it did not exist
"""
cursor = self.conn.execute(
"DELETE FROM channel WHERE token_network_address = ? AND channel_id = ?",
[to_checksum_address(token_network_address), hex256(channel_id)],
)
assert cursor.rowcount <= 1, "Did delete more than one channel"
return cursor.rowcount == 1
示例11: update_feedback
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import to_checksum_address [as 别名]
def update_feedback(self, token: FeedbackToken, route: List[Address], successful: bool) -> int:
hexed_route = [to_checksum_address(e) for e in route]
token_dict = dict(
token_id=token.uuid.hex,
token_network_address=to_checksum_address(token.token_network_address),
route=json.dumps(hexed_route),
successful=successful,
feedback_time=datetime.utcnow(),
)
updated_rows = self.conn.execute(
"""
UPDATE feedback
SET
successful = :successful,
feedback_time = :feedback_time
WHERE
token_id = :token_id AND
token_network_address = :token_network_address AND
route = :route AND
successful IS NULL;
""",
token_dict,
).rowcount
return updated_rows
示例12: get_feedback_token
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import to_checksum_address [as 别名]
def get_feedback_token(
self, token_id: UUID, token_network_address: TokenNetworkAddress, route: List[Address]
) -> Optional[FeedbackToken]:
hexed_route = [to_checksum_address(e) for e in route]
token = self.conn.execute(
"""SELECT * FROM feedback WHERE
token_id = ? AND
token_network_address = ? AND
route = ?;
""",
[token_id.hex, to_checksum_address(token_network_address), json.dumps(hexed_route)],
).fetchone()
if token:
return FeedbackToken(
token_network_address=TokenNetworkAddress(
to_canonical_address(token["token_network_address"])
),
uuid=UUID(token["token_id"]),
creation_time=token["creation_time"],
)
return None
示例13: pop_waiting_messages
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import to_checksum_address [as 别名]
def pop_waiting_messages(
self, token_network_address: TokenNetworkAddress, channel_id: ChannelID
) -> Iterator[DeferableMessage]:
"""Return all waiting messages for the given channel and delete them from the db"""
# Return messages
for row in self.conn.execute(
"""
SELECT message FROM waiting_message
WHERE token_network_address = ? AND channel_id = ?
""",
[to_checksum_address(token_network_address), hex256(channel_id)],
):
yield JSONSerializer.deserialize(row["message"])
# Delete returned messages
self.conn.execute(
"DELETE FROM waiting_message WHERE token_network_address = ? AND channel_id = ?",
[to_checksum_address(token_network_address), hex256(channel_id)],
)
示例14: test_save_and_load_channel
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import to_checksum_address [as 别名]
def test_save_and_load_channel(ms_database: Database):
ms_database.conn.execute(
"INSERT INTO token_network (address) VALUES (?)",
[to_checksum_address(DEFAULT_TOKEN_NETWORK_ADDRESS)],
)
for update_status in [
None,
OnChainUpdateStatus(
update_sender_address=Address(bytes([1] * 20)), nonce=random.randint(0, UINT256_MAX)
),
]:
channel = create_channel(update_status)
ms_database.upsert_channel(channel)
loaded_channel = ms_database.get_channel(
token_network_address=channel.token_network_address, channel_id=channel.identifier
)
assert loaded_channel == channel
示例15: monitoring_service_mock
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import to_checksum_address [as 别名]
def monitoring_service_mock() -> Generator[MonitoringService, None, None]:
web3_mock = Web3Mock()
mock_udc = Mock(address=bytes([8] * 20))
mock_udc.functions.effectiveBalance.return_value.call.return_value = 10000
mock_udc.functions.token.return_value.call.return_value = to_checksum_address(bytes([7] * 20))
ms = MonitoringService(
web3=web3_mock,
private_key=PrivateKey(
decode_hex("3a1076bf45ab87712ad64ccb3b10217737f7faacbf2872e88fdd9a537d8fe266")
),
db_filename=":memory:",
contracts={
CONTRACT_TOKEN_NETWORK_REGISTRY: Mock(address=bytes([9] * 20)),
CONTRACT_USER_DEPOSIT: mock_udc,
CONTRACT_MONITORING_SERVICE: Mock(address=bytes([1] * 20)),
CONTRACT_SERVICE_REGISTRY: Mock(address=bytes([2] * 20)),
},
sync_start_block=BlockNumber(0),
required_confirmations=BlockTimeout(0),
poll_interval=0,
)
yield ms