import { DebuggerClient, InitArguments } from "@sentio/debugger"
const selectors = require("@sentio/truffle-debugger").selectors;
let { data, evm, trace, session, sourcemapping, stacktrace, controller, txlog } = selectors;

console.log(new Date().toLocaleTimeString(), "!!! start")

const url = 'https://test.sentio.xyz/api/v1/solidity/fetch_and_compile?txHash=0xf86a40d6421b7b0f29a6baacd8d11e1d2444dd4974e4cf554a367c95fdb1d79c';
fetch(url)
.then(data => { return data.json() })
.then(res => {
  console.log(new Date().toLocaleTimeString(), "!!! compile end")
  const shimmedCompilations = res.result;
  const init_args: InitArguments = {
    providerURL: 'https://test.sentio.xyz/api/v1/solidity',
    txnHash: "0xf86a40d6421b7b0f29a6baacd8d11e1d2444dd4974e4cf554a367c95fdb1d79c",
    shimmedCompilations: shimmedCompilations,
    chainId: "0x1",
    storageLookup: false,
  }
  const d = new DebuggerClient();

  d.initialize(init_args).then(
    () => {
    console.log(d.initialized);
    console.log(new Date().toLocaleTimeString(), "!!! init end")

      // while (true) {
      //   console.log((await d.requireCurrentStep()).pc)
      //   await d.advance()
      // }

    d.getCallTrace().then(r => {
      console.log(new Date().toLocaleTimeString(), "!!! call trace end")
      console.log(r)
    })

      // d.advance(638).then(x => {
      //   d.requireVariables().then(x => {
      //     console.log(JSON.stringify(x))
      //     //process.exit()
      //   })
      // });

    // d.stepInto().then(d => {
    //   console.log(JSON.stringify(d))
    // })
  });
})

