From 94f9437e27115af9523a2f4701646f55ad4b5d59 Mon Sep 17 00:00:00 2001 From: Chengcheng Zhang <943420582@qq.com> Date: Tue, 2 Jul 2019 02:05:27 +0800 Subject: [PATCH] update --- database/account_store.go | 7 +++++-- database/wallet_store.go | 25 +++++-------------------- test/accounts_test.go | 10 ++++++---- wallet/utxo_test.go | 1 + 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/database/account_store.go b/database/account_store.go index 2f4aca75..91a00a9d 100644 --- a/database/account_store.go +++ b/database/account_store.go @@ -1,6 +1,7 @@ package database import ( + "encoding/hex" "encoding/json" "fmt" "strings" @@ -58,6 +59,7 @@ func (store *AccountStore) DeleteAccount(account *acc.Account) error { // delete account control program cps, err := store.ListControlPrograms() + fmt.Println("len(cps):", len(cps)) if err != nil { return err } @@ -232,12 +234,13 @@ func (store *AccountStore) ListAccounts(id string) ([]*acc.Account, error) { func (store *AccountStore) ListControlPrograms() ([]*acc.CtrlProgram, error) { cps := []*acc.CtrlProgram{} cpIter := store.accountDB.IteratorPrefix([]byte(ContractPrefix)) + // cpIter := store.accountDB.IteratorPrefix([]byte{0x02, 0x3a}) defer cpIter.Release() for cpIter.Next() { cp := new(acc.CtrlProgram) - fmt.Printf("cpiter value: %s, len: %v", cpIter.Value(), len(cpIter.Value())) - + v := hex.EncodeToString(cpIter.Value()) + fmt.Println("v:", v) if err := json.Unmarshal(cpIter.Value(), cp); err != nil { return nil, err } diff --git a/database/wallet_store.go b/database/wallet_store.go index 2c8fcf78..7b3450b6 100644 --- a/database/wallet_store.go +++ b/database/wallet_store.go @@ -18,25 +18,6 @@ import ( ) const ( - // UTXOPrefix = "ACU:" //UTXOPrefix is StandardUTXOKey prefix - // SUTXOPrefix = "SCU:" //SUTXOPrefix is ContractUTXOKey prefix - - ContractPrefix = "Contract:" - -// ContractIndexPrefix = "ContractIndex:" -// AccountPrefix = "Account:" // AccountPrefix is account ID prefix -// AccountAliasPrefix = "AccountAlias:" -// AccountIndexPrefix = "AccountIndex:" -// TxPrefix = "TXS:" //TxPrefix is wallet database transactions prefix -// TxIndexPrefix = "TID:" //TxIndexPrefix is wallet database tx index prefix -// UnconfirmedTxPrefix = "UTXS:" //UnconfirmedTxPrefix is txpool unconfirmed transactions prefix -// GlobalTxIndexPrefix = "GTID:" //GlobalTxIndexPrefix is wallet database global tx index prefix -// WalletKey = "WalletInfo" -// MiningAddressKey = "MiningAddress" -// CoinbaseAbKey = "CoinbaseArbitrary" -) - -const ( utxoPrefix byte = iota //UTXOPrefix is StandardUTXOKey prefix sUTXOPrefix //SUTXOPrefix is ContractUTXOKey prefix contractPrefix @@ -58,7 +39,8 @@ const ( var ( UTXOPrefix = []byte{utxoPrefix, colon} SUTXOPrefix = []byte{sUTXOPrefix, colon} - // ContractPrefix = []byte{contractPrefix, colon} + // ContractPrefix = []byte{contractPrefix, contractPrefix, colon} + ContractPrefix = "Contract:" ContractIndexPrefix = []byte{contractIndexPrefix, colon} AccountPrefix = []byte{accountPrefix, colon} // AccountPrefix is account ID prefix AccountAliasPrefix = []byte{accountAliasPrefix, colon} @@ -102,6 +84,9 @@ func Bip44ContractIndexKey(accountID string, change bool) []byte { // ContractKey account control promgram store prefix func ContractKey(hash bc.Hash) []byte { + fmt.Println("ContractKey...") + // h := hash.String() + // return append([]byte(ContractPrefix), []byte(h)...) return append([]byte(ContractPrefix), hash.Bytes()...) } diff --git a/test/accounts_test.go b/test/accounts_test.go index f8bef099..d2ad1802 100644 --- a/test/accounts_test.go +++ b/test/accounts_test.go @@ -88,16 +88,18 @@ func TestUpdateAccountAlias(t *testing.T) { m := mockAccountManager(t) account := m.createTestAccount(t, oldAlias, nil) - if err := m.Manager.UpdateAccountAlias("testID", newAlias); err == nil { - t.Fatal("expected error when using an invalid account id") + err := m.Manager.UpdateAccountAlias("testID", newAlias) + if err == nil { + t.Errorf("expected error when using an invalid account id") } - err := m.Manager.UpdateAccountAlias(account.ID, oldAlias) + err = m.Manager.UpdateAccountAlias(account.ID, oldAlias) if errors.Root(err) != acc.ErrDuplicateAlias { t.Errorf("expected %s when using a duplicate alias, got %v", acc.ErrDuplicateAlias, err) } - if err := m.Manager.UpdateAccountAlias(account.ID, newAlias); err != nil { + err = m.Manager.UpdateAccountAlias(account.ID, newAlias) + if err != nil { t.Errorf("expected account %v alias should be update", account) } diff --git a/wallet/utxo_test.go b/wallet/utxo_test.go index 75ddc607..7a7fc221 100644 --- a/wallet/utxo_test.go +++ b/wallet/utxo_test.go @@ -367,6 +367,7 @@ func TestFilterAccountUtxo(t *testing.T) { testDB.Set(key, data) } + fmt.Println("len(c.input):", len(c.input)) gotUtxos := w.filterAccountUtxo(c.input) sort.Slice(gotUtxos[:], func(i, j int) bool { return gotUtxos[i].Amount < gotUtxos[j].Amount -- 2.11.0