Move cmd libraries to internal/

This is to stay compliant
https://github.com/golang-standards/project-layout/tree/master/cmd, to
quote which:

“Don't put a lot of code in the application directory. If you think the
code can be imported and used in other projects, then it should live in
the /pkg directory. If the code is not reusable or if you don't want
others to reuse it, put that code in the /internal directory.”
pull/577/head
Eugene Kim 6 years ago
parent 1ee916eaa5
commit 67eac97cde
  1. 2
      cmd/client/txgen/main.go
  2. 14
      cmd/client/wallet/main.go
  3. 0
      internal/txgen/account_txs_generator.go
  4. 2
      internal/wallet/wallet/lib.go
  5. 2
      internal/wallet/wallet/lib_test.go

@ -12,10 +12,10 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/harmony/api/client" "github.com/harmony-one/harmony/api/client"
proto_node "github.com/harmony-one/harmony/api/proto/node" proto_node "github.com/harmony-one/harmony/api/proto/node"
"github.com/harmony-one/harmony/cmd/client/txgen/txgen"
"github.com/harmony-one/harmony/consensus" "github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/harmony-one/harmony/internal/txgen"
"github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/node" "github.com/harmony-one/harmony/node"
"github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p"

@ -19,8 +19,8 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
clientService "github.com/harmony-one/harmony/api/client/service" clientService "github.com/harmony-one/harmony/api/client/service"
"github.com/harmony-one/harmony/cmd/client/wallet/lib"
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/wallet/wallet"
"github.com/harmony-one/harmony/node" "github.com/harmony-one/harmony/node"
) )
@ -172,7 +172,7 @@ func processImportCommnad() {
func processBalancesCommand() { func processBalancesCommand() {
balanceCommand.Parse(os.Args[2:]) balanceCommand.Parse(os.Args[2:])
walletNode := lib.CreateWalletNode() walletNode := wallet.CreateWalletNode()
if *balanceAddressPtr == "" { if *balanceAddressPtr == "" {
for i, address := range ReadAddresses() { for i, address := range ReadAddresses() {
@ -192,7 +192,7 @@ func processBalancesCommand() {
func processGetFreeToken() { func processGetFreeToken() {
freeTokenCommand.Parse(os.Args[2:]) freeTokenCommand.Parse(os.Args[2:])
walletNode := lib.CreateWalletNode() walletNode := wallet.CreateWalletNode()
if *freeTokenAddressPtr == "" { if *freeTokenAddressPtr == "" {
fmt.Println("Error: --address is required") fmt.Println("Error: --address is required")
@ -256,7 +256,7 @@ func processTransferCommand() {
// Generate transaction // Generate transaction
senderPriKey := priKeys[senderIndex] senderPriKey := priKeys[senderIndex]
senderAddress := addresses[senderIndex] senderAddress := addresses[senderIndex]
walletNode := lib.CreateWalletNode() walletNode := wallet.CreateWalletNode()
shardIDToAccountState := FetchBalance(senderAddress, walletNode) shardIDToAccountState := FetchBalance(senderAddress, walletNode)
state, ok := shardIDToAccountState[uint32(shardID)] state, ok := shardIDToAccountState[uint32(shardID)]
@ -274,7 +274,7 @@ func processTransferCommand() {
amountBigInt := big.NewInt(int64(amount * params.GWei)) amountBigInt := big.NewInt(int64(amount * params.GWei))
amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(params.GWei)) amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(params.GWei))
tx, _ := types.SignTx(types.NewTransaction(state.nonce, receiverAddress, uint32(shardID), amountBigInt, params.TxGas, nil, nil), types.HomesteadSigner{}, senderPriKey) tx, _ := types.SignTx(types.NewTransaction(state.nonce, receiverAddress, uint32(shardID), amountBigInt, params.TxGas, nil, nil), types.HomesteadSigner{}, senderPriKey)
lib.SubmitTransaction(tx, walletNode, uint32(shardID)) wallet.SubmitTransaction(tx, walletNode, uint32(shardID))
} }
func convertBalanceIntoReadableFormat(balance *big.Int) string { func convertBalanceIntoReadableFormat(balance *big.Int) string {
@ -321,7 +321,7 @@ func convertBalanceIntoReadableFormat(balance *big.Int) string {
// TODO add support for non beacon chain shards // TODO add support for non beacon chain shards
func FetchBalance(address common.Address, walletNode *node.Node) map[uint32]AccountState { func FetchBalance(address common.Address, walletNode *node.Node) map[uint32]AccountState {
result := make(map[uint32]AccountState) result := make(map[uint32]AccountState)
peers := lib.GetPeersFromBeaconChain(walletNode) peers := wallet.GetPeersFromBeaconChain(walletNode)
if len(peers) == 0 { if len(peers) == 0 {
fmt.Printf("[FATAL] Can't find peers\n") fmt.Printf("[FATAL] Can't find peers\n")
return nil return nil
@ -338,7 +338,7 @@ func FetchBalance(address common.Address, walletNode *node.Node) map[uint32]Acco
// GetFreeToken requests for token test token on each shard // GetFreeToken requests for token test token on each shard
func GetFreeToken(address common.Address, walletNode *node.Node) { func GetFreeToken(address common.Address, walletNode *node.Node) {
peers := lib.GetPeersFromBeaconChain(walletNode) peers := wallet.GetPeersFromBeaconChain(walletNode)
if len(peers) == 0 { if len(peers) == 0 {
fmt.Printf("[FATAL] Can't find peers\n") fmt.Printf("[FATAL] Can't find peers\n")
return return

@ -1,4 +1,4 @@
package lib package wallet
import ( import (
"fmt" "fmt"

@ -1,4 +1,4 @@
package lib package wallet
import ( import (
"testing" "testing"
Loading…
Cancel
Save