func Allow(opts *Options) http.HandlerFunc {
	return func(res http.ResponseWriter, req *http.Request) {
		var (
			origin           = req.Header.Get(headerOrigin)
			requestedMethod  = req.Header.Get(headerRequestMethod)
			requestedHeaders = req.Header.Get(headerRequestHeaders)
			// additional headers to be added
			// to the response.
			headers map[string]string
		)

		if req.Method == "OPTIONS" &&
			(requestedMethod != "" || requestedHeaders != "") {
			// TODO: if preflight, respond with exact headers if allowed
			headers = opts.PreflightHeader(origin, requestedMethod, requestedHeaders)
		} else {
			headers = opts.Header(origin)
		}

		for key, value := range headers {
			res.Header().Set(key, value)
		}
	}
}

// Allows CORS for requests those match the provided options.

Allows CORS for requests those match the provided options .


func Renderer(options ...Options) martini.Handler {
	opt := prepareOptions(options)
	cs := prepareCharset(opt.Charset)
	t := compile(opt)
	return func(res http.ResponseWriter, req *http.Request, c martini.Context) {
		// recompile for easy development
		if martini.Env == martini.Dev {
			t = compile(opt)
		}
		tc, _ := t.Clone()
		c.MapTo(&renderer{res, req, tc, opt, cs}, (*Render)(nil))
	}
}

func
Renderer
(
options
...
Options
)
martini
.
Handler
{
opt
:=
prepareOptions
(
options
)
cs
:=
prepareCharset
(
opt
.
Charset
)
t
:=
compile
(
opt
)
return
func
(
res
http
.
ResponseWriter
,
req
*
http
.
Request
,
c
martini
.
Context
)
{
// recompile for easy development
if
martini
.
Env
==
martini
.
Dev
{
t
=
compile
(
opt
)
}
tc
,
_
:=
t
.
Clone
(
)
c
.
MapTo
(
&
renderer
{
res
,
req
,
tc
,
opt
,
cs
}
,
(
*
Render
)
(
)
)
}
}

// Renderer is a Middleware that maps a render.Render service into the Martini handler chain. An single variadic render.Options
// struct can be optionally provided to configure HTML rendering. The default directory for templates is "templates" and the default
// file extension is ".tmpl".
//
// If MARTINI_ENV is set to "" or "development" then templates will be recompiled on every request. For more performance, set the
// MARTINI_ENV environment variable to "production"

Renderer is a Middleware that maps a render . Render service into the Martini handler chain . An single variadic render . Options struct can be optionally provided to configure HTML rendering . The default directory for templates is templates and the default file extension is . tmpl . If MARTINI_ENV is set to or development then templates will be recompiled on every request . For more performance set the MARTINI_ENV environment variable to production


func (al AcceptLanguages) String() string {
	output := bytes.NewBufferString("")
	for i, language := range al {
		output.WriteString(fmt.Sprintf("%s (%1.1f)", language.Language, language.Quality))
		if i != len(al)-1 {
			output.WriteString(", ")
		}
	}

	if output.Len() == 0 {
		output.WriteString("[]")
	}

	return output.String()
}

func ( al AcceptLanguages ) String ( ) string { output := bytes . NewBufferString ( " " ) for i , language := range al { output . WriteString ( fmt . Sprintf ( " " , language . Language , language . Quality ) ) if i != len ( al ) - 1 { output . WriteString ( " " ) } } if output . Len ( ) == 0 { output . WriteString ( " " ) } return output . String ( ) }

// Returns the parsed languages in a human readable fashion.

Returns the parsed languages in a human readable fashion .


func Languages() martini.Handler {
	return func(context martini.Context, request *http.Request) {
		header := request.Header.Get(acceptLanguageHeader)
		if header != "" {
			acceptLanguageHeaderValues := strings.Split(header, ",")
			acceptLanguages := make(AcceptLanguages, len(acceptLanguageHeaderValues))

			for i, languageRange := range acceptLanguageHeaderValues {
				// Check if a given range is qualified or not
				if qualifiedRange := strings.Split(languageRange, ";q="); len(qualifiedRange) == 2 {
					quality, error := strconv.ParseFloat(qualifiedRange[1], 32)
					if error != nil {
						// When the quality is unparseable, assume it's 1
						acceptLanguages[i] = AcceptLanguage{trimLanguage(qualifiedRange[0]), 1}
					} else {
						acceptLanguages[i] = AcceptLanguage{trimLanguage(qualifiedRange[0]), float32(quality)}
					}
				} else {
					acceptLanguages[i] = AcceptLanguage{trimLanguage(languageRange), 1}
				}
			}

			sort.Sort(acceptLanguages)
			context.Map(acceptLanguages)
		} else {
			// If we have no Accept-Language header just map an empty slice
			context.Map(make(AcceptLanguages, 0))
		}
	}
}

// Creates a new handler that parses the Accept-Language HTTP header.
//
// The parsed structure is a slice of Accept-Language values stored in an
// AcceptLanguages instance, sorted based on the language qualifier.

Creates a new handler that parses the Accept - Language HTTP header . The parsed structure is a slice of Accept - Language values stored in an AcceptLanguages instance sorted based on the language qualifier .


func Prefix(prefix string) martini.Handler {
	return func(w http.ResponseWriter, r *http.Request) {
		if prefix == "" {
			return
		}
		if p := strings.TrimPrefix(r.URL.Path, prefix); len(p) < len(r.URL.Path) {
			r.URL.Path = p
		} else {
			http.NotFound(w, r)
		}
	}
}

func Prefix ( prefix string ) martini . Handler { return func ( w http . ResponseWriter , r * http . Request ) { if prefix == " " { return } if p := strings . TrimPrefix ( r . URL . Path , prefix ) ; len ( p ) < len ( r . URL . Path ) { r . URL . Path = p } else { http . NotFound ( w , r ) } } }

// strip Prefix for every incoming http request


func Basic(username string, password string) http.HandlerFunc {
	var siteAuth = base64.StdEncoding.EncodeToString([]byte(username + ":" + password))
	return func(res http.ResponseWriter, req *http.Request) {
		auth := req.Header.Get("Authorization")
		if !SecureCompare(auth, "Basic "+siteAuth) {
			res.Header().Set("WWW-Authenticate", "Basic realm=\"Authorization Required\"")
			http.Error(res, "Not Authorized", http.StatusUnauthorized)
		}
	}
}

func Basic ( username string , password string ) http . HandlerFunc { var siteAuth = base64 . StdEncoding . EncodeToString ( [ ] byte ( username + " " + password ) ) return func ( res http . ResponseWriter , req * http . Request ) { auth := req . Header . Get ( " " ) if ! SecureCompare ( auth , " " + siteAuth ) { res . Header ( ) . Set ( " " , " \" \" " ) http . Error ( res , " " , http . StatusUnauthorized ) } } }

// Basic returns a Handler that authenticates via Basic Auth. Writes a http.StatusUnauthorized
// if authentication fails

Basic returns a Handler that authenticates via Basic Auth . Writes a http . StatusUnauthorized if authentication fails


func UpdateUser(s sessions.Session, user User) error {
	s.Set(SessionKey, user.UniqueId())
	return nil
}

func UpdateUser ( s sessions . Session , user User ) error { s . Set ( SessionKey , user . UniqueId ( ) ) return nil }

// UpdateUser updates the User object stored in the session. This is useful incase a change
// is made to the user model that needs to persist across requests.

UpdateUser updates the User object stored in the session . This is useful incase a change is made to the user model that needs to persist across requests .


func (u *MyUserModel) GetById(id interface{}) error {
	err := dbmap.SelectOne(u, "SELECT * FROM users WHERE id = $1", id)
	if err != nil {
		return err
	}

	return nil
}

func ( u * MyUserModel ) GetById ( id interface { } ) error { err := dbmap . SelectOne ( u , " " , id ) if err != nil { return err } return nil }

// GetById will populate a user object from a database model with
// a matching id.

GetById will populate a user object from a database model with a matching id .


func AddressToAccountId(address string) (result xdr.AccountId, err error) {

	bytes, err := strkey.Decode(strkey.VersionByteAccountID, address)

	if err != nil {
		return
	}

	var raw xdr.Uint256
	copy(raw[:], bytes)
	pk, err := xdr.NewPublicKey(xdr.CryptoKeyTypeKeyTypeEd25519, raw)
	if err != nil {
		return
	}

	result = xdr.AccountId(pk)

	return
}

func AddressToAccountId ( address string ) ( result xdr . AccountId , err error ) { bytes , err := strkey . Decode ( strkey . VersionByteAccountID , address ) if err != nil { return } var raw xdr . Uint256 copy ( raw [ : ] , bytes ) pk , err := xdr . NewPublicKey ( xdr . CryptoKeyTypeKeyTypeEd25519 , raw ) if err != nil { return } result = xdr . AccountId ( pk ) return }

// AddressToAccountId converts the provided address into a xdr.AccountId

AddressToAccountId converts the provided address into a xdr . AccountId


func (m Asset) MutateChangeTrust(o *xdr.ChangeTrustOp) (err error) {
	if m.Native {
		return errors.New("Native asset not allowed")
	}

	o.Line, err = m.ToXdrObject()
	return
}

func ( m Asset ) MutateChangeTrust ( o * xdr . ChangeTrustOp ) ( err error ) { if m . Native { return errors . New ( " " ) } o . Line , err = m . ToXdrObject ( ) return }

// MutateChangeTrust for Asset sets the ChangeTrustOp's Line field

MutateChangeTrust for Asset sets the ChangeTrustOp s Line field


func (m Limit) MutateChangeTrust(o *xdr.ChangeTrustOp) (err error) {
	o.Limit, err = amount.Parse(string(m))
	return
}

func ( m Limit ) MutateChangeTrust ( o * xdr . ChangeTrustOp ) ( err error ) { o . Limit , err = amount . Parse ( string ( m ) ) return }

// MutateChangeTrust for Limit sets the ChangeTrustOp's Limit field

MutateChangeTrust for Limit sets the ChangeTrustOp s Limit field


func Trust(code, issuer string, args ...interface{}) (result ChangeTrustBuilder) {
	mutators := []interface{}{
		CreditAsset(code, issuer),
	}

	limitSet := false

	for _, mut := range args {
		mutators = append(mutators, mut)
		_, isLimit := mut.(Limit)
		if isLimit {
			limitSet = true
		}
	}

	if !limitSet {
		mutators = append(mutators, MaxLimit)
	}

	return ChangeTrust(mutators...)
}

func Trust ( code , issuer string , args ... interface { } ) ( result ChangeTrustBuilder ) { mutators := [ ] interface { } { CreditAsset ( code , issuer ) , } limitSet := false for _ , mut := range args { mutators = append ( mutators , mut ) _ , isLimit := mut . ( Limit ) if isLimit { limitSet = true } } if ! limitSet { mutators = append ( mutators , MaxLimit ) } return ChangeTrust ( mutators ... ) }

// Trust is a helper that creates ChangeTrustBuilder


func RemoveTrust(code, issuer string, args ...interface{}) (result ChangeTrustBuilder) {
	mutators := []interface{}{
		CreditAsset(code, issuer),
		Limit("0"),
	}

	for _, mut := range args {
		mutators = append(mutators, mut)
	}

	return ChangeTrust(mutators...)
}

func RemoveTrust ( code , issuer string , args ... interface { } ) ( result ChangeTrustBuilder ) { mutators := [ ] interface { } { CreditAsset ( code , issuer ) , Limit ( " " ) , } for _ , mut := range args { mutators = append ( mutators , mut ) } return ChangeTrust ( mutators ... ) }

// RemoveTrust is a helper that creates ChangeTrustBuilder


func (m CreditAmount) MutatePayment(o interface{}) (err error) {
	switch o := o.(type) {
	default:
		err = errors.New("Unexpected operation type")
	case *xdr.PaymentOp:
		o.Amount, err = amount.Parse(m.Amount)
		if err != nil {
			return
		}

		o.Asset, err = createAlphaNumAsset(m.Code, m.Issuer)
	case *xdr.PathPaymentOp:
		o.DestAmount, err = amount.Parse(m.Amount)
		if err != nil {
			return
		}

		o.DestAsset, err = createAlphaNumAsset(m.Code, m.Issuer)
	}
	return
}

func ( m CreditAmount ) MutatePayment ( o interface { } ) ( err error ) { switch o := o . ( type ) { default : err = errors . New ( " " ) case * xdr . PaymentOp : o . Amount , err = amount . Parse ( m . Amount ) if err != nil { return } o . Asset , err = createAlphaNumAsset ( m . Code , m . Issuer ) case * xdr . PathPaymentOp : o . DestAmount , err = amount . Parse ( m . Amount ) if err != nil { return } o . DestAsset , err = createAlphaNumAsset ( m . Code , m . Issuer ) } return }

// MutatePayment for Asset sets the PaymentOp's Asset field

MutatePayment for Asset sets the PaymentOp s Asset field


func (m Destination) MutatePayment(o interface{}) error {
	switch o := o.(type) {
	default:
		return errors.New("Unexpected operation type")
	case *xdr.PaymentOp:
		return setAccountId(m.AddressOrSeed, &o.Destination)
	case *xdr.PathPaymentOp:
		return setAccountId(m.AddressOrSeed, &o.Destination)
	}
	return nil
}

func ( m Destination ) MutatePayment ( o interface { } ) error { switch o := o . ( type ) { default : return errors . New ( " " ) case * xdr . PaymentOp : return setAccountId ( m . AddressOrSeed , & o . Destination ) case * xdr . PathPaymentOp : return setAccountId ( m . AddressOrSeed , & o . Destination ) } return nil }

// MutatePayment for Destination sets the PaymentOp's Destination field

MutatePayment for Destination sets the PaymentOp s Destination field


func (m NativeAmount) MutatePayment(o interface{}) (err error) {
	switch o := o.(type) {
	default:
		err = errors.New("Unexpected operation type")
	case *xdr.PaymentOp:
		o.Amount, err = amount.Parse(m.Amount)
		if err != nil {
			return
		}

		o.Asset, err = xdr.NewAsset(xdr.AssetTypeAssetTypeNative, nil)
	case *xdr.PathPaymentOp:
		o.DestAmount, err = amount.Parse(m.Amount)
		if err != nil {
			return
		}

		o.DestAsset, err = xdr.NewAsset(xdr.AssetTypeAssetTypeNative, nil)
	}
	return
}

