}
func (w *Wallet) getExternalDefinition(assetID *bc.AssetID) json.RawMessage {
- definitionByte := w.store.GetAssetDefinition(assetID)
- if definitionByte == nil {
- return nil
+ externalAsset, err := w.store.GetAssetDefinition(assetID)
+ if err != nil {
+ log.WithFields(log.Fields{"module": logModule, "err": err}).Warning("fail on get asset definition.")
}
-
- definitionMap := make(map[string]interface{})
- if err := json.Unmarshal(definitionByte, &definitionMap); err != nil {
+ if externalAsset == nil {
return nil
}
- alias := assetID.String()
- externalAsset := &asset.Asset{
- AssetID: *assetID,
- Alias: &alias,
- DefinitionMap: definitionMap,
- RawDefinitionByte: definitionByte,
+ if err := w.AssetReg.SaveAsset(externalAsset, *externalAsset.Alias); err != nil {
+ log.WithFields(log.Fields{"module": logModule, "err": err, "assetAlias": *externalAsset.Alias}).Warning("fail on save external asset to internal asset DB")
}
-
- if err := w.AssetReg.SaveAsset(externalAsset, alias); err != nil {
- log.WithFields(log.Fields{"module": logModule, "err": err, "assetID": alias}).Warning("fail on save external asset to internal asset DB")
- }
- return definitionByte
+ return json.RawMessage(externalAsset.RawDefinitionByte)
}
func (w *Wallet) getAliasDefinition(assetID bc.AssetID) (string, json.RawMessage) {
func getAccountFromACP(program []byte, store WalletStorer) (*account.Account, error) {
var hash common.Hash
- accountCP := account.CtrlProgram{}
localAccount := account.Account{}
sha3pool.Sum256(hash[:], program)
- rawProgram := store.GetRawProgram(hash)
- if rawProgram == nil {
- return nil, fmt.Errorf("failed get account control program:%x ", hash)
- }
-
- if err := json.Unmarshal(rawProgram, &accountCP); err != nil {
+ accountCP, err := store.GetControlProgram(hash)
+ if err != nil {
return nil, err
}
+ if accountCP == nil {
+ return nil, fmt.Errorf("failed get account control program:%x ", hash)
+ }
- accountValue := store.GetAccount(accountCP.AccountID)
+ accountValue := store.GetAccountByAccountID(accountCP.AccountID)
if accountValue == nil {
return nil, fmt.Errorf("failed get account:%s ", accountCP.AccountID)
}
if segwit.IsP2WPKHScript(prog) {
if pubHash, err := segwit.GetHashFromStandardProg(prog); err == nil {
- return buildP2PKHAddress(pubHash, netParams)
+ return BuildP2PKHAddress(pubHash, netParams)
}
} else if segwit.IsP2WSHScript(prog) {
if scriptHash, err := segwit.GetHashFromStandardProg(prog); err == nil {
- return buildP2SHAddress(scriptHash, netParams)
+ return BuildP2SHAddress(scriptHash, netParams)
}
}
return ""
}
-func buildP2PKHAddress(pubHash []byte, netParams *consensus.Params) string {
+func BuildP2PKHAddress(pubHash []byte, netParams *consensus.Params) string {
address, err := common.NewAddressWitnessPubKeyHash(pubHash, netParams)
if err != nil {
return ""
return address.EncodeAddress()
}
-func buildP2SHAddress(scriptHash []byte, netParams *consensus.Params) string {
+func BuildP2SHAddress(scriptHash []byte, netParams *consensus.Params) string {
address, err := common.NewAddressWitnessScriptHash(scriptHash, netParams)
if err != nil {
return ""