Example #1
0
// MutateManageOffer for Rate sets the ManageOfferOp's selling, buying and price fields
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
}
Example #2
0
func TestParse(t *testing.T) {
	for _, v := range Tests {
		o, err := price.Parse(v.S)
		if err != nil {
			t.Errorf("Couldn't parse %s: %v+", v.S, err)
			continue
		}

		if o.N != v.P.N || o.D != v.P.D {
			t.Errorf("%s parsed to %d, not %d", v.S, o, v.P)
		}
	}

	_, err := price.Parse("0.0000000003")
	if err == nil {
		t.Error("Expected error")
	}

	_, err = price.Parse("2147483649")
	if err == nil {
		t.Error("Expected error")
	}
}