Skip to content

Commit

Permalink
muck with how receipts are made
Browse files Browse the repository at this point in the history
  • Loading branch information
pipermerriam committed Oct 20, 2017
1 parent a0ffd53 commit 121b572
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions evm/vm/forks/frontier/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,34 @@ def get_cumulative_gas_used(self):
def receipts(self):
return self.chaindb.get_receipts(self.header, Receipt)

def make_receipt(self, transaction, computation):
logs = [
Log(address, topics, data)
for address, topics, data
in computation.get_log_entries()
]

if computation.error:
tx_gas_used = transaction.gas
else:
gas_remaining = computation.get_gas_remaining()
gas_refund = computation.get_gas_refund()
tx_gas_used = (
transaction.gas - gas_remaining
) - min(
gas_refund,
(transaction.gas - gas_remaining) // 2,
)

gas_used = self.header.gas_used + tx_gas_used

receipt = Receipt(
state_root=self.header.state_root,
gas_used=gas_used,
logs=logs,
)
return receipt

#
# Header API
#
Expand All @@ -236,31 +264,7 @@ def from_header(cls, header, chaindb):
# Execution API
#
def add_transaction(self, transaction, computation):
logs = [
Log(address, topics, data)
for address, topics, data
in computation.get_log_entries()
]

if computation.error:
tx_gas_used = transaction.gas
else:
gas_remaining = computation.get_gas_remaining()
gas_refund = computation.get_gas_refund()
tx_gas_used = (
transaction.gas - gas_remaining
) - min(
gas_refund,
(transaction.gas - gas_remaining) // 2,
)

gas_used = self.header.gas_used + tx_gas_used

receipt = Receipt(
state_root=self.header.state_root,
gas_used=gas_used,
logs=logs,
)
receipt = self.make_receipt(transaction, computation)

transaction_idx = len(self.transactions)

Expand All @@ -276,7 +280,7 @@ def add_transaction(self, transaction, computation):
self.header.transaction_root = tx_root_hash
self.header.receipt_root = receipt_root_hash
self.header.bloom = int(self.bloom_filter)
self.header.gas_used = gas_used
self.header.gas_used = receipt.gas_used

return self

Expand Down

0 comments on commit 121b572

Please sign in to comment.