git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit fa75e6ce5dba39ae90d9ff2364aad9b08d9c4e93

Interface: implement log properly

Alex Beregszaszi committed on 8/25/2016, 2:39:12 AM
Parent: 00b2375ce8a8d25dbfe66d174a6ea9ed9c2e867c

Files changed

interface.jschanged
interface.jsView
@@ -310,18 +310,39 @@
310310 /**
311311 * Creates a new log in the current environment
312312 * @param {integer} dataOffset the offset in memory to load the memory
313313 * @param {integer} length the data length
314- * TODO: replace with variadic
314+ * @param {integer} number of topics
315315 */
316- log (dataOffset, length, topic1, topic2, topic3, topic4, topic5) {
317- // FIXME: calculate gas for topics set
318- this.takeGas(375 + length * 8)
316+ log (dataOffset, length, numberOfTopics, topic1, topic2, topic3, topic4) {
317+ if (numberOfTopics < 0 || numberOfTopics > 4) {
318+ throw new Error('Invalid numberOfTopics')
319+ }
319320
321+ this.takeGas(375 + length * 8 + numberOfTopics * 375)
322+
320323 const data = this.getMemory(dataOffset, length)
324+ let topics = []
325+
326+ if (numberOfTopics > 0) {
327+ topics.push(U256.fromMemory(this.getMemory(topic1, constants.U256_SIZE_BYTES)))
328+ }
329+
330+ if (numberOfTopics > 1) {
331+ topics.push(U256.fromMemory(this.getMemory(topic2, constants.U256_SIZE_BYTES)))
332+ }
333+
334+ if (numberOfTopics > 2) {
335+ topics.push(U256.fromMemory(this.getMemory(topic3, constants.U256_SIZE_BYTES)))
336+ }
337+
338+ if (numberOfTopics > 3) {
339+ topics.push(U256.fromMemory(this.getMemory(topic4, constants.U256_SIZE_BYTES)))
340+ }
341+
321342 this.environment.logs.push({
322343 data: data,
323- topics: [topic1, topic2, topic3, topic4, topic5]
344+ topics: topics
324345 })
325346 }
326347
327348 /**

Built with git-ssb-web