func ( m NativeAmount ) MutatePayment ( o interface { } ) ( err error ) { switch o := o . ( type ) { default : err = errors . New ( " " ) case * xdr . PaymentOp : o . Amount , err = amount . Parse ( m . Amount ) if err != nil { return } o . Asset , err = xdr . NewAsset ( xdr . AssetTypeAssetTypeNative , nil ) case * xdr . PathPaymentOp : o . DestAmount , err = amount . Parse ( m . Amount ) if err != nil { return } o . DestAsset , err = xdr . NewAsset ( xdr . AssetTypeAssetTypeNative , nil ) } return }

// MutatePayment for NativeAmount sets the PaymentOp's currency field to
// native and sets its amount to the provided integer

MutatePayment for NativeAmount sets the PaymentOp s currency field to native and sets its amount to the provided integer


func (m PayWithPath) MutatePayment(o interface{}) (err error) {
	var pathPaymentOp *xdr.PathPaymentOp
	var ok bool
	if pathPaymentOp, ok = o.(*xdr.PathPaymentOp); !ok {
		return errors.New("Unexpected operation type")
	}

	// MaxAmount
	pathPaymentOp.SendMax, err = amount.Parse(m.MaxAmount)
	if err != nil {
		return
	}

	// Path
	var path []xdr.Asset
	var xdrAsset xdr.Asset

	for _, asset := range m.Path {
		xdrAsset, err = asset.ToXdrObject()
		if err != nil {
			return err
		}

		path = append(path, xdrAsset)
	}

	pathPaymentOp.Path = path

	// Asset
	pathPaymentOp.SendAsset, err = m.Asset.ToXdrObject()
	return
}

func
(
m
PayWithPath
)
MutatePayment
(
o
interface
{
}
)
(
err
error
)
{
var
pathPaymentOp
*
xdr
.
PathPaymentOp
var
ok
bool
if
pathPaymentOp
,
ok
=
o
.
(
*
xdr
.
PathPaymentOp
)
;
!
ok
{
return
errors
.
New
(
"
"
)
}
// MaxAmount
pathPaymentOp
.
SendMax
,
err
=
amount
.
Parse
(
m
.
MaxAmount
)
if
err
!=
{
return
}
// Path
var
path
[
]
xdr
.
Asset
var
xdrAsset
xdr
.
Asset
for
_
,
asset
:=
range
m
.
Path
{
xdrAsset
,
err
=
asset
.
ToXdrObject
(
)
if
err
!=
{
return
err
}
path
=
append
(
path
,
xdrAsset
)
}
pathPaymentOp
.
Path
=
path
// Asset
pathPaymentOp
.
SendAsset
,
err
=
m
.
Asset
.
ToXdrObject
(
)
return
}

// MutatePayment for PayWithPath sets the PathPaymentOp's SendAsset,
// SendMax and Path fields

MutatePayment for PayWithPath sets the PathPaymentOp s SendAsset SendMax and Path fields


func (m Destination) MutateAccountMerge(o *AccountMergeBuilder) error {
	return setAccountId(m.AddressOrSeed, &o.Destination)
}

func ( m Destination ) MutateAccountMerge ( o * AccountMergeBuilder ) error { return setAccountId ( m . AddressOrSeed , & o . Destination ) }

// MutateAccountMerge for Destination sets the AccountMergeBuilder's Destination field

MutateAccountMerge for Destination sets the AccountMergeBuilder s Destination field


func MustParse(v string) xdr.Int64 {
	ret, err := Parse(v)
	if err != nil {
		panic(err)
	}
	return ret
}

func MustParse ( v string ) xdr . Int64 { ret , err := Parse ( v ) if err != nil { panic ( err ) } return ret }

// MustParse is the panicking version of Parse


func Parse(v string) (xdr.Int64, error) {
	var f, o, r big.Rat

	_, ok := f.SetString(v)
	if !ok {
		return xdr.Int64(0), fmt.Errorf("cannot parse amount: %s", v)
	}

	o.SetInt64(One)
	r.Mul(&f, &o)

	is := r.FloatString(0)
	i, err := strconv.ParseInt(is, 10, 64)
	if err != nil {
		return xdr.Int64(0), err
	}
	return xdr.Int64(i), nil
}

func Parse ( v string ) ( xdr . Int64 , error ) { var f , o , r big . Rat _ , ok := f . SetString ( v ) if ! ok { return xdr . Int64 ( 0 ) , fmt . Errorf ( " " , v ) } o . SetInt64 ( One ) r . Mul ( & f , & o ) is := r . FloatString ( 0 ) i , err := strconv . ParseInt ( is , 10 , 64 ) if err != nil { return xdr . Int64 ( 0 ) , err } return xdr . Int64 ( i ) , nil }

// Parse parses the provided as a stellar "amount", i.e. A 64-bit signed integer
// that represents a decimal number with 7 digits of significance in the
// fractional portion of the number.

Parse parses the provided as a stellar amount i . e . A 64 - bit signed integer that represents a decimal number with 7 digits of significance in the fractional portion of the number .


func String(v xdr.Int64) string {
	var f, o, r big.Rat

	f.SetInt64(int64(v))
	o.SetInt64(One)
	r.Quo(&f, &o)

	return r.FloatString(7)
}

func String ( v xdr . Int64 ) string { var f , o , r big . Rat f . SetInt64 ( int64 ( v ) ) o . SetInt64 ( One ) r . Quo ( & f , & o ) return r . FloatString ( 7 ) }

// String returns an "amount string" from the provided raw value `v`.

String returns an amount string from the provided raw value v .


func CreateOffer(rate Rate, amount Amount) (result ManageOfferBuilder) {
	return ManageOffer(false, rate, amount)
}

func CreateOffer ( rate Rate , amount Amount ) ( result ManageOfferBuilder ) { return ManageOffer ( false , rate , amount ) }


func CreatePassiveOffer(rate Rate, amount Amount) (result ManageOfferBuilder) {
	return ManageOffer(true, rate, amount)
}

func CreatePassiveOffer ( rate Rate , amount Amount ) ( result ManageOfferBuilder ) { return ManageOffer ( true , rate , amount ) }

// CreatePassiveOffer creates a new passive offer


func UpdateOffer(rate Rate, amount Amount, offerID OfferID) (result ManageOfferBuilder) {
	return ManageOffer(false, rate, amount, offerID)
}

func UpdateOffer ( rate Rate , amount Amount , offerID OfferID ) ( result ManageOfferBuilder ) { return ManageOffer ( false , rate , amount , offerID ) }

// UpdateOffer updates an existing offer


func DeleteOffer(rate Rate, offerID OfferID) (result ManageOfferBuilder) {
	return ManageOffer(false, rate, Amount("0"), offerID)
}

func DeleteOffer ( rate Rate , offerID OfferID ) ( result ManageOfferBuilder ) { return ManageOffer ( false , rate , Amount ( " " ) , offerID ) }

// DeleteOffer deletes an existing offer


func ManageOffer(passiveOffer bool, muts ...interface{}) (result ManageOfferBuilder) {
	result.PassiveOffer = passiveOffer
	result.Mutate(muts...)
	return
}

func ManageOffer ( passiveOffer bool , muts ... interface { } ) ( result ManageOfferBuilder ) { result . PassiveOffer = passiveOffer result . Mutate ( muts ... ) return }

// ManageOffer groups the creation of a new ManageOfferBuilder with a call to Mutate.

ManageOffer groups the creation of a new ManageOfferBuilder with a call to Mutate .


func (b *ManageOfferBuilder) Mutate(muts ...interface{}) {
	for _, m := range muts {
		var err error
		switch mut := m.(type) {
		case ManageOfferMutator:
			if b.PassiveOffer {
				err = mut.MutateManageOffer(&b.PO)
			} else {
				err = mut.MutateManageOffer(&b.MO)
			}
		case OperationMutator:
			err = mut.MutateOperation(&b.O)
		default:
			err = errors.New("Mutator type not allowed")
		}

		if err != nil {
			b.Err = err
			return
		}
	}
}

func ( b * ManageOfferBuilder ) Mutate ( muts ... interface { } ) { for _ , m := range muts { var err error switch mut := m . ( type ) { case ManageOfferMutator : if b . PassiveOffer { err = mut . MutateManageOffer ( & b . PO ) } else { err = mut . MutateManageOffer ( & b . MO ) } case OperationMutator : err = mut . MutateOperation ( & b . O ) default : err = errors . New ( " " ) } if err != nil { b . Err = err return } } }

// Mutate applies the provided mutators to this builder's offer or operation.

Mutate applies the provided mutators to this builder s offer or operation .


func (m Amount) MutateManageOffer(o interface{}) (err error) {
	switch o := o.(type) {
	default:
		err = errors.New("Unexpected operation type")
	case *xdr.ManageOfferOp:
		o.Amount, err = amount.Parse(string(m))
	case *xdr.CreatePassiveOfferOp:
		o.Amount, err = amount.Parse(string(m))
	}
	return
}

func ( m Amount ) MutateManageOffer ( o interface { } ) ( err error ) { switch o := o . ( type ) { default : err = errors . New ( " " ) case * xdr . ManageOfferOp : o . Amount , err = amount . Parse ( string ( m ) ) case * xdr . CreatePassiveOfferOp : o . Amount , err = amount . Parse ( string ( m ) ) } return }

// MutateManageOffer for Amount sets the ManageOfferOp's Amount field

MutateManageOffer for Amount sets the ManageOfferOp s Amount field


func (m OfferID) MutateManageOffer(o interface{}) (err error) {
	switch o := o.(type) {
	default:
		err = errors.New("Unexpected operation type")
	case *xdr.ManageOfferOp:
		o.OfferId = xdr.Uint64(m)
	}
	return
}

func ( m OfferID ) MutateManageOffer ( o interface { } ) ( err error ) { switch o := o . ( type ) { default : err = errors . New ( " " ) case * xdr . ManageOfferOp : o . OfferId = xdr . Uint64 ( m ) } return }

// MutateManageOffer for OfferID sets the ManageOfferOp's OfferID field

MutateManageOffer for OfferID sets the ManageOfferOp s OfferID field


func (m Rate) MutateManageOffer(o interface{}) (err error) {
	switch o := o.(type) {
	default:
		err = errors.New("Unexpected operation type")
	case *xdr.ManageOfferOp:
		o.Selling, err = m.Selling.ToXdrObject()
		if err != nil {
			return
		}

		o.Buying, err = m.Buying.ToXdrObject()
		if err != nil {
			return
		}

		o.Price, err = price.Parse(string(m.Price))
	case *xdr.CreatePassiveOfferOp:
		o.Selling, err = m.Selling.ToXdrObject()
		if err != nil {
			return
		}

		o.Buying, err = m.Buying.ToXdrObject()
		if err != nil {
			return
		}

		o.Price, err = price.Parse(string(m.Price))
	}
	return
}

func ( m Rate ) MutateManageOffer ( o interface { } ) ( err error ) { switch o := o . ( type ) { default : err = errors . New ( " " ) case * xdr . ManageOfferOp : o . Selling , err = m . Selling . ToXdrObject ( ) if err != nil { return } o . Buying , err = m . Buying . ToXdrObject ( ) if err != nil { return } o . Price , err = price . Parse ( string ( m . Price ) ) case * xdr . CreatePassiveOfferOp : o . Selling , err = m . Selling . ToXdrObject ( ) if err != nil { return } o . Buying , err = m . Buying . ToXdrObject ( ) if err != nil { return } o . Price , err = price . Parse ( string ( m . Price ) ) } return }

// MutateManageOffer for Rate sets the ManageOfferOp's selling, buying and price fields

MutateManageOffer for Rate sets the ManageOfferOp s selling buying and price fields


func (m SourceAccount) MutateOperation(o *xdr.Operation) error {
	o.SourceAccount = &xdr.AccountId{}
	return setAccountId(m.AddressOrSeed, o.SourceAccount)
}

func ( m SourceAccount ) MutateOperation ( o * xdr . Operation ) error { o . SourceAccount = & xdr . AccountId { } return setAccountId ( m . AddressOrSeed , o . SourceAccount ) }

// MutateOperation for SourceAccount sets the operation's SourceAccount
// to the pubilic key for the address provided

MutateOperation for SourceAccount sets the operation s SourceAccount to the pubilic key for the address provided


func (p *Price) String() string {
	return big.NewRat(int64(p.N), int64(p.D)).FloatString(7)
}

func ( p * Price ) String ( ) string { return big . NewRat ( int64 ( p . N ) , int64 ( p . D ) ) . FloatString ( 7 ) }

// String returns a string represenation of `p`

String returns a string represenation of p


func Transaction(muts ...TransactionMutator) (result *TransactionBuilder) {
	result = &TransactionBuilder{}
	result.Mutate(muts...)
	result.Mutate(Defaults{})
	return
}

func Transaction ( muts ... TransactionMutator ) ( result * TransactionBuilder ) { result = & TransactionBuilder { } result . Mutate ( muts ... ) result . Mutate ( Defaults { } ) return }

// Transaction groups the creation of a new TransactionBuilder with a call
// to Mutate.

Transaction groups the creation of a new TransactionBuilder with a call to Mutate .


func (b *TransactionBuilder) Mutate(muts ...TransactionMutator) {
	if b.TX == nil {
		b.TX = &xdr.Transaction{}
	}

	for _, m := range muts {
		err := m.MutateTransaction(b)
		if err != nil {
			b.Err = err
			return
		}
	}
}

func ( b * TransactionBuilder ) Mutate ( muts ... TransactionMutator ) { if b . TX == nil { b . TX = & xdr . Transaction { } } for _ , m := range muts { err := m . MutateTransaction ( b ) if err != nil { b . Err = err return } } }

// Mutate applies the provided TransactionMutators to this builder's transaction

Mutate applies the provided TransactionMutators to this builder s transaction


func (b *TransactionBuilder) Hash() ([32]byte, error) {
	var txBytes bytes.Buffer

	_, err := fmt.Fprintf(&txBytes, "%s", b.NetworkID)
	if err != nil {
		return [32]byte{}, err
	}

	_, err = xdr.Marshal(&txBytes, xdr.EnvelopeTypeEnvelopeTypeTx)
	if err != nil {
		return [32]byte{}, err
	}

	_, err = xdr.Marshal(&txBytes, b.TX)
	if err != nil {
		return [32]byte{}, err
	}

	return hash.Hash(txBytes.Bytes()), nil
}

