aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-11-04 20:00:47 +0800
committerobscuren <geffobscura@gmail.com>2014-11-04 20:00:47 +0800
commita9db1ee8d45b3395df13b27a901567fde310a3c7 (patch)
tree6160365d6ee20559e6fabf3d115229983ccd4fdf
parent699dcaf65ced99517724984f5930845417cfdfca (diff)
downloaddexon-a9db1ee8d45b3395df13b27a901567fde310a3c7.tar
dexon-a9db1ee8d45b3395df13b27a901567fde310a3c7.tar.gz
dexon-a9db1ee8d45b3395df13b27a901567fde310a3c7.tar.bz2
dexon-a9db1ee8d45b3395df13b27a901567fde310a3c7.tar.lz
dexon-a9db1ee8d45b3395df13b27a901567fde310a3c7.tar.xz
dexon-a9db1ee8d45b3395df13b27a901567fde310a3c7.tar.zst
dexon-a9db1ee8d45b3395df13b27a901567fde310a3c7.zip
Replaced to return the td and throw a specific error on TD
-rw-r--r--chain/chain_manager.go9
-rw-r--r--chain/error.go12
2 files changed, 15 insertions, 6 deletions
diff --git a/chain/chain_manager.go b/chain/chain_manager.go
index 60de377aa..dd965e85b 100644
--- a/chain/chain_manager.go
+++ b/chain/chain_manager.go
@@ -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)
@@ -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
}
diff --git a/chain/error.go b/chain/error.go
index 204b8b873..71bda8e7b 100644
--- a/chain/error.go
+++ b/chain/error.go
@@ -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
+}