From 0ed666b083ec3d183965a92d8b1c2dd9bd288591 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Fri, 12 Jul 2019 12:03:31 -0400 Subject: [PATCH] handle CALLER_ID == ACCT_ID move getting the contract to a helper function and add a condition to handle if the CALLER_ID == ACCT_ID and CALLER_ID is passed as CALL_ID --- lib/evmv.js | 6 ++++-- lib/modules.js | 4 ++-- lib/srchandler.js | 12 ++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/evmv.js b/lib/evmv.js index 6775ad3b..fff27e62 100644 --- a/lib/evmv.js +++ b/lib/evmv.js @@ -1,4 +1,7 @@ const kast = require("./kast.js"); +const { + getContractFromCallId, +} = require("../lib/srchandler.js"); const { buildDisplayInfo } = require("../lib/clean-evm-node.js"); @@ -38,8 +41,7 @@ module.exports = function (state) { } = node; // console.log(bin_runtime); - let contract_o = state.config.implementations[state.config.v2n[call_id]]; - let contract = state.config.contracts[contract_o.name]; + let contract = getContractFromCallId(state, call_id); // TODO - use var to contractname map to get the contractname // and use it to get the right contract here diff --git a/lib/modules.js b/lib/modules.js index 29a46d33..99972631 100644 --- a/lib/modules.js +++ b/lib/modules.js @@ -14,6 +14,7 @@ const { genBehaviour } = require("./behavior.js"); const evmv = require("./evmv.js"); const fs = require("fs"); const { + getContractFromCallId, getCodeStringFromPc, } = require("../lib/srchandler.js"); const { @@ -69,8 +70,7 @@ const view = { pc, call_id } = buildDisplayInfo(k); - let contract_o = state.config.implementations[state.config.v2n[call_id]]; - let contract = state.config.contracts[contract_o.name]; + let contract = getContractFromCallId(state, call_id); let src = getCodeStringFromPc(state.config.srcs, contract, parseInt(pc), true); return src; }, diff --git a/lib/srchandler.js b/lib/srchandler.js index c1c1bd75..ccedc82f 100644 --- a/lib/srchandler.js +++ b/lib/srchandler.js @@ -62,6 +62,17 @@ const get_pc_to_inst_map = bin_string => { }; } +const getContractFromCallId = (state, call_id) => { + const contract_look_up = call_id == 'CALLER_ID' ? 'ACCT_ID' : call_id; + let contract_o = state.config.implementations[state.config.v2n[contract_look_up]]; + if (!contract_o) { + console.log('impl', state.config.implementations, 'v2n', state.config.v2n, 'lookup', contract_look_up); + throw new Error('contract not found'); + } else { + return state.config.contracts[contract_o.name]; + } +} + // EXPORT // This mess deals with displaying the highlighted compact // source code with lines. @@ -205,6 +216,7 @@ let functionNameToPcRange = (sig, srcmapArr, ast, bin_runtime, inst_to_pc) => { } module.exports = { + getContractFromCallId, getCodeStringFromPc, get_pc_to_inst_map, genSrcmapArr,