func ( b * TransactionBuilder ) Hash ( ) ( [ 32 ] byte , error ) { var txBytes bytes . Buffer _ , err := fmt . Fprintf ( & txBytes , " " , b . NetworkID ) if err != nil { return [ 32 ] byte { } , err } _ , err = xdr . Marshal ( & txBytes , xdr . EnvelopeTypeEnvelopeTypeTx ) if err != nil { return [ 32 ] byte { } , err } _ , err = xdr . Marshal ( & txBytes , b . TX ) if err != nil { return [ 32 ] byte { } , err } return hash . Hash ( txBytes . Bytes ( ) ) , nil }

// Hash returns the hash of this builder's transaction.

Hash returns the hash of this builder s transaction .


func (b *TransactionBuilder) HashHex() (string, error) {
	hash, err := b.Hash()
	if err != nil {
		return "", err
	}

	return hex.EncodeToString(hash[:]), nil
}

func ( b * TransactionBuilder ) HashHex ( ) ( string , error ) { hash , err := b . Hash ( ) if err != nil { return " " , err } return hex . EncodeToString ( hash [ : ] ) , nil }

// HashHex returns the hex-encoded hash of this builder's transaction

HashHex returns the hex - encoded hash of this builder s transaction


func (b *TransactionBuilder) Sign(signers ...string) (result TransactionEnvelopeBuilder) {
	result.Mutate(b)

	for _, s := range signers {
		result.Mutate(Sign{s})
	}

	return
}

func ( b * TransactionBuilder ) Sign ( signers ... string ) ( result TransactionEnvelopeBuilder ) { result . Mutate ( b ) for _ , s := range signers { result . Mutate ( Sign { s } ) } return }

// Sign returns an new TransactionEnvelopeBuilder using this builder's
// transaction as the basis and with signatures of that transaction from the
// provided Signers.

Sign returns an new TransactionEnvelopeBuilder using this builder s transaction as the basis and with signatures of that transaction from the provided Signers .


func (m AllowTrustBuilder) MutateTransaction(o *TransactionBuilder) error {
	if m.Err != nil {
		return m.Err
	}

	m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeAllowTrust, m.AT)
	o.TX.Operations = append(o.TX.Operations, m.O)
	return m.Err
}

func ( m AllowTrustBuilder ) MutateTransaction ( o * TransactionBuilder ) error { if m . Err != nil { return m . Err } m . O . Body , m . Err = xdr . NewOperationBody ( xdr . OperationTypeAllowTrust , m . AT ) o . TX . Operations = append ( o . TX . Operations , m . O ) return m . Err }

// MutateTransaction for AllowTrustBuilder causes the underylying AllowTrustOp
// to be added to the operation list for the provided transaction

MutateTransaction for AllowTrustBuilder causes the underylying AllowTrustOp to be added to the operation list for the provided transaction


func (m ChangeTrustBuilder) MutateTransaction(o *TransactionBuilder) error {
	if m.Err != nil {
		return m.Err
	}

	m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeChangeTrust, m.CT)
	o.TX.Operations = append(o.TX.Operations, m.O)
	return m.Err
}

func ( m ChangeTrustBuilder ) MutateTransaction ( o * TransactionBuilder ) error { if m . Err != nil { return m . Err } m . O . Body , m . Err = xdr . NewOperationBody ( xdr . OperationTypeChangeTrust , m . CT ) o . TX . Operations = append ( o . TX . Operations , m . O ) return m . Err }

// MutateTransaction for ChangeTrustBuilder causes the underylying
// CreateAccountOp to be added to the operation list for the provided
// transaction

MutateTransaction for ChangeTrustBuilder causes the underylying CreateAccountOp to be added to the operation list for the provided transaction


func (m CreateAccountBuilder) MutateTransaction(o *TransactionBuilder) error {
	if m.Err != nil {
		return m.Err
	}

	m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeCreateAccount, m.CA)
	o.TX.Operations = append(o.TX.Operations, m.O)
	return m.Err
}

func ( m CreateAccountBuilder ) MutateTransaction ( o * TransactionBuilder ) error { if m . Err != nil { return m . Err } m . O . Body , m . Err = xdr . NewOperationBody ( xdr . OperationTypeCreateAccount , m . CA ) o . TX . Operations = append ( o . TX . Operations , m . O ) return m . Err }

// MutateTransaction for CreateAccountBuilder causes the underylying
// CreateAccountOp to be added to the operation list for the provided
// transaction

MutateTransaction for CreateAccountBuilder causes the underylying CreateAccountOp to be added to the operation list for the provided transaction


func (m Defaults) MutateTransaction(o *TransactionBuilder) error {

	if o.TX.Fee == 0 {
		o.TX.Fee = xdr.Uint32(100 * len(o.TX.Operations))
	}

	if o.NetworkID == [32]byte{} {
		o.NetworkID = DefaultNetwork.ID()
	}
	return nil
}

func ( m Defaults ) MutateTransaction ( o * TransactionBuilder ) error { if o . TX . Fee == 0 { o . TX . Fee = xdr . Uint32 ( 100 * len ( o . TX . Operations ) ) } if o . NetworkID == [ 32 ] byte { } { o . NetworkID = DefaultNetwork . ID ( ) } return nil }

// MutateTransaction for Defaults sets reasonable defaults on the transaction being built


func (m InflationBuilder) MutateTransaction(o *TransactionBuilder) error {
	if m.Err != nil {
		return m.Err
	}

	m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeInflation, nil)
	o.TX.Operations = append(o.TX.Operations, m.O)
	return m.Err
}

func ( m InflationBuilder ) MutateTransaction ( o * TransactionBuilder ) error { if m . Err != nil { return m . Err } m . O . Body , m . Err = xdr . NewOperationBody ( xdr . OperationTypeInflation , nil ) o . TX . Operations = append ( o . TX . Operations , m . O ) return m . Err }

// MutateTransaction for InflationBuilder causes the underylying
// InflationOp to be added to the operation list for the provided
// transaction

MutateTransaction for InflationBuilder causes the underylying InflationOp to be added to the operation list for the provided transaction


func (m ManageDataBuilder) MutateTransaction(o *TransactionBuilder) error {
	if m.Err != nil {
		return m.Err
	}

	m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeManageData, m.MD)
	o.TX.Operations = append(o.TX.Operations, m.O)
	return m.Err
}

func ( m ManageDataBuilder ) MutateTransaction ( o * TransactionBuilder ) error { if m . Err != nil { return m . Err } m . O . Body , m . Err = xdr . NewOperationBody ( xdr . OperationTypeManageData , m . MD ) o . TX . Operations = append ( o . TX . Operations , m . O ) return m . Err }

// MutateTransaction for ManageDataBuilder causes the underylying
// ManageData to be added to the operation list for the provided
// transaction

MutateTransaction for ManageDataBuilder causes the underylying ManageData to be added to the operation list for the provided transaction


func (m ManageOfferBuilder) MutateTransaction(o *TransactionBuilder) error {
	if m.Err != nil {
		return m.Err
	}

	if m.PassiveOffer {
		m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeCreatePassiveOffer, m.PO)
		o.TX.Operations = append(o.TX.Operations, m.O)
	} else {
		m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeManageOffer, m.MO)
		o.TX.Operations = append(o.TX.Operations, m.O)
	}
	return m.Err
}

func ( m ManageOfferBuilder ) MutateTransaction ( o * TransactionBuilder ) error { if m . Err != nil { return m . Err } if m . PassiveOffer { m . O . Body , m . Err = xdr . NewOperationBody ( xdr . OperationTypeCreatePassiveOffer , m . PO ) o . TX . Operations = append ( o . TX . Operations , m . O ) } else { m . O . Body , m . Err = xdr . NewOperationBody ( xdr . OperationTypeManageOffer , m . MO ) o . TX . Operations = append ( o . TX . Operations , m . O ) } return m . Err }

// MutateTransaction for ManageOfferBuilder causes the underylying
// ManageData to be added to the operation list for the provided
// transaction

MutateTransaction for ManageOfferBuilder causes the underylying ManageData to be added to the operation list for the provided transaction


func (m MemoHash) MutateTransaction(o *TransactionBuilder) (err error) {
	o.TX.Memo, err = xdr.NewMemo(xdr.MemoTypeMemoHash, m.Value)
	return
}

func ( m MemoHash ) MutateTransaction ( o * TransactionBuilder ) ( err error ) { o . TX . Memo , err = xdr . NewMemo ( xdr . MemoTypeMemoHash , m . Value ) return }

// MutateTransaction for MemoHash sets the memo.

MutateTransaction for MemoHash sets the memo .


func (m MemoID) MutateTransaction(o *TransactionBuilder) (err error) {
	o.TX.Memo, err = xdr.NewMemo(xdr.MemoTypeMemoId, xdr.Uint64(m.Value))
	return
}

func ( m MemoID ) MutateTransaction ( o * TransactionBuilder ) ( err error ) { o . TX . Memo , err = xdr . NewMemo ( xdr . MemoTypeMemoId , xdr . Uint64 ( m . Value ) ) return }

// MutateTransaction for MemoID sets the memo.

MutateTransaction for MemoID sets the memo .


func (m MemoReturn) MutateTransaction(o *TransactionBuilder) (err error) {
	o.TX.Memo, err = xdr.NewMemo(xdr.MemoTypeMemoReturn, m.Value)
	return
}

func ( m MemoReturn ) MutateTransaction ( o * TransactionBuilder ) ( err error ) { o . TX . Memo , err = xdr . NewMemo ( xdr . MemoTypeMemoReturn , m . Value ) return }

// MutateTransaction for MemoReturn sets the memo.

MutateTransaction for MemoReturn sets the memo .


func (m MemoText) MutateTransaction(o *TransactionBuilder) (err error) {

	if len([]byte(m.Value)) > MemoTextMaxLength {
		err = errors.New("Memo too long; over 28 bytes")
		return
	}

	o.TX.Memo, err = xdr.NewMemo(xdr.MemoTypeMemoText, m.Value)
	return
}

func ( m MemoText ) MutateTransaction ( o * TransactionBuilder ) ( err error ) { if len ( [ ] byte ( m . Value ) ) > MemoTextMaxLength { err = errors . New ( " " ) return } o . TX . Memo , err = xdr . NewMemo ( xdr . MemoTypeMemoText , m . Value ) return }

// MutateTransaction for MemoText sets the memo.

MutateTransaction for MemoText sets the memo .


func (m Network) MutateTransaction(o *TransactionBuilder) error {
	o.NetworkID = m.ID()
	return nil
}

func ( m Network ) MutateTransaction ( o * TransactionBuilder ) error { o . NetworkID = m . ID ( ) return nil }

// MutateTransaction for Network sets the Network ID to use when signing this transaction


func (m PaymentBuilder) MutateTransaction(o *TransactionBuilder) error {
	if m.Err != nil {
		return m.Err
	}

	if m.PathPayment {
		m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypePathPayment, m.PP)
		o.TX.Operations = append(o.TX.Operations, m.O)
		return m.Err
	}

	m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypePayment, m.P)
	o.TX.Operations = append(o.TX.Operations, m.O)
	return m.Err
}

func ( m PaymentBuilder ) MutateTransaction ( o * TransactionBuilder ) error { if m . Err != nil { return m . Err } if m . PathPayment { m . O . Body , m . Err = xdr . NewOperationBody ( xdr . OperationTypePathPayment , m . PP ) o . TX . Operations = append ( o . TX . Operations , m . O ) return m . Err } m . O . Body , m . Err = xdr . NewOperationBody ( xdr . OperationTypePayment , m . P ) o . TX . Operations = append ( o . TX . Operations , m . O ) return m . Err }

// MutateTransaction for PaymentBuilder causes the underylying PaymentOp
// or PathPaymentOp to be added to the operation list for the provided transaction

MutateTransaction for PaymentBuilder causes the underylying PaymentOp or PathPaymentOp to be added to the operation list for the provided transaction


func (m SetOptionsBuilder) MutateTransaction(o *TransactionBuilder) error {
	if m.Err != nil {
		return m.Err
	}

	m.O.Body, m.Err = xdr.NewOperationBody(xdr.OperationTypeSetOptions, m.SO)
	o.TX.Operations = append(o.TX.Operations, m.O)
	return m.Err
}

func ( m SetOptionsBuilder ) MutateTransaction ( o * TransactionBuilder ) error { if m . Err != nil { return m . Err } m . O . Body , m . Err = xdr . NewOperationBody ( xdr . OperationTypeSetOptions , m . SO ) o . TX . Operations = append ( o . TX . Operations , m . O ) return m . Err }

// MutateTransaction for SetOptionsBuilder causes the underylying
// SetOptionsOp to be added to the operation list for the provided
// transaction

MutateTransaction for SetOptionsBuilder causes the underylying SetOptionsOp to be added to the operation list for the provided transaction


func (m Sequence) MutateTransaction(o *TransactionBuilder) error {
	o.TX.SeqNum = xdr.SequenceNumber(m.Sequence)
	return nil
}

func ( m Sequence ) MutateTransaction ( o * TransactionBuilder ) error { o . TX . SeqNum = xdr . SequenceNumber ( m . Sequence ) return nil }

// MutateTransaction for Sequence sets the SeqNum on the transaction.

MutateTransaction for Sequence sets the SeqNum on the transaction .


func (m SourceAccount) MutateTransaction(o *TransactionBuilder) error {
	return setAccountId(m.AddressOrSeed, &o.TX.SourceAccount)
}

func ( m SourceAccount ) MutateTransaction ( o * TransactionBuilder ) error { return setAccountId ( m . AddressOrSeed , & o . TX . SourceAccount ) }

// MutateTransaction for SourceAccount sets the transaction's SourceAccount
// to the pubilic key for the address provided

MutateTransaction for SourceAccount sets the transaction s SourceAccount to the pubilic key for the address provided


func (t *Int64) Scan(src interface{}) error {
	val, ok := src.(int64)
	if !ok {
		return errors.New("Invalid value for xdr.Int64")
	}

	*t = Int64(val)
	return nil
}

func ( t * Int64 ) Scan ( src interface { } ) error { val , ok := src . ( int64 ) if ! ok { return errors . New ( " " ) } * t = Int64 ( val ) return nil }


