Esempio n. 1
0
// MutateManageOffer for Amount sets the ManageOfferOp's Amount field
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
}
Esempio n. 2
0
// MutatePayment for PayWithPath sets the PathPaymentOp's SendAsset,
// SendMax and Path fields
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
}
Esempio n. 3
0
// MutatePayment for Asset sets the PaymentOp's Asset field
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
}
Esempio n. 4
0
// MutatePayment for NativeAmount sets the PaymentOp's currency field to
// native and sets its amount to the provided integer
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
}
Esempio n. 5
0
func TestParse(t *testing.T) {
	for _, v := range Tests {
		o, err := amount.Parse(v.S)
		if err != nil {
			t.Errorf("Couldn't parse %s: %v+", v.S, err)
			continue
		}

		if o != v.I {
			t.Errorf("%s parsed to %d, not %d", v.S, o, v.I)
		}
	}
}
Esempio n. 6
0
// MutateChangeTrust for Limit sets the ChangeTrustOp's Limit field
func (m Limit) MutateChangeTrust(o *xdr.ChangeTrustOp) (err error) {
	o.Limit, err = amount.Parse(string(m))
	return
}
Esempio n. 7
0
// MutateCreateAccount for NativeAmount sets the CreateAccountOp's
// StartingBalance field
func (m NativeAmount) MutateCreateAccount(o *xdr.CreateAccountOp) (err error) {
	o.StartingBalance, err = amount.Parse(m.Amount)
	return
}