import (
"bytes"
"container/list"
- "encoding/json"
"sort"
"sync"
"sync/atomic"
"time"
- log "github.com/sirupsen/logrus"
-
- "github.com/vapor/database"
"github.com/vapor/errors"
"github.com/vapor/protocol/bc"
)
// `sync/atomic` expects the first word in an allocated struct to be 64-bit
// aligned on both ARM and x86-32. See https://goo.gl/zW7dgq for more details.
nextIndex uint64
- store database.AccountStorer
+ store AccountStorer
mtx sync.RWMutex
currentHeight func() uint64
reservations map[uint64]*reservation
}
-func newUtxoKeeper(f func() uint64, store database.AccountStorer) *utxoKeeper {
+func newUtxoKeeper(f func() uint64, store AccountStorer) *utxoKeeper {
uk := &utxoKeeper{
store: store,
currentHeight: f,
}
}
- rawUTXOs := uk.store.GetUTXOs()
- for _, rawUTXO := range rawUTXOs {
- utxo := new(UTXO)
- if err := json.Unmarshal(rawUTXO, utxo); err != nil {
- log.WithFields(log.Fields{"module": logModule, "err": err}).Error("utxoKeeper findUtxos fail on unmarshal utxo")
- continue
- }
- appendUtxo(utxo)
+ UTXOs := uk.store.GetUTXOs()
+ for _, UTXO := range UTXOs {
+ appendUtxo(UTXO)
}
if !useUnconfirmed {
if u, ok := uk.unconfirmed[outHash]; useUnconfirmed && ok {
return u, nil
}
-
- u := &UTXO{}
- if data := uk.store.GetStandardUTXO(outHash); data != nil {
- return u, json.Unmarshal(data, u)
- }
- if data := uk.store.GetContractUTXO(outHash); data != nil {
- return u, json.Unmarshal(data, u)
- }
- return nil, ErrMatchUTXO
+ return uk.store.GetUTXO(outHash)
}
func (uk *utxoKeeper) optUTXOs(utxos []*UTXO, amount uint64) ([]*UTXO, uint64, uint64) {