func (b *Bundle) InitialState(key xdr.LedgerKey) (*xdr.LedgerEntry, error) {
	all := b.Changes(key)

	if len(all) == 0 {
		return nil, ErrMetaNotFound
	}

	first := all[0]

	if first.Type != xdr.LedgerEntryChangeTypeLedgerEntryState {
		return nil, nil
	}

	result := first.MustState()

	return &result, nil
}

func ( b * Bundle ) InitialState ( key xdr . LedgerKey ) ( * xdr . LedgerEntry , error ) { all := b . Changes ( key ) if len ( all ) == 0 { return nil , ErrMetaNotFound } first := all [ 0 ] if first . Type != xdr . LedgerEntryChangeTypeLedgerEntryState { return nil , nil } result := first . MustState ( ) return & result , nil }

// InitialState returns the initial state of the LedgerEntry identified by `key`
// just prior to the application of the transaction the produced `b`.  Returns
// nil if the ledger entry did not exist prior to the bundle.

InitialState returns the initial state of the LedgerEntry identified by key just prior to the application of the transaction the produced b . Returns nil if the ledger entry did not exist prior to the bundle .


func (b *Bundle) Changes(target xdr.LedgerKey) (ret []xdr.LedgerEntryChange) {
	return b.changes(target, math.MaxInt32)
}

func ( b * Bundle ) Changes ( target xdr . LedgerKey ) ( ret [ ] xdr . LedgerEntryChange ) { return b . changes ( target , math . MaxInt32 ) }

// Changes returns any changes within the bundle that apply to the entry
// identified by `key`.

Changes returns any changes within the bundle that apply to the entry identified by key .


func (b *Bundle) StateAfter(key xdr.LedgerKey, opidx int) (*xdr.LedgerEntry, error) {
	all := b.changes(key, opidx)

	if len(all) == 0 {
		return nil, ErrMetaNotFound
	}

	change := all[len(all)-1]

	switch change.Type {
	case xdr.LedgerEntryChangeTypeLedgerEntryCreated:
		entry := change.MustCreated()
		return &entry, nil
	case xdr.LedgerEntryChangeTypeLedgerEntryRemoved:
		return nil, nil
	case xdr.LedgerEntryChangeTypeLedgerEntryUpdated:
		entry := change.MustUpdated()
		return &entry, nil
	case xdr.LedgerEntryChangeTypeLedgerEntryState:
		// scott: stellar-core should not emit a lone state entry, and we are
		// retrieving changes from the end of the collection.  If this situation
		// occurs, it means that I didn't understand something correctly or there is
		// a bug in stellar-core.
		panic(fmt.Errorf("Unexpected 'state' entry"))
	default:
		panic(fmt.Errorf("Unknown change type: %v", change.Type))
	}
}

// StateAfter returns the state of entry `key` after the application of the
// operation at `opidx`

StateAfter returns the state of entry key after the application of the operation at opidx


func (b *Bundle) changes(target xdr.LedgerKey, maxOp int) (ret []xdr.LedgerEntryChange) {
	for _, change := range b.FeeMeta {
		key := change.LedgerKey()

		if !key.Equals(target) {
			continue
		}

		ret = append(ret, change)
	}

	for i, op := range b.TransactionMeta.MustOperations() {
		if i > maxOp {
			break
		}

		for _, change := range op.Changes {
			key := change.LedgerKey()

			if !key.Equals(target) {
				continue
			}

			ret = append(ret, change)
		}
	}

	return
}

func ( b * Bundle ) changes ( target xdr . LedgerKey , maxOp int ) ( ret [ ] xdr . LedgerEntryChange ) { for _ , change := range b . FeeMeta { key := change . LedgerKey ( ) if ! key . Equals ( target ) { continue } ret = append ( ret , change ) } for i , op := range b . TransactionMeta . MustOperations ( ) { if i > maxOp { break } for _ , change := range op . Changes { key := change . LedgerKey ( ) if ! key . Equals ( target ) { continue } ret = append ( ret , change ) } } return }

// changes returns any changes within the bundle that apply to the entry
// identified by `key` that occurred at or before `maxOp`.

changes returns any changes within the bundle that apply to the entry identified by key that occurred at or before maxOp .


func MustDecode(expected VersionByte, src string) []byte {
	d, err := Decode(expected, src)
	if err != nil {
		panic(err)
	}
	return d
}

func MustDecode ( expected VersionByte , src string ) [ ] byte { d , err := Decode ( expected , src ) if err != nil { panic ( err ) } return d }

// MustDecode is like Decode, but panics on error

MustDecode is like Decode but panics on error


func Encode(version VersionByte, src []byte) (string, error) {
	if err := checkValidVersionByte(version); err != nil {
		return "", err
	}

	var raw bytes.Buffer

	// write version byte
	if err := binary.Write(&raw, binary.LittleEndian, version); err != nil {
		return "", err
	}

	// write payload
	if _, err := raw.Write(src); err != nil {
		return "", err
	}

	// calculate and write checksum
	checksum := crc16.Checksum(raw.Bytes())
	if _, err := raw.Write(checksum); err != nil {
		return "", err
	}

	result := base32.StdEncoding.EncodeToString(raw.Bytes())
	return result, nil
}

func
Encode
(
version
VersionByte
,
src
[
]
byte
)
(
string
,
error
)
{
if
err
:=
checkValidVersionByte
(
version
)
;
err
!=
{
return
"
"
,
err
}
var
raw
bytes
.
Buffer
// write version byte
if
err
:=
binary
.
Write
(
&
raw
,
binary
.
LittleEndian
,
version
)
;
err
!=
{
return
"
"
,
err
}
// write payload
if
_
,
err
:=
raw
.
Write
(
src
)
;
err
!=
{
return
"
"
,
err
}
// calculate and write checksum
checksum
:=
crc16
.
Checksum
(
raw
.
Bytes
(
)
)
if
_
,
err
:=
raw
.
Write
(
checksum
)
;
err
!=
{
return
"
"
,
err
}
result
:=
base32
.
StdEncoding
.
EncodeToString
(
raw
.
Bytes
(
)
)
return
result
,
}

// Encode encodes the provided data to a StrKey, using the provided version
// byte.

Encode encodes the provided data to a StrKey using the provided version byte .


func MustEncode(version VersionByte, src []byte) string {
	e, err := Encode(version, src)
	if err != nil {
		panic(err)
	}
	return e
}

func MustEncode ( version VersionByte , src [ ] byte ) string { e , err := Encode ( version , src ) if err != nil { panic ( err ) } return e }

// MustEncode is like Encode, but panics on error

MustEncode is like Encode but panics on error


func checkValidVersionByte(version VersionByte) error {
	if version == VersionByteAccountID {
		return nil
	}
	if version == VersionByteSeed {
		return nil
	}

	return ErrInvalidVersionByte
}

func checkValidVersionByte ( version VersionByte ) error { if version == VersionByteAccountID { return nil } if version == VersionByteSeed { return nil } return ErrInvalidVersionByte }

// checkValidVersionByte returns an error if the provided value
// is not one of the defined valid version byte constants.

checkValidVersionByte returns an error if the provided value is not one of the defined valid version byte constants .


func Checksum(data []byte) []byte {
	var crc uint16
	var out bytes.Buffer
	for _, b := range data {
		crc = ((crc << 8) & 0xffff) ^ crc16tab[((crc>>8)^uint16(b))&0x00FF]
	}

	err := binary.Write(&out, binary.LittleEndian, crc)
	if err != nil {
		panic(err)
	}

	return out.Bytes()
}

func Checksum ( data [ ] byte ) [ ] byte { var crc uint16 var out bytes . Buffer for _ , b := range data { crc = ( ( crc << 8 ) & 0xffff ) ^ crc16tab [ ( ( crc >> 8 ) ^ uint16 ( b ) ) & 0x00FF ] } err := binary . Write ( & out , binary . LittleEndian , crc ) if err != nil { panic ( err ) } return out . Bytes ( ) }

// Checksum returns the 2-byte checksum for the provided data

Checksum returns the 2 - byte checksum for the provided data


func Validate(data []byte, expected []byte) error {

	actual := Checksum(data)

	// validate the provided checksum against the calculated
	if !bytes.Equal(actual, expected) {
		return ErrInvalidChecksum
	}

	return nil
}

// Validate returns an error if the provided checksum does not match
// the calculated checksum of the provided data

Validate returns an error if the provided checksum does not match the calculated checksum of the provided data


func (change *LedgerEntryChange) LedgerKey() LedgerKey {
	switch change.Type {
	case LedgerEntryChangeTypeLedgerEntryCreated:
		change := change.MustCreated()
		return change.LedgerKey()
	case LedgerEntryChangeTypeLedgerEntryRemoved:
		return change.MustRemoved()
	case LedgerEntryChangeTypeLedgerEntryUpdated:
		change := change.MustUpdated()
		return change.LedgerKey()
	case LedgerEntryChangeTypeLedgerEntryState:
		change := change.MustState()
		return change.LedgerKey()
	default:
		panic(fmt.Errorf("Unknown change type: %v", change.Type))
	}
}

func ( change * LedgerEntryChange ) LedgerKey ( ) LedgerKey { switch change . Type { case LedgerEntryChangeTypeLedgerEntryCreated : change := change . MustCreated ( ) return change . LedgerKey ( ) case LedgerEntryChangeTypeLedgerEntryRemoved : return change . MustRemoved ( ) case LedgerEntryChangeTypeLedgerEntryUpdated : change := change . MustUpdated ( ) return change . LedgerKey ( ) case LedgerEntryChangeTypeLedgerEntryState : change := change . MustState ( ) return change . LedgerKey ( ) default : panic ( fmt . Errorf ( " " , change . Type ) ) } }

// LedgerKey returns the key for the ledger entry that was changed
// in `change`.

LedgerKey returns the key for the ledger entry that was changed in change .


func checkPlausible() {
	for _, r := range prefix {
		if !strings.ContainsRune(alphabet, r) {
			fmt.Printf("Invalid prefix: %s is not in the base32 alphabet\n", strconv.QuoteRune(r))
			os.Exit(1)
		}
	}
}

func checkPlausible ( ) { for _ , r := range prefix { if ! strings . ContainsRune ( alphabet , r ) { fmt . Printf ( " \n " , strconv . QuoteRune ( r ) ) os . Exit ( 1 ) } } }

// aborts the attempt if a desired character is not a valid base32 digit


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 ( 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 ( " " , aid . Type ) ) } }

// 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.

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) Equals(other AccountId) bool {
	if aid.Type != other.Type {
		return false
	}

	switch aid.Type {
	case CryptoKeyTypeKeyTypeEd25519:
		l := aid.MustEd25519()
		r := other.MustEd25519()
		return l == r
	default:
		panic(fmt.Errorf("Unknown account id type: %v", aid.Type))
	}
}

func ( aid * AccountId ) Equals ( other AccountId ) bool { if aid . Type != other . Type { return false } switch aid . Type { case CryptoKeyTypeKeyTypeEd25519 : l := aid . MustEd25519 ( ) r := other . MustEd25519 ( ) return l == r default : panic ( fmt . Errorf ( " " , aid . Type ) ) } }

// Equals returns true if `other` is equivalent to `aid`

Equals returns true if other is equivalent to aid


func (aid *AccountId) SetAddress(address string) error {
	if aid == nil {
		return nil
	}

	raw, err := strkey.Decode(strkey.VersionByteAccountID, address)
	if err != nil {
		return err
	}

	if len(raw) != 32 {
		return errors.New("invalid address")
	}

	var ui Uint256
	copy(ui[:], raw)

	*aid, err = NewAccountId(CryptoKeyTypeKeyTypeEd25519, ui)

	return err
}

func ( aid * AccountId ) SetAddress ( address string ) error { if aid == nil { return nil } raw , err := strkey . Decode ( strkey . VersionByteAccountID , address ) if err != nil { return err } if len ( raw ) != 32 { return errors . New ( " " ) } var ui Uint256 copy ( ui [ : ] , raw ) * aid , err = NewAccountId ( CryptoKeyTypeKeyTypeEd25519 , ui ) return err }

// SetAddress modifies the receiver, setting it's value to the AccountId form
// of the provided address.

SetAddress modifies the receiver setting it s value to the AccountId form of the provided address .


func (a Asset) ToXdrObject() (xdr.Asset, error) {
	if a.Native {
		return xdr.NewAsset(xdr.AssetTypeAssetTypeNative, nil)
	}

	var issuer xdr.AccountId
	err := setAccountId(a.Issuer, &issuer)
	if err != nil {
		return xdr.Asset{}, err
	}

	length := len(a.Code)
	switch {
	case length >= 1 && length <= 4:
		var codeArray [4]byte
		byteArray := []byte(a.Code)
		copy(codeArray[:], byteArray[0:length])
		asset := xdr.AssetAlphaNum4{codeArray, issuer}
		return xdr.NewAsset(xdr.AssetTypeAssetTypeCreditAlphanum4, asset)
	case length >= 5 && length <= 12:
		var codeArray [12]byte
		byteArray := []byte(a.Code)
		copy(codeArray[:], byteArray[0:length])
		asset := xdr.AssetAlphaNum12{codeArray, issuer}
		return xdr.NewAsset(xdr.AssetTypeAssetTypeCreditAlphanum12, asset)
	default:
		return xdr.Asset{}, errors.New("Asset code length is invalid")
	}
}

func ( a Asset ) ToXdrObject ( ) ( xdr . Asset , error ) { if a . Native { return xdr . NewAsset ( xdr . AssetTypeAssetTypeNative , nil ) } var issuer xdr . AccountId err := setAccountId ( a . Issuer , & issuer ) if err != nil { return xdr . Asset { } , err } length := len ( a . Code ) switch { case length >= 1 && length <= 4 : var codeArray [ 4 ] byte byteArray := [ ] byte ( a . Code ) copy ( codeArray [ : ] , byteArray [ 0 : length ] ) asset := xdr . AssetAlphaNum4 { codeArray , issuer } return xdr . NewAsset ( xdr . AssetTypeAssetTypeCreditAlphanum4 , asset ) case length >= 5 && length <= 12 : var codeArray [ 12 ] byte byteArray := [ ] byte ( a . Code ) copy ( codeArray [ : ] , byteArray [ 0 : length ] ) asset := xdr . AssetAlphaNum12 { codeArray , issuer } return xdr . NewAsset ( xdr . AssetTypeAssetTypeCreditAlphanum12 , asset ) default : return xdr . Asset { } , errors . New ( " " ) } }

