Commit fa75e6ce5dba39ae90d9ff2364aad9b08d9c4e93
Interface: implement log properly
Alex Beregszaszi committed on 8/25/2016, 2:39:12 AMParent: 00b2375ce8a8d25dbfe66d174a6ea9ed9c2e867c
Files changed
interface.js | changed |
interface.js | ||
---|---|---|
@@ -310,18 +310,39 @@ | ||
310 | 310 | /** |
311 | 311 | * Creates a new log in the current environment |
312 | 312 | * @param {integer} dataOffset the offset in memory to load the memory |
313 | 313 | * @param {integer} length the data length |
314 | - * TODO: replace with variadic | |
314 | + * @param {integer} number of topics | |
315 | 315 | */ |
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 | + } | |
319 | 320 | |
321 | + this.takeGas(375 + length * 8 + numberOfTopics * 375) | |
322 | + | |
320 | 323 | 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 | + | |
321 | 342 | this.environment.logs.push({ |
322 | 343 | data: data, |
323 | - topics: [topic1, topic2, topic3, topic4, topic5] | |
344 | + topics: topics | |
324 | 345 | }) |
325 | 346 | } |
326 | 347 | |
327 | 348 | /** |
Built with git-ssb-web