コード例 #1
0
ファイル: manage_offer.go プロジェクト: stellar/bridge-server
// 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
}
コード例 #2
0
ファイル: payment.go プロジェクト: influx6/go-stellar-base
// MutatePayment for Asset sets the PaymentOp's Asset field
func (m CreditAmount) MutatePayment(o *xdr.PaymentOp) (err error) {
	o.Amount, err = amount.Parse(m.Amount)
	if err != nil {
		return
	}

	length := len(m.Code)

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

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

	return
}
コード例 #3
0
ファイル: validation.go プロジェクト: stellar/bridge-server
// IsValidAmount returns true if amount is valid
func IsValidAmount(a string) bool {
	_, err := amount.Parse(a)
	if err != nil {
		return false
	}
	return true
}
コード例 #4
0
ファイル: payment.go プロジェクト: FihlaTV/bridge-server
// 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
}
コード例 #5
0
ファイル: payment.go プロジェクト: influx6/go-stellar-base
// MutatePayment for NativeAmount sets the PaymentOp's currency field to
// native and sets its amount to the provided integer
func (m NativeAmount) MutatePayment(o *xdr.PaymentOp) (err error) {
	o.Asset, err = xdr.NewAsset(xdr.AssetTypeAssetTypeNative, nil)
	if err != nil {
		return
	}

	o.Amount, err = amount.Parse(m.Amount)
	return
}
コード例 #6
0
ファイル: helpers.go プロジェクト: zenododobird/horizon
// GetAmount returns a native amount (i.e. 64-bit integer) by parsing
// the string at the provided name in accordance with the stellar client
// conventions
func (base *Base) GetAmount(name string) (result xdr.Int64) {
	var err error
	result, err = amount.Parse(base.GetString("destination_amount"))

	if err != nil {
		base.SetInvalidField(name, err)
		return
	}

	return
}
コード例 #7
0
ファイル: payment.go プロジェクト: FihlaTV/bridge-server
// 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
}
コード例 #8
0
ファイル: payment.go プロジェクト: FihlaTV/bridge-server
// 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
}
コード例 #9
0
ファイル: main_test.go プロジェクト: zenododobird/horizon
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)
		}
	}
}
コード例 #10
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
}
コード例 #11
0
ファイル: change_trust.go プロジェクト: stellar/bridge-server
// 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
}