Merge pull request #221 from jangko/remove_tabs

remove tabs from js_tracer.nim
This commit is contained in:
Ștefan Talpalaru 2019-01-28 15:08:49 +01:00 committed by GitHub
commit bf8e7a74b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 56 additions and 54 deletions

View File

@ -1,66 +1,68 @@
const postStateTracer* = """{ const postStateTracer* = """{
postState: {}, postState: {},
// lookupAccount injects the specified account into the postState object. // lookupAccount injects the specified account into the postState object.
lookupAccount: function(addr, db){ lookupAccount: function(addr, db){
var acc = toHex(addr); var acc = toHex(addr);
if (this.postState[acc] === undefined) { if (this.postState[acc] === undefined) {
this.postState[acc] = { this.postState[acc] = {
code: toHex(db.getCode(addr)), code: toHex(db.getCode(addr)),
storage: {} storage: {}
}; };
} }
}, },
// lookupStorage injects the specified storage entry of the given account into // lookupStorage injects the specified storage entry of the given account into
// the postState object. // the postState object.
lookupStorage: function(addr, key, db){ lookupStorage: function(addr, key, db){
var acc = toHex(addr); var acc = toHex(addr);
var idx = toHex(key); var idx = toHex(key);
this.lookupAccount(addr, db); this.lookupAccount(addr, db);
if (this.postState[acc].storage[idx] === undefined) { if (this.postState[acc].storage[idx] === undefined) {
// bug in geth js tracer
// we will use eth_getProof to fill the storage later
this.postState[acc].storage[idx] = ""; this.postState[acc].storage[idx] = "";
} }
}, },
// result is invoked when all the opcodes have been iterated over and returns // result is invoked when all the opcodes have been iterated over and returns
// the final result of the tracing. // the final result of the tracing.
result: function(ctx, db) { result: function(ctx, db) {
this.lookupAccount(ctx.from, db); this.lookupAccount(ctx.from, db);
this.lookupAccount(ctx.to, db); this.lookupAccount(ctx.to, db);
// Return the assembled allocations (postState) // Return the assembled allocations (postState)
return this.postState; return this.postState;
}, },
// step is invoked for every opcode that the VM executes. // step is invoked for every opcode that the VM executes.
step: function(log, db) { step: function(log, db) {
// Add the current account if we just started tracing // Add the current account if we just started tracing
if (this.postState === null){ if (this.postState === null){
this.postState = {}; this.postState = {};
// Balance will potentially be wrong here, since this will include the value // Balance will potentially be wrong here, since this will include the value
// sent along with the message. We fix that in 'result()'. // sent along with the message. We fix that in 'result()'.
this.lookupAccount(log.contract.getAddress(), db); this.lookupAccount(log.contract.getAddress(), db);
} }
// Whenever new state is accessed, add it to the postState // Whenever new state is accessed, add it to the postState
switch (log.op.toString()) { switch (log.op.toString()) {
case "EXTCODECOPY": case "EXTCODESIZE": case "BALANCE": case "EXTCODECOPY": case "EXTCODESIZE": case "BALANCE":
this.lookupAccount(toAddress(log.stack.peek(0).toString(16)), db); this.lookupAccount(toAddress(log.stack.peek(0).toString(16)), db);
break; break;
case "CREATE": case "CREATE":
var from = log.contract.getAddress(); var from = log.contract.getAddress();
this.lookupAccount(toContract(from, db.getNonce(from)), db); this.lookupAccount(toContract(from, db.getNonce(from)), db);
break; break;
case "CALL": case "CALLCODE": case "DELEGATECALL": case "STATICCALL": case "CALL": case "CALLCODE": case "DELEGATECALL": case "STATICCALL":
this.lookupAccount(toAddress(log.stack.peek(1).toString(16)), db); this.lookupAccount(toAddress(log.stack.peek(1).toString(16)), db);
break; break;
case 'SSTORE':case 'SLOAD': case 'SSTORE':case 'SLOAD':
this.lookupStorage(log.contract.getAddress(), toWord(log.stack.peek(0).toString(16)), db); this.lookupStorage(log.contract.getAddress(), toWord(log.stack.peek(0).toString(16)), db);
break; break;
} }
}, },
// fault is invoked when the actual execution of an opcode fails. // fault is invoked when the actual execution of an opcode fails.
fault: function(log, db) {} fault: function(log, db) {}
} }
""" """