integrate evmc 'emitLog'
This commit is contained in:
parent
bf7b4c7273
commit
62f96e9bd4
|
@ -91,9 +91,12 @@ proc selfdestruct*(ctx: HostContext, address, beneficiary: EthAddress) =
|
|||
{.gcsafe.}:
|
||||
ctx.host.selfdestruct(ctx.context, address.addr, beneficiary.addr)
|
||||
|
||||
proc emitLog*(ctx: HostContext, address: EthAddress, data: openArray[byte], topics: openArray[evmc_bytes32]) =
|
||||
proc emitLog*(ctx: HostContext, address: EthAddress, data: openArray[byte],
|
||||
topics: ptr evmc_bytes32, topicsCount: int) =
|
||||
var address = toEvmc(address)
|
||||
ctx.host.emit_log(ctx.context, address.addr, data[0].unsafeAddr, data.len.uint, topics[0].unsafeAddr, topics.len.uint)
|
||||
{.gcsafe.}:
|
||||
ctx.host.emit_log(ctx.context, address.addr, if data.len > 0: data[0].unsafeAddr else: nil,
|
||||
data.len.uint, topics, topicsCount.uint)
|
||||
|
||||
proc call*(ctx: HostContext, msg: evmc_message): evmc_result =
|
||||
ctx.host.call(ctx.context, msg.unsafeAddr)
|
||||
|
|
|
@ -117,15 +117,18 @@ proc hostSelfdestructImpl(ctx: Computation, address, beneficiary: var evmc_addre
|
|||
ctx.registerAccountForDeletion(fromEvmc(beneficiary))
|
||||
|
||||
proc hostEmitLogImpl(ctx: Computation, address: var evmc_address,
|
||||
data: ptr byte, dataSize: uint,
|
||||
topics: UncheckedArray[evmc_bytes32], topicsCount: uint) {.cdecl.} =
|
||||
data: ptr byte, dataSize: int,
|
||||
topics: UncheckedArray[evmc_bytes32], topicsCount: int) {.cdecl.} =
|
||||
var log: Log
|
||||
log.topics = newSeq[Topic](topicsCount)
|
||||
for i in 0 ..< topicsCount:
|
||||
log.topics[i] = topics[i].bytes
|
||||
if topicsCount > 0:
|
||||
log.topics = newSeq[Topic](topicsCount)
|
||||
for i in 0 ..< topicsCount:
|
||||
log.topics[i] = topics[i].bytes
|
||||
|
||||
if dataSize > 0:
|
||||
log.data = newSeq[byte](dataSize)
|
||||
copyMem(log.data[0].addr, data, dataSize)
|
||||
|
||||
log.data = newSeq[byte](dataSize)
|
||||
copyMem(log.data[0].addr, data, dataSize)
|
||||
log.address = fromEvmc(address)
|
||||
ctx.addLogEntry(log)
|
||||
|
||||
|
|
|
@ -13,7 +13,8 @@ import
|
|||
../../computation, ../../stack, ../../code_stream,
|
||||
../../../vm_types, ../../memory,
|
||||
../../../errors, ../../message, ../../interpreter/[gas_meter, opcode_values],
|
||||
../../interpreter/utils/utils_numeric
|
||||
../../interpreter/utils/utils_numeric,
|
||||
../../evmc_api, evmc/evmc
|
||||
|
||||
proc pop(tree: var NimNode): NimNode =
|
||||
## Returns the last value of a NimNode and remove it
|
||||
|
@ -115,18 +116,28 @@ proc logImpl(c: Computation, opcode: Op, topicCount: int) =
|
|||
if memPos < 0 or len < 0:
|
||||
raise newException(OutOfBoundsRead, "Out of bounds memory access")
|
||||
|
||||
var log: Log
|
||||
log.topics = newSeqOfCap[Topic](topicCount)
|
||||
for i in 0 ..< topicCount:
|
||||
log.topics.add(c.stack.popTopic())
|
||||
c.gasMeter.consumeGas(
|
||||
c.gasCosts[opcode].m_handler(c.memory.len, memPos, len),
|
||||
reason="Memory expansion, Log topic and data gas cost")
|
||||
|
||||
c.memory.extend(memPos, len)
|
||||
log.data = c.memory.read(memPos, len)
|
||||
log.address = c.msg.contractAddress
|
||||
c.addLogEntry(log)
|
||||
|
||||
when evmc_enabled:
|
||||
var topics: array[4, evmc_bytes32]
|
||||
for i in 0 ..< topicCount:
|
||||
topics[i].bytes = c.stack.popTopic()
|
||||
|
||||
c.host.emitLog(c.msg.contractAddress,
|
||||
c.memory.read(memPos, len),
|
||||
topics[0].addr, topicCount)
|
||||
else:
|
||||
var log: Log
|
||||
log.topics = newSeqOfCap[Topic](topicCount)
|
||||
for i in 0 ..< topicCount:
|
||||
log.topics.add(c.stack.popTopic())
|
||||
|
||||
log.data = c.memory.read(memPos, len)
|
||||
log.address = c.msg.contractAddress
|
||||
c.addLogEntry(log)
|
||||
|
||||
template genLog*() =
|
||||
proc log0*(c: Computation) {.inline.} = logImpl(c, Log0, 0)
|
||||
|
|
Loading…
Reference in New Issue