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()
}
batch = store.batch
}
batch.Delete(AccountIDKey(accountID))
- batch.Delete(AccountAliasKey(accountAlias))
+ batch.Delete(accountAliasKey(accountAlias))
if store.batch == nil {
batch.Write()
}
// 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
// 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))
}
}
// 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
// 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))
}
}
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[:]...)
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)...)
}
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")
}
}