// ToXdrObject creates xdr.Asset object from build.Asset object

ToXdrObject creates xdr . Asset object from build . Asset object


func (pathSend PayWithPath) Through(asset Asset) PayWithPath {
	pathSend.Path = append(pathSend.Path, asset)
	return pathSend
}

func ( pathSend PayWithPath ) Through ( asset Asset ) PayWithPath { pathSend . Path = append ( pathSend . Path , asset ) return pathSend }

// Through appends a new asset to the path


func PayWith(sendAsset Asset, maxAmount string) PayWithPath {
	return PayWithPath{
		Asset:     sendAsset,
		MaxAmount: maxAmount,
	}
}

func PayWith ( sendAsset Asset , maxAmount string ) PayWithPath { return PayWithPath { Asset : sendAsset , MaxAmount : maxAmount , } }

// PayWith is a helper to create PayWithPath struct


func continuedFraction(price string) (xdrPrice xdr.Price, err error) {
	number := &big.Rat{}
	maxInt32 := &big.Rat{}
	zero := &big.Rat{}
	one := &big.Rat{}

	_, ok := number.SetString(price)
	if !ok {
		return xdrPrice, fmt.Errorf("cannot parse price: %s", price)
	}

	maxInt32.SetInt64(int64(math.MaxInt32))
	zero.SetInt64(int64(0))
	one.SetInt64(int64(1))

	fractions := [][2]*big.Rat{
		{zero, one},
		{one, zero},
	}

	i := 2
	for {
		if number.Cmp(maxInt32) == 1 {
			break
		}

		f := &big.Rat{}
		h := &big.Rat{}
		k := &big.Rat{}

		a := floor(number)
		f.Sub(number, a)
		h.Mul(a, fractions[i-1][0])
		h.Add(h, fractions[i-2][0])
		k.Mul(a, fractions[i-1][1])
		k.Add(k, fractions[i-2][1])

		if h.Cmp(maxInt32) == 1 || k.Cmp(maxInt32) == 1 {
			break
		}

		fractions = append(fractions, [2]*big.Rat{h, k})
		if f.Cmp(zero) == 0 {
			break
		}
		number.Quo(one, f)
		i++
	}

	n, d := fractions[len(fractions)-1][0], fractions[len(fractions)-1][1]

	if n.Cmp(zero) == 0 || d.Cmp(zero) == 0 {
		return xdrPrice, errors.New("Couldn't find approximation")
	}

	return xdr.Price{
		N: xdr.Int32(n.Num().Int64()),
		D: xdr.Int32(d.Num().Int64()),
	}, nil
}

func continuedFraction ( price string ) ( xdrPrice xdr . Price , err error ) { number := & big . Rat { } maxInt32 := & big . Rat { } zero := & big . Rat { } one := & big . Rat { } _ , ok := number . SetString ( price ) if ! ok { return xdrPrice , fmt . Errorf ( " " , price ) } maxInt32 . SetInt64 ( int64 ( math . MaxInt32 ) ) zero . SetInt64 ( int64 ( 0 ) ) one . SetInt64 ( int64 ( 1 ) ) fractions := [ ] [ 2 ] * big . Rat { { zero , one } , { one , zero } , } i := 2 for { if number . Cmp ( maxInt32 ) == 1 { break } f := & big . Rat { } h := & big . Rat { } k := & big . Rat { } a := floor ( number ) f . Sub ( number , a ) h . Mul ( a , fractions [ i - 1 ] [ 0 ] ) h . Add ( h , fractions [ i - 2 ] [ 0 ] ) k . Mul ( a , fractions [ i - 1 ] [ 1 ] ) k . Add ( k , fractions [ i - 2 ] [ 1 ] ) if h . Cmp ( maxInt32 ) == 1 || k . Cmp ( maxInt32 ) == 1 { break } fractions = append ( fractions , [ 2 ] * big . Rat { h , k } ) if f . Cmp ( zero ) == 0 { break } number . Quo ( one , f ) i ++ } n , d := fractions [ len ( fractions ) - 1 ] [ 0 ] , fractions [ len ( fractions ) - 1 ] [ 1 ] if n . Cmp ( zero ) == 0 || d . Cmp ( zero ) == 0 { return xdrPrice , errors . New ( " " ) } return xdr . Price { N : xdr . Int32 ( n . Num ( ) . Int64 ( ) ) , D : xdr . Int32 ( d . Num ( ) . Int64 ( ) ) , } , nil }

// continuedFraction calculates and returns the best rational approximation of the given real number.

continuedFraction calculates and returns the best rational approximation of the given real number .


func (b *TransactionEnvelopeBuilder) Mutate(muts ...TransactionEnvelopeMutator) {
	b.Init()

	for _, m := range muts {
		err := m.MutateTransactionEnvelope(b)
		if err != nil {
			b.Err = err
			return
		}
	}
}

func ( b * TransactionEnvelopeBuilder ) Mutate ( muts ... TransactionEnvelopeMutator ) { b . Init ( ) for _ , m := range muts { err := m . MutateTransactionEnvelope ( b ) if err != nil { b . Err = err return } } }

// Mutate applies the provided TransactionEnvelopeMutators to this builder's
// envelope

Mutate applies the provided TransactionEnvelopeMutators to this builder s envelope


func (b *TransactionEnvelopeBuilder) MutateTX(muts ...TransactionMutator) {
	b.Init()

	if b.Err != nil {
		return
	}

	b.child.Mutate(muts...)
	b.Err = b.child.Err
}

func ( b * TransactionEnvelopeBuilder ) MutateTX ( muts ... TransactionMutator ) { b . Init ( ) if b . Err != nil { return } b . child . Mutate ( muts ... ) b . Err = b . child . Err }

// MutateTX runs Mutate on the underlying transaction using the provided
// mutators.

MutateTX runs Mutate on the underlying transaction using the provided mutators .


func (b *TransactionEnvelopeBuilder) Bytes() ([]byte, error) {
	if b.Err != nil {
		return nil, b.Err
	}

	var txBytes bytes.Buffer
	_, err := xdr.Marshal(&txBytes, b.E)
	if err != nil {
		return nil, err
	}

	return txBytes.Bytes(), nil
}

func ( b * TransactionEnvelopeBuilder ) Bytes ( ) ( [ ] byte , error ) { if b . Err != nil { return nil , b . Err } var txBytes bytes . Buffer _ , err := xdr . Marshal ( & txBytes , b . E ) if err != nil { return nil , err } return txBytes . Bytes ( ) , nil }

// Bytes encodes the builder's underlying envelope to XDR

Bytes encodes the builder s underlying envelope to XDR


func (b *TransactionEnvelopeBuilder) Base64() (string, error) {
	bs, err := b.Bytes()
	return base64.StdEncoding.EncodeToString(bs), err
}

func ( b * TransactionEnvelopeBuilder ) Base64 ( ) ( string , error ) { bs , err := b . Bytes ( ) return base64 . StdEncoding . EncodeToString ( bs ) , err }

// Base64 returns a string which is the xdr-then-base64-encoded form
// of the builder's underlying transaction envelope

Base64 returns a string which is the xdr - then - base64 - encoded form of the builder s underlying transaction envelope


func (m *TransactionBuilder) MutateTransactionEnvelope(txe *TransactionEnvelopeBuilder) error {
	if m.Err != nil {
		return m.Err
	}

	txe.E.Tx = *m.TX
	newChild := *m
	txe.child = &newChild
	m.TX = &txe.E.Tx
	return nil
}

func ( m * TransactionBuilder ) MutateTransactionEnvelope ( txe * TransactionEnvelopeBuilder ) error { if m . Err != nil { return m . Err } txe . E . Tx = * m . TX newChild := * m txe . child = & newChild m . TX = & txe . E . Tx return nil }

// MutateTransactionEnvelope for TransactionBuilder causes the underylying
// transaction to be set as the provided envelope's Tx field

MutateTransactionEnvelope for TransactionBuilder causes the underylying transaction to be set as the provided envelope s Tx field


func (m HomeDomain) MutateSetOptions(o *xdr.SetOptionsOp) (err error) {
	if len(m) > 32 {
		return errors.New("HomeDomain is too long")
	}

	value := xdr.String32(m)
	o.HomeDomain = &value
	return
}

func ( m HomeDomain ) MutateSetOptions ( o * xdr . SetOptionsOp ) ( err error ) { if len ( m ) > 32 { return errors . New ( " " ) } value := xdr . String32 ( m ) o . HomeDomain = & value return }

// MutateSetOptions for HomeDomain sets the SetOptionsOp's HomeDomain field

MutateSetOptions for HomeDomain sets the SetOptionsOp s HomeDomain field


func (m InflationDest) MutateSetOptions(o *xdr.SetOptionsOp) (err error) {
	o.InflationDest = &xdr.AccountId{}
	err = setAccountId(string(m), o.InflationDest)
	return
}

func ( m InflationDest ) MutateSetOptions ( o * xdr . SetOptionsOp ) ( err error ) { o . InflationDest = & xdr . AccountId { } err = setAccountId ( string ( m ) , o . InflationDest ) return }

// MutateSetOptions for InflationDest sets the SetOptionsOp's InflationDest field

MutateSetOptions for InflationDest sets the SetOptionsOp s InflationDest field


func (m MasterWeight) MutateSetOptions(o *xdr.SetOptionsOp) (err error) {
	val := xdr.Uint32(m)
	o.MasterWeight = &val
	return
}

func ( m MasterWeight ) MutateSetOptions ( o * xdr . SetOptionsOp ) ( err error ) { val := xdr . Uint32 ( m ) o . MasterWeight = & val return }

// MutateSetOptions for MasterWeight sets the SetOptionsOp's MasterWeight field

MutateSetOptions for MasterWeight sets the SetOptionsOp s MasterWeight field


func (m Signer) MutateSetOptions(o *xdr.SetOptionsOp) (err error) {
	var signer xdr.Signer
	signer.Weight = xdr.Uint32(m.Weight)
	err = setAccountId(m.PublicKey, &signer.PubKey)
	o.Signer = &signer
	return
}

func ( m Signer ) MutateSetOptions ( o * xdr . SetOptionsOp ) ( err error ) { var signer xdr . Signer signer . Weight = xdr . Uint32 ( m . Weight ) err = setAccountId ( m . PublicKey , & signer . PubKey ) o . Signer = & signer return }

// MutateSetOptions for Signer sets the SetOptionsOp's signer field

MutateSetOptions for Signer sets the SetOptionsOp s signer field


func SetThresholds(low, medium, high uint32) Thresholds {
	return Thresholds{
		Low:    &low,
		Medium: &medium,
		High:   &high,
	}
}

func SetThresholds ( low , medium , high uint32 ) Thresholds { return Thresholds { Low : & low , Medium : & medium , High : & high , } }

// SetThresholds creates Thresholds mutator


func (m Thresholds) MutateSetOptions(o *xdr.SetOptionsOp) (err error) {
	if m.Low != nil {
		val := xdr.Uint32(*m.Low)
		o.LowThreshold = &val
	}

	if m.Medium != nil {
		val := xdr.Uint32(*m.Medium)
		o.MedThreshold = &val
	}

	if m.High != nil {
		val := xdr.Uint32(*m.High)
		o.HighThreshold = &val
	}

	return
}

func ( m Thresholds ) MutateSetOptions ( o * xdr . SetOptionsOp ) ( err error ) { if m . Low != nil { val := xdr . Uint32 ( * m . Low ) o . LowThreshold = & val } if m . Medium != nil { val := xdr . Uint32 ( * m . Medium ) o . MedThreshold = & val } if m . High != nil { val := xdr . Uint32 ( * m . High ) o . HighThreshold = & val } return }

// MutateSetOptions for Thresholds sets the SetOptionsOp's thresholds fields

MutateSetOptions for Thresholds sets the SetOptionsOp s thresholds fields


func (m SetFlag) MutateSetOptions(o *xdr.SetOptionsOp) (err error) {
	if !isFlagValid(xdr.AccountFlags(m)) {
		return errors.New("Unknown flag in SetFlag mutator")
	}

	var val xdr.Uint32
	if o.SetFlags == nil {
		val = xdr.Uint32(m)
	} else {
		val = xdr.Uint32(m) | *o.SetFlags
	}
	o.SetFlags = &val
	return
}

func ( m SetFlag ) MutateSetOptions ( o * xdr . SetOptionsOp ) ( err error ) { if ! isFlagValid ( xdr . AccountFlags ( m ) ) { return errors . New ( " " ) } var val xdr . Uint32 if o . SetFlags == nil { val = xdr . Uint32 ( m ) } else { val = xdr . Uint32 ( m ) | * o . SetFlags } o . SetFlags = & val return }

// MutateSetOptions for SetFlag sets the SetOptionsOp's SetFlags field

MutateSetOptions for SetFlag sets the SetOptionsOp s SetFlags field


func (m ClearFlag) MutateSetOptions(o *xdr.SetOptionsOp) (err error) {
	if !isFlagValid(xdr.AccountFlags(m)) {
		return errors.New("Unknown flag in SetFlag mutator")
	}

	var val xdr.Uint32
	if o.ClearFlags == nil {
		val = xdr.Uint32(m)
	} else {
		val = xdr.Uint32(m) | *o.ClearFlags
	}
	o.ClearFlags = &val
	return
}

func ( m ClearFlag ) MutateSetOptions ( o * xdr . SetOptionsOp ) ( err error ) { if ! isFlagValid ( xdr . AccountFlags ( m ) ) { return errors . New ( " " ) } var val xdr . Uint32 if o . ClearFlags == nil { val = xdr . Uint32 ( m ) } else { val = xdr . Uint32 ( m ) | * o . ClearFlags } o . ClearFlags = & val return }

// MutateSetOptions for ClearFlag sets the SetOptionsOp's ClearFlags field

MutateSetOptions for ClearFlag sets the SetOptionsOp s ClearFlags field


func (m Destination) MutateCreateAccount(o *xdr.CreateAccountOp) error {
	return setAccountId(m.AddressOrSeed, &o.Destination)
}

func ( m Destination ) MutateCreateAccount ( o * xdr . CreateAccountOp ) error { return setAccountId ( m . AddressOrSeed , & o . Destination ) }

