contract TimeIndex {
	function onCreate(arg){
	  Global.rocksdb = com.yancloud.sc.db.RocksDBUtil.loadDB(${indexData},"false");
	  Global.height = com.yancloud.sc.util.HashUtil.byteArrayToInt(rocksdb.get("height".getBytes()));
	  return "success";
	}
	function saveckpt(args){
	  var height = Global.height;
	  #if($syncbyheight)
	    Global.rocksdb.put("height".getBytes(),com.yancloud.sc.util.HashUtil.intToByteArray(height));
	} 
	export function getDBStatus(arg){
      return JSON.stringify(Global.db);
    }
    export function onBlock(args){
      YancloudUtil.setTimeOut(onBlockInternal,1,args);
      return "success";
    }
    export function onTransaction(args){
      var chainblock = Global.dbs[args.ledgerName].queryBlock(prehash);
      var chaintrans = chainblock.getTransactionsList();
      for (var i = 0; i < chaintrans.size(); i++) {
        var chaintran = chaintrans.get(i);
        var tranadapter = new com.yancloud.sc.commParser.TransAdapter(chaintran);
        var tran = tranadapter.trans;
        var transhash = tran.hash;
        var frombytes = undefined;
        if (chaintran.getTxInputsCount() == 0) {
            continue;
        }
        var frombytes = tran.srcID;
        var from = com.yancloud.sc.util.HashUtil.byteArray2Str(frombytes);
        argg = {};
        argg.file = "account";
        if (Global.rocksdb.get(frombytes) == undefined) {
            print("undefined account :" + from);
            argg.dataLength = 32;
            var acindex = com.yancloud.sc.boundry.TimeIndex.createIndex();
            var res = acindex.createFile(argg);
            print(JSON.stringify(res));
            Global.rocksdb.put(frombytes, frombytes);
        }
        argg = {};
        argg.file = "time";
        argg.date = tran.timestamp;
        argg.content = com.yancloud.sc.util.HashUtil.byteArray2Str(transhash);
        var acindex = com.yancloud.sc.boundry.TimeIndex.createIndex();
        var res = acindex.manullyIndex(argg);
        saveckpt({})
        
    }
    export function onQuery(args){
        //request by time
        argg = {};
        var pars = JSON.parse(args);
        argg.file = pars.type;
        print(argg.file);
        argg.startTime = pars.start;
        argg.endTime = pars.end;
        var acindex = com.yancloud.sc.boundry.AccountIndex.createIndex() var ss = acindex.requestByTime(argg);
        print(JSON.stringify(ss));
        return "success";
    }
}