Skip to content

Commit

Permalink
Merge pull request #402 from wavesplatform/version-0.9
Browse files Browse the repository at this point in the history
Version 0.9 Feature Branch
  • Loading branch information
alexeykiselev authored Jun 15, 2021
2 parents c6ea75f + bedcb85 commit f595426
Show file tree
Hide file tree
Showing 160 changed files with 16,129 additions and 3,806 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
vendor/
build/
out/
.run/

*.lock
*.txt
Expand Down
35 changes: 32 additions & 3 deletions cmd/custom/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/wavesplatform/gowaves/pkg/node/blocks_applier"
"github.com/wavesplatform/gowaves/pkg/node/messages"
"github.com/wavesplatform/gowaves/pkg/node/peer_manager"
"github.com/wavesplatform/gowaves/pkg/node/peer_manager/storage"
peersPersistentStorage "github.com/wavesplatform/gowaves/pkg/node/peer_manager/storage"
"github.com/wavesplatform/gowaves/pkg/node/state_fsm/ng"
"github.com/wavesplatform/gowaves/pkg/p2p/peer"
"github.com/wavesplatform/gowaves/pkg/proto"
Expand Down Expand Up @@ -57,6 +57,7 @@ var (
walletPassword = flag.String("wallet-password", "", "Pass password for wallet. Extremely insecure")
limitConnectionsS = flag.String("limit-connections", "30", "N incoming and outgoing connections")
minPeersMining = flag.Int("min-peers-mining", 1, "Minimum connected peers for allow mining")
dropPeers = flag.Bool("drop-peers", false, "Drop peers storage before node start.")
)

