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..f2dc52e6eebd8821eed601b1b69df000df0a2b4c 100644 --- a/client/cmd/transaction.go +++ b/client/cmd/transaction.go @@ -24,30 +24,29 @@ import ( log "github.com/eris-ltd/eris-logger" - "github.com/eris-ltd/eris-db/client/transaction" + "github.com/eris-ltd/eris-db/client/methods" ) -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>", Run: func(cmd *cobra.Command, args []string) { - transaction.Send(clientDo) + methods.Send(clientDo) }, PreRun: assertParameters, } @@ -55,7 +54,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,12 +70,12 @@ 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>", Run: func(cmd *cobra.Command, args []string) { - transaction.Call(clientDo) + methods.Call(clientDo) }, PreRun: assertParameters, } @@ -87,7 +86,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 +99,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 +125,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 +135,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/methods/call.go b/client/methods/call.go new file mode 100644 index 0000000000000000000000000000000000000000..abe2fe91a28dc927bf5714e4caa63bc4d0e8c3fb --- /dev/null +++ b/client/methods/call.go @@ -0,0 +1,47 @@ +// Copyright 2015, 2016 Eris Industries (UK) Ltd. +// This file is part of Eris-RT + +// Eris-RT is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Eris-RT is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. + +package methods + +import ( + log "github.com/eris-ltd/eris-logger" + + "github.com/eris-ltd/eris-db/client" + "github.com/eris-ltd/eris-db/client/rpc" + "github.com/eris-ltd/eris-db/definitions" + "github.com/eris-ltd/eris-db/keys" +) + +func Call(do *definitions.ClientDo) { + // construct two clients to call out to keys server and + // blockchain node. + erisKeyClient := keys.NewErisKeyClient(do.SignAddrFlag) + erisNodeClient := client.NewErisNodeClient(do.NodeAddrFlag) + // form the call transaction + callTransaction, err := rpc.Call(erisNodeClient, erisKeyClient, + do.PubkeyFlag, do.AddrFlag, do.ToFlag, do.AmtFlag, do.NonceFlag, + do.GasFlag, do.FeeFlag, do.DataFlag) + if err != nil { + log.Fatalf("Failed on forming Call Transaction: %s", err) + return + } + // TODO: [ben] we carry over the sign bool, but always set it to true, + // as we move away from and deprecate the api that allows sending unsigned + // transactions and relying on (our) receiving node to sign it. + unpackSignAndBroadcast( + rpc.SignAndBroadcast(do.ChainidFlag, erisNodeClient, + erisKeyClient, callTransaction, true, do.BroadcastFlag, do.WaitFlag)) +} diff --git a/client/methods/helpers.go b/client/methods/helpers.go new file mode 100644 index 0000000000000000000000000000000000000000..93c34ee51b25a2e227d08894f480f340ffb0d2a3 --- /dev/null +++ b/client/methods/helpers.go @@ -0,0 +1,49 @@ +// Copyright 2015, 2016 Eris Industries (UK) Ltd. +// This file is part of Eris-RT + +// Eris-RT is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Eris-RT is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. + +package methods + +import ( + "fmt" + "os" + + log "github.com/eris-ltd/eris-logger" + + "github.com/eris-ltd/eris-db/client/rpc" +) + +func unpackSignAndBroadcast(result *rpc.TxResult, err error) { + if err != nil { + log.Fatalf("Failed on signing (and broadcasting) transaction: %s", err) + os.Exit(1) + } + if result == nil { + // if we don't provide --sign or --broadcast + return + } + printResult := log.Fields{ + "transaction hash": fmt.Sprintf("%X", result.Hash), + } + if result.Address != nil { + printResult["Contract Address"] = fmt.Sprintf("%X", result.Address) + } + if result.Return != nil { + printResult["Block Hash"] = fmt.Sprintf("%X", result.BlockHash) + printResult["Return Value"] = fmt.Sprintf("%X", result.Return) + printResult["Exception"] = fmt.Sprintf("%s", result.Exception) + } + log.WithFields(printResult).Warn("Result") +} diff --git a/client/methods/send.go b/client/methods/send.go new file mode 100644 index 0000000000000000000000000000000000000000..af393e029f454e43a953aeae759c45575fd8c6ec --- /dev/null +++ b/client/methods/send.go @@ -0,0 +1,46 @@ +// Copyright 2015, 2016 Eris Industries (UK) Ltd. +// This file is part of Eris-RT + +// Eris-RT is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Eris-RT is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. + +package methods + +import ( + log "github.com/eris-ltd/eris-logger" + + "github.com/eris-ltd/eris-db/client" + "github.com/eris-ltd/eris-db/client/rpc" + "github.com/eris-ltd/eris-db/definitions" + "github.com/eris-ltd/eris-db/keys" +) + +func Send(do *definitions.ClientDo) { + // construct two clients to call out to keys server and + // blockchain node. + erisKeyClient := keys.NewErisKeyClient(do.SignAddrFlag) + erisNodeClient := client.NewErisNodeClient(do.NodeAddrFlag) + // form the send transaction + sendTransaction, err := rpc.Send(erisNodeClient, erisKeyClient, + do.PubkeyFlag, do.AddrFlag, do.ToFlag, do.AmtFlag, do.NonceFlag) + if err != nil { + log.Fatalf("Failed on forming Send Transaction: %s", err) + return + } + // TODO: [ben] we carry over the sign bool, but always set it to true, + // as we move away from and deprecate the api that allows sending unsigned + // transactions and relying on (our) receiving node to sign it. + unpackSignAndBroadcast( + rpc.SignAndBroadcast(do.ChainidFlag, erisNodeClient, + erisKeyClient, sendTransaction, true, do.BroadcastFlag, do.WaitFlag)) +} diff --git a/client/client.go b/client/node_client.go similarity index 100% rename from client/client.go rename to client/node_client.go diff --git a/client/core/transaction_factory.go b/client/rpc/client.go similarity index 99% rename from client/core/transaction_factory.go rename to client/rpc/client.go index 569e1d8a2cd3fb5131ca42f9c96d4e6a5633a613..b82527ef72e961c05ce876034ed6863f9088495b 100644 --- a/client/core/transaction_factory.go +++ b/client/rpc/client.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. -package core +package rpc import ( "encoding/hex" @@ -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/core/transaction_factory_test.go b/client/rpc/client_test.go similarity index 91% rename from client/core/transaction_factory_test.go rename to client/rpc/client_test.go index 4544655e1d045332e07678a772b09a1c267b155b..6541bd3f9f3b92b29a3c1c231669afde4350a0a2 100644 --- a/client/core/transaction_factory_test.go +++ b/client/rpc/client_test.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. -package core +package rpc import ( "fmt" @@ -26,19 +26,19 @@ import ( mockkeys "github.com/eris-ltd/eris-db/keys/mock" ) -func TestTransactionFactory(t *testing.T) { +func Test(t *testing.T) { mockKeyClient := mockkeys.NewMockKeyClient() mockNodeClient := mockclient.NewMockNodeClient() - testTransactionFactorySend(t, mockNodeClient, mockKeyClient) - testTransactionFactoryCall(t, mockNodeClient, mockKeyClient) - testTransactionFactoryName(t, mockNodeClient, mockKeyClient) - testTransactionFactoryPermissions(t, mockNodeClient, mockKeyClient) + testSend(t, mockNodeClient, mockKeyClient) + testCall(t, mockNodeClient, mockKeyClient) + testName(t, mockNodeClient, mockKeyClient) + testPermissions(t, mockNodeClient, mockKeyClient) // t.Run("BondTransaction", ) // t.Run("UnbondTransaction", ) // t.Run("RebondTransaction", ) } -func testTransactionFactorySend(t *testing.T, +func testSend(t *testing.T, nodeClient *mockclient.MockNodeClient, keyClient *mockkeys.MockKeyClient) { // generate an ED25519 key and ripemd160 address @@ -66,7 +66,7 @@ func testTransactionFactorySend(t *testing.T, // TODO: test content of Transaction } -func testTransactionFactoryCall(t *testing.T, +func testCall(t *testing.T, nodeClient *mockclient.MockNodeClient, keyClient *mockkeys.MockKeyClient) { // generate an ED25519 key and ripemd160 address @@ -99,7 +99,7 @@ func testTransactionFactoryCall(t *testing.T, // TODO: test content of Transaction } -func testTransactionFactoryName(t *testing.T, +func testName(t *testing.T, nodeClient *mockclient.MockNodeClient, keyClient *mockkeys.MockKeyClient) { // generate an ED25519 key and ripemd160 address @@ -130,7 +130,7 @@ func testTransactionFactoryName(t *testing.T, // TODO: test content of Transaction } -func testTransactionFactoryPermissions(t *testing.T, +func testPermissions(t *testing.T, nodeClient *mockclient.MockNodeClient, keyClient *mockkeys.MockKeyClient) { // generate an ED25519 key and ripemd160 address diff --git a/client/core/transaction_factory_util.go b/client/rpc/client_util.go similarity index 99% rename from client/core/transaction_factory_util.go rename to client/rpc/client_util.go index 3ad64a6ba36ad88ad5c11b6a0d70584285239095..3e995a8acf9a9d28366d7b00aa85013457f733f5 100644 --- a/client/core/transaction_factory_util.go +++ b/client/rpc/client_util.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. -package core +package rpc import ( "encoding/hex" diff --git a/client/transaction/transaction.go b/client/transaction/transaction.go deleted file mode 100644 index e9840d244cacff3bb8b88d90d6dd23bf4eb00974..0000000000000000000000000000000000000000 --- a/client/transaction/transaction.go +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. - -package transaction - -import ( - "fmt" - "os" - - log "github.com/eris-ltd/eris-logger" - - "github.com/eris-ltd/eris-db/client" - "github.com/eris-ltd/eris-db/client/core" - "github.com/eris-ltd/eris-db/definitions" - "github.com/eris-ltd/eris-db/keys" -) - -func Send(do *definitions.ClientDo) { - // construct two clients to call out to keys server and - // blockchain node. - erisKeyClient := keys.NewErisKeyClient(do.SignAddrFlag) - erisNodeClient := client.NewErisNodeClient(do.NodeAddrFlag) - // form the send transaction - sendTransaction, err := core.Send(erisNodeClient, erisKeyClient, - do.PubkeyFlag, do.AddrFlag, do.ToFlag, do.AmtFlag, do.NonceFlag) - if err != nil { - log.Fatalf("Failed on forming Send Transaction: %s", err) - return - } - // TODO: [ben] we carry over the sign bool, but always set it to true, - // as we move away from and deprecate the api that allows sending unsigned - // transactions and relying on (our) receiving node to sign it. - unpackSignAndBroadcast( - core.SignAndBroadcast(do.ChainidFlag, erisNodeClient, - erisKeyClient, sendTransaction, true, do.BroadcastFlag, do.WaitFlag)) -} - -func Call(do *definitions.ClientDo) { - // construct two clients to call out to keys server and - // blockchain node. - erisKeyClient := keys.NewErisKeyClient(do.SignAddrFlag) - erisNodeClient := client.NewErisNodeClient(do.NodeAddrFlag) - // form the call transaction - callTransaction, err := core.Call(erisNodeClient, erisKeyClient, - do.PubkeyFlag, do.AddrFlag, do.ToFlag, do.AmtFlag, do.NonceFlag, - do.GasFlag, do.FeeFlag, do.DataFlag) - if err != nil { - log.Fatalf("Failed on forming Call Transaction: %s", err) - return - } - // TODO: [ben] we carry over the sign bool, but always set it to true, - // as we move away from and deprecate the api that allows sending unsigned - // transactions and relying on (our) receiving node to sign it. - unpackSignAndBroadcast( - core.SignAndBroadcast(do.ChainidFlag, erisNodeClient, - erisKeyClient, callTransaction, true, do.BroadcastFlag, do.WaitFlag)) -} - -//---------------------------------------------------------------------- -// Helper functions - -func unpackSignAndBroadcast(result *core.TxResult, err error) { - if err != nil { - log.Fatalf("Failed on signing (and broadcasting) transaction: %s", err) - os.Exit(1) - } - if result == nil { - // if we don't provide --sign or --broadcast - return - } - printResult := log.Fields{ - "transaction hash": fmt.Sprintf("%X", result.Hash), - } - if result.Address != nil { - printResult["Contract Address"] = fmt.Sprintf("%X", result.Address) - } - if result.Return != nil { - printResult["Block Hash"] = fmt.Sprintf("%X", result.BlockHash) - printResult["Return Value"] = fmt.Sprintf("%X", result.Return) - printResult["Exception"] = fmt.Sprintf("%s", result.Exception) - } - log.WithFields(printResult).Warn("Result") -} 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))