package database
import (
+ "encoding/hex"
"encoding/json"
"fmt"
"strings"
// delete account control program
cps, err := store.ListControlPrograms()
+ fmt.Println("len(cps):", len(cps))
if err != nil {
return err
}
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
}
)
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
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}
// 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()...)
}
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)
}
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