// MutateCreateAccount for Destination sets the CreateAccountOp's Destination
// field

MutateCreateAccount for Destination sets the CreateAccountOp s Destination field


func (m NativeAmount) MutateCreateAccount(o *xdr.CreateAccountOp) (err error) {
	o.StartingBalance, err = amount.Parse(m.Amount)
	return
}

func ( m NativeAmount ) MutateCreateAccount ( o * xdr . CreateAccountOp ) ( err error ) { o . StartingBalance , err = amount . Parse ( m . Amount ) return }

// MutateCreateAccount for NativeAmount sets the CreateAccountOp's
// StartingBalance field

MutateCreateAccount for NativeAmount sets the CreateAccountOp s StartingBalance field


func Random() (*Full, error) {
	var rawSeed [32]byte

	_, err := io.ReadFull(rand.Reader, rawSeed[:])
	if err != nil {
		return nil, err
	}

	kp, err := FromRawSeed(rawSeed)

	if err != nil {
		return nil, err
	}

	return kp, nil
}

func Random ( ) ( * Full , error ) { var rawSeed [ 32 ] byte _ , err := io . ReadFull ( rand . Reader , rawSeed [ : ] ) if err != nil { return nil , err } kp , err := FromRawSeed ( rawSeed ) if err != nil { return nil , err } return kp , nil }


func Master(networkPassphrase string) KP {
	kp, err := FromRawSeed(network.ID(networkPassphrase))

	if err != nil {
		panic(err)
	}

	return kp
}

func Master ( networkPassphrase string ) KP { kp , err := FromRawSeed ( network . ID ( networkPassphrase ) ) if err != nil { panic ( err ) } return kp }

// Master returns the master keypair for a given network passphrase


func Parse(addressOrSeed string) (KP, error) {
	_, err := strkey.Decode(strkey.VersionByteAccountID, addressOrSeed)
	if err == nil {
		return &FromAddress{addressOrSeed}, nil
	}

	if err != strkey.ErrInvalidVersionByte {
		return nil, err
	}

	_, err = strkey.Decode(strkey.VersionByteSeed, addressOrSeed)
	if err == nil {
		return &Full{addressOrSeed}, nil
	}

	return nil, err
}

func Parse ( addressOrSeed string ) ( KP , error ) { _ , err := strkey . Decode ( strkey . VersionByteAccountID , addressOrSeed ) if err == nil { return & FromAddress { addressOrSeed } , nil } if err != strkey . ErrInvalidVersionByte { return nil , err } _ , err = strkey . Decode ( strkey . VersionByteSeed , addressOrSeed ) if err == nil { return & Full { addressOrSeed } , nil } return nil , err }

// Parse constructs a new KP from the provided string, which should be either
// an address, or a seed.  If the provided input is a seed, the resulting KP
// will have signing capabilities.

Parse constructs a new KP from the provided string which should be either an address or a seed . If the provided input is a seed the resulting KP will have signing capabilities .


func MustParse(addressOrSeed string) KP {
	kp, err := Parse(addressOrSeed)
	if err != nil {
		panic(err)
	}

	return kp
}

func MustParse ( addressOrSeed string ) KP { kp , err := Parse ( addressOrSeed ) if err != nil { panic ( err ) } return kp }

// MustParse is the panic-on-fail version of Parse

MustParse is the panic - on - fail version of Parse


func (m Authorize) MutateAllowTrust(o *xdr.AllowTrustOp) error {
	o.Authorize = m.Value
	return nil
}

func ( m Authorize ) MutateAllowTrust ( o * xdr . AllowTrustOp ) error { o . Authorize = m . Value return nil }

// MutateAllowTrust for Authorize sets the AllowTrustOp's Authorize field

MutateAllowTrust for Authorize sets the AllowTrustOp s Authorize field


func (m AllowTrustAsset) MutateAllowTrust(o *xdr.AllowTrustOp) (err error) {
	length := len(m.Code)

	switch {
	case length >= 1 && length <= 4:
		var code [4]byte
		byteArray := []byte(m.Code)
		copy(code[:], byteArray[0:length])
		o.Asset, err = xdr.NewAllowTrustOpAsset(xdr.AssetTypeAssetTypeCreditAlphanum4, code)
	case length >= 5 && length <= 12:
		var code [12]byte
		byteArray := []byte(m.Code)
		copy(code[:], byteArray[0:length])
		o.Asset, err = xdr.NewAllowTrustOpAsset(xdr.AssetTypeAssetTypeCreditAlphanum12, code)
	default:
		err = errors.New("Asset code length is invalid")
	}

	return
}

func ( m AllowTrustAsset ) MutateAllowTrust ( o * xdr . AllowTrustOp ) ( err error ) { length := len ( m . Code ) switch { case length >= 1 && length <= 4 : var code [ 4 ] byte byteArray := [ ] byte ( m . Code ) copy ( code [ : ] , byteArray [ 0 : length ] ) o . Asset , err = xdr . NewAllowTrustOpAsset ( xdr . AssetTypeAssetTypeCreditAlphanum4 , code ) case length >= 5 && length <= 12 : var code [ 12 ] byte byteArray := [ ] byte ( m . Code ) copy ( code [ : ] , byteArray [ 0 : length ] ) o . Asset , err = xdr . NewAllowTrustOpAsset ( xdr . AssetTypeAssetTypeCreditAlphanum12 , code ) default : err = errors . New ( " " ) } return }

// MutateAllowTrust for Asset sets the AllowTrustOp's Asset field

MutateAllowTrust for Asset sets the AllowTrustOp s Asset field


func (m Trustor) MutateAllowTrust(o *xdr.AllowTrustOp) error {
	return setAccountId(m.Address, &o.Trustor)
}

func ( m Trustor ) MutateAllowTrust ( o * xdr . AllowTrustOp ) error { return setAccountId ( m . Address , & o . Trustor ) }

// MutateAllowTrust for Trustor sets the AllowTrustOp's Trustor field

MutateAllowTrust for Trustor sets the AllowTrustOp s Trustor field


func (a AllowTrustOpAsset) ToAsset(issuer AccountId) (ret Asset) {
	var err error

	switch a.Type {
	case AssetTypeAssetTypeCreditAlphanum4:

		ret, err = NewAsset(AssetTypeAssetTypeCreditAlphanum4, AssetAlphaNum4{
			AssetCode: a.MustAssetCode4(),
			Issuer:    issuer,
		})
	case AssetTypeAssetTypeCreditAlphanum12:
		ret, err = NewAsset(AssetTypeAssetTypeCreditAlphanum12, AssetAlphaNum12{
			AssetCode: a.MustAssetCode12(),
			Issuer:    issuer,
		})
	default:
		err = fmt.Errorf("Unexpected type for AllowTrustOpAsset: %d", a.Type)
	}

	if err != nil {
		panic(err)
	}
	return
}

func ( a AllowTrustOpAsset ) ToAsset ( issuer AccountId ) ( ret Asset ) { var err error switch a . Type { case AssetTypeAssetTypeCreditAlphanum4 : ret , err = NewAsset ( AssetTypeAssetTypeCreditAlphanum4 , AssetAlphaNum4 { AssetCode : a . MustAssetCode4 ( ) , Issuer : issuer , } ) case AssetTypeAssetTypeCreditAlphanum12 : ret , err = NewAsset ( AssetTypeAssetTypeCreditAlphanum12 , AssetAlphaNum12 { AssetCode : a . MustAssetCode12 ( ) , Issuer : issuer , } ) default : err = fmt . Errorf ( " " , a . Type ) } if err != nil { panic ( err ) } return }

// ToAsset converts `a` to a proper xdr.Asset

ToAsset converts a to a proper xdr . Asset


func (a *Asset) SetNative() error {
	newa, err := NewAsset(AssetTypeAssetTypeNative, nil)
	if err != nil {
		return err
	}
	*a = newa
	return nil
}

func ( a * Asset ) SetNative ( ) error { newa , err := NewAsset ( AssetTypeAssetTypeNative , nil ) if err != nil { return err } * a = newa return nil }

// SetNative overwrites `a` with the native asset type

SetNative overwrites a with the native asset type


func (a Asset) String() string {
	var t, c, i string

	a.MustExtract(&t, &c, &i)

	if a.Type == AssetTypeAssetTypeNative {
		return t
	}

	return fmt.Sprintf("%s/%s/%s", t, c, i)
}

func ( a Asset ) String ( ) string { var t , c , i string a . MustExtract ( & t , & c , & i ) if a . Type == AssetTypeAssetTypeNative { return t } return fmt . Sprintf ( " " , t , c , i ) }

// String returns a display friendly form of the asset


func (a Asset) Equals(other Asset) bool {
	if a.Type != other.Type {
		return false
	}
	switch a.Type {
	case AssetTypeAssetTypeNative:
		return true
	case AssetTypeAssetTypeCreditAlphanum4:
		l := a.MustAlphaNum4()
		r := other.MustAlphaNum4()
		return l.AssetCode == r.AssetCode && l.Issuer.Equals(r.Issuer)
	case AssetTypeAssetTypeCreditAlphanum12:
		l := a.MustAlphaNum12()
		r := other.MustAlphaNum12()
		return l.AssetCode == r.AssetCode && l.Issuer.Equals(r.Issuer)
	default:
		panic(fmt.Errorf("Unknown asset type: %v", a.Type))
	}
}

func ( a Asset ) Equals ( other Asset ) bool { if a . Type != other . Type { return false } switch a . Type { case AssetTypeAssetTypeNative : return true case AssetTypeAssetTypeCreditAlphanum4 : l := a . MustAlphaNum4 ( ) r := other . MustAlphaNum4 ( ) return l . AssetCode == r . AssetCode && l . Issuer . Equals ( r . Issuer ) case AssetTypeAssetTypeCreditAlphanum12 : l := a . MustAlphaNum12 ( ) r := other . MustAlphaNum12 ( ) return l . AssetCode == r . AssetCode && l . Issuer . Equals ( r . Issuer ) default : panic ( fmt . Errorf ( " " , a . Type ) ) } }

// Equals returns true if `other` is equivalent to `a`

Equals returns true if other is equivalent to a


func (a Asset) MustExtract(typ interface{}, code interface{}, issuer interface{}) {
	err := a.Extract(typ, code, issuer)

	if err != nil {
		panic(err)
	}
}

func ( a Asset ) MustExtract ( typ interface { } , code interface { } , issuer interface { } ) { err := a . Extract ( typ , code , issuer ) if err != nil { panic ( err ) } }

// MustExtract behaves as Extract, but panics if an error occurs.

MustExtract behaves as Extract but panics if an error occurs .


func Unmarshal(r io.Reader, v interface{}) (int, error) {
	// delegate to xdr package's Unmarshal
	return xdr.Unmarshal(r, v)
}

func
Unmarshal
(
r
io
.
Reader
,
v
interface
{
}
)
(
int
,
error
)
{
// delegate to xdr package's Unmarshal
return
xdr
.
Unmarshal
(
r
,
v
)
}

// Unmarshal reads an xdr element from `r` into `v`.

Unmarshal reads an xdr element from r into v .


func Marshal(w io.Writer, v interface{}) (int, error) {
	// delegate to xdr package's Marshal
	return xdr.Marshal(w, v)
}

func
Marshal
(
w
io
.
Writer
,
v
interface
{
}
)
(
int
,
error
)
{
// delegate to xdr package's Marshal
return
xdr
.
Marshal
(
w
,
v
)
}

// Marshal writes an xdr element `v` into `w`.

Marshal writes an xdr element v into w .


func (e CryptoKeyType) ValidEnum(v int32) bool {
	_, ok := cryptoKeyTypeMap[v]
	return ok
}

func ( e CryptoKeyType ) ValidEnum ( v int32 ) bool { _ , ok := cryptoKeyTypeMap [ v ] return ok }

// ValidEnum validates a proposed value for this enum.  Implements
// the Enum interface for CryptoKeyType

ValidEnum validates a proposed value for this enum . Implements the Enum interface for CryptoKeyType


func NewPublicKey(aType CryptoKeyType, value interface{}) (result PublicKey, err error) {
	result.Type = aType
	switch CryptoKeyType(aType) {
	case CryptoKeyTypeKeyTypeEd25519:
		tv, ok := value.(Uint256)
		if !ok {
			err = fmt.Errorf("invalid value, must be Uint256")
			return
		}
		result.Ed25519 = &tv
	}
	return
}

func NewPublicKey ( aType CryptoKeyType , value interface { } ) ( result PublicKey , err error ) { result . Type = aType switch CryptoKeyType ( aType ) { case CryptoKeyTypeKeyTypeEd25519 : tv , ok := value . ( Uint256 ) if ! ok { err = fmt . Errorf ( " " ) return } result . Ed25519 = & tv } return }

// NewPublicKey creates a new  PublicKey.


func (u PublicKey) MustEd25519() Uint256 {
	val, ok := u.GetEd25519()

	if !ok {
		panic("arm Ed25519 is not set")
	}

	return val
}

func ( u PublicKey ) MustEd25519 ( ) Uint256 { val , ok := u . GetEd25519 ( ) if ! ok { panic ( " " ) } return val }

// MustEd25519 retrieves the Ed25519 value from the union,
// panicing if the value is not set.

MustEd25519 retrieves the Ed25519 value from the union panicing if the value is not set .


func NewNodeId(aType CryptoKeyType, value interface{}) (result NodeId, err error) {
	u, err := NewPublicKey(aType, value)
	result = NodeId(u)
	return
}

func NewNodeId ( aType CryptoKeyType , value interface { } ) ( result NodeId , err error ) { u , err := NewPublicKey ( aType , value ) result = NodeId ( u ) return }


func NewAccountId(aType CryptoKeyType, value interface{}) (result AccountId, err error) {
	u, err := NewPublicKey(aType, value)
	result = AccountId(u)
	return
}

func NewAccountId ( aType CryptoKeyType , value interface { } ) ( result AccountId , err error ) { u , err := NewPublicKey ( aType , value ) result = AccountId ( u ) return }

// NewAccountId creates a new  AccountId.


func (e AssetType) ValidEnum(v int32) bool {
	_, ok := assetTypeMap[v]
	return ok
}

func ( e AssetType ) ValidEnum ( v int32 ) bool { _ , ok := assetTypeMap [ v ] return ok }

