Add load address by serialized address descriptor
parent
95ac05b280
commit
af1d3fceaa
|
@ -652,7 +652,12 @@ func (w *Worker) txFromTxid(txid string, bestheight uint32, option AccountDetail
|
||||||
func (w *Worker) getAddrDescAndNormalizeAddress(address string) (bchain.AddressDescriptor, string, error) {
|
func (w *Worker) getAddrDescAndNormalizeAddress(address string) (bchain.AddressDescriptor, string, error) {
|
||||||
addrDesc, err := w.chainParser.GetAddrDescFromAddress(address)
|
addrDesc, err := w.chainParser.GetAddrDescFromAddress(address)
|
||||||
if err != nil {
|
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
|
// convert the address to the format defined by the parser
|
||||||
addresses, _, err := w.chainParser.GetAddressesFromAddrDesc(addrDesc)
|
addresses, _, err := w.chainParser.GetAddressesFromAddrDesc(addrDesc)
|
||||||
|
|
|
@ -168,6 +168,14 @@ func (ad AddressDescriptor) String() string {
|
||||||
return "ad:" + hex.EncodeToString(ad)
|
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
|
// EthereumType specific
|
||||||
|
|
||||||
// Erc20Contract contains info about ERC20 contract
|
// Erc20Contract contains info about ERC20 contract
|
||||||
|
|
Loading…
Reference in New Issue