)
const (
- maxAccountCache = 1000
- aliasPrefix = "ALI:"
- accountCPPrefix = "ACP:"
- contractIndexPrefix = "ACPI:"
+ maxAccountCache = 1000
)
var (
- miningAddressKey = []byte("miningAddress")
- accountIndexKey = []byte("accountIndex")
- accountPrefix = []byte("ACC:")
+ accountIndexKey = []byte("AccountIndex")
+ accountPrefix = []byte("Account:")
+ aliasPrefix = []byte("AccountAlias:")
+ contractIndexPrefix = []byte("ContractIndex")
+ contractPrefix = []byte("Contract:")
+ miningAddressKey = []byte("MiningAddress")
)
// pre-define errors for supporting bytom errorFormatter
)
func aliasKey(name string) []byte {
- return []byte(aliasPrefix + name)
+ return append(aliasPrefix, []byte(name)...)
}
-//Key account store prefix
+// Key account store prefix
func Key(name string) []byte {
return append(accountPrefix, []byte(name)...)
}
-//CPKey account control promgram store prefix
-func CPKey(hash common.Hash) []byte {
- return append([]byte(accountCPPrefix), hash[:]...)
+// ContractKey account control promgram store prefix
+func ContractKey(hash common.Hash) []byte {
+ return append(contractPrefix, hash[:]...)
}
func contractIndexKey(accountID string) []byte {
- return append([]byte(contractIndexPrefix), []byte(accountID)...)
+ return append(contractIndexPrefix, []byte(accountID)...)
}
// NewManager creates a new account manager
return account.Alias
}
-// CreateAddressForChange generate an address for the UTXO change
-func (m *Manager) CreateCtrlProgramForChange(ctx context.Context, accountID string) (cp *CtrlProgram, err error) {
- return m.CreateAddress(ctx, accountID, true)
-}
-
// CreateAddress generate an address for the select account
func (m *Manager) CreateAddress(ctx context.Context, accountID string, change bool) (cp *CtrlProgram, err error) {
account, err := m.FindByID(ctx, accountID)
return cp, nil
}
-// ListCtrlProgramsByAccountId
-func (m *Manager) ListCtrlProgramsByAccountId(ctx context.Context, accountId string) ([]*CtrlProgram, error) {
- cps, err := m.ListControlProgram()
- if err != nil {
- return nil, err
- }
-
- var result []*CtrlProgram
- for _, cp := range cps {
- if cp.Address == "" || cp.AccountID != accountId {
- continue
- }
- result = append(result, cp)
- }
- return result, nil
-}
-
func (m *Manager) createP2PKH(ctx context.Context, account *Account, change bool) (*CtrlProgram, error) {
idx := m.getNextContractIndex(account.ID)
path := signers.Path(account.Signer, signers.AccountKeySpace, idx)
}
sha3pool.Sum256(hash[:], prog.ControlProgram)
- m.db.Set(CPKey(hash), accountCP)
+ m.db.Set(ContractKey(hash), accountCP)
}
return nil
}
-func (m *Manager) DeleteAccountControlProgram(prog []byte) {
- var hash common.Hash
- sha3pool.Sum256(hash[:], prog)
- m.db.Delete(CPKey(hash))
-}
-
// IsLocalControlProgram check is the input control program belong to local
func (m *Manager) IsLocalControlProgram(prog []byte) bool {
var hash common.Hash
sha3pool.Sum256(hash[:], prog)
- bytes := m.db.Get(CPKey(hash))
+ bytes := m.db.Get(ContractKey(hash))
return bytes != nil
}
return program.ControlProgram, nil
}
-// AccountInfo
-type Info struct {
- AccountInfo string `json:"account_info"`
-}
-
// DeleteAccount deletes the account's ID or alias matching accountInfo.
-func (m *Manager) DeleteAccount(aliasOrId string) (err error) {
+func (m *Manager) DeleteAccount(aliasOrID string) (err error) {
account := &Account{}
- if account, err = m.FindByAlias(nil, aliasOrId); err != nil {
- if account, err = m.FindByID(nil, aliasOrId); err != nil {
+ if account, err = m.FindByAlias(nil, aliasOrID); err != nil {
+ if account, err = m.FindByID(nil, aliasOrID); err != nil {
return err
}
}
// ListControlProgram return all the local control program
func (m *Manager) ListControlProgram() ([]*CtrlProgram, error) {
var cps []*CtrlProgram
- cpIter := m.db.IteratorPrefix([]byte(accountCPPrefix))
+ cpIter := m.db.IteratorPrefix(contractPrefix)
defer cpIter.Release()
for cpIter.Next() {
const (
maxAssetCache = 1000
- //AliasPrefix is asset alias prefix
- AliasPrefix = "ALS:"
- //ExternalAssetPrefix is external definition assets prefix
- ExternalAssetPrefix = "EXA"
)
var (
- assetIndexKey = []byte("assetIndex")
- assetPrefix = []byte("ASS:")
+ assetIndexKey = []byte("AssetIndex")
+ assetPrefix = []byte("Asset:")
+ aliasPrefix = []byte("AssetAlias:")
+ extAssetPrefix = []byte("EXA:")
)
func initNativeAsset() {
// AliasKey store asset alias prefix
func AliasKey(name string) []byte {
- return []byte(AliasPrefix + name)
+ return append(aliasPrefix, []byte(name)...)
}
-//Key asset store prefix
+// AssetKey asset store prefix
func Key(id *bc.AssetID) []byte {
return append(assetPrefix, id.Bytes()...)
}
-//CalcExtAssetKey return store external assets key
-func CalcExtAssetKey(id *bc.AssetID) []byte {
- name := id.String()
- return []byte(ExternalAssetPrefix + name)
+// ExtAssetKey return store external assets key
+func ExtAssetKey(id *bc.AssetID) []byte {
+ return append(extAssetPrefix, id.Bytes()...)
}
// pre-define errors for supporting bytom errorFormatter
return asset, nil
}
- if extAsset := reg.db.Get(CalcExtAssetKey(id)); extAsset != nil {
+ if extAsset := reg.db.Get(ExtAssetKey(id)); extAsset != nil {
if err := json.Unmarshal(extAsset, asset); err != nil {
return nil, err
}
)
type rawOutput struct {
- OutputID bc.Hash
+ OutputID bc.Hash
bc.AssetAmount
ControlProgram []byte
txHash bc.Hash
if ii, ok := orig.TypedInput.(*types.IssuanceInput); ok {
if isValidJSON(ii.AssetDefinition) {
assetID := ii.AssetID()
- if assetExist := walletDB.Get(asset.CalcExtAssetKey(&assetID)); assetExist == nil {
- storeBatch.Set(asset.CalcExtAssetKey(&assetID), ii.AssetDefinition)
+ if assetExist := walletDB.Get(asset.ExtAssetKey(&assetID)); assetExist == nil {
+ storeBatch.Set(asset.ExtAssetKey(&assetID), ii.AssetDefinition)
}
}
}
}
sha3pool.Sum256(hash[:], []byte(s))
- bytes := w.DB.Get(account.CPKey(hash))
+ bytes := w.DB.Get(account.ContractKey(hash))
if bytes == nil {
continue
}
for _, v := range tx.Outputs {
var hash [32]byte
sha3pool.Sum256(hash[:], v.ControlProgram)
- if bytes := w.DB.Get(account.CPKey(hash)); bytes != nil {
+ if bytes := w.DB.Get(account.ContractKey(hash)); bytes != nil {
annotatedTxs = append(annotatedTxs, w.buildAnnotatedTransaction(tx, b, statusFail, pos))
continue transactionLoop
}