コード例 #1
0
ファイル: blockmanager.go プロジェクト: jjdevbiz/factomd
// isSyncCandidateFactom returns whether or not the peer is a candidate to consider
// syncing from.
func (b *blockManager) isSyncCandidateFactom(p *peer) bool {
	// Typically a peer is not a candidate for sync if it's not a Factom SERVER node,
	if SERVER_NODE == util.ReadConfig("").App.NodeMode {
		return true
	}
	return true
}
コード例 #2
0
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)
		}
	}
}
コード例 #3
0
ファイル: anchor.go プロジェクト: FactomProject/factomd
func (a *Anchor) readConfig() {
	anchorLog.Info("readConfig")
	a.cfg = util.ReadConfig("")
	a.confirmationsNeeded = a.cfg.Anchor.ConfirmationsNeeded
	a.fee, _ = btcutil.NewAmount(a.cfg.Btc.BtcTransFee)

	var err error
	a.serverPrivKey, err = primitives.NewPrivateKeyFromHex(a.cfg.App.LocalServerPrivKey)
	if err != nil {
		panic("Cannot parse Server Private Key from configuration file: " + err.Error())
	}
	a.serverECKey, err = primitives.NewPrivateKeyFromHex(a.cfg.Anchor.ServerECPrivKey)
	if err != nil {
		panic("Cannot parse Server EC Key from configuration file: " + err.Error())
	}
	a.anchorChainID, err = primitives.HexToHash(a.cfg.Anchor.AnchorChainID)
	anchorLog.Debug("anchorChainID: ", a.anchorChainID)
	if err != nil || a.anchorChainID == nil {
		panic("Cannot parse Server AnchorChainID from configuration file: " + err.Error())
	}
}
コード例 #4
0
ファイル: util.go プロジェクト: jjdevbiz/factomd
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]
	}

	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.GetDB()

	if chainID != "" {
		err := ExportEChain(chainID, dbo)
		if err != nil {
			panic(err)
		}
	} else {
		err := ExportDChain(dbo)
		if err != nil {
			panic(err)
		}
		err = ExportECChain(dbo)
		if err != nil {
			panic(err)
		}
		err = ExportAChain(dbo)
		if err != nil {
			panic(err)
		}
		err = ExportFctChain(dbo)
		if err != nil {
			panic(err)
		}
		err = ExportDirBlockInfo(dbo)
		if err != nil {
			panic(err)
		}
	}
}
コード例 #5
0
ファイル: main.go プロジェクト: FactomProject/factom-cli2
func main() {
	var (
		hflag              = flag.Bool("h", false, "help")
		walletRpcUser      = flag.String("walletuser", "", "Username for API connections to factom-walletd")
		walletRpcPassword  = flag.String("walletpassword", "", "Password for API connections to factom-walletd")
		factomdRpcUser     = flag.String("factomduser", "", "Username for API connections to factomd")
		factomdRpcPassword = flag.String("factomdpassword", "", "Password for API connections to factomd")

		factomdLocation = flag.String("s", "", "IPAddr:port# of factomd API to use to access blockchain (default localhost:8088)")
		walletdLocation = flag.String("w", "", "IPAddr:port# of factom-walletd API to use to create transactions (default localhost:8089)")

		walletTLSflag = flag.Bool("wallettls", false, "Set to true when the wallet API is encrypted")
		walletTLSCert = flag.String("walletcert", "", "This file is the TLS certificate provided by the factom-walletd API. (default ~/.factom/walletAPIpub.cert)")

		factomdTLSflag = flag.Bool("factomdtls", false, "Set to true when the factomd API is encrypted")
		factomdTLSCert = flag.String("factomdcert", "", "This file is the TLS certificate provided by the factomd API. (default ~/.factom/m2/factomdAPIpub.cert)")
	)
	flag.Parse()

	//see if the config file has values which should be used instead of null strings
	filename := util.ConfigFilename() //file name and path to factomd.conf file
	//if the config file doesn't exist, it gives lots of warnings when util.ReadConfig is called.
	//instead of giving warnings, check that the file exists before attempting to read it.
	//if it doesn't exist, silently ignore the file
	if _, err := os.Stat(filename); err == nil {
		cfg := util.ReadConfig(filename)

		if *walletRpcUser == "" {
			if cfg.Walletd.WalletRpcUser != "" {
				//fmt.Printf("using factom-walletd API user and password specified in \"%s\" at WalletRpcUser & WalletRpcPass\n", filename)
				*walletRpcUser = cfg.Walletd.WalletRpcUser
				*walletRpcPassword = cfg.Walletd.WalletRpcPass
			}
		}

		if *factomdRpcUser == "" {
			if cfg.App.FactomdRpcUser != "" {
				//fmt.Printf("using factomd API user and password specified in \"%s\" at FactomdRpcUser & FactomdRpcPass\n", filename)
				*factomdRpcUser = cfg.App.FactomdRpcUser
				*factomdRpcPassword = cfg.App.FactomdRpcPass
			}
		}

		if *factomdLocation == "" {
			if cfg.Walletd.FactomdLocation != "localhost:8088" {
				//fmt.Printf("using factomd location specified in \"%s\" as FactomdLocation = \"%s\"\n", filename, cfg.Walletd.FactomdLocation)
				*factomdLocation = cfg.Walletd.FactomdLocation
			}
		}

		if *walletdLocation == "" {
			if cfg.Walletd.WalletdLocation != "localhost:8089" {
				//fmt.Printf("using factom-walletd location specified in \"%s\" as WalletdLocation = \"%s\"\n", filename, cfg.Walletd.WalletdLocation)
				*walletdLocation = cfg.Walletd.WalletdLocation
			}
		}

		if cfg.Walletd.WalletTlsEnabled == true { //if a config file is found, and the wallet will start with TLS, factom-cli should use TLS too
			*walletTLSflag = true
		}

		if *walletTLSCert == "" { //if specified on the command line, don't use the config file
			if cfg.Walletd.WalletTlsPublicCert != "/full/path/to/walletAPIpub.cert" { //otherwise check if the the config file has something new
				//fmt.Printf("using wallet TLS certificate file specified in \"%s\" at WalletTlsPublicCert = \"%s\"\n", filename, cfg.Walletd.WalletTlsPublicCert)
				*walletTLSCert = cfg.Walletd.WalletTlsPublicCert
			}
		}

		if cfg.App.FactomdTlsEnabled == true { //if a config file is found, and the factomd will start with TLS, factom-cli should use TLS too
			*factomdTLSflag = true
		}

		if *factomdTLSCert == "" { //if specified on the command line, don't use the config file
			if cfg.App.FactomdTlsPublicCert != "/full/path/to/factomdAPIpub.cert" { //otherwise check if the the config file has something new
				//fmt.Printf("using wallet TLS certificate file specified in \"%s\" at FactomdTlsPublicCert = \"%s\"\n", filename, cfg.App.FactomdTlsPublicCert)
				*factomdTLSCert = cfg.App.FactomdTlsPublicCert
			}
		}
	}

	if *walletTLSCert == "" { //if all defaults were specified on both the command line and config file
		*walletTLSCert = fmt.Sprint(util.GetHomeDir(), "/.factom/walletAPIpub.cert")
		//fmt.Printf("using default wallet TLS certificate file \"%s\"\n", *walletTLSCert)
	}
	if *factomdTLSCert == "" { //if all defaults were specified on both the command line and config file
		*factomdTLSCert = fmt.Sprint(util.GetHomeDir(), "/.factom/m2/factomdAPIpub.cert")
		//fmt.Printf("using default factomd TLS certificate file \"%s\"\n", *factomdTLSCert)
	}

	if *factomdLocation == "" { //set the default if a config file doesn't exist
		*factomdLocation = "localhost:8088"
	}
	if *walletdLocation == "" { //set the default if a config file doesn't exist
		*walletdLocation = "localhost:8089"
	}

	args := flag.Args()

	if *hflag {
		args = []string{"help"}
	}
	factom.SetFactomdServer(*factomdLocation)
	factom.SetWalletServer(*walletdLocation)
	factom.SetFactomdRpcConfig(*factomdRpcUser, *factomdRpcPassword)
	factom.SetWalletRpcConfig(*walletRpcUser, *walletRpcPassword)
	factom.SetWalletEncryption(*walletTLSflag, *walletTLSCert)
	factom.SetFactomdEncryption(*factomdTLSflag, *factomdTLSCert)
	c := cli.New()
	c.Handle("help", help)
	c.Handle("ack", ack)
	c.Handle("addchain", addchain)
	c.Handle("addentry", addentry)
	c.Handle("backupwallet", backupwallet)
	c.Handle("balance", balance)
	c.Handle("composechain", composechain)
	c.Handle("composeentry", composeentry)
	c.Handle("ecrate", ecrate)
	c.Handle("exportaddresses", exportaddresses)
	c.Handle("get", get)
	c.Handle("importaddress", importaddresses)
	c.Handle("importwords", importwords)
	c.Handle("listaddresses", listaddresses)
	c.Handle("newecaddress", newecaddress)
	c.Handle("newfctaddress", newfctaddress)
	c.Handle("properties", properties)
	c.Handle("receipt", receipt)
	c.Handle("backupwallet", backupwallet)

	// transaction commands
	c.Handle("newtx", newtx)
	c.Handle("rmtx", rmtx)
	c.Handle("listtxs", listtxs)
	c.Handle("addtxinput", addtxinput)
	c.Handle("addtxoutput", addtxoutput)
	c.Handle("addtxecoutput", addtxecoutput)
	c.Handle("addtxfee", addtxfee)
	c.Handle("subtxfee", subtxfee)
	c.Handle("signtx", signtx)
	c.Handle("composetx", composetx)
	c.Handle("sendtx", sendtx)
	c.Handle("sendfct", sendfct)
	c.Handle("buyec", buyec)

	c.HandleDefault(help)
	c.Execute(args)
}
コード例 #6
0
ファイル: log.go プロジェクト: FactomProject/factomd
// Copyright 2015 FactomProject Authors. All rights reserved.
// Use of this source code is governed by the MIT license
// that can be found in the LICENSE file.

