Insert utxos in fixUtxo in the growing order

utxocheck
Martin Boehm 2020-02-17 12:19:44 +01:00
parent 72e48ce658
commit b6e3f26eb2
1 changed files with 25 additions and 21 deletions

View File

@ -1898,30 +1898,34 @@ 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 { err := d.GetAddrDescTransactions(addrDesc, 0, ^uint32(0), func(txid string, height uint32, indexes []int32) error {
var ta *TxAddresses var ta *TxAddresses
var err error 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 { for _, index := range indexes {
// take only outputs // take only outputs
if index >= 0 { if index < 0 {
if ta == nil { break
ta, err = d.GetTxAddresses(txid) }
if err != nil { if ta == nil {
return err ta, err = d.GetTxAddresses(txid)
} if err != nil {
return err
} }
if ta == nil { }
return errors.New("DB inconsistency: tx " + txid + ": not found in txAddresses") if ta == nil {
} else { return errors.New("DB inconsistency: tx " + txid + ": not found in txAddresses")
if len(ta.Outputs) <= int(index) { }
glog.Warning("DB inconsistency: txAddresses " + txid + " does not have enough outputs") if len(ta.Outputs) <= int(index) {
} else { glog.Warning("DB inconsistency: txAddresses " + txid + " does not have enough outputs")
tao := &ta.Outputs[index] } else {
if !tao.Spent { tao := &ta.Outputs[index]
bTxid, _ := d.chainParser.PackTxid(txid) if !tao.Spent {
checksumFromTxs.Add(&checksumFromTxs, &tao.ValueSat) bTxid, _ := d.chainParser.PackTxid(txid)
utxos = append(utxos, Utxo{BtxID: bTxid, Height: height, Vout: index, ValueSat: tao.ValueSat}) checksumFromTxs.Add(&checksumFromTxs, &tao.ValueSat)
if checksumFromTxs.Cmp(&ba.BalanceSat) == 0 { utxos = append(utxos, Utxo{BtxID: bTxid, Height: height, Vout: index, ValueSat: tao.ValueSat})
return &StopIteration{} if checksumFromTxs.Cmp(&ba.BalanceSat) == 0 {
} return &StopIteration{}
}
} }
} }
} }