Insert utxos in fixUtxo in the growing order

pull/380/head
Martin Boehm 2020-02-17 12:19:44 +01:00
parent 9feccfdb2e
commit a4da2f3865
1 changed files with 25 additions and 21 deletions

View File

@ -1898,9 +1898,15 @@ func (d *RocksDB) fixUtxo(addrDesc bchain.AddressDescriptor, ba *AddrBalance) (b
err := d.GetAddrDescTransactions(addrDesc, 0, ^uint32(0), func(txid string, height uint32, indexes []int32) error {
var ta *TxAddresses
var err error
// sort the indexes so that the utxos are appended in the reverse order
sort.Slice(indexes, func(i, j int) bool {
return indexes[i] > indexes[j]
})
for _, index := range indexes {
// take only outputs
if index >= 0 {
if index < 0 {
break
}
if ta == nil {
ta, err = d.GetTxAddresses(txid)
if err != nil {
@ -1909,7 +1915,7 @@ func (d *RocksDB) fixUtxo(addrDesc bchain.AddressDescriptor, ba *AddrBalance) (b
}
if ta == nil {
return errors.New("DB inconsistency: tx " + txid + ": not found in txAddresses")
} else {
}
if len(ta.Outputs) <= int(index) {
glog.Warning("DB inconsistency: txAddresses " + txid + " does not have enough outputs")
} else {
@ -1924,8 +1930,6 @@ func (d *RocksDB) fixUtxo(addrDesc bchain.AddressDescriptor, ba *AddrBalance) (b
}
}
}
}
}
return nil
})
if err != nil {