diff --git a/client/cmd/eris-client.go b/client/cmd/eris-client.go index b5082860789f729a0c0a0fa0f2fda7c928df8038..0c7585230a93199ff8d06b68039404340a21c38e 100644 --- a/client/cmd/eris-client.go +++ b/client/cmd/eris-client.go @@ -60,11 +60,8 @@ func AddGlobalFlags() { } func AddClientCommands() { - buildTransactionCommand() - ErisClientCmd.AddCommand(TransactionCmd) - - buildStatusCommand() - ErisClientCmd.AddCommand(StatusCmd) + ErisClientCmd.AddCommand(buildTransactionCommand()) + ErisClientCmd.AddCommand(buildStatusCommand()) } //------------------------------------------------------------------------------ diff --git a/client/cmd/status.go b/client/cmd/status.go index 5b29803d848fba681b028bcc0cae3cf969853968..45e8096285b9b031062988bd8255d240e25ec834 100644 --- a/client/cmd/status.go +++ b/client/cmd/status.go @@ -22,22 +22,18 @@ import ( "github.com/eris-ltd/eris-db/client/methods" ) -var StatusCmd = &cobra.Command{ - Use: "status", - Short: "eris-client status returns the current status from a chain.", - Long: `eris-client status returns the current status from a chain. -`, - Run: func(cmd *cobra.Command, args []string) { - methods.Status(clientDo) - }, -} - -func buildStatusCommand() { - addStatusPersistentFlags() -} -func addStatusPersistentFlags() { - StatusCmd.PersistentFlags().StringVarP(&clientDo.NodeAddrFlag, "node-addr", "", defaultNodeRpcAddress(), "set the eris-db node rpc server address (default respects $ERIS_CLIENT_NODE_ADDRESS)") +func buildStatusCommand() *cobra.Command{ + statusCmd := &cobra.Command{ + Use: "status", + Short: "eris-client status returns the current status from a chain.", + Long: `eris-client status returns the current status from a chain. +`, + Run: func(cmd *cobra.Command, args []string) { + methods.Status(clientDo) + }, + } + statusCmd.PersistentFlags().StringVarP(&clientDo.NodeAddrFlag, "node-addr", "", defaultNodeRpcAddress(), "set the eris-db node rpc server address (default respects $ERIS_CLIENT_NODE_ADDRESS)") // TransactionCmd.PersistentFlags().StringVarP(&clientDo.PubkeyFlag, "pubkey", "", defaultPublicKey(), "specify the public key to sign with (defaults to $ERIS_CLIENT_PUBLIC_KEY)") // TransactionCmd.PersistentFlags().StringVarP(&clientDo.AddrFlag, "addr", "", defaultAddress(), "specify the account address (for which the public key can be found at eris-keys) (default respects $ERIS_CLIENT_ADDRESS)") // TransactionCmd.PersistentFlags().StringVarP(&clientDo.ChainidFlag, "chain-id", "", defaultChainId(), "specify the chainID (default respects $CHAIN_ID)") @@ -46,4 +42,7 @@ func addStatusPersistentFlags() { // // TransactionCmd.PersistentFlags().BoolVarP(&clientDo.SignFlag, "sign", "s", false, "sign the transaction using the eris-keys daemon") // TransactionCmd.PersistentFlags().BoolVarP(&clientDo.BroadcastFlag, "broadcast", "b", true, "broadcast the transaction to the blockchain") // TransactionCmd.PersistentFlags().BoolVarP(&clientDo.WaitFlag, "wait", "w", false, "wait for the transaction to be committed in a block") + + return statusCmd } + diff --git a/client/cmd/transaction.go b/client/cmd/transaction.go index 87a3e10c5ee99aeb84a97062280d98c4047d0016..1f5dd379c3215e109ebfcde4950346d104d41b7a 100644 --- a/client/cmd/transaction.go +++ b/client/cmd/transaction.go @@ -27,22 +27,22 @@ import ( "github.com/eris-ltd/eris-db/client/transaction" ) -var TransactionCmd = &cobra.Command{ - Use: "tx", - Short: "eris-client tx formulates and signs a transaction to a chain", - Long: `eris-client tx formulates and signs a transaction to a chain. -`, - Run: func(cmd *cobra.Command, args []string) { cmd.Help() }, -} -func buildTransactionCommand() { +func buildTransactionCommand() *cobra.Command { // Transaction command has subcommands send, name, call, bond, // unbond, rebond, permissions. Dupeout transaction is not accessible through the command line. + transactionCmd := &cobra.Command{ + Use: "tx", + Short: "eris-client tx formulates and signs a transaction to a chain", + Long: `eris-client tx formulates and signs a transaction to a chain. +`, + Run: func(cmd *cobra.Command, args []string) { cmd.Help() }, + } - addTransactionPersistentFlags() + addTransactionPersistentFlags(transactionCmd) // SendTx - var sendCmd = &cobra.Command{ + sendCmd := &cobra.Command{ Use: "send", Short: "eris-client tx send --amt <amt> --to <addr>", Long: "eris-client tx send --amt <amt> --to <addr>", @@ -55,7 +55,7 @@ func buildTransactionCommand() { sendCmd.Flags().StringVarP(&clientDo.ToFlag, "to", "t", "", "specify an address to send to") // NameTx - var nameCmd = &cobra.Command{ + nameCmd := &cobra.Command{ Use: "name", Short: "eris-client tx name --amt <amt> --name <name> --data <data>", Long: "eris-client tx name --amt <amt> --name <name> --data <data>", @@ -71,7 +71,7 @@ func buildTransactionCommand() { nameCmd.Flags().StringVarP(&clientDo.FeeFlag, "fee", "f", "", "specify the fee to send") // CallTx - var callCmd = &cobra.Command{ + callCmd := &cobra.Command{ Use: "call", Short: "eris-client tx call --amt <amt> --fee <fee> --gas <gas> --to <contract addr> --data <data>", Long: "eris-client tx call --amt <amt> --fee <fee> --gas <gas> --to <contract addr> --data <data>", @@ -87,7 +87,7 @@ func buildTransactionCommand() { callCmd.Flags().StringVarP(&clientDo.GasFlag, "gas", "g", "", "specify the gas limit for a CallTx") // BondTx - var bondCmd = &cobra.Command{ + bondCmd := &cobra.Command{ Use: "bond", Short: "eris-client tx bond --pubkey <pubkey> --amt <amt> --unbond-to <address>", Long: "eris-client tx bond --pubkey <pubkey> --amt <amt> --unbond-to <address>", @@ -100,7 +100,7 @@ func buildTransactionCommand() { bondCmd.Flags().StringVarP(&clientDo.UnbondtoFlag, "to", "t", "", "specify an address to unbond to") // UnbondTx - var unbondCmd = &cobra.Command{ + unbondCmd := &cobra.Command{ Use: "unbond", Short: "eris-client tx unbond --addr <address> --height <block_height>", Long: "eris-client tx unbond --addr <address> --height <block_height>", @@ -126,7 +126,7 @@ func buildTransactionCommand() { rebondCmd.Flags().StringVarP(&clientDo.HeightFlag, "height", "n", "", "specify a height to unbond at") // PermissionsTx - var permissionsCmd = &cobra.Command{ + permissionsCmd := &cobra.Command{ Use: "permission", Short: "eris-client tx perm <function name> <args ...>", Long: "eris-client tx perm <function name> <args ...>", @@ -136,20 +136,21 @@ func buildTransactionCommand() { PreRun: assertParameters, } - TransactionCmd.AddCommand(sendCmd, nameCmd, callCmd, bondCmd, unbondCmd, rebondCmd, permissionsCmd) + transactionCmd.AddCommand(sendCmd, nameCmd, callCmd, bondCmd, unbondCmd, rebondCmd, permissionsCmd) + return transactionCmd } -func addTransactionPersistentFlags() { - TransactionCmd.PersistentFlags().StringVarP(&clientDo.SignAddrFlag, "sign-addr", "", defaultKeyDaemonAddress(), "set eris-keys daemon address (default respects $ERIS_CLIENT_SIGN_ADDRESS)") - TransactionCmd.PersistentFlags().StringVarP(&clientDo.NodeAddrFlag, "node-addr", "", defaultNodeRpcAddress(), "set the eris-db node rpc server address (default respects $ERIS_CLIENT_NODE_ADDRESS)") - TransactionCmd.PersistentFlags().StringVarP(&clientDo.PubkeyFlag, "pubkey", "", defaultPublicKey(), "specify the public key to sign with (defaults to $ERIS_CLIENT_PUBLIC_KEY)") - TransactionCmd.PersistentFlags().StringVarP(&clientDo.AddrFlag, "addr", "", defaultAddress(), "specify the account address (for which the public key can be found at eris-keys) (default respects $ERIS_CLIENT_ADDRESS)") - TransactionCmd.PersistentFlags().StringVarP(&clientDo.ChainidFlag, "chain-id", "", defaultChainId(), "specify the chainID (default respects $CHAIN_ID)") - TransactionCmd.PersistentFlags().StringVarP(&clientDo.NonceFlag, "nonce", "", "", "specify the nonce to use for the transaction (should equal the sender account's nonce + 1)") - - // TransactionCmd.PersistentFlags().BoolVarP(&clientDo.SignFlag, "sign", "s", false, "sign the transaction using the eris-keys daemon") - TransactionCmd.PersistentFlags().BoolVarP(&clientDo.BroadcastFlag, "broadcast", "b", true, "broadcast the transaction to the blockchain") - TransactionCmd.PersistentFlags().BoolVarP(&clientDo.WaitFlag, "wait", "w", true, "wait for the transaction to be committed in a block") +func addTransactionPersistentFlags(transactionCmd *cobra.Command) { + transactionCmd.PersistentFlags().StringVarP(&clientDo.SignAddrFlag, "sign-addr", "", defaultKeyDaemonAddress(), "set eris-keys daemon address (default respects $ERIS_CLIENT_SIGN_ADDRESS)") + transactionCmd.PersistentFlags().StringVarP(&clientDo.NodeAddrFlag, "node-addr", "", defaultNodeRpcAddress(), "set the eris-db node rpc server address (default respects $ERIS_CLIENT_NODE_ADDRESS)") + transactionCmd.PersistentFlags().StringVarP(&clientDo.PubkeyFlag, "pubkey", "", defaultPublicKey(), "specify the public key to sign with (defaults to $ERIS_CLIENT_PUBLIC_KEY)") + transactionCmd.PersistentFlags().StringVarP(&clientDo.AddrFlag, "addr", "", defaultAddress(), "specify the account address (for which the public key can be found at eris-keys) (default respects $ERIS_CLIENT_ADDRESS)") + transactionCmd.PersistentFlags().StringVarP(&clientDo.ChainidFlag, "chain-id", "", defaultChainId(), "specify the chainID (default respects $CHAIN_ID)") + transactionCmd.PersistentFlags().StringVarP(&clientDo.NonceFlag, "nonce", "", "", "specify the nonce to use for the transaction (should equal the sender account's nonce + 1)") + + // transactionCmd.PersistentFlags().BoolVarP(&clientDo.SignFlag, "sign", "s", false, "sign the transaction using the eris-keys daemon") + transactionCmd.PersistentFlags().BoolVarP(&clientDo.BroadcastFlag, "broadcast", "b", true, "broadcast the transaction to the blockchain") + transactionCmd.PersistentFlags().BoolVarP(&clientDo.WaitFlag, "wait", "w", true, "wait for the transaction to be committed in a block") } //------------------------------------------------------------------------------ diff --git a/client/core/transaction_factory.go b/client/core/transaction_factory.go index 569e1d8a2cd3fb5131ca42f9c96d4e6a5633a613..0ca51284a12626e3c603768a0381f219c341e068 100644 --- a/client/core/transaction_factory.go +++ b/client/core/transaction_factory.go @@ -31,10 +31,6 @@ import ( "github.com/eris-ltd/eris-db/txs" ) -var ( - MaxCommitWaitTimeSeconds = 20 -) - //------------------------------------------------------------------------------------ // core functions with string args. // validates strings and forms transaction diff --git a/client/transaction/transaction.go b/client/transaction/transaction.go index e9840d244cacff3bb8b88d90d6dd23bf4eb00974..3a589cfe23505e916dca5e21dfd9b8e6ca9b5989 100644 --- a/client/transaction/transaction.go +++ b/client/transaction/transaction.go @@ -26,11 +26,13 @@ import ( "github.com/eris-ltd/eris-db/client/core" "github.com/eris-ltd/eris-db/definitions" "github.com/eris-ltd/eris-db/keys" + "github.com/eris-ltd/eris-db/logging/lifecycle" ) func Send(do *definitions.ClientDo) { // construct two clients to call out to keys server and // blockchain node. + lifecycle.NewLoggerFromLoggingConfig() erisKeyClient := keys.NewErisKeyClient(do.SignAddrFlag) erisNodeClient := client.NewErisNodeClient(do.NodeAddrFlag) // form the send transaction @@ -94,3 +96,11 @@ func unpackSignAndBroadcast(result *core.TxResult, err error) { } log.WithFields(printResult).Warn("Result") } + +func loggerFromClientDo(){ + + loggerConfig, err := core.LoadLoggingConfigFromDo(do) + if err != nil { + return nil, fmt.Errorf("Failed to load logging config: %s", err) + } +} \ No newline at end of file diff --git a/cmd/serve.go b/cmd/serve.go index 2c78c307b18392a907dbda59621b0709e9939ec6..49bc665be308c0a5bbe23deaeba3e7d9f9c97730 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -105,13 +105,13 @@ func NewCoreFromDo(do *definitions.Do) (*core.Core, error) { return nil, fmt.Errorf("Failed to initialise data directory (%s): %v", do.DataDir, err) } - loggerConfig, err := core.LoadLoggingConfig(do) + loggerConfig, err := core.LoadLoggingConfigFromDo(do) if err != nil { return nil, fmt.Errorf("Failed to load logging config: %s", err) } // Create a root logger to pass through to dependencies - logger := logging.WithScope(lifecycle.NewServerLoggerFromConfig(*loggerConfig), "Serve") + logger := logging.WithScope(lifecycle.NewLoggerFromLoggingConfig(*loggerConfig), "Serve") // Capture all logging from tendermint/tendermint and tendermint/go-* // dependencies lifecycle.CaptureTendermintLog15Output(logger) diff --git a/core/config.go b/core/config.go index cb8239ffee07b25c1cc5039cc32a87a7670c8975..f9ffc6be57ea6f69f44158943a3970c391a4743b 100644 --- a/core/config.go +++ b/core/config.go @@ -114,12 +114,16 @@ func LoadServerConfig(do *definitions.Do) (*server.ServerConfig, error) { return serverConfig, err } -func LoadLoggingConfig(do *definitions.Do) (*logging.LoggingConfig, error) { +func LoadLoggingConfigFromDo(do *definitions.Do) (*logging.LoggingConfig, error) { //subConfig, err := SubConfig(conf, "logging") loggingConfig := &logging.LoggingConfig{} return loggingConfig, nil } +func LoadLoggingConfigFromClientDo(do *definitions.ClientDo) (*logging.LoggingConfig, error) { + loggingConfig := &logging.LoggingConfig{} + return loggingConfig, nil +} //------------------------------------------------------------------------------ // Helper functions diff --git a/logging/lifecycle/lifecycle.go b/logging/lifecycle/lifecycle.go index 1a9608fa230b2ae55f535911f3e80f493dc066bc..026c07025942d27e6f8da19f52d4ed57eebf1d26 100644 --- a/logging/lifecycle/lifecycle.go +++ b/logging/lifecycle/lifecycle.go @@ -16,15 +16,8 @@ import ( "time" ) -// Obtain a default eris-client logger from config -func NewClientLoggerFromConfig(LoggingConfig logging.LoggingConfig) loggers.InfoTraceLogger { - infoLogger := kitlog.NewLogfmtLogger(os.Stderr) - traceLogger := kitlog.NewLogfmtLogger(os.Stderr) - return logging.WithMetadata(loggers.NewInfoTraceLogger(infoLogger, traceLogger)) -} - -// Obtain a default eris-server (eris-db serve ...) logger -func NewServerLoggerFromConfig(LoggingConfig logging.LoggingConfig) loggers.InfoTraceLogger { +// Obtain a logger from a LoggingConfig +func NewLoggerFromLoggingConfig(LoggingConfig logging.LoggingConfig) loggers.InfoTraceLogger { infoLogger := kitlog.NewLogfmtLogger(os.Stderr) traceLogger := kitlog.NewLogfmtLogger(os.Stderr) return logging.WithMetadata(loggers.NewInfoTraceLogger(infoLogger, traceLogger))