Release v0.3.0

This commit is contained in:
Manu Herrera
2020-11-09 10:05:29 -03:00
parent 4e9aa7a3c5
commit 8107c4478b
1265 changed files with 440488 additions and 107809 deletions

View File

@@ -39,6 +39,7 @@ type TxDetails struct {
Block BlockMeta
Credits []CreditRecord
Debits []DebitRecord
Label string
}
// minedTxDetails fetches the TxDetails for the mined transaction with hash
@@ -90,7 +91,17 @@ func (s *Store) minedTxDetails(ns walletdb.ReadBucket, txHash *chainhash.Hash, r
details.Debits = append(details.Debits, debIter.elem)
}
return &details, debIter.err
if debIter.err != nil {
return nil, debIter.err
}
// Finally, we add the transaction label to details.
details.Label, err = s.TxLabel(ns, *txHash)
if err != nil {
return nil, err
}
return &details, nil
}
// unminedTxDetails fetches the TxDetails for the unmined transaction with the
@@ -158,9 +169,40 @@ func (s *Store) unminedTxDetails(ns walletdb.ReadBucket, txHash *chainhash.Hash,
})
}
// Finally, we add the transaction label to details.
details.Label, err = s.TxLabel(ns, *txHash)
if err != nil {
return nil, err
}
return &details, nil
}
// TxLabel looks up a transaction label for the txHash provided. If the store
// has no labels in it, or the specific txHash does not have a label, an empty
// string and no error are returned.
func (s *Store) TxLabel(ns walletdb.ReadBucket, txHash chainhash.Hash) (string,
error) {
label, err := FetchTxLabel(ns, txHash)
switch err {
// If there are no saved labels yet (the bucket has not been created) or
// there is not a label for this particular tx, we ignore the error.
case ErrNoLabelBucket:
fallthrough
case ErrTxLabelNotFound:
return "", nil
// If we found the label, we return it.
case nil:
return label, nil
}
// Otherwise, another error occurred while looking uo the label, so we
// return it.
return "", err
}
// TxDetails looks up all recorded details regarding a transaction with some
// hash. In case of a hash collision, the most recent transaction with a
// matching hash is returned.
@@ -296,52 +338,13 @@ func (s *Store) rangeBlockTransactions(ns walletdb.ReadBucket, begin, end int32,
"block %v", txHash, block.Height)
return false, storeError(ErrData, str, nil)
}
detail := TxDetails{
Block: BlockMeta{
Block: block.Block,
Time: block.Time,
},
}
err := readRawTxRecord(&txHash, v, &detail.TxRecord)
detail, err := s.minedTxDetails(ns, &txHash, k, v)
if err != nil {
return false, err
}
credIter := makeReadCreditIterator(ns, k)
for credIter.next() {
if int(credIter.elem.Index) >= len(detail.MsgTx.TxOut) {
str := "saved credit index exceeds number of outputs"
return false, storeError(ErrData, str, nil)
}
// The credit iterator does not record whether
// this credit was spent by an unmined
// transaction, so check that here.
if !credIter.elem.Spent {
k := canonicalOutPoint(&txHash, credIter.elem.Index)
spent := existsRawUnminedInput(ns, k) != nil
credIter.elem.Spent = spent
}
detail.Credits = append(detail.Credits, credIter.elem)
}
if credIter.err != nil {
return false, credIter.err
}
debIter := makeReadDebitIterator(ns, k)
for debIter.next() {
if int(debIter.elem.Index) >= len(detail.MsgTx.TxIn) {
str := "saved debit index exceeds number of inputs"
return false, storeError(ErrData, str, nil)
}
detail.Debits = append(detail.Debits, debIter.elem)
}
if debIter.err != nil {
return false, debIter.err
}
details = append(details, detail)
details = append(details, *detail)
}
// Every block record must have at least one transaction, so it