From 34a9ea561d64e5a835c2da189712afd934be6413 Mon Sep 17 00:00:00 2001
From: Silas Davis <silas@erisindustries.com>
Date: Wed, 18 Jan 2017 10:58:03 +0000
Subject: [PATCH] Small rename/reorg of client package

---
 client/cmd/transaction.go                     |   7 +-
 client/methods/call.go                        |  47 ++++++++
 client/methods/helpers.go                     |  49 ++++++++
 client/methods/send.go                        |  46 ++++++++
 client/{client.go => node_client.go}          |   0
 .../transaction_factory.go => rpc/client.go}  |   2 +-
 .../client_test.go}                           |  20 ++--
 .../client_util.go}                           |   2 +-
 client/transaction/transaction.go             | 106 ------------------
 9 files changed, 157 insertions(+), 122 deletions(-)
 create mode 100644 client/methods/call.go
 create mode 100644 client/methods/helpers.go
 create mode 100644 client/methods/send.go
 rename client/{client.go => node_client.go} (100%)
 rename client/{core/transaction_factory.go => rpc/client.go} (99%)
 rename client/{core/transaction_factory_test.go => rpc/client_test.go} (91%)
 rename client/{core/transaction_factory_util.go => rpc/client_util.go} (99%)
 delete mode 100644 client/transaction/transaction.go

diff --git a/client/cmd/transaction.go b/client/cmd/transaction.go
index 1f5dd379..f2dc52e6 100644
--- a/client/cmd/transaction.go
+++ b/client/cmd/transaction.go
@@ -24,10 +24,9 @@ import (
 
 	log "github.com/eris-ltd/eris-logger"
 
-	"github.com/eris-ltd/eris-db/client/transaction"
+	"github.com/eris-ltd/eris-db/client/methods"
 )
 
-
 func buildTransactionCommand() *cobra.Command {
 	// Transaction command has subcommands send, name, call, bond,
 	// unbond, rebond, permissions. Dupeout transaction is not accessible through the command line.
@@ -47,7 +46,7 @@ func buildTransactionCommand() *cobra.Command {
 		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,
 	}
@@ -76,7 +75,7 @@ func buildTransactionCommand() *cobra.Command {
 		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,
 	}
diff --git a/client/methods/call.go b/client/methods/call.go
new file mode 100644
index 00000000..abe2fe91
--- /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 00000000..93c34ee5
--- /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 00000000..af393e02
--- /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 0ca51284..b82527ef 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"
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 4544655e..6541bd3f 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 3ad64a6b..3e995a8a 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 3a589cfe..00000000
--- a/client/transaction/transaction.go
+++ /dev/null
@@ -1,106 +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"
-	"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
-	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")
-}
-
-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
-- 
GitLab