From 273b880245db229c743dd221dda484c643fe63a2 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Sat, 25 Jan 2020 22:17:17 +0100 Subject: [PATCH] Add load address by serialized address descriptor --- api/worker.go | 7 ++++++- bchain/types.go | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/api/worker.go b/api/worker.go index 42f881b3..e1802cca 100644 --- a/api/worker.go +++ b/api/worker.go @@ -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) diff --git a/bchain/types.go b/bchain/types.go index cad6b465..05523bf5 100644 --- a/bchain/types.go +++ b/bchain/types.go @@ -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