package anchor

import (
	"os"
	"strings"

	"github.com/FactomProject/factomd/logger"
	"github.com/FactomProject/factomd/util"
)

var (
	cfg        = util.ReadConfig("")
	homedir    = cfg.App.HomeDir
	network    = strings.ToLower(cfg.App.Network) + "-"
	logPath    = cfg.Log.LogPath
	logLevel   = cfg.Log.LogLevel
	logfile, _ = os.OpenFile(homedir+network+logPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0660)
)

// setup subsystem loggers
var (
	anchorLog = logger.New(logfile, logLevel, "ANCH")
)
コード例 #7
0
ファイル: state.go プロジェクト: jjdevbiz/factomd
// ReadCfg forces a read of the factom config file.  However, it does not change the
// state of any cfg object held by other processes... Only what will be returned by
// future calls to Cfg().(s.Cfg.(*util.FactomdConfig)).String()
func (s *State) ReadCfg(filename string) interfaces.IFactomConfig {
	s.Cfg = util.ReadConfig(filename)
	return s.Cfg
}
コード例 #8
0
ファイル: log.go プロジェクト: jjdevbiz/factomd
// Copyright 2015 FactomProject Authors. All rights reserved.
// Use of this source code is governed by the MIT license
// that can be found in the LICENSE file.

