本文整理汇总了Python中ethereum.transactions.Transaction.sender方法的典型用法代码示例。如果您正苦于以下问题:Python Transaction.sender方法的具体用法?Python Transaction.sender怎么用?Python Transaction.sender使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ethereum.transactions.Transaction
的用法示例。
在下文中一共展示了Transaction.sender方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_call
# 需要导入模块: from ethereum.transactions import Transaction [as 别名]
# 或者: from ethereum.transactions.Transaction import sender [as 别名]
def test_call(block, sender, to, data='', gasprice=0, value=0):
state_root_before = block.state_root
assert block.has_parent()
# rebuild block state before finalization
parent = block.get_parent()
test_block = block.init_from_parent(parent, block.coinbase,
timestamp=block.timestamp)
for _tx in block.get_transactions():
success, output = processblock.apply_transaction(test_block, _tx)
assert success
# apply transaction
startgas = block.gas_limit - block.gas_used
gasprice = 0
nonce = test_block.get_nonce(sender)
tx = Transaction(nonce, gasprice, startgas, to, value, data)
tx.sender = sender
try:
success, output = processblock.apply_transaction(test_block, tx)
except processblock.InvalidTransaction as e:
success = False
assert block.state_root == state_root_before
if success:
return output
else:
log.debug('test_call failed', error=e)
return None
示例2: call
# 需要导入模块: from ethereum.transactions import Transaction [as 别名]
# 或者: from ethereum.transactions.Transaction import sender [as 别名]
def call(this, to, value=0, data='', sender=None,
startgas=25000, gasprice=10*denoms.szabo):
sender = address20(sender or this.coinbase)
to = address20(to)
block = this.head_candidate
state_root_before = block.state_root
assert block.has_parent()
# rebuild block state before finalization
parent = block.get_parent()
test_block = block.init_from_parent(parent, block.coinbase,
timestamp=block.timestamp)
for tx in block.get_transactions():
success, output = processblock.apply_transaction(test_block, tx)
assert success
# apply transaction
nonce = test_block.get_nonce(sender)
tx = Transaction(nonce, gasprice, startgas, to, value, data)
tx.sender = sender
try:
success, output = processblock.apply_transaction(test_block, tx)
except processblock.InvalidTransaction as e:
success = False
assert block.state_root == state_root_before
if success:
return output
else:
return False
示例3: call
# 需要导入模块: from ethereum.transactions import Transaction [as 别名]
# 或者: from ethereum.transactions.Transaction import sender [as 别名]
def call(self, data, block_id=None):
block = self.json_rpc_server.get_block(block_id)
state_root_before = block.state_root
# rebuild block state before finalization
if block.has_parent():
parent = block.get_parent()
test_block = block.init_from_parent(parent, block.coinbase,
timestamp=block.timestamp)
for tx in block.get_transactions():
success, output = processblock.apply_transaction(test_block, tx)
assert success
else:
original = block.snapshot()
original['journal'] = deepcopy(original['journal']) # do not alter original journal
test_block = ethereum.blocks.genesis(block.db)
test_block.revert(original)
# validate transaction
if not isinstance(data, dict):
raise BadRequestError('Transaction must be an object')
to = address_decoder(data['to'])
try:
startgas = quantity_decoder(data['gas'])
except KeyError:
startgas = block.gas_limit - block.gas_used
try:
gasprice = quantity_decoder(data['gasPrice'])
except KeyError:
gasprice = 0
try:
value = quantity_decoder(data['value'])
except KeyError:
value = 0
try:
data_ = data_decoder(data['data'])
except KeyError:
data_ = b''
try:
sender = address_decoder(data['from'])
except KeyError:
sender = '\x00' * 20
# apply transaction
nonce = test_block.get_nonce(sender)
tx = Transaction(nonce, gasprice, startgas, to, value, data_)
tx.sender = sender
try:
success, output = processblock.apply_transaction(test_block, tx)
except processblock.InvalidTransaction as e:
success = False
assert block.state_root == state_root_before
if success:
return output
else:
return False
示例4: create_transaction
# 需要导入模块: from ethereum.transactions import Transaction [as 别名]
# 或者: from ethereum.transactions.Transaction import sender [as 别名]
def create_transaction(
web3: Web3,
from_: str,
to: str,
data: bytes = b'',
nonce_offset: int = 0,
value: int = 0,
gas_price: Union[int, None] = None,
gas_limit: int = NETWORK_CFG.POT_GAS_LIMIT
) -> Transaction:
if gas_price is None:
gas_price = NETWORK_CFG.GAS_PRICE
nonce = web3.eth.getTransactionCount(from_, 'pending') + nonce_offset
tx = Transaction(nonce, gas_price, gas_limit, to, value, data)
tx.sender = decode_hex(from_)
return tx
示例5: call
# 需要导入模块: from ethereum.transactions import Transaction [as 别名]
# 或者: from ethereum.transactions.Transaction import sender [as 别名]
def call(self, data, block_id=None):
block = self.json_rpc_server.get_block(block_id)
# rebuild block state before finalization
parent = block.get_parent()
test_block = block.init_from_parent(parent, block.coinbase,
timestamp=block.timestamp)
for tx in block.get_transactions():
success, output = processblock.apply_transaction(test_block, tx)
assert success
# validate transaction
if not isinstance(data, dict):
raise BadRequestError('Transaction must be an object')
to = address_decoder(data['to'])
try:
startgas = quantity_decoder(data['gas'])
except KeyError:
startgas = block.gas_limit - block.gas_used
try:
gasprice = quantity_decoder(data['gasPrice'])
except KeyError:
gasprice = 0
try:
value = quantity_decoder(data['value'])
except KeyError:
value = 0
try:
data_ = data_decoder(data['data'])
except KeyError:
data_ = b''
try:
sender = address_decoder(data['from'])
except KeyError:
sender = '\x00' * 20
# initialize transaction
nonce = block.get_nonce(sender)
tx = Transaction(nonce, gasprice, startgas, to, value, data_)
tx.sender = sender
# apply transaction
try:
success, output = processblock.apply_transaction(test_block, tx)
except processblock.InvalidTransaction:
success = False
if success:
return output
else:
return False