ZCashRPC.GetBlock skips invalid/missing transactions during sync

indexv1
Jakub Matys 2018-03-22 15:45:08 +01:00
parent 4421dc94dc
commit 80959fd9d6
1 changed files with 20 additions and 0 deletions

View File

@ -89,6 +89,10 @@ func (z *ZCashRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) {
for i, txid := range res.Result.Txids {
tx, err := z.GetTransaction(txid)
if err != nil {
if isInvalidTx(err) {
glog.Errorf("rpc: getblock: skipping transanction in block %s due error: %s", hash, err)
continue
}
return nil, err
}
txs[i] = *tx
@ -100,6 +104,20 @@ func (z *ZCashRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) {
return block, nil
}
func isInvalidTx(err error) bool {
switch e1 := err.(type) {
case *errors.Err:
switch e2 := e1.Cause().(type) {
case *bchain.RPCError:
if e2.Code == -5 { // "No information available about transaction"
return true
}
}
}
return false
}
// GetTransaction returns a transaction by the transaction ID.
func (z *ZCashRPC) GetTransaction(txid string) (*bchain.Tx, error) {
glog.V(1).Info("rpc: getrawtransaction ", txid)
@ -155,6 +173,8 @@ func (z *ZCashRPC) GetBlockHeader(hash string) (*bchain.BlockHeader, error) {
}
return &res.Result, nil
}
// TODO pouzit misto toho estimate fee?
// EstimateSmartFee returns fee estimation.
func (b *ZCashRPC) EstimateSmartFee(blocks int, conservative bool) (float64, error) {
return 0, errors.New("EstimateSmartFee: not implemented")