diff --git a/client/txgen/main.go b/client/txgen/main.go index 95a877912..9b97e022c 100644 --- a/client/txgen/main.go +++ b/client/txgen/main.go @@ -35,6 +35,8 @@ func printVersion(me string) { os.Exit(0) } +// The main entrance for the transaction generator program which simulate transactions and send to the network for +// processing. func main() { ip := flag.String("ip", "127.0.0.1", "IP of the node") port := flag.String("port", "9999", "port of the node.") @@ -155,8 +157,6 @@ func main() { start := time.Now() totalTime := float64(*duration) - client.InitLookUpIntPriKeyMap() - for { t := time.Now() if totalTime > 0 && t.Sub(start).Seconds() >= totalTime { diff --git a/client/utils.go b/client/utils.go deleted file mode 100644 index d5f31ee8e..000000000 --- a/client/utils.go +++ /dev/null @@ -1,50 +0,0 @@ -package client - -import ( - "bytes" - "io" - "log" - "net/http" - "sync" - - "github.com/harmony-one/harmony/crypto/pki" -) - -// AddressToIntPriKeyMap is the map from address to private key. -var AddressToIntPriKeyMap map[[20]byte]int // For convenience, we use int as the secret seed for generating private key -// AddressToIntPriKeyMapLock is the lock of AddressToIntPriKeyMap. -var AddressToIntPriKeyMapLock sync.Mutex - -// InitLookUpIntPriKeyMap inits AddressToIntPriKeyMap. -func InitLookUpIntPriKeyMap() { - if AddressToIntPriKeyMap == nil { - AddressToIntPriKeyMapLock.Lock() - AddressToIntPriKeyMap = make(map[[20]byte]int) - for i := 1; i <= 10000; i++ { - AddressToIntPriKeyMap[pki.GetAddressFromInt(i)] = i - } - AddressToIntPriKeyMapLock.Unlock() - } -} - -// LookUpIntPriKey looks up private key by address. -func LookUpIntPriKey(address [20]byte) (int, bool) { - value, ok := AddressToIntPriKeyMap[address] - return value, ok -} - -// DownloadURLAsString downloads url as string. -func DownloadURLAsString(url string) (string, error) { - response, err := http.Get(url) - buf := bytes.NewBufferString("") - if err != nil { - log.Fatal(err) - } else { - defer response.Body.Close() - _, err := io.Copy(buf, response.Body) - if err != nil { - log.Fatal(err) - } - } - return buf.String(), err -} diff --git a/client/wallet/main.go b/client/wallet/main.go index ff52feb2b..03bc9c1b1 100644 --- a/client/wallet/main.go +++ b/client/wallet/main.go @@ -11,19 +11,16 @@ import ( "github.com/ethereum/go-ethereum/params" libs "github.com/harmony-one/harmony/beaconchain/libs" "github.com/harmony-one/harmony/beaconchain/rpc" + "github.com/harmony-one/harmony/client" client2 "github.com/harmony-one/harmony/client/service" "github.com/harmony-one/harmony/core/types" - "github.com/harmony-one/harmony/p2p/p2pimpl" - "log" - "math/big" - "strings" - - "github.com/harmony-one/harmony/client" "github.com/harmony-one/harmony/node" "github.com/harmony-one/harmony/p2p" + "github.com/harmony-one/harmony/p2p/p2pimpl" proto_node "github.com/harmony-one/harmony/proto/node" "io" "io/ioutil" + "math/big" "os" "path" "strconv" @@ -42,12 +39,14 @@ func printVersion(me string) { os.Exit(0) } -// AccountState includes the state of an account +// AccountState includes the balance and nonce of an account type AccountState struct { balance *big.Int nonce uint64 } +// The main wallet program entrance. Note the this wallet program is for demo-purpose only. It does not implement +// the secure storage of keys. func main() { // Account subcommands accountImportCommand := flag.NewFlagSet("import", flag.ExitOnError) @@ -280,28 +279,6 @@ func convertBalanceIntoReadableFormat(balance *big.Int) string { } return string(bytes) } -func getShardIDToLeaderMap() map[uint32]p2p.Peer { - // TODO(ricl): Later use data.harmony.one for API. - str, _ := client.DownloadURLAsString("https://s3-us-west-2.amazonaws.com/unique-bucket-bin/leaders.txt") - lines := strings.Split(str, "\n") - shardIDLeaderMap := map[uint32]p2p.Peer{} - log.Print(lines) - for _, line := range lines { - if line == "" { - continue - } - parts := strings.Split(line, " ") - - shardID := parts[3] - id, err := strconv.Atoi(shardID) - if err == nil { - shardIDLeaderMap[uint32(id)] = p2p.Peer{IP: parts[0], Port: parts[1]} - } else { - log.Print("[Generator] Error parsing the shard Id ", shardID) - } - } - return shardIDLeaderMap -} // CreateWalletNode creates wallet server node. func CreateWalletNode() *node.Node {