// ValidEnum validates a proposed value for this enum.  Implements
// the Enum interface for AssetType

ValidEnum validates a proposed value for this enum . Implements the Enum interface for AssetType


func (u Asset) ArmForSwitch(sw int32) (string, bool) {
	switch AssetType(sw) {
	case AssetTypeAssetTypeNative:
		return "", true
	case AssetTypeAssetTypeCreditAlphanum4:
		return "AlphaNum4", true
	case AssetTypeAssetTypeCreditAlphanum12:
		return "AlphaNum12", true
	}
	return "-", false
}

func ( u Asset ) ArmForSwitch ( sw int32 ) ( string , bool ) { switch AssetType ( sw ) { case AssetTypeAssetTypeNative : return " " , true case AssetTypeAssetTypeCreditAlphanum4 : return " " , true case AssetTypeAssetTypeCreditAlphanum12 : return " " , true } return " " , false }

// ArmForSwitch returns which field name should be used for storing
// the value for an instance of Asset

ArmForSwitch returns which field name should be used for storing the value for an instance of Asset


func NewAsset(aType AssetType, value interface{}) (result Asset, err error) {
	result.Type = aType
	switch AssetType(aType) {
	case AssetTypeAssetTypeNative:
		// void
	case AssetTypeAssetTypeCreditAlphanum4:
		tv, ok := value.(AssetAlphaNum4)
		if !ok {
			err = fmt.Errorf("invalid value, must be AssetAlphaNum4")
			return
		}
		result.AlphaNum4 = &tv
	case AssetTypeAssetTypeCreditAlphanum12:
		tv, ok := value.(AssetAlphaNum12)
		if !ok {
			err = fmt.Errorf("invalid value, must be AssetAlphaNum12")
			return
		}
		result.AlphaNum12 = &tv
	}
	return
}

func
NewAsset
(
aType
AssetType
,
value
interface
{
}
)
(
result
Asset
,
err
error
)
{
result
.
Type
=
aType
switch
AssetType
(
aType
)
{
case
AssetTypeAssetTypeNative
:
// void
case
AssetTypeAssetTypeCreditAlphanum4
:
tv
,
ok
:=
value
.
(
AssetAlphaNum4
)
if
!
ok
{
err
=
fmt
.
Errorf
(
"
"
)
return
}
result
.
AlphaNum4
=
&
tv
case
AssetTypeAssetTypeCreditAlphanum12
:
tv
,
ok
:=
value
.
(
AssetAlphaNum12
)
if
!
ok
{
err
=
fmt
.
Errorf
(
"
"
)
return
}
result
.
AlphaNum12
=
&
tv
}
return
}


func (u Asset) MustAlphaNum4() AssetAlphaNum4 {
	val, ok := u.GetAlphaNum4()

	if !ok {
		panic("arm AlphaNum4 is not set")
	}

	return val
}

func ( u Asset ) MustAlphaNum4 ( ) AssetAlphaNum4 { val , ok := u . GetAlphaNum4 ( ) if ! ok { panic ( " " ) } return val }

// MustAlphaNum4 retrieves the AlphaNum4 value from the union,
// panicing if the value is not set.

MustAlphaNum4 retrieves the AlphaNum4 value from the union panicing if the value is not set .


func (u Asset) GetAlphaNum4() (result AssetAlphaNum4, ok bool) {
	armName, _ := u.ArmForSwitch(int32(u.Type))

	if armName == "AlphaNum4" {
		result = *u.AlphaNum4
		ok = true
	}

	return
}

func ( u Asset ) GetAlphaNum4 ( ) ( result AssetAlphaNum4 , ok bool ) { armName , _ := u . ArmForSwitch ( int32 ( u . Type ) ) if armName == " " { result = * u . AlphaNum4 ok = true } return }

// GetAlphaNum4 retrieves the AlphaNum4 value from the union,
// returning ok if the union's switch indicated the value is valid.

GetAlphaNum4 retrieves the AlphaNum4 value from the union returning ok if the union s switch indicated the value is valid .


func (u Asset) MustAlphaNum12() AssetAlphaNum12 {
	val, ok := u.GetAlphaNum12()

	if !ok {
		panic("arm AlphaNum12 is not set")
	}

	return val
}

func ( u Asset ) MustAlphaNum12 ( ) AssetAlphaNum12 { val , ok := u . GetAlphaNum12 ( ) if ! ok { panic ( " " ) } return val }

// MustAlphaNum12 retrieves the AlphaNum12 value from the union,
// panicing if the value is not set.

MustAlphaNum12 retrieves the AlphaNum12 value from the union panicing if the value is not set .


func (u Asset) GetAlphaNum12() (result AssetAlphaNum12, ok bool) {
	armName, _ := u.ArmForSwitch(int32(u.Type))

	if armName == "AlphaNum12" {
		result = *u.AlphaNum12
		ok = true
	}

	return
}

func ( u Asset ) GetAlphaNum12 ( ) ( result AssetAlphaNum12 , ok bool ) { armName , _ := u . ArmForSwitch ( int32 ( u . Type ) ) if armName == " " { result = * u . AlphaNum12 ok = true } return }

// GetAlphaNum12 retrieves the AlphaNum12 value from the union,
// returning ok if the union's switch indicated the value is valid.

GetAlphaNum12 retrieves the AlphaNum12 value from the union returning ok if the union s switch indicated the value is valid .


func (e ThresholdIndexes) ValidEnum(v int32) bool {
	_, ok := thresholdIndexesMap[v]
	return ok
}

func ( e ThresholdIndexes ) ValidEnum ( v int32 ) bool { _ , ok := thresholdIndexesMap [ v ] return ok }

// ValidEnum validates a proposed value for this enum.  Implements
// the Enum interface for ThresholdIndexes

ValidEnum validates a proposed value for this enum . Implements the Enum interface for ThresholdIndexes


func (e LedgerEntryType) ValidEnum(v int32) bool {
	_, ok := ledgerEntryTypeMap[v]
	return ok
}

func ( e LedgerEntryType ) ValidEnum ( v int32 ) bool { _ , ok := ledgerEntryTypeMap [ v ] return ok }

// ValidEnum validates a proposed value for this enum.  Implements
// the Enum interface for LedgerEntryType

ValidEnum validates a proposed value for this enum . Implements the Enum interface for LedgerEntryType


func (e AccountFlags) ValidEnum(v int32) bool {
	_, ok := accountFlagsMap[v]
	return ok
}

func ( e AccountFlags ) ValidEnum ( v int32 ) bool { _ , ok := accountFlagsMap [ v ] return ok }

// ValidEnum validates a proposed value for this enum.  Implements
// the Enum interface for AccountFlags

ValidEnum validates a proposed value for this enum . Implements the Enum interface for AccountFlags


func NewAccountEntryExt(v int32, value interface{}) (result AccountEntryExt, err error) {
	result.V = v
	switch int32(v) {
	case 0:
		// void
	}
	return
}

func
NewAccountEntryExt
(
v
int32
,
value
interface
{
}
)
(
result
AccountEntryExt
,
err
error
)
{
result
.
V
=
v
switch
int32
(
v
)
{
case
0
:
// void
}
return
}

// NewAccountEntryExt creates a new  AccountEntryExt.

NewAccountEntryExt creates a new AccountEntryExt .


func (e TrustLineFlags) ValidEnum(v int32) bool {
	_, ok := trustLineFlagsMap[v]
	return ok
}

func ( e TrustLineFlags ) ValidEnum ( v int32 ) bool { _ , ok := trustLineFlagsMap [ v ] return ok }

// ValidEnum validates a proposed value for this enum.  Implements
// the Enum interface for TrustLineFlags

ValidEnum validates a proposed value for this enum . Implements the Enum interface for TrustLineFlags


func NewTrustLineEntryExt(v int32, value interface{}) (result TrustLineEntryExt, err error) {
	result.V = v
	switch int32(v) {
	case 0:
		// void
	}
	return
}

func
NewTrustLineEntryExt
(
v
int32
,
value
interface
{
}
)
(
result
TrustLineEntryExt
,
err
error
)
{
result
.
V
=
v
switch
int32
(
v
)
{
case
0
:
// void
}
return
}

// NewTrustLineEntryExt creates a new  TrustLineEntryExt.

NewTrustLineEntryExt creates a new TrustLineEntryExt .


func (e OfferEntryFlags) ValidEnum(v int32) bool {
	_, ok := offerEntryFlagsMap[v]
	return ok
}

func ( e OfferEntryFlags ) ValidEnum ( v int32 ) bool { _ , ok := offerEntryFlagsMap [ v ] return ok }

// ValidEnum validates a proposed value for this enum.  Implements
// the Enum interface for OfferEntryFlags

ValidEnum validates a proposed value for this enum . Implements the Enum interface for OfferEntryFlags


func NewOfferEntryExt(v int32, value interface{}) (result OfferEntryExt, err error) {
	result.V = v
	switch int32(v) {
	case 0:
		// void
	}
	return
}

func
NewOfferEntryExt
(
v
int32
,
value
interface
{
}
)
(
result
OfferEntryExt
,
err
error
)
{
result
.
V
=
v
switch
int32
(
v
)
{
case
0
:
// void
}
return
}

// NewOfferEntryExt creates a new  OfferEntryExt.

NewOfferEntryExt creates a new OfferEntryExt .


func NewDataEntryExt(v int32, value interface{}) (result DataEntryExt, err error) {
	result.V = v
	switch int32(v) {
	case 0:
		// void
	}
	return
}

func
NewDataEntryExt
(
v
int32
,
value
interface
{
}
)
(
result
DataEntryExt
,
err
error
)
{
result
.
V
=
v
switch
int32
(
v
)
{
case
0
:
// void
}
return
}

// NewDataEntryExt creates a new  DataEntryExt.

NewDataEntryExt creates a new DataEntryExt .


func NewLedgerEntryData(aType LedgerEntryType, value interface{}) (result LedgerEntryData, err error) {
	result.Type = aType
	switch LedgerEntryType(aType) {
	case LedgerEntryTypeAccount:
		tv, ok := value.(AccountEntry)
		if !ok {
			err = fmt.Errorf("invalid value, must be AccountEntry")
			return
		}
		result.Account = &tv
	case LedgerEntryTypeTrustline:
		tv, ok := value.(TrustLineEntry)
		if !ok {
			err = fmt.Errorf("invalid value, must be TrustLineEntry")
			return
		}
		result.TrustLine = &tv
	case LedgerEntryTypeOffer:
		tv, ok := value.(OfferEntry)
		if !ok {
			err = fmt.Errorf("invalid value, must be OfferEntry")
			return
		}
		result.Offer = &tv
	case LedgerEntryTypeData:
		tv, ok := value.(DataEntry)
		if !ok {
			err = fmt.Errorf("invalid value, must be DataEntry")
			return
		}
		result.Data = &tv
	}
	return
}

func NewLedgerEntryData ( aType LedgerEntryType , value interface { } ) ( result LedgerEntryData , err error ) { result . Type = aType switch LedgerEntryType ( aType ) { case LedgerEntryTypeAccount : tv , ok := value . ( AccountEntry ) if ! ok { err = fmt . Errorf ( " " ) return } result . Account = & tv case LedgerEntryTypeTrustline : tv , ok := value . ( TrustLineEntry ) if ! ok { err = fmt . Errorf ( " " ) return } result . TrustLine = & tv case LedgerEntryTypeOffer : tv , ok := value . ( OfferEntry ) if ! ok { err = fmt . Errorf ( " " ) return } result . Offer = & tv case LedgerEntryTypeData : tv , ok := value . ( DataEntry ) if ! ok { err = fmt . Errorf ( " " ) return } result . Data = & tv } return }

// NewLedgerEntryData creates a new  LedgerEntryData.

NewLedgerEntryData creates a new LedgerEntryData .


func NewLedgerEntryExt(v int32, value interface{}) (result LedgerEntryExt, err error) {
	result.V = v
	switch int32(v) {
	case 0:
		// void
	}
	return
}

func
NewLedgerEntryExt
(
v
int32
,
value
interface
{
}
)
(
result
LedgerEntryExt
,
err
error
)
{
result
.
V
=
v
switch
int32
(
v
)
{
case
0
:
// void
}
return
}

// NewLedgerEntryExt creates a new  LedgerEntryExt.

NewLedgerEntryExt creates a new LedgerEntryExt .


func (e EnvelopeType) ValidEnum(v int32) bool {
	_, ok := envelopeTypeMap[v]
	return ok
}

func ( e EnvelopeType ) ValidEnum ( v int32 ) bool { _ , ok := envelopeTypeMap [ v ] return ok }

// ValidEnum validates a proposed value for this enum.  Implements
// the Enum interface for EnvelopeType

ValidEnum validates a proposed value for this enum . Implements the Enum interface for EnvelopeType


func (e OperationType) ValidEnum(v int32) bool {
	_, ok := operationTypeMap[v]
	return ok
}

func ( e OperationType ) ValidEnum ( v int32 ) bool { _ , ok := operationTypeMap [ v ] return ok }

// ValidEnum validates a proposed value for this enum.  Implements
// the Enum interface for OperationType

ValidEnum validates a proposed value for this enum . Implements the Enum interface for OperationType


func (u AllowTrustOpAsset) ArmForSwitch(sw int32) (string, bool) {
	switch AssetType(sw) {
	case AssetTypeAssetTypeCreditAlphanum4:
		return "AssetCode4", true
	case AssetTypeAssetTypeCreditAlphanum12:
		return "AssetCode12", true
	}
	return "-", false
}

func ( u AllowTrustOpAsset ) ArmForSwitch ( sw int32 ) ( string , bool ) { switch AssetType ( sw ) { case AssetTypeAssetTypeCreditAlphanum4 : return " " , true case AssetTypeAssetTypeCreditAlphanum12 : return " " , true } return " " , false }

// ArmForSwitch returns which field name should be used for storing
// the value for an instance of AllowTrustOpAsset

ArmForSwitch returns which field name should be used for storing the value for an instance of AllowTrustOpAsset


