func AssetFromDB(typ xdr.AssetType, code string, issuer string) (result xdr.Asset, err error) { switch typ { case xdr.AssetTypeAssetTypeNative: result, err = xdr.NewAsset(xdr.AssetTypeAssetTypeNative, nil) case xdr.AssetTypeAssetTypeCreditAlphanum4: var ( an xdr.AssetAlphaNum4 decoded []byte pkey xdr.Uint256 ) copy(an.AssetCode[:], []byte(code)) decoded, err = strkey.Decode(strkey.VersionByteAccountID, issuer) if err != nil { return } copy(pkey[:], decoded) an.Issuer, err = xdr.NewAccountId(xdr.CryptoKeyTypeKeyTypeEd25519, pkey) if err != nil { return } result, err = xdr.NewAsset(xdr.AssetTypeAssetTypeCreditAlphanum4, an) case xdr.AssetTypeAssetTypeCreditAlphanum12: var ( an xdr.AssetAlphaNum12 decoded []byte pkey xdr.Uint256 ) copy(an.AssetCode[:], []byte(code)) decoded, err = strkey.Decode(strkey.VersionByteAccountID, issuer) if err != nil { return } copy(pkey[:], decoded) an.Issuer, err = xdr.NewAccountId(xdr.CryptoKeyTypeKeyTypeEd25519, pkey) if err != nil { return } result, err = xdr.NewAsset(xdr.AssetTypeAssetTypeCreditAlphanum12, an) } return }
func makeAsset(typ xdr.AssetType, code string, issuer string) xdr.Asset { if typ == xdr.AssetTypeAssetTypeNative { result, _ := xdr.NewAsset(typ, nil) return result } an := xdr.AssetAlphaNum4{} copy(an.AssetCode[:], code[:]) raw := strkey.MustDecode(strkey.VersionByteAccountID, issuer) var key xdr.Uint256 copy(key[:], raw) an.Issuer, _ = xdr.NewAccountId(xdr.CryptoKeyTypeKeyTypeEd25519, key) result, _ := xdr.NewAsset(typ, an) return result }
// GetAccountID retireves an xdr.AccountID by attempting to decode a stellar // address at the provided name. func (base *Base) GetAccountID(name string) (result xdr.AccountId) { raw, err := strkey.Decode(strkey.VersionByteAccountID, base.GetString(name)) if base.Err != nil { return } if err != nil { base.SetInvalidField(name, err) return } var key xdr.Uint256 copy(key[:], raw) result, err = xdr.NewAccountId(xdr.CryptoKeyTypeKeyTypeEd25519, key) if err != nil { base.SetInvalidField(name, err) return } return }