// cleanAndExpandPath expands environement variables and leading ~ in the // passed path, cleans the result, and returns it. func cleanAndExpandPath(path string) string { // Expand initial ~ to OS specific home directory. if strings.HasPrefix(path, "~") { appHomeDir := btcutil.AppDataDir("gencerts", false) homeDir := filepath.Dir(appHomeDir) path = strings.Replace(path, "~", homeDir, 1) } // NOTE: The os.ExpandEnv doesn't work with Windows-style %VARIABLE%, // but they variables can still be expanded via POSIX-style $VARIABLE. return filepath.Clean(os.ExpandEnv(path)) }
func main() { // message is the JSON to be sent to the websocket connection var simnet bool var mainnet bool var port int flag.BoolVar(&simnet, "simnet", false, "connect to simnet") flag.BoolVar(&mainnet, "mainnet", false, "connect to mainnet") flag.IntVar(&port, "port", 18332, "specific port to connect to") flag.Parse() if mainnet { port = 8332 } else if simnet { port = 18554 } arguments := flag.Args() if len(arguments) != 1 { fmt.Println("Usage: websocket <JSON to send to btcwallet websocket server>") return } message := []byte(arguments[0]) // get the root cert for connecting to secure websocket btcwalletHomeDir := btcutil.AppDataDir("btcwallet", false) certs, err := ioutil.ReadFile(filepath.Join(btcwalletHomeDir, "rpc.cert")) if err != nil { log.Fatal(err) } // Setup TLS var tlsConfig *tls.Config pool := x509.NewCertPool() pool.AppendCertsFromPEM(certs) tlsConfig = &tls.Config{ RootCAs: pool, MinVersion: tls.VersionTLS12, } // Create a websocket dialer that will be used to make the connection. dialer := websocket.Dialer{TLSClientConfig: tlsConfig} // The RPC server requires basic authorization, so create a custom // request header with the Authorization header set. login := "******" auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(login)) requestHeader := make(http.Header) requestHeader.Add("Authorization", auth) // Dial the connection. url := fmt.Sprintf("wss://localhost:%v/ws", port) conn, resp, err := dialer.Dial(url, requestHeader) if err != nil { log.Println(resp) log.Fatal(err) } // send message to websocket connection. conn.WriteMessage(websocket.TextMessage, message) for { _, msg, err := conn.ReadMessage() if err != nil { log.Fatal(err) } m := string(msg) log.Println(m) } }
"github.com/monetas/btcdb" _ "github.com/monetas/btcdb/ldb" "github.com/monetas/btcnet" "github.com/monetas/btcutil" "github.com/monetas/btcwire" flags "github.com/monetas/go-flags" ) const ( defaultDbType = "leveldb" defaultDataFile = "bootstrap.dat" defaultProgress = 10 ) var ( btcdHomeDir = btcutil.AppDataDir("btcd", false) defaultDataDir = filepath.Join(btcdHomeDir, "data") knownDbTypes = btcdb.SupportedDBs() activeNetParams = &btcnet.MainNetParams ) // config defines the configuration options for findcheckpoint. // // See loadConfig for details on the configuration load process. type config struct { DataDir string `short:"b" long:"datadir" description:"Location of the btcd data directory"` DbType string `long:"dbtype" description:"Database backend to use for the Block Chain"` TestNet3 bool `long:"testnet" description:"Use the test network"` RegressionTest bool `long:"regtest" description:"Use the regression test network"` SimNet bool `long:"simnet" description:"Use the simulation test network"` InFile string `short:"i" long:"infile" description:"File containing the block(s)"`
package main import ( "fmt" "net" "os" "path/filepath" "strings" "github.com/monetas/btcutil" flags "github.com/monetas/go-flags" ) var ( btcdHomeDir = btcutil.AppDataDir("btcd", false) btcctlHomeDir = btcutil.AppDataDir("btcctl", false) btcwalletHomeDir = btcutil.AppDataDir("btcwallet", false) defaultConfigFile = filepath.Join(btcctlHomeDir, "btcctl.conf") defaultRPCServer = "localhost" defaultRPCCertFile = filepath.Join(btcdHomeDir, "rpc.cert") defaultWalletCertFile = filepath.Join(btcwalletHomeDir, "rpc.cert") ) // config defines the configuration options for btcctl. // // See loadConfig for details on the configuration load process. type config struct { ShowVersion bool `short:"V" long:"version" description:"Display version information and exit"` ConfigFile string `short:"C" long:"configfile" description:"Path to configuration file"` RPCUser string `short:"u" long:"rpcuser" description:"RPC username"` RPCPassword string `short:"P" long:"rpcpass" default-mask:"-" description:"RPC password"`