本文整理汇总了Python中ethereum.transactions.Transaction.log_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Transaction.log_dict方法的具体用法?Python Transaction.log_dict怎么用?Python Transaction.log_dict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ethereum.transactions.Transaction
的用法示例。
在下文中一共展示了Transaction.log_dict方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendTransaction
# 需要导入模块: from ethereum.transactions import Transaction [as 别名]
# 或者: from ethereum.transactions.Transaction import log_dict [as 别名]
def sendTransaction(self, data):
"""
extend spec to support v,r,s signed transactions
"""
if not isinstance(data, dict):
raise BadRequestError('Transaction must be an object')
def get_data_default(key, decoder, default=None):
if key in data:
return decoder(data[key])
return default
to = get_data_default('to', address_decoder, b'')
gas_key = 'gas' if 'gas' in data else 'startgas'
startgas = get_data_default(gas_key, quantity_decoder, default_startgas)
gasprice_key = 'gasPrice' if 'gasPrice' in data else 'gasprice'
gasprice = get_data_default(gasprice_key, quantity_decoder, default_gasprice)
value = get_data_default('value', quantity_decoder, 0)
data_ = get_data_default('data', data_decoder, b'')
v = signed = get_data_default('v', quantity_decoder, 0)
r = get_data_default('r', quantity_decoder, 0)
s = get_data_default('s', quantity_decoder, 0)
nonce = get_data_default('nonce', quantity_decoder, None)
sender = get_data_default('from', address_decoder, self.app.services.accounts.coinbase)
assert len(sender) == 20
# create transaction
if signed:
assert nonce is not None, 'signed but no nonce provided'
assert v and r and s
else:
nonce = self.app.services.chain.chain.head_candidate.get_nonce(sender)
tx = Transaction(nonce, gasprice, startgas, to, value, data_, v, r, s)
tx._sender = None
print tx.log_dict()
if not signed:
assert sender in self.app.services.accounts, 'no account for sender'
self.app.services.accounts.sign_tx(sender, tx)
self.app.services.chain.add_transaction(tx, origin=None)
log.debug('decoded tx', tx=tx.log_dict())
if to == b'': # create
return address_encoder(processblock.mk_contract_address(tx.sender, nonce))
else:
return data_encoder(tx.hash)