From 28357d657b8c46e841fc96a61758652d2617b068 Mon Sep 17 00:00:00 2001 From: Maran Date: Tue, 13 May 2014 14:43:29 +0200 Subject: [PATCH] Implemented new JS/EthPub methods - getTxCountAt - getPeerCount - getIsMining - getIsListening - getCoinbase --- ethchain/state_manager.go | 3 +++ ethereum.go | 15 +++++++++++++++ ethpub/pub.go | 25 ++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go index dd21a31b1..bc8b46831 100644 --- a/ethchain/state_manager.go +++ b/ethchain/state_manager.go @@ -20,6 +20,9 @@ type EthManager interface { TxPool() *TxPool Broadcast(msgType ethwire.MsgType, data []interface{}) Reactor() *ethutil.ReactorEngine + PeerCount() int + IsMining() bool + IsListening() bool } type StateManager struct { diff --git a/ethereum.go b/ethereum.go index 92c4e4ba1..94e338c56 100644 --- a/ethereum.go +++ b/ethereum.go @@ -65,6 +65,10 @@ type Ethereum struct { // Specifies the desired amount of maximum peers MaxPeers int + Mining bool + + listening bool + reactor *ethutil.ReactorEngine RpcServer *ethrpc.JsonRpcServer @@ -128,6 +132,15 @@ func (s *Ethereum) TxPool() *ethchain.TxPool { func (s *Ethereum) ServerCaps() Caps { return s.serverCaps } +func (s *Ethereum) IsMining() bool { + return s.Mining +} +func (s *Ethereum) PeerCount() int { + return s.peers.Len() +} +func (s *Ethereum) IsListening() bool { + return s.listening +} func (s *Ethereum) AddPeer(conn net.Conn) { peer := NewPeer(conn, s, true) @@ -305,7 +318,9 @@ func (s *Ethereum) Start(seed bool) { ln, err := net.Listen("tcp", ":"+s.Port) if err != nil { log.Println("Connection listening disabled. Acting as client") + s.listening = false } else { + s.listening = true // Starting accepting connections ethutil.Config.Log.Infoln("Ready and accepting connections") // Start the peer handler diff --git a/ethpub/pub.go b/ethpub/pub.go index 4ced632f5..1866d6fdf 100644 --- a/ethpub/pub.go +++ b/ethpub/pub.go @@ -1,6 +1,8 @@ package ethpub import ( + "encoding/hex" + "fmt" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" ) @@ -56,11 +58,32 @@ func (lib *PEthereum) GetStateObject(address string) *PStateObject { return NewPStateObject(nil) } +func (lib *PEthereum) GetPeerCount() int { + return lib.manager.PeerCount() +} + +func (lib *PEthereum) GetIsMining() bool { + return lib.manager.IsMining() +} + +func (lib *PEthereum) GetIsListening() bool { + return lib.manager.IsListening() +} + +func (lib *PEthereum) GetCoinBase() string { + data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) + keyRing := ethutil.NewValueFromBytes(data) + key := keyRing.Get(0).Bytes() + + return lib.SecretToAddress(hex.EncodeToString(key)) +} + func (lib *PEthereum) GetStorage(address, storageAddress string) string { return lib.GetStateObject(address).GetStorage(storageAddress) } -func (lib *PEthereum) GetTxCount(address string) int { +func (lib *PEthereum) GetTxCountAt(address string) int { + fmt.Println("GO") return lib.GetStateObject(address).Nonce() }