本文整理汇总了Python中ethereum.transactions.Transaction._sender方法的典型用法代码示例。如果您正苦于以下问题:Python Transaction._sender方法的具体用法?Python Transaction._sender怎么用?Python Transaction._sender使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ethereum.transactions.Transaction
的用法示例。
在下文中一共展示了Transaction._sender方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendTransaction
# 需要导入模块: from ethereum.transactions import Transaction [as 别名]
# 或者: from ethereum.transactions.Transaction import _sender [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)
示例2: get_dao_balance
# 需要导入模块: from ethereum.transactions import Transaction [as 别名]
# 或者: from ethereum.transactions.Transaction import _sender [as 别名]
print 'State created'
# Check pre-balance
pre_balance = state.get_balance(my_account)
pre_dao_tokens = get_dao_balance(state, my_account)
pre_withdrawer_balance = state.get_balance(withdrawer)
print 'Pre ETH (wei) balance: %d' % pre_balance
print 'Pre DAO (base unit) balance: %d' % pre_dao_tokens
# Attempt to claim the ETH without approving (should fail)
tx0 = Transaction(state.get_nonce(my_account), 0, 1000000, withdrawer, 0, withdrawer_ct.encode('withdraw', [])).sign('\x33' * 32)
tx0._sender = normalize_address(my_account)
apply_transaction(state, tx0)
med_balance = state.get_balance(my_account)
med_dao_tokens = get_dao_balance(state, my_account)
med_withdrawer_balance = state.get_balance(withdrawer)
assert med_balance == pre_balance
assert med_dao_tokens == pre_dao_tokens
assert med_withdrawer_balance == pre_withdrawer_balance > 0
print 'ETH claim without approving failed, as expected'
# Approve the withdrawal
tx1 = Transaction(state.get_nonce(my_account), 0, 1000000, dao, 0, dao_ct.encode('approve', [withdrawer, 100000 * 10**18])).sign('\x33' * 32)