-
Notifications
You must be signed in to change notification settings - Fork 106
/
executor_helpers.nim
69 lines (57 loc) · 2.13 KB
/
executor_helpers.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Nimbus
# Copyright (c) 2018 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http:https://www.apache.org/licenses/LICENSE-2.0)
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
# http:https://opensource.org/licenses/MIT)
# at your option. This file may not be copied, modified, or distributed except
# according to those terms.
{.push raises: [].}
import
../../common/common,
../../db/accounts_cache,
../../vm_state,
../../vm_types,
eth/[bloom]
type
ExecutorError* = object of CatchableError
## Catch and relay exception error
# TODO: these types need to be removed
# once eth/bloom and eth/common sync'ed
Bloom = common.BloomFilter
LogsBloom = bloom.BloomFilter
# ------------------------------------------------------------------------------
# Private functions
# ------------------------------------------------------------------------------
func logsBloom(logs: openArray[Log]): LogsBloom =
for log in logs:
result.incl log.address
for topic in log.topics:
result.incl topic
# ------------------------------------------------------------------------------
# Public functions
# ------------------------------------------------------------------------------
func createBloom*(receipts: openArray[Receipt]): Bloom =
var bloom: LogsBloom
for rec in receipts:
bloom.value = bloom.value or logsBloom(rec.logs).value
result = bloom.value.toByteArrayBE
proc makeReceipt*(vmState: BaseVMState; txType: TxType): Receipt =
var rec: Receipt
if vmState.com.forkGTE(Byzantium):
rec.isHash = false
rec.status = vmState.status
else:
rec.isHash = true
rec.hash = vmState.stateDB.rootHash
# we set the status for the t8n output consistency
rec.status = vmState.status
rec.receiptType = txType
rec.cumulativeGasUsed = vmState.cumulativeGasUsed
rec.logs = vmState.getAndClearLogEntries()
rec.bloom = logsBloom(rec.logs).value.toByteArrayBE
rec
# ------------------------------------------------------------------------------
# End
# ------------------------------------------------------------------------------