func NewAllowTrustOpAsset(aType AssetType, value interface{}) (result AllowTrustOpAsset, err error) {
	result.Type = aType
	switch AssetType(aType) {
	case AssetTypeAssetTypeCreditAlphanum4:
		tv, ok := value.([4]byte)
		if !ok {
			err = fmt.Errorf("invalid value, must be [4]byte")
			return
		}
		result.AssetCode4 = &tv
	case AssetTypeAssetTypeCreditAlphanum12:
		tv, ok := value.([12]byte)
		if !ok {
			err = fmt.Errorf("invalid value, must be [12]byte")
			return
		}
		result.AssetCode12 = &tv
	}
	return
}

func NewAllowTrustOpAsset ( aType AssetType , value interface { } ) ( result AllowTrustOpAsset , err error ) { result . Type = aType switch AssetType ( aType ) { case AssetTypeAssetTypeCreditAlphanum4 : tv , ok := value . ( [ 4 ] byte ) if ! ok { err = fmt . Errorf ( " " ) return } result . AssetCode4 = & tv case AssetTypeAssetTypeCreditAlphanum12 : tv , ok := value . ( [ 12 ] byte ) if ! ok { err = fmt . Errorf ( " " ) return } result . AssetCode12 = & tv } return }

// NewAllowTrustOpAsset creates a new  AllowTrustOpAsset.

NewAllowTrustOpAsset creates a new AllowTrustOpAsset .


func (u AllowTrustOpAsset) MustAssetCode4() [4]byte {
	val, ok := u.GetAssetCode4()

	if !ok {
		panic("arm AssetCode4 is not set")
	}

	return val
}

func ( u AllowTrustOpAsset ) MustAssetCode4 ( ) [ 4 ] byte { val , ok := u . GetAssetCode4 ( ) if ! ok { panic ( " " ) } return val }

// MustAssetCode4 retrieves the AssetCode4 value from the union,
// panicing if the value is not set.

MustAssetCode4 retrieves the AssetCode4 value from the union panicing if the value is not set .


func (u AllowTrustOpAsset) GetAssetCode4() (result [4]byte, ok bool) {
	armName, _ := u.ArmForSwitch(int32(u.Type))

	if armName == "AssetCode4" {
		result = *u.AssetCode4
		ok = true
	}

	return
}

func ( u AllowTrustOpAsset ) GetAssetCode4 ( ) ( result [ 4 ] byte , ok bool ) { armName , _ := u . ArmForSwitch ( int32 ( u . Type ) ) if armName == " " { result = * u . AssetCode4 ok = true } return }

// GetAssetCode4 retrieves the AssetCode4 value from the union,
// returning ok if the union's switch indicated the value is valid.

GetAssetCode4 retrieves the AssetCode4 value from the union returning ok if the union s switch indicated the value is valid .


func (u AllowTrustOpAsset) MustAssetCode12() [12]byte {
	val, ok := u.GetAssetCode12()

	if !ok {
		panic("arm AssetCode12 is not set")
	}

	return val
}

func ( u AllowTrustOpAsset ) MustAssetCode12 ( ) [ 12 ] byte { val , ok := u . GetAssetCode12 ( ) if ! ok { panic ( " " ) } return val }

// MustAssetCode12 retrieves the AssetCode12 value from the union,
// panicing if the value is not set.

MustAssetCode12 retrieves the AssetCode12 value from the union panicing if the value is not set .


func (u AllowTrustOpAsset) GetAssetCode12() (result [12]byte, ok bool) {
	armName, _ := u.ArmForSwitch(int32(u.Type))

	if armName == "AssetCode12" {
		result = *u.AssetCode12
		ok = true
	}

	return
}

func ( u AllowTrustOpAsset ) GetAssetCode12 ( ) ( result [ 12 ] byte , ok bool ) { armName , _ := u . ArmForSwitch ( int32 ( u . Type ) ) if armName == " " { result = * u . AssetCode12 ok = true } return }

// GetAssetCode12 retrieves the AssetCode12 value from the union,
// returning ok if the union's switch indicated the value is valid.

GetAssetCode12 retrieves the AssetCode12 value from the union returning ok if the union s switch indicated the value is valid .


func NewOperationBody(aType OperationType, value interface{}) (result OperationBody, err error) {
	result.Type = aType
	switch OperationType(aType) {
	case OperationTypeCreateAccount:
		tv, ok := value.(CreateAccountOp)
		if !ok {
			err = fmt.Errorf("invalid value, must be CreateAccountOp")
			return
		}
		result.CreateAccountOp = &tv
	case OperationTypePayment:
		tv, ok := value.(PaymentOp)
		if !ok {
			err = fmt.Errorf("invalid value, must be PaymentOp")
			return
		}
		result.PaymentOp = &tv
	case OperationTypePathPayment:
		tv, ok := value.(PathPaymentOp)
		if !ok {
			err = fmt.Errorf("invalid value, must be PathPaymentOp")
			return
		}
		result.PathPaymentOp = &tv
	case OperationTypeManageOffer:
		tv, ok := value.(ManageOfferOp)
		if !ok {
			err = fmt.Errorf("invalid value, must be ManageOfferOp")
			return
		}
		result.ManageOfferOp = &tv
	case OperationTypeCreatePassiveOffer:
		tv, ok := value.(CreatePassiveOfferOp)
		if !ok {
			err = fmt.Errorf("invalid value, must be CreatePassiveOfferOp")
			return
		}
		result.CreatePassiveOfferOp = &tv
	case OperationTypeSetOptions:
		tv, ok := value.(SetOptionsOp)
		if !ok {
			err = fmt.Errorf("invalid value, must be SetOptionsOp")
			return
		}
		result.SetOptionsOp = &tv
	case OperationTypeChangeTrust:
		tv, ok := value.(ChangeTrustOp)
		if !ok {
			err = fmt.Errorf("invalid value, must be ChangeTrustOp")
			return
		}
		result.ChangeTrustOp = &tv
	case OperationTypeAllowTrust:
		tv, ok := value.(AllowTrustOp)
		if !ok {
			err = fmt.Errorf("invalid value, must be AllowTrustOp")
			return
		}
		result.AllowTrustOp = &tv
	case OperationTypeAccountMerge:
		tv, ok := value.(AccountId)
		if !ok {
			err = fmt.Errorf("invalid value, must be AccountId")
			return
		}
		result.Destination = &tv
	case OperationTypeInflation:
		// void
	case OperationTypeManageData:
		tv, ok := value.(ManageDataOp)
		if !ok {
			err = fmt.Errorf("invalid value, must be ManageDataOp")
			return
		}
		result.ManageDataOp = &tv
	}
	return
}

func
NewOperationBody
(
aType
OperationType
,
value
interface
{
}
)
(
result
OperationBody
,
err
error
)
{
result
.
Type
=
aType
switch
OperationType
(
aType
)
{
case
OperationTypeCreateAccount
:
tv
,
ok
:=
value
.
(
CreateAccountOp
)
if
!
ok
{
err
=
fmt
.
Errorf
(
"
"
)
return
}
result
.
CreateAccountOp
=
&
tv
case
OperationTypePayment
:
tv
,
ok
:=
value
.
(
PaymentOp
)
if
!
ok
{
err
=
fmt
.
Errorf
(
"
"
)
return
}
result
.
PaymentOp
=
&
tv
case
OperationTypePathPayment
:
tv
,
ok
:=
value
.
(
PathPaymentOp
)
if
!
ok
{
err
=
fmt
.
Errorf
(
"
"
)
return
}
result
.
PathPaymentOp
=
&
tv
case
OperationTypeManageOffer
:
tv
,
ok
:=
value
.
(
ManageOfferOp
)
if
!
ok
{
err
=
fmt
.
Errorf
(
"
"
)
return
}
result
.
ManageOfferOp
=
&
tv
case
OperationTypeCreatePassiveOffer
:
tv
,
ok
:=
value
.
(
CreatePassiveOfferOp
)
if
!
ok
{
err
=
fmt
.
Errorf
(
"
"
)
return
}
result
.
CreatePassiveOfferOp
=
&
tv
case
OperationTypeSetOptions
:
tv
,
ok
:=
value
.
(
SetOptionsOp
)
if
!
ok
{
err
=
fmt
.
Errorf
(
"
"
)
return
}
result
.
SetOptionsOp
=
&
tv
case
OperationTypeChangeTrust
:
tv
,
ok
:=
value
.
(
ChangeTrustOp
)
if
!
ok
{
err
=
fmt
.
Errorf
(
"
"
)
return
}
result
.
ChangeTrustOp
=
&
tv
case
OperationTypeAllowTrust
:
tv
,
ok
:=
value
.
(
AllowTrustOp
)
if
!
ok
{
err
=
fmt
.
Errorf
(
"
"
)
return
}
result
.
AllowTrustOp
=
&
tv
case
OperationTypeAccountMerge
:
tv
,
ok
:=
value
.
(
AccountId
)
if
!
ok
{
err
=
fmt
.
Errorf
(
"
"
)
return
}
result
.
Destination
=
&
tv
case
OperationTypeInflation
:
// void
case
OperationTypeManageData
:
tv
,
ok
:=
value
.
(
ManageDataOp
)
if
!
ok
{
err
=
fmt
.
Errorf
(
"
"
)
return
}
result
.
ManageDataOp
=
&
tv
}
return
}

// NewOperationBody creates a new  OperationBody.

NewOperationBody creates a new OperationBody .


func (u OperationBody) MustCreateAccountOp() CreateAccountOp {
	val, ok := u.GetCreateAccountOp()

	if !ok {
		panic("arm CreateAccountOp is not set")
	}

	return val
}

func ( u OperationBody ) MustCreateAccountOp ( ) CreateAccountOp { val , ok := u . GetCreateAccountOp ( ) if ! ok { panic ( " " ) } return val }

// MustCreateAccountOp retrieves the CreateAccountOp value from the union,
// panicing if the value is not set.

MustCreateAccountOp retrieves the CreateAccountOp value from the union panicing if the value is not set .


func (u OperationBody) GetCreateAccountOp() (result CreateAccountOp, ok bool) {
	armName, _ := u.ArmForSwitch(int32(u.Type))

	if armName == "CreateAccountOp" {
		result = *u.CreateAccountOp
		ok = true
	}

	return
}

func ( u OperationBody ) GetCreateAccountOp ( ) ( result CreateAccountOp , ok bool ) { armName , _ := u . ArmForSwitch ( int32 ( u . Type ) ) if armName == " " { result = * u . CreateAccountOp ok = true } return }

// GetCreateAccountOp retrieves the CreateAccountOp value from the union,
// returning ok if the union's switch indicated the value is valid.

GetCreateAccountOp retrieves the CreateAccountOp value from the union returning ok if the union s switch indicated the value is valid .


func (u OperationBody) MustPaymentOp() PaymentOp {
	val, ok := u.GetPaymentOp()

	if !ok {
		panic("arm PaymentOp is not set")
	}

	return val
}

func ( u OperationBody ) MustPaymentOp ( ) PaymentOp { val , ok := u . GetPaymentOp ( ) if ! ok { panic ( " " ) } return val }

// MustPaymentOp retrieves the PaymentOp value from the union,
// panicing if the value is not set.

MustPaymentOp retrieves the PaymentOp value from the union panicing if the value is not set .


func (u OperationBody) GetPaymentOp() (result PaymentOp, ok bool) {
	armName, _ := u.ArmForSwitch(int32(u.Type))

	if armName == "PaymentOp" {
		result = *u.PaymentOp
		ok = true
	}

	return
}

func ( u OperationBody ) GetPaymentOp ( ) ( result PaymentOp , ok bool ) { armName , _ := u . ArmForSwitch ( int32 ( u . Type ) ) if armName == " " { result = * u . PaymentOp ok = true } return }

// GetPaymentOp retrieves the PaymentOp value from the union,
// returning ok if the union's switch indicated the value is valid.

GetPaymentOp retrieves the PaymentOp value from the union returning ok if the union s switch indicated the value is valid .


func (u OperationBody) MustPathPaymentOp() PathPaymentOp {
	val, ok := u.GetPathPaymentOp()

	if !ok {
		panic("arm PathPaymentOp is not set")
	}

	return val
}

func ( u OperationBody ) MustPathPaymentOp ( ) PathPaymentOp { val , ok := u . GetPathPaymentOp ( ) if ! ok { panic ( " " ) } return val }

// MustPathPaymentOp retrieves the PathPaymentOp value from the union,
// panicing if the value is not set.

MustPathPaymentOp retrieves the PathPaymentOp value from the union panicing if the value is not set .


func (u OperationBody) GetPathPaymentOp() (result PathPaymentOp, ok bool) {
	armName, _ := u.ArmForSwitch(int32(u.Type))

	if armName == "PathPaymentOp" {
		result = *u.PathPaymentOp
		ok = true
	}

	return
}

func ( u OperationBody ) GetPathPaymentOp ( ) ( result PathPaymentOp , ok bool ) { armName , _ := u . ArmForSwitch ( int32 ( u . Type ) ) if armName == " " { result = * u . PathPaymentOp ok = true } return }

// GetPathPaymentOp retrieves the PathPaymentOp value from the union,
// returning ok if the union's switch indicated the value is valid.

GetPathPaymentOp retrieves the PathPaymentOp value from the union returning ok if the union s switch indicated the value is valid .


func (u OperationBody) MustManageOfferOp() ManageOfferOp {
	val, ok := u.GetManageOfferOp()

	if !ok {
		panic("arm ManageOfferOp is not set")
	}

	return val
}

func ( u OperationBody ) MustManageOfferOp ( ) ManageOfferOp { val , ok := u . GetManageOfferOp ( ) if ! ok { panic ( " " ) } return val }

// MustManageOfferOp retrieves the ManageOfferOp value from the union,
// panicing if the value is not set.

MustManageOfferOp retrieves the ManageOfferOp value from the union panicing if the value is not set .


func (u OperationBody) GetManageOfferOp() (result ManageOfferOp, ok bool) {
	armName, _ := u.ArmForSwitch(int32(u.Type))

	if armName == "ManageOfferOp" {
		result = *u.ManageOfferOp
		ok = true
	}

	return
}

func ( u OperationBody ) GetManageOfferOp ( ) ( result ManageOfferOp , ok bool ) { armName , _ := u . ArmForSwitch ( int32 ( u . Type ) ) if armName == " " { result = * u . ManageOfferOp ok = true } return }

// GetManageOfferOp retrieves the ManageOfferOp value from the union,
// returning ok if the union's switch indicated the value is valid.

GetManageOfferOp retrieves the ManageOfferOp value from the union returning ok if the union s switch indicated the value is valid .