package anchor

import (
	"os"

	"github.com/FactomProject/factomd/logger"
	"github.com/FactomProject/factomd/util"
)

var (
	logcfg     = util.ReadConfig("").Log
	logPath    = logcfg.LogPath
	logLevel   = logcfg.LogLevel
	logfile, _ = os.OpenFile(logPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0660)
)

// setup subsystem loggers
var (
	anchorLog = logger.New(logfile, logLevel, "ANCH")
)
コード例 #9
0
ファイル: porter.go プロジェクト: FactomProject/factomd
func main() {
	fmt.Println("DatabasePorter")

	cfg = util.ReadConfig("")

	if dbo != nil {
		dbo.Close()
	}
	switch cfg.App.DBType {
	case "Bolt":
		dbo = InitBolt(cfg)
		break
	case "LDB":
		dbo = InitLevelDB(cfg)
		break
	default:
		dbo = InitMapDB(cfg)
		break
	}

	dbHead, err := dbo.FetchDirectoryBlockHead()
	if err != nil {
		panic(err)
	}

	c := make(chan []interfaces.IDirectoryBlock, 5)
	done := make(chan int, 100)

	go SaveBlocksLoop(c, done)
	go PrintoutLoop()
	doPrint = true

	savedBatches := 0
	for _, keymr := range GetDBlockList() {
		endKeyMR := "0000000000000000000000000000000000000000000000000000000000000000"
		startIndex := 0
		if dbHead != nil {
			endKeyMR = dbHead.GetHeader().GetPrevKeyMR().String()
			//fmt.Printf("Local DB Head - %v - %v\n", dbHead.GetDatabaseHeight(), endKeyMR)
			startIndex = int(dbHead.GetDatabaseHeight())

			printout.FetchingUntil = dbHead.GetDatabaseHeight()
		}

		if keymr == endKeyMR {
			continue
		}

		dBlock, err := GetDBlock(keymr)
		if err != nil {
			panic(err)
		}
		if dbHead != nil {
			if dbHead.GetDatabaseHeight() > dBlock.GetDatabaseHeight() {
				continue
			}
		}

		if dBlock == nil {
			panic("dblock head not found")
		}
		nextHead := dBlock

		dBlockList := make([]interfaces.IDirectoryBlock, int(dBlock.GetDatabaseHeight())+1)
		dBlockList[int(dBlock.GetDatabaseHeight())] = dBlock

		//fmt.Printf("\t\tFetching DBlocks\n")
		for {
			keymr = dBlock.GetHeader().GetPrevKeyMR().String()
			if keymr == endKeyMR {
				break
			}
			dBlock, err = GetDBlock(keymr)
			if err != nil {
				panic(err)
			}
			if dBlock == nil {
				panic("dblock " + keymr + " not found")
			}

			if dbHead != nil {
				if dbHead.GetDatabaseHeight() > dBlock.GetDatabaseHeight() {
					continue
				}
			}
			dBlockList[int(dBlock.GetDatabaseHeight())] = dBlock
			printout.FetchedBlock = dBlock.GetDatabaseHeight()
			//fmt.Printf("Fetched dblock %v\n", dBlock.GetDatabaseHeight())
		}

		dBlockList = dBlockList[startIndex:]
		c <- dBlockList
		savedBatches++

		dbHead = nextHead
	}

	for i := 0; i < savedBatches; i++ {
		<-done
	}
	doPrint = false
	time.Sleep(time.Second)

	if dbo != nil {
		dbo.Close()
	}
	switch cfg.App.DBType {
	case "Bolt":
		dbo = InitBolt(cfg)
		break
	case "LDB":
		dbo = InitLevelDB(cfg)
		break
	default:
		dbo = InitMapDB(cfg)
		break
	}

	CheckDatabaseForMissingEntries(dbo)

	if dbo != nil {
		dbo.Close()
	}
	switch cfg.App.DBType {
	case "Bolt":
		dbo = InitBolt(cfg)
		break
	case "LDB":
		dbo = InitLevelDB(cfg)
		break
	default:
		dbo = InitMapDB(cfg)
		break
	}

	fmt.Printf("\t\tRebulding DirBlockInfo\n")
	err = dbo.RebuildDirBlockInfo()
	if err != nil {
		panic(err)
	}

	dbo.Close()
}