// Extract is a helper function to extract information from an xdr.Asset // structure. It extracts the asset's type to the `typ` input parameter (which // must be either a *string or *xdr.AssetType). It also extracts the asset's // code and issuer to `code` and `issuer` respectively if they are of type // *string and the asset is non-native func (a Asset) Extract(typ interface{}, code interface{}, issuer interface{}) error { switch typ := typ.(type) { case *AssetType: *typ = a.Type case *string: switch a.Type { case AssetTypeAssetTypeNative: *typ = "native" case AssetTypeAssetTypeCreditAlphanum4: *typ = "credit_alphanum4" case AssetTypeAssetTypeCreditAlphanum12: *typ = "credit_alphanum12" } default: return errors.New("can't extract type") } if code != nil { switch code := code.(type) { case *string: switch a.Type { case AssetTypeAssetTypeCreditAlphanum4: an := a.MustAlphaNum4() *code = strings.TrimRight(string(an.AssetCode[:]), "\x00") case AssetTypeAssetTypeCreditAlphanum12: an := a.MustAlphaNum12() *code = strings.TrimRight(string(an.AssetCode[:]), "\x00") } default: return errors.New("can't extract code") } } if issuer != nil { switch issuer := issuer.(type) { case *string: switch a.Type { case AssetTypeAssetTypeCreditAlphanum4: an := a.MustAlphaNum4() raw := an.Issuer.MustEd25519() *issuer = strkey.MustEncode(strkey.VersionByteAccountID, raw[:]) case AssetTypeAssetTypeCreditAlphanum12: an := a.MustAlphaNum12() raw := an.Issuer.MustEd25519() *issuer = strkey.MustEncode(strkey.VersionByteAccountID, raw[:]) } default: return errors.New("can't extract issuer") } } return nil }
func (kp *Full) Address() string { return strkey.MustEncode(strkey.VersionByteAccountID, kp.publicKey()[:]) }