Skip to content

Commit

Permalink
add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
GregTheGreek committed Feb 23, 2022
1 parent 3b3a28e commit fba283f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/engine.ts
Expand Up @@ -16,11 +16,16 @@ export class RuleEngine {

constructor(provider: JsonRpcProvider, rules: Rule[] = []) {
this.provider = provider;
// Create ganache instancing for forking features
this.ganache = new GanacheEngine(provider.connection.url)
rules.map(x => this.addRule(x));
};

addRule(rule: Rule): void {
// If rule requires ganache forking, swap provider
// @TODO - ganache may need to be instatiated in the rule itself
// I think this is actually causing the fork to happen too early.
// We should fork on demand
if (rule.useGanache) {
rule.provider = this.ganache.provider;
}
Expand Down
9 changes: 6 additions & 3 deletions src/index.ts
Expand Up @@ -13,29 +13,32 @@ const program = new Command();
program
.option('-r --rpc <url>', 'RPC URL to proxy to', 'http://localhost:8545/')
.option('-p --port <number>', 'Port number to listen on', '9545');

program.parse(process.argv);
const options = program.opts();

(async () => {

// Setup proxy and rules
// Instantiate provider from cli
const provider = new ethers.providers.JsonRpcProvider({ url: options.rpc });

// Prompt user to select rules
const selectedRules = await selectRules();
const rules = selectedRules.map((name:string) => {
// Not sure how to get around typings for this.
// @ts-ignore
return new Rules[name](provider);
})

// Setup rule engine and proxy
const ruleEngine = new RuleEngine(provider, rules);
const proxy = new Proxy(provider, ruleEngine);

// Proxy server Logic
// Proxy server configuration
const app = express();
app.use(express.json());
app.use(cors());

// Proxy server routes
app.post('/', async (req, res) => {
const { id, method, params } = req.body;
try {
Expand Down

0 comments on commit fba283f

Please sign in to comment.