Add load address by serialized address descriptor

pull/380/head
Martin Boehm 2020-01-25 22:17:17 +01:00
parent d6de5b8048
commit 273b880245
2 changed files with 14 additions and 1 deletions

View File

@ -652,7 +652,12 @@ func (w *Worker) txFromTxid(txid string, bestheight uint32, option AccountDetail
func (w *Worker) getAddrDescAndNormalizeAddress(address string) (bchain.AddressDescriptor, string, error) {
addrDesc, err := w.chainParser.GetAddrDescFromAddress(address)
if err != nil {
return nil, "", NewAPIError(fmt.Sprintf("Invalid address, %v", err), true)
var errAd error
// try if the address is not address descriptor converted to string
addrDesc, errAd = bchain.AddressDescriptorFromString(address)
if errAd != nil {
return nil, "", NewAPIError(fmt.Sprintf("Invalid address, %v", err), true)
}
}
// convert the address to the format defined by the parser
addresses, _, err := w.chainParser.GetAddressesFromAddrDesc(addrDesc)

View File

@ -168,6 +168,14 @@ func (ad AddressDescriptor) String() string {
return "ad:" + hex.EncodeToString(ad)
}
// AddressDescriptorFromString converts string created by AddressDescriptor.String to AddressDescriptor
func AddressDescriptorFromString(s string) (AddressDescriptor, error) {
if len(s) > 3 && s[0:3] == "ad:" {
return hex.DecodeString(s[3:])
}
return nil, errors.New("Not AddressDescriptor")
}
// EthereumType specific
// Erc20Contract contains info about ERC20 contract