• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: Commit

Golang implemented sidechain for Bytom


Commit MetaInfo

Revisionb91e39242eda6dfe7111f461e6624245248e555d (tree)
Time2019-07-18 18:06:58
AuthorChengcheng Zhang <943420582@qq.c...>
CommiterChengcheng Zhang

Log Message

update GetNodeInfo

Change Summary

Incremental Difference

--- a/api/nodeinfo.go
+++ b/api/nodeinfo.go
@@ -4,10 +4,17 @@ import (
44 "context"
55 "net"
66
7+ log "github.com/sirupsen/logrus"
8+
9+ "github.com/vapor/common"
710 cfg "github.com/vapor/config"
11+ "github.com/vapor/consensus"
12+ "github.com/vapor/crypto"
13+ "github.com/vapor/crypto/ed25519/chainkd"
814 "github.com/vapor/errors"
915 "github.com/vapor/netsync/peers"
1016 "github.com/vapor/p2p"
17+ "github.com/vapor/protocol/vm/vmutil"
1118 "github.com/vapor/version"
1219 )
1320
@@ -23,6 +30,7 @@ type NetInfo struct {
2330 Syncing bool `json:"syncing"`
2431 Mining bool `json:"mining"`
2532 NodeXPub string `json:"node_xpub"`
33+ FedAddress string `json:"fed_address"`
2634 PeerCount int `json:"peer_count"`
2735 CurrentBlock uint64 `json:"current_block"`
2836 HighestBlock uint64 `json:"highest_block"`
@@ -33,11 +41,27 @@ type NetInfo struct {
3341 // GetNodeInfo return net information
3442 func (a *API) GetNodeInfo() *NetInfo {
3543 nodeXPub := cfg.CommonConfig.PrivateKey().XPub()
44+
45+ federationXPubs := cfg.CommonConfig.Federation.Xpubs
46+ fedDerivedPKs := chainkd.XPubKeys(federationXPubs)
47+ federationQuorum := cfg.CommonConfig.Federation.Quorum
48+ signScript, err := vmutil.P2SPMultiSigProgram(fedDerivedPKs, federationQuorum)
49+ if err != nil {
50+ log.WithFields(log.Fields{"module": logModule, "err": err}).Fatal("Failed to get federation signScript.")
51+ }
52+
53+ scriptHash := crypto.Sha256(signScript)
54+ address, err := common.NewAddressWitnessScriptHash(scriptHash, &consensus.ActiveNetParams)
55+ if err != nil {
56+ log.WithFields(log.Fields{"module": logModule, "err": err}).Fatal("Failed to get federation address.")
57+ }
58+
3659 info := &NetInfo{
3760 Listening: a.sync.IsListening(),
3861 Syncing: !a.sync.IsCaughtUp(),
3962 Mining: a.blockProposer.IsProposing(),
4063 NodeXPub: nodeXPub.String(),
64+ FedAddress: address.EncodeAddress(),
4165 PeerCount: a.sync.PeerCount(),
4266 CurrentBlock: a.chain.BestBlockHeight(),
4367 NetWorkID: a.sync.GetNetwork(),
Show on old repository browser