// 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 }
// Address returns the strkey encoded form of this AccountId. This method will // panic if the accountid is backed by a public key of an unknown type. func (aid *AccountId) Address() string { if aid == nil { return "" } switch aid.Type { case CryptoKeyTypeKeyTypeEd25519: ed := aid.MustEd25519() raw := make([]byte, 32) copy(raw, ed[:]) return strkey.MustEncode(strkey.VersionByteAccountID, raw) default: panic(fmt.Errorf("Unknown account id type: %v", aid.Type)) } }
func (kp *Full) Address() string { return strkey.MustEncode(strkey.VersionByteAccountID, kp.publicKey()[:]) }