Skip to content

Commit

Permalink
Replaced to return the td and throw a specific error on TD
Browse files Browse the repository at this point in the history
  • Loading branch information
obscuren committed Nov 4, 2014
1 parent 699dcaf commit a9db1ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
9 changes: 3 additions & 6 deletions chain/chain_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,7 @@ func (self *ChainManager) InsertChain(chain *BlockChain) {
}
}

func (self *ChainManager) TestChain(chain *BlockChain) (i int, err error) {
var (
td *big.Int
)
func (self *ChainManager) TestChain(chain *BlockChain) (td *big.Int, err error) {
for e := chain.Front(); e != nil; e = e.Next() {
var (
l = e.Value.(*link)
Expand Down Expand Up @@ -355,9 +352,9 @@ func (self *ChainManager) TestChain(chain *BlockChain) (i int, err error) {
}

if td.Cmp(self.TD) <= 0 {
err = fmt.Errorf("incoming chain has a lower or equal TD (%v <= %v)", td, self.TD)
err = &TDError{td, self.TD}
return
}

return i, nil
return
}
12 changes: 12 additions & 0 deletions chain/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,15 @@ func IsOutOfGasErr(err error) bool {

return ok
}

type TDError struct {
a, b *big.Int
}

func (self *TDError) Error() string {
return fmt.Sprintf("incoming chain has a lower or equal TD (%v <= %v)", self.a, self.b)
}
func IsTDError(e error) bool {
_, ok := err.(*TDError)
return ok
}

0 comments on commit a9db1ee

Please sign in to comment.