func main() {
	fmt.Println("Usage:")
	fmt.Println("ReceiptGenerator level/bolt [EntryID-To-Extract]")
	fmt.Println("Leave out the last one to export all entries")
	if len(os.Args) < 1 {
		fmt.Println("\nNot enough arguments passed")
		os.Exit(1)
	}
	if len(os.Args) > 2 {
		fmt.Println("\nToo many arguments passed")
		os.Exit(1)
	}

	levelBolt := os.Args[1]

	if levelBolt != level && levelBolt != bolt {
		fmt.Println("\nFirst argument should be `level` or `bolt`")
		os.Exit(1)
	}

	entryID := ""
	if len(os.Args) == 3 {
		entryID = os.Args[2]
	}

	state := new(state.State)
	state.Cfg = util.ReadConfig("")
	if levelBolt == level {
		err := state.InitLevelDB()
		if err != nil {
			panic(err)
		}
	}
	if levelBolt == bolt {
		err := state.InitBoltDB()
		if err != nil {
			panic(err)
		}
	}
	dbo := state.GetAndLockDB()
	defer state.UnlockDB()

	if entryID != "" {
		err := ExportEntryReceipt(entryID, dbo)
		if err != nil {
			panic(err)
		}
	} else {
		err := ExportAllEntryReceipts(dbo)
		if err != nil {
			panic(err)
		}
	}
}
Exemple #2
0
func main() {
	fmt.Println("Usage:")
	fmt.Println("BlockExtractor level/bolt [ChainID-To-Extract]")
	fmt.Println("Leave out the last one to export basic chains (A, D, EC, F)")
	if len(os.Args) < 1 {
		fmt.Println("\nNot enough arguments passed")
		os.Exit(1)
	}
	if len(os.Args) > 2 {
		fmt.Println("\nToo many arguments passed")
		os.Exit(1)
	}

	levelBolt := os.Args[1]

	if levelBolt != level && levelBolt != bolt {
		fmt.Println("\nFirst argument should be `level` or `bolt`")
		os.Exit(1)
	}

	chainID := ""
	if len(os.Args) == 3 {
		chainID = os.Args[2]
	}

	be := new(BlockExtractor)

	state := new(state.State)
	state.Cfg = util.ReadConfig("")
	if levelBolt == level {
		err := state.InitLevelDB()
		if err != nil {
			panic(err)
		}
	}
	if levelBolt == bolt {
		err := state.InitBoltDB()
		if err != nil {
			panic(err)
		}
	}
	dbo := state.GetAndLockDB()
	defer state.UnlockDB()

	if chainID != "" {
		err := be.ExportEChain(chainID, dbo)
		if err != nil {
			panic(err)
		}
	} else {
		err := be.ExportDChain(dbo)
		if err != nil {
			panic(err)
		}
		err = be.ExportECChain(dbo)
		if err != nil {
			panic(err)
		}
		err = be.ExportAChain(dbo)
		if err != nil {
			panic(err)
		}
		err = be.ExportFctChain(dbo)
		if err != nil {
			panic(err)
		}
		err = be.ExportDirBlockInfo(dbo)
		if err != nil {
			panic(err)
		}
	}
}
Exemple #3
0
func searchDB(searchitem string, st state.State) (bool, string) {
	if len(searchitem) < 32 {
		heightInt, err := strconv.Atoi(searchitem)
		if err != nil {
			return false, ""
		}
		height := uint32(heightInt)
		if height < DisplayState.CurrentNodeHeight {
			dbase := StatePointer.GetAndLockDB()
			dBlock, err := dbase.FetchDBlockByHeight(height)
			StatePointer.UnlockDB()
			if err != nil {
				return false, ""
			}
			resp := `{"Type":"dblockHeight","item":"` + dBlock.GetKeyMR().String() + `"}`
			return true, resp
		}
		return false, ""
	}
	switch searchitem[:2] {
	case "EC":
		hash := base58.Decode(searchitem)
		if len(hash) < 34 {
			return false, ""
		}
		var fixed [32]byte
		copy(fixed[:], hash[2:34])
		bal := fmt.Sprintf("%d", st.FactoidState.GetECBalance(fixed))
		return true, `{"Type":"EC","item":` + bal + "}"
	case "FA":
		hash := base58.Decode(searchitem)
		if len(hash) < 34 {
			return false, ""
		}
		var fixed [32]byte
		copy(fixed[:], hash[2:34])
		bal := fmt.Sprintf("%.8f", float64(st.FactoidState.GetFactoidBalance(fixed))/1e8)
		return true, `{"Type":"FA","item":` + bal + "}"
	}
	if len(searchitem) == 64 {
		hash, err := primitives.HexToHash(searchitem)
		if err != nil {
			return false, ""
		}

		// Must unlock manually when returining. Function continues to wsapi, who needs the dbase
		dbase := st.GetAndLockDB()

		// Search for Entry
		if entry, err := dbase.FetchEntry(hash); err == nil && entry != nil {
			resp := newSearchResponse("entry", entry)
			if len(resp) > 1 {
				st.UnlockDB()
				return true, resp
			}
		}
		// Search for Chain
		if mr, err := dbase.FetchHeadIndexByChainID(hash); err == nil && mr != nil {
			resp := newSearchResponse("chainhead", mr)
			if len(resp) > 1 {
				st.UnlockDB()
				return true, resp
			}
		}
		// Search for EBlock
		if eBlock, err := dbase.FetchEBlockByPrimary(hash); err == nil && eBlock != nil {
			resp := newSearchResponse("eblock", eBlock)
			if len(resp) > 1 {
				st.UnlockDB()
				return true, resp
			}
		}
		// Search for DBlock
		if dBlock, err := dbase.FetchDBlockByPrimary(hash); err == nil && dBlock != nil {
			resp := newSearchResponse("dblock", dBlock)
			if len(resp) > 1 {
				st.UnlockDB()
				return true, resp
			}
		}
		// Search for ABlock
		if aBlock, err := dbase.FetchABlock(hash); err == nil && aBlock != nil {
			resp := newSearchResponse("ablock", aBlock)
			if len(resp) > 1 {
				st.UnlockDB()
				return true, resp
			}
		}
		// Search for Factoid Block
		if fBlock, err := dbase.FetchFBlock(hash); err == nil && fBlock != nil {
			resp := newSearchResponse("fblock", fBlock)
			if len(resp) > 1 {
				st.UnlockDB()
				return true, resp
			}
		}
		// Search for Entry Credit Block
		if ecBlock, err := dbase.FetchECBlock(hash); err == nil && ecBlock != nil {
			resp := newSearchResponse("ecblock", ecBlock)
			if len(resp) > 1 {
				st.UnlockDB()
				return true, resp
			}
		}

		// Search for Factoid Transaction
		if trans, err := dbase.FetchFactoidTransaction(hash); err == nil && trans != nil {
			resp := newSearchResponse("facttransaction", trans)
			if len(resp) > 1 {
				st.UnlockDB()
				return true, resp
			}
		}

		// Search for Entry Credit Transaction
		if trans, err := dbase.FetchECTransaction(hash); err == nil && trans != nil {
			resp := newSearchResponse("ectransaction", trans)
			if len(resp) > 1 {
				st.UnlockDB()
				return true, resp
			}
		}

		st.UnlockDB()

		// Search for Entry Transaction
		ackReq := new(wsapi.AckRequest)
		ackReq.TxID = hash.String()
		if entryAck, err := wsapi.HandleV2EntryACK(&st, ackReq); err == nil && entryAck != nil && len(entryAck.(*wsapi.EntryStatus).EntryHash) == 64 {
			resp := newSearchResponse("entryack", nil)
			if len(resp) > 1 {
				return true, resp
			}
		}

		// Search for Factoid Transaction
		ackReq = new(wsapi.AckRequest)
		ackReq.TxID = hash.String()
		if factoidAck, err := wsapi.HandleV2FactoidACK(&st, ackReq); err == nil && factoidAck != nil && factoidAck.(*wsapi.FactoidTxStatus).BlockDate > 0 {
			resp := newSearchResponse("factoidack", nil)
			if len(resp) > 1 {
				return true, resp
			}
		}

	}

	return false, ""
}