X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=account%2Futxo_keeper.go;fp=account%2Futxo_keeper.go;h=cd9beea656c15de3335ae75fea54bb3f4c8f25c3;hp=27055269e1762c91eec591f9f587b5f6ef28d14e;hb=cc0bcc7e1e4fc53e669ac46ba3fe919b5c6a79c9;hpb=d2ec2911b1f5642c1b74b450b6e69e69a4a80fa1 diff --git a/account/utxo_keeper.go b/account/utxo_keeper.go index 27055269..cd9beea6 100644 --- a/account/utxo_keeper.go +++ b/account/utxo_keeper.go @@ -1,6 +1,7 @@ package account import ( + "bytes" "container/list" "encoding/json" "sort" @@ -112,11 +113,11 @@ func (uk *utxoKeeper) RemoveUnconfirmedUtxo(hashes []*bc.Hash) { } } -func (uk *utxoKeeper) Reserve(accountID string, assetID *bc.AssetID, amount uint64, useUnconfirmed bool, exp time.Time) (*reservation, error) { +func (uk *utxoKeeper) Reserve(accountID string, assetID *bc.AssetID, amount uint64, useUnconfirmed bool, vote []byte, exp time.Time) (*reservation, error) { uk.mtx.Lock() defer uk.mtx.Unlock() - utxos, immatureAmount := uk.findUtxos(accountID, assetID, useUnconfirmed) + utxos, immatureAmount := uk.findUtxos(accountID, assetID, useUnconfirmed, vote) optUtxos, optAmount, reservedAmount := uk.optUTXOs(utxos, amount) if optAmount+reservedAmount+immatureAmount < amount { return nil, ErrInsufficient @@ -203,12 +204,12 @@ func (uk *utxoKeeper) expireReservation(t time.Time) { } } -func (uk *utxoKeeper) findUtxos(accountID string, assetID *bc.AssetID, useUnconfirmed bool) ([]*UTXO, uint64) { +func (uk *utxoKeeper) findUtxos(accountID string, assetID *bc.AssetID, useUnconfirmed bool, vote []byte) ([]*UTXO, uint64) { immatureAmount := uint64(0) currentHeight := uk.currentHeight() utxos := []*UTXO{} appendUtxo := func(u *UTXO) { - if u.AccountID != accountID || u.AssetID != *assetID { + if u.AccountID != accountID || u.AssetID != *assetID || !bytes.Equal(u.Vote, vote) { return } if u.ValidHeight > currentHeight {