OSDN Git Service

update
authorChengcheng Zhang <943420582@qq.com>
Wed, 26 Jun 2019 10:37:39 +0000 (18:37 +0800)
committerChengcheng Zhang <943420582@qq.com>
Wed, 26 Jun 2019 10:37:39 +0000 (18:37 +0800)
database/account_store.go
database/store_key.go
database/store_key_test.go

index 2a7e158..3b5e281 100644 (file)
@@ -45,7 +45,7 @@ func (store *AccountStore) SetAccount(accountID, accountAlias string, rawAccount
                batch = store.batch
        }
        batch.Set(AccountIDKey(accountID), rawAccount)
-       batch.Set(AccountAliasKey(accountAlias), []byte(accountID))
+       batch.Set(accountAliasKey(accountAlias), []byte(accountID))
        if store.batch == nil {
                batch.Write()
        }
@@ -58,7 +58,7 @@ func (store *AccountStore) DeleteAccount(accountID, accountAlias string) {
                batch = store.batch
        }
        batch.Delete(AccountIDKey(accountID))
-       batch.Delete(AccountAliasKey(accountAlias))
+       batch.Delete(accountAliasKey(accountAlias))
        if store.batch == nil {
                batch.Write()
        }
@@ -67,15 +67,15 @@ func (store *AccountStore) DeleteAccount(accountID, accountAlias string) {
 // SetAccountIndex set account index
 func (store *AccountStore) SetAccountIndex(xpubs []chainkd.XPub, keyIndex uint64) {
        if store.batch == nil {
-               store.accountDB.Set(AccountIndexKey(xpubs), common.Unit64ToBytes(keyIndex))
+               store.accountDB.Set(accountIndexKey(xpubs), common.Unit64ToBytes(keyIndex))
        } else {
-               store.batch.Set(AccountIndexKey(xpubs), common.Unit64ToBytes(keyIndex))
+               store.batch.Set(accountIndexKey(xpubs), common.Unit64ToBytes(keyIndex))
        }
 }
 
 // GetAccountByAccountAlias get account by account alias
 func (store *AccountStore) GetAccountByAccountAlias(accountAlias string) []byte {
-       return store.accountDB.Get(AccountAliasKey(accountAlias))
+       return store.accountDB.Get(accountAliasKey(accountAlias))
 }
 
 // GetAccountByAccountID get account by accountID
@@ -85,15 +85,15 @@ func (store *AccountStore) GetAccountByAccountID(accountID string) []byte {
 
 // GetAccountIndex get account index by account xpubs
 func (store *AccountStore) GetAccountIndex(xpubs []chainkd.XPub) []byte {
-       return store.accountDB.Get(AccountIndexKey(xpubs))
+       return store.accountDB.Get(accountIndexKey(xpubs))
 }
 
 // DeleteAccountByAccountAlias delete account by account alias
 func (store *AccountStore) DeleteAccountByAccountAlias(accountAlias string) {
        if store.batch == nil {
-               store.accountDB.Delete(AccountAliasKey(accountAlias))
+               store.accountDB.Delete(accountAliasKey(accountAlias))
        } else {
-               store.batch.Delete(AccountAliasKey(accountAlias))
+               store.batch.Delete(accountAliasKey(accountAlias))
        }
 }
 
@@ -131,15 +131,15 @@ func (store *AccountStore) DeleteBip44ContractIndex(accountID string) {
 // DeleteContractIndex delete contract index by accountID
 func (store *AccountStore) DeleteContractIndex(accountID string) {
        if store.batch == nil {
-               store.accountDB.Delete(ContractIndexKey(accountID))
+               store.accountDB.Delete(contractIndexKey(accountID))
        } else {
-               store.batch.Delete(ContractIndexKey(accountID))
+               store.batch.Delete(contractIndexKey(accountID))
        }
 }
 
 // GetContractIndex get contract index
 func (store *AccountStore) GetContractIndex(accountID string) []byte {
-       return store.accountDB.Get(ContractIndexKey(accountID))
+       return store.accountDB.Get(contractIndexKey(accountID))
 }
 
 // GetAccountUTXOs get account utxos by account id
@@ -237,9 +237,9 @@ func (store *AccountStore) SetRawProgram(hash common.Hash, program []byte) {
 // SetContractIndex set contract index
 func (store *AccountStore) SetContractIndex(accountID string, index uint64) {
        if store.batch == nil {
-               store.accountDB.Set(ContractIndexKey(accountID), common.Unit64ToBytes(index))
+               store.accountDB.Set(contractIndexKey(accountID), common.Unit64ToBytes(index))
        } else {
-               store.batch.Set(ContractIndexKey(accountID), common.Unit64ToBytes(index))
+               store.batch.Set(contractIndexKey(accountID), common.Unit64ToBytes(index))
        }
 }
 
index 85810ab..22d96fb 100644 (file)
@@ -30,12 +30,31 @@ const (
        CoinbaseAbKey       = "CoinbaseArbitrary"
 )
 
+// // leveldb key prefix
+// const (
+//     UTXOPrefix  = iota //UTXOPrefix is StandardUTXOKey prefix
+//     SUTXOPrefix        //SUTXOPrefix is ContractUTXOKey prefix
+//     ContractPrefix
+//     ContractIndexPrefix
+//     AccountPrefix // AccountPrefix is account ID prefix
+//     AccountAliasPrefix
+//     AccountIndexPrefix
+//     TxPrefix            //TxPrefix is wallet database transactions prefix
+//     TxIndexPrefix       //TxIndexPrefix is wallet database tx index prefix
+//     UnconfirmedTxPrefix //UnconfirmedTxPrefix is txpool unconfirmed transactions prefix
+//     GlobalTxIndexPrefix //GlobalTxIndexPrefix is wallet database global tx index prefix
+//     WalletKey
+//     MiningAddressKey
+//     CoinbaseAbKey
+// )
+
+// errors
 var (
        ErrFindAccount       = errors.New("Failed to find account")
        errAccntTxIDNotFound = errors.New("account TXID not found")
 )
 
-func AccountIndexKey(xpubs []chainkd.XPub) []byte {
+func accountIndexKey(xpubs []chainkd.XPub) []byte {
        var hash [32]byte
        var xPubs []byte
        cpy := append([]chainkd.XPub{}, xpubs[:]...)
@@ -108,10 +127,10 @@ func formatKey(blockHeight uint64, position uint32) string {
        return fmt.Sprintf("%016x%08x", blockHeight, position)
 }
 
-func ContractIndexKey(accountID string) []byte {
+func contractIndexKey(accountID string) []byte {
        return append([]byte(ContractIndexPrefix), []byte(accountID)...)
 }
 
-func AccountAliasKey(name string) []byte {
+func accountAliasKey(name string) []byte {
        return append([]byte(AccountAliasPrefix), []byte(name)...)
 }
index 317369d..f2aa943 100644 (file)
@@ -34,11 +34,11 @@ func TestAccountIndexKey(t *testing.T) {
 
        xpubs1 := []chainkd.XPub{xpub1.XPub, xpub2.XPub}
        xpubs2 := []chainkd.XPub{xpub2.XPub, xpub1.XPub}
-       if !reflect.DeepEqual(AccountIndexKey(xpubs1), AccountIndexKey(xpubs2)) {
-               t.Fatal("AccountIndexKey test err")
+       if !reflect.DeepEqual(accountIndexKey(xpubs1), accountIndexKey(xpubs2)) {
+               t.Fatal("accountIndexKey test err")
        }
 
        if reflect.DeepEqual(xpubs1, xpubs2) {
-               t.Fatal("AccountIndexKey test err")
+               t.Fatal("accountIndexKey test err")
        }
 }