import { Dcomm, BinTools, Buffer } from "../../src"
import { IndexAPI } from "../../src/apis/index/index"
import { GetLastAcceptedResponse } from "../../src/apis/index/interfaces"
import { Vertex } from "../../src/apis/dvm"

const ip: string = "indexer-demo.dcm.network"
const port: number = 443
const protocol: string = "https"
const networkID: number = 1
const dcomm: Dcomm = new Dcomm(ip, port, protocol, networkID)
const index: IndexAPI = dcomm.Index()
const bintools: BinTools = BinTools.getInstance()

const main = async (): Promise<any> => {
  const encoding: string = "cb58"
  const baseurl: string = "/ext/index/AST/vtx"
  const lastVertex: GetLastAcceptedResponse = await index.getLastAccepted(
    encoding,
    baseurl
  )
  console.log(lastVertex)

  const vertex: Vertex = new Vertex()
  vertex.fromBuffer(bintools.cb58Decode(lastVertex.bytes))
  console.log(vertex)
  console.log("--------")

  const buf: Buffer = vertex.toBuffer()
  const v: Vertex = new Vertex()
  v.fromBuffer(buf)
  console.log(v)
}

main()
