"github.com/vapor/consensus"
"github.com/vapor/consensus/segwit"
"github.com/vapor/crypto/sha3pool"
- "github.com/vapor/database"
"github.com/vapor/protocol/bc"
"github.com/vapor/protocol/bc/types"
)
}
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) {
}
// annotateTxs adds account data to transactions
-func annotateTxsAccount(txs []*query.AnnotatedTx, store database.WalletStorer) {
+func annotateTxsAccount(txs []*query.AnnotatedTx, store WalletStorer) {
for i, tx := range txs {
for j, input := range tx.Inputs {
//issue asset tx input SpentOutputID is nil
}
}
-func getAccountFromACP(program []byte, store database.WalletStorer) (*account.Account, error) {
+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.GetAccountByAccountID(accountCP.AccountID)
if accountValue == nil {
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 ""