Format
This commit is contained in:
parent
e280a2a7e3
commit
f78bd4d5d0
@ -1,9 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ethereum/ethutil-go"
|
"github.com/ethereum/ethutil-go"
|
||||||
"errors"
|
|
||||||
"log"
|
"log"
|
||||||
"math/big"
|
"math/big"
|
||||||
)
|
)
|
||||||
@ -24,7 +24,6 @@ func NewBlockChain() *BlockChain {
|
|||||||
bc.TD = new(big.Int)
|
bc.TD = new(big.Int)
|
||||||
bc.TD.SetBytes(ethutil.Config.Db.LastKnownTD())
|
bc.TD.SetBytes(ethutil.Config.Db.LastKnownTD())
|
||||||
|
|
||||||
|
|
||||||
// TODO get last block from the database
|
// TODO get last block from the database
|
||||||
//bc.LastBlock = bc.genesisBlock
|
//bc.LastBlock = bc.genesisBlock
|
||||||
|
|
||||||
@ -136,7 +135,7 @@ func (bm *BlockManager) ValidateBlock(block *ethutil.Block) error {
|
|||||||
// Check if we have the parent hash, if it isn't known we discard it
|
// Check if we have the parent hash, if it isn't known we discard it
|
||||||
// Reasons might be catching up or simply an invalid block
|
// Reasons might be catching up or simply an invalid block
|
||||||
if bm.bc.LastBlock != nil && block.PrevHash == "" &&
|
if bm.bc.LastBlock != nil && block.PrevHash == "" &&
|
||||||
!bm.bc.HasBlock(block.PrevHash) {
|
!bm.bc.HasBlock(block.PrevHash) {
|
||||||
return errors.New("Block's parent unknown")
|
return errors.New("Block's parent unknown")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +153,7 @@ func (bm *BlockManager) ValidateBlock(block *ethutil.Block) error {
|
|||||||
|
|
||||||
// Verify the nonce of the block. Return an error if it's not valid
|
// Verify the nonce of the block. Return an error if it's not valid
|
||||||
if bm.bc.LastBlock != nil && block.PrevHash == "" &&
|
if bm.bc.LastBlock != nil && block.PrevHash == "" &&
|
||||||
!DaggerVerify(ethutil.BigD(block.Hash()), block.Difficulty, block.Nonce) {
|
!DaggerVerify(ethutil.BigD(block.Hash()), block.Difficulty, block.Nonce) {
|
||||||
return errors.New("Block's nonce is invalid")
|
return errors.New("Block's nonce is invalid")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +174,6 @@ func (bm *BlockManager) AccumelateRewards(block *ethutil.Block) error {
|
|||||||
|
|
||||||
// TODO Reward each uncle
|
// TODO Reward each uncle
|
||||||
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
peer.go
11
peer.go
@ -1,8 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/ethwire-go"
|
|
||||||
"github.com/ethereum/ethutil-go"
|
"github.com/ethereum/ethutil-go"
|
||||||
|
"github.com/ethereum/ethwire-go"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
@ -24,15 +24,15 @@ func NewPeer(conn net.Conn, server *Server, inbound bool) *Peer {
|
|||||||
return &Peer{
|
return &Peer{
|
||||||
outputQueue: make(chan *ethwire.InOutMsg, 1), // Buffered chan of 1 is enough
|
outputQueue: make(chan *ethwire.InOutMsg, 1), // Buffered chan of 1 is enough
|
||||||
quit: make(chan bool),
|
quit: make(chan bool),
|
||||||
server: server,
|
server: server,
|
||||||
conn: conn,
|
conn: conn,
|
||||||
inbound: inbound,
|
inbound: inbound,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Outputs any RLP encoded data to the peer
|
// Outputs any RLP encoded data to the peer
|
||||||
func (p *Peer) QueueMessage(msg *ethwire.InOutMsg) {
|
func (p *Peer) QueueMessage(msg *ethwire.InOutMsg) {
|
||||||
p.outputQueue <- msg//ethwire.InOutMsg{MsgType: msgType, Nonce: ethutil.RandomUint64(), Data: data}
|
p.outputQueue <- msg //ethwire.InOutMsg{MsgType: msgType, Nonce: ethutil.RandomUint64(), Data: data}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Outbound message handler. Outbound messages are handled here
|
// Outbound message handler. Outbound messages are handled here
|
||||||
@ -145,4 +145,3 @@ func (p *Peer) handleVersionAck(msg *ethwire.InOutMsg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user