func init() {
Expand Down Expand Up @@ -190,7 +191,23 @@ func main() {

peerSpawnerImpl := peer_manager.NewPeerSpawner(btsPool, parent, conf.WavesNetwork, declAddr, "gowaves", uint64(rand.Int()), version)

peerStorage := storage.NewBinaryStorage(path)
peerStorage, err := peersPersistentStorage.NewCBORStorage(*statePath, time.Now())
if err != nil {
zap.S().Errorf("Failed to open or create peers storage: %v", err)
cancel()
return
}
if *dropPeers {
if err := peerStorage.DropStorage(); err != nil {
zap.S().Errorf(
"Failed to drop peers storage. Drop peers storage manually. Err: %v",
err,
)
cancel()
return
}
zap.S().Info("Successfully dropped peers storage")
}

peerManager := peer_manager.NewPeerManager(peerSpawnerImpl, peerStorage, int(limitConnections), version)
go peerManager.Run(ctx)
Expand Down Expand Up @@ -234,7 +251,19 @@ func main() {
if len(conf.Addresses) > 0 {
addresses := strings.Split(conf.Addresses, ",")
for _, addr := range addresses {
peerManager.AddAddress(ctx, addr)
tcpAddr := proto.NewTCPAddrFromString(addr)
if tcpAddr.Empty() {
// nickeskov: that means that configuration parameter is invalid
zap.S().Errorf("Failed to parse TCPAddr from string %q", tcpAddr.String())
cancel()
return
}
if err := peerManager.AddAddress(ctx, tcpAddr); err != nil {
// nickeskov: than means that we have problems with peers storage
zap.S().Errorf("Failed to add addres into know peers storage: %v", err)
cancel()
return
}
}
}

Expand Down
14 changes: 7 additions & 7 deletions cmd/forkdetector/internal/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (a *api) routes() chi.Router {
r := chi.NewRouter()
r.Get("/status", a.status) // Status information
r.Get("/peers/all", a.peers) // Returns the list of all known peers
r.Get("/peers/friendly", a.friendly) // Returns the list of peers that have been successfully handshaked at least once
r.Get("/peers/friendly", a.friendly) // Returns the list of peers that have been successfully connected at least once
r.Get("/connections", a.connections) // Returns the list of active connections
r.Get("/forks", a.forks) // Returns the combined info about forks for all connected peers
r.Get("/all-forks", a.allForks) // Returns the combined info about all registered forks
Expand All @@ -129,7 +129,7 @@ func (a *api) routes() chi.Router {
return r
}

func (a *api) status(w http.ResponseWriter, r *http.Request) {
func (a *api) status(w http.ResponseWriter, _ *http.Request) {
goroutines := runtime.NumGoroutine()
stats := a.drawer.stats()
peers, err := a.registry.Peers()
Expand Down Expand Up @@ -159,7 +159,7 @@ func (a *api) status(w http.ResponseWriter, r *http.Request) {
}
}

func (a *api) peers(w http.ResponseWriter, r *http.Request) {
func (a *api) peers(w http.ResponseWriter, _ *http.Request) {
peers, err := a.registry.Peers()
if err != nil {
http.Error(w, fmt.Sprintf("Failed to complete request: %v", err), http.StatusInternalServerError)
Expand All @@ -172,7 +172,7 @@ func (a *api) peers(w http.ResponseWriter, r *http.Request) {
}
}

func (a *api) friendly(w http.ResponseWriter, r *http.Request) {
func (a *api) friendly(w http.ResponseWriter, _ *http.Request) {
peers, err := a.registry.FriendlyPeers()
if err != nil {
http.Error(w, fmt.Sprintf("Failed to complete request: %v", err), http.StatusInternalServerError)
Expand All @@ -185,7 +185,7 @@ func (a *api) friendly(w http.ResponseWriter, r *http.Request) {
}
}

func (a *api) connections(w http.ResponseWriter, r *http.Request) {
func (a *api) connections(w http.ResponseWriter, _ *http.Request) {
connections := a.registry.Connections()
err := json.NewEncoder(w).Encode(connections)
if err != nil {
Expand All @@ -194,7 +194,7 @@ func (a *api) connections(w http.ResponseWriter, r *http.Request) {
}
}

func (a *api) forks(w http.ResponseWriter, r *http.Request) {
func (a *api) forks(w http.ResponseWriter, _ *http.Request) {
nodes := a.registry.Connections()
ips := make([]net.IP, len(nodes))
for i, n := range nodes {
Expand All @@ -214,7 +214,7 @@ func (a *api) forks(w http.ResponseWriter, r *http.Request) {
}
}

func (a *api) allForks(w http.ResponseWriter, r *http.Request) {
func (a *api) allForks(w http.ResponseWriter, _ *http.Request) {
nodes, err := a.registry.Peers()
if err != nil {
http.Error(w, fmt.Sprintf("Failed to complete request: %v", err), http.StatusInternalServerError)
Expand Down
38 changes: 35 additions & 3 deletions cmd/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/wavesplatform/gowaves/pkg/node/blocks_applier"
"github.com/wavesplatform/gowaves/pkg/node/messages"
"github.com/wavesplatform/gowaves/pkg/node/peer_manager"
"github.com/wavesplatform/gowaves/pkg/node/peer_manager/storage"
peersPersistentStorage "github.com/wavesplatform/gowaves/pkg/node/peer_manager/storage"
"github.com/wavesplatform/gowaves/pkg/p2p/peer"
"github.com/wavesplatform/gowaves/pkg/proto"
"github.com/wavesplatform/gowaves/pkg/services"
Expand Down Expand Up @@ -83,6 +83,7 @@ var (
integrationMinAssetInfoUpdateInterval = flag.Int("integration.min-asset-info-update-interval", 100000, "Minimum asset info update interval for integration tests.")
metricsID = flag.Int("metrics-id", -1, "ID of the node on the metrics collection system")
metricsURL = flag.String("metrics-url", "", "URL of InfluxDB or Telegraf in form of 'http://username:password@host:port/db'")
dropPeers = flag.Bool("drop-peers", false, "Drop peers storage before node start.")
)

var defaultPeers = map[string]string{
Expand Down Expand Up @@ -120,6 +121,7 @@ func debugCommandLineParameters() {
zap.S().Debugf("limit-connections: %s", *limitConnectionsS)
zap.S().Debugf("profiler: %v", *profiler)
zap.S().Debugf("bloom: %v", *bloomFilter)
zap.S().Debugf("drop-peers: %v", *dropPeers)
}

func main() {
Expand Down Expand Up @@ -294,7 +296,23 @@ func main() {

peerSpawnerImpl := peer_manager.NewPeerSpawner(pool, parent, conf.WavesNetwork, declAddr, *nodeName, uint64(rand.Int()), version)

peerStorage := storage.NewBinaryStorage(path)
peerStorage, err := peersPersistentStorage.NewCBORStorage(*statePath, time.Now())
if err != nil {
zap.S().Errorf("Failed to open or create peers storage: %v", err)
cancel()
return
}
if *dropPeers {
if err := peerStorage.DropStorage(); err != nil {
zap.S().Errorf(
"Failed to drop peers storage. Drop peers storage manually. Err: %v",
err,
)
cancel()
return
}
zap.S().Info("Successfully dropped peers storage")
}

peerManager := peer_manager.NewPeerManager(
peerSpawnerImpl,
Expand Down Expand Up @@ -344,7 +362,19 @@ func main() {
if len(conf.Addresses) > 0 {
addresses := strings.Split(conf.Addresses, ",")
for _, addr := range addresses {
peerManager.AddAddress(ctx, addr)
tcpAddr := proto.NewTCPAddrFromString(addr)
if tcpAddr.Empty() {
// nickeskov: that means that configuration parameter is invalid
zap.S().Errorf("Failed to parse TCPAddr from string %q", tcpAddr.String())
cancel()
return
}
if err := peerManager.AddAddress(ctx, tcpAddr); err != nil {
// nickeskov: than means that we have problems with peers storage
zap.S().Errorf("Failed to add addres into know peers storage: %v", err)
cancel()
return
}
}
}

Expand All @@ -357,6 +387,7 @@ func main() {

webApi := api.NewNodeApi(app, st, n)
go func() {
zap.S().Infof("Starting node HTTP API on '%v'", conf.HttpAddr)
err := api.Run(ctx, conf.HttpAddr, webApi)
if err != nil {
zap.S().Errorf("Failed to start API: %v", err)
Expand All @@ -368,6 +399,7 @@ func main() {
h := http.NewServeMux()
h.Handle("/metrics", promhttp.Handler())
s := &http.Server{Addr: *prometheus, Handler: h}
zap.S().Infof("Starting node metrics endpoint on '%v'", *prometheus)
_ = s.ListenAndServe()
}
}()
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/coocood/freecache v1.1.0
github.com/dgryski/go-metro v0.0.0-20180109044635-280f6062b5bc // indirect
github.com/ericlagergren/decimal v0.0.0-20190912144844-2c3e3e1ef942
github.com/fxamacker/cbor/v2 v2.2.0
github.com/fxamacker/cbor/v2 v2.3.0
github.com/go-chi/chi v4.0.3+incompatible
github.com/golang/mock v1.4.3
github.com/golang/protobuf v1.4.2
Expand All @@ -23,8 +23,6 @@ require (
github.com/kilic/bn254 v0.0.0-20200902152204-ab63fe16fead
github.com/magiconair/properties v1.8.1
github.com/mr-tron/base58 v1.1.2
github.com/onsi/ginkgo v1.10.1 // indirect
github.com/onsi/gomega v1.7.0 // indirect
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.7.1
Expand All @@ -37,6 +35,7 @@ require (
github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570
github.com/stretchr/testify v1.6.1
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d
github.com/throttled/throttled/v2 v2.7.1
github.com/valyala/bytebufferpool v1.0.0
github.com/xenolf/lego v2.7.2+incompatible
go.uber.org/atomic v1.4.0
Expand Down
13 changes: 11 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fxamacker/cbor/v2 v2.2.0 h1:6eXqdDDe588rSYAi1HfZKbx6YYQO4mxQ9eC6xYpU/JQ=
github.com/fxamacker/cbor/v2 v2.2.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
github.com/fxamacker/cbor/v2 v2.3.0 h1:aM45YGMctNakddNNAezPxDUpv38j44Abh+hifNuqXik=
github.com/fxamacker/cbor/v2 v2.3.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww=
github.com/go-chi/chi v4.0.3+incompatible h1:gakN3pDJnzZN5jqFV2TEdF66rTfKeITyR8qu6ekICEY=
github.com/go-chi/chi v4.0.3+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
Expand All @@ -93,6 +93,7 @@ github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
github.com/go-redis/redis v6.15.8+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
Expand All @@ -115,6 +116,8 @@ github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
Expand All @@ -126,6 +129,7 @@ github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/websocket v1.4.1-0.20190629185528-ae1634f6a989/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/graph-gophers/graphql-go v0.0.0-20191115155744-f33e81362277/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c h1:aY2hhxLhjEAbfXOx2nRJxCXezC6CO2V/yN+OCr1srtk=
github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs=
Expand Down Expand Up @@ -256,6 +260,8 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d h1:gZZadD8H+fF+n9CmNhYL1Y0dJB+kLOmKd7FbPJLeGHs=
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA=
github.com/throttled/throttled/v2 v2.7.1 h1:FnBysDX4Sok55bvfDMI0l2Y71V1vM2wi7O79OW7fNtw=
github.com/throttled/throttled/v2 v2.7.1/go.mod h1:fuOeyK9fmnA+LQnsBbfT/mmPHjmkdogRBQxaD8YsgZ8=
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
Expand Down Expand Up @@ -290,6 +296,7 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0 h1:wBouT66WTYFXdxfVdz9sVWARVd/2vfGcmI45D2gj45M=
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
Expand All @@ -307,6 +314,7 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191025090151-53bf42e6b339/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -371,6 +379,7 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
Expand Down
22 changes: 13 additions & 9 deletions pkg/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,30 +97,34 @@ func (a *App) LoadKeys(apiKey string, password []byte) error {
}

func (a *App) Accounts() ([]account, error) {
r := make([]account, 0)
for _, s := range a.services.Wallet.Seeds() {
_, pk, err := crypto.GenerateKeyPair(s)
seeds := a.services.Wallet.Seeds()

accounts := make([]account, 0, len(seeds))
for _, seed := range seeds {
_, pk, err := crypto.GenerateKeyPair(seed)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "failed to generate key pair for seed")
}
a, err := proto.NewAddressFromPublicKey(a.services.Scheme, pk)
addr, err := proto.NewAddressFromPublicKey(a.services.Scheme, pk)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "failed to generate new address from public key")
}
r = append(r, account{Address: a, PublicKey: pk})
accounts = append(accounts, account{Address: addr, PublicKey: pk})
}
return r, nil
return accounts, nil
}

func (a *App) checkAuth(key string) error {
if !a.apiKeyEnabled {
// TODO(nickeskov): use new types of errors
return &AuthError{errors.New("api key disabled")}
}
d, err := crypto.SecureHash([]byte(key))
if err != nil {
return &AuthError{err}
return errors.Wrap(err, "failed to calculate secure hash for API key")
}
if d != a.hashedApiKey {
// TODO(nickeskov): use new types of errors
return &AuthError{errors.New("invalid api key")}
}
return nil
Expand Down
17 changes: 17 additions & 0 deletions pkg/api/app_addresses.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package api

import "github.com/pkg/errors"

func (a *App) Addresses() ([]string, error) {
accounts, err := a.Accounts()
if err != nil {
return nil, errors.Wrap(err, "failed to get wallet accounts")
}

addresses := make([]string, 0, len(accounts))
for i := range accounts {
addresses = append(addresses, accounts[i].Address.String())
}

return addresses, nil
}
Loading

0 comments on commit f595426

Please sign in to comment.