// StandardUTXOKey makes an account unspent outputs key to store
func StandardUTXOKey(id bc.Hash) []byte {
- name := id.String()
- return append(UTXOPrefix, []byte(name)...)
+ // name := id.String()
+ // return append(UTXOPrefix, []byte(name)...)
+ return append(UTXOPrefix, id.Bytes()...)
}
// ContractUTXOKey makes a smart contract unspent outputs key to store
func ContractUTXOKey(id bc.Hash) []byte {
- name := id.String()
- return append(SUTXOPrefix, []byte(name)...)
+ // name := id.String()
+ // return append(SUTXOPrefix, []byte(name)...)
+ return append(SUTXOPrefix, id.Bytes()...)
}
func calcDeleteKey(blockHeight uint64) []byte {
// ListAccountUTXOs get all account unspent outputs
func (store *WalletStore) ListAccountUTXOs(key string) ([]*acc.UTXO, error) {
+ fmt.Println("ListAccountUTXOs []byte(key):", []byte(key))
accountUtxoIter := store.walletDB.IteratorPrefix([]byte(key))
defer accountUtxoIter.Release()
)
const (
- colon = 0x3a
utxoPrefix byte = iota //UTXOPrefix is StandardUTXOKey prefix
sutxoPrefix //SUTXOPrefix is ContractUTXOKey prefix
contractPrefix
// leveldb key prefix
var (
- UTXOPrefix = []byte{utxoPrefix, colon}
- SUTXOPrefix = []byte{sutxoPrefix, colon}
+ colon byte = 0x3a
+ UTXOPrefix = []byte{utxoPrefix, colon}
+ SUTXOPrefix = []byte{sutxoPrefix, colon}
// ContractPrefix = []byte{contractPrefix, contractPrefix, colon}
ContractPrefix = "Contract:"
ContractIndexPrefix = []byte{contractIndexPrefix, colon}
// StandardUTXOKey makes an account unspent outputs key to store
func StandardUTXOKey(id bc.Hash) []byte {
- name := id.String()
- return append(UTXOPrefix, []byte(name)...)
+ // name := id.String()
+ // return append(UTXOPrefix, []byte(name)...)
+ return append(UTXOPrefix, id.Bytes()...)
}
// ContractUTXOKey makes a smart contract unspent outputs key to store
func ContractUTXOKey(id bc.Hash) []byte {
- name := id.String()
- return append(SUTXOPrefix, []byte(name)...)
+ // name := id.String()
+ // return append(SUTXOPrefix, []byte(name)...)
+ return append(SUTXOPrefix, id.Bytes()...)
}
func calcDeleteKey(blockHeight uint64) []byte {
// ListAccountUTXOs get all account unspent outputs
func (store *MockWalletStore) ListAccountUTXOs(key string) ([]*acc.UTXO, error) {
+ fmt.Println("ListAccountUTXOs []byte(key):", []byte(key))
accountUtxoIter := store.walletDB.IteratorPrefix([]byte(key))
defer accountUtxoIter.Release()
package wallet
import (
+ "encoding/hex"
+
log "github.com/sirupsen/logrus"
"github.com/vapor/account"
if unconfirmed {
accountUtxos = w.AccountMgr.ListUnconfirmedUtxo(accountID, isSmartContract)
}
+ idBytes, _ := hex.DecodeString(id)
- confirmedUTXOs, err := w.store.ListAccountUTXOs(string(prefix) + id)
+ // confirmedUTXOs, err := w.store.ListAccountUTXOs(string(prefix) + id)
+ confirmedUTXOs, err := w.store.ListAccountUTXOs(string(append(prefix, idBytes...)))
if err != nil {
log.WithFields(log.Fields{"module": logModule, "err": err}).Error("GetAccountUtxos fail.")
}
},
{
dbUtxos: map[string]*account.UTXO{
- string(database.StandardUTXOKey(bc.Hash{V0: 1})): &account.UTXO{
+ string(mock.StandardUTXOKey(bc.Hash{V0: 1})): &account.UTXO{
OutputID: bc.Hash{V0: 1},
},
- string(database.StandardUTXOKey(bc.Hash{V0: 1, V1: 2})): &account.UTXO{
+ string(mock.StandardUTXOKey(bc.Hash{V0: 1, V1: 2})): &account.UTXO{
OutputID: bc.Hash{V0: 1, V1: 2},
},
- string(database.StandardUTXOKey(bc.Hash{V0: 2})): &account.UTXO{
+ string(mock.StandardUTXOKey(bc.Hash{V0: 2})): &account.UTXO{
OutputID: bc.Hash{V0: 2},
},
- string(database.StandardUTXOKey(bc.Hash{V0: 2, V1: 2})): &account.UTXO{
+ string(mock.StandardUTXOKey(bc.Hash{V0: 2, V1: 2})): &account.UTXO{
OutputID: bc.Hash{V0: 2, V1: 2},
},
+
+ // hex.EncodeToString(mock.StandardUTXOKey(bc.Hash{V0: 1})): &account.UTXO{
+ // OutputID: bc.Hash{V0: 1},
+ // },
+ // hex.EncodeToString(mock.StandardUTXOKey(bc.Hash{V0: 1, V1: 2})): &account.UTXO{
+ // OutputID: bc.Hash{V0: 1, V1: 2},
+ // },
+ // hex.EncodeToString(mock.StandardUTXOKey(bc.Hash{V0: 2})): &account.UTXO{
+ // OutputID: bc.Hash{V0: 2},
+ // },
+ // hex.EncodeToString(mock.StandardUTXOKey(bc.Hash{V0: 2, V1: 2})): &account.UTXO{
+ // OutputID: bc.Hash{V0: 2, V1: 2},
+ // },
},
unconfirmedUtxos: []*account.UTXO{
&account.UTXO{
if err != nil {
t.Error(err)
}
+ fmt.Println("k:", []byte(k))
+ // newKey, _ := hex.DecodeString(k)
+ // fmt.Println("newkey:", newKey)
+ // testDB.Set([]byte(k), data)
testDB.Set([]byte(k), data)
}
}
for k := range c.dbUtxos {
+ // newKey, _ := hex.DecodeString(k)
+ // testDB.Delete([]byte(k))
testDB.Delete([]byte(k))
}
}