Merge pull request #179 from harmony-one/rj_branch

Clear out unused code and add more comments
pull/181/head
Rongjian Lan 6 years ago committed by GitHub
commit 89b2c42857
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      client/txgen/main.go
  2. 50
      client/utils.go
  3. 35
      client/wallet/main.go

@ -35,6 +35,8 @@ func printVersion(me string) {
os.Exit(0) os.Exit(0)
} }
// The main entrance for the transaction generator program which simulate transactions and send to the network for
// processing.
func main() { func main() {
ip := flag.String("ip", "127.0.0.1", "IP of the node") ip := flag.String("ip", "127.0.0.1", "IP of the node")
port := flag.String("port", "9999", "port of the node.") port := flag.String("port", "9999", "port of the node.")
@ -155,8 +157,6 @@ func main() {
start := time.Now() start := time.Now()
totalTime := float64(*duration) totalTime := float64(*duration)
client.InitLookUpIntPriKeyMap()
for { for {
t := time.Now() t := time.Now()
if totalTime > 0 && t.Sub(start).Seconds() >= totalTime { if totalTime > 0 && t.Sub(start).Seconds() >= totalTime {

@ -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
}

@ -11,19 +11,16 @@ import (
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
libs "github.com/harmony-one/harmony/beaconchain/libs" libs "github.com/harmony-one/harmony/beaconchain/libs"
"github.com/harmony-one/harmony/beaconchain/rpc" "github.com/harmony-one/harmony/beaconchain/rpc"
"github.com/harmony-one/harmony/client"
client2 "github.com/harmony-one/harmony/client/service" client2 "github.com/harmony-one/harmony/client/service"
"github.com/harmony-one/harmony/core/types" "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/node"
"github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/p2pimpl"
proto_node "github.com/harmony-one/harmony/proto/node" proto_node "github.com/harmony-one/harmony/proto/node"
"io" "io"
"io/ioutil" "io/ioutil"
"math/big"
"os" "os"
"path" "path"
"strconv" "strconv"
@ -42,12 +39,14 @@ func printVersion(me string) {
os.Exit(0) os.Exit(0)
} }
// AccountState includes the state of an account // AccountState includes the balance and nonce of an account
type AccountState struct { type AccountState struct {
balance *big.Int balance *big.Int
nonce uint64 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() { func main() {
// Account subcommands // Account subcommands
accountImportCommand := flag.NewFlagSet("import", flag.ExitOnError) accountImportCommand := flag.NewFlagSet("import", flag.ExitOnError)
@ -280,28 +279,6 @@ func convertBalanceIntoReadableFormat(balance *big.Int) string {
} }
return string(bytes) 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. // CreateWalletNode creates wallet server node.
func CreateWalletNode() *node.Node { func CreateWalletNode() *node.Node {

Loading…
Cancel
Save