Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
handle CALLER_ID == ACCT_ID
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Chris Smith committed Jul 12, 2019
1 parent 1264166 commit 0ed666b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/evmv.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const kast = require("./kast.js");
const {
getContractFromCallId,
} = require("../lib/srchandler.js");
const {
buildDisplayInfo
} = require("../lib/clean-evm-node.js");
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
},
Expand Down
12 changes: 12 additions & 0 deletions lib/srchandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -205,6 +216,7 @@ let functionNameToPcRange = (sig, srcmapArr, ast, bin_runtime, inst_to_pc) => {
}

module.exports = {
getContractFromCallId,
getCodeStringFromPc,
get_pc_to_inst_map,
genSrcmapArr,
Expand Down

0 comments on commit 0ed666b

Please sign in to comment.