Exemplo n.º 1
0
// Validate validates if operation body is valid.
func (op PathPaymentOperationBody) Validate() error {
	if !protocols.IsValidAccountID(op.Destination) {
		return protocols.NewInvalidParameterError("destination", op.Destination)
	}

	if !protocols.IsValidAmount(op.SendMax) {
		return protocols.NewInvalidParameterError("send_max", op.SendMax)
	}

	if !protocols.IsValidAmount(op.DestinationAmount) {
		return protocols.NewInvalidParameterError("destination_amount", op.DestinationAmount)
	}

	if !op.SendAsset.Validate() {
		return protocols.NewInvalidParameterError("send_asset", op.SendAsset.String())
	}

	if !op.DestinationAsset.Validate() {
		return protocols.NewInvalidParameterError("destination_asset", op.DestinationAsset.String())
	}

	if op.Source != nil && !protocols.IsValidAccountID(*op.Source) {
		return protocols.NewInvalidParameterError("source", *op.Source)
	}

	for i, asset := range op.Path {
		if !asset.Validate() {
			return protocols.NewInvalidParameterError("path["+strconv.Itoa(i)+"]", asset.String())
		}
	}

	return nil
}
// Validate validates if operation body is valid.
func (op AccountMergeOperationBody) Validate() error {
	if !protocols.IsValidAccountID(op.Destination) {
		return protocols.NewInvalidParameterError("destination", op.Destination)
	}

	if op.Source != nil && !protocols.IsValidAccountID(*op.Source) {
		return protocols.NewInvalidParameterError("source", *op.Source)
	}

	return nil
}
// Validate validates if operation body is valid.
func (op CreateAccountOperationBody) Validate() error {
	if !protocols.IsValidAccountID(op.Destination) {
		return protocols.NewInvalidParameterError("destination", op.Destination)
	}

	if !protocols.IsValidAmount(op.StartingBalance) {
		return protocols.NewInvalidParameterError("starting_balance", op.StartingBalance)
	}

	if op.Source != nil && !protocols.IsValidAccountID(*op.Source) {
		return protocols.NewInvalidParameterError("source", *op.Source)
	}

	return nil
}
Exemplo n.º 4
0
// Validate validates if operation body is valid.
func (op AllowTrustOperationBody) Validate() error {
	if !protocols.IsValidAssetCode(op.AssetCode) {
		return protocols.NewInvalidParameterError("asset_code", op.AssetCode)
	}

	if !protocols.IsValidAccountID(op.Trustor) {
		return protocols.NewInvalidParameterError("trustor", op.Trustor)
	}

	if op.Source != nil && !protocols.IsValidAccountID(*op.Source) {
		return protocols.NewInvalidParameterError("source", *op.Source)
	}

	return nil
}
Exemplo n.º 5
0
// Validate validates if operation body is valid.
func (op InflationOperationBody) Validate() error {
	if op.Source != nil && !protocols.IsValidAccountID(*op.Source) {
		return protocols.NewInvalidParameterError("source", *op.Source)
	}

	return nil
}
Exemplo n.º 6
0
// Validate validates if operation body is valid.
func (op SetOptionsOperationBody) Validate() error {
	if op.InflationDest != nil && !protocols.IsValidAccountID(*op.InflationDest) {
		return protocols.NewInvalidParameterError("inflation_dest", *op.InflationDest)
	}

	if op.Signer != nil {
		if !protocols.IsValidAccountID(op.Signer.PublicKey) {
			return protocols.NewInvalidParameterError("signer.public_key", op.Signer.PublicKey)
		}
	}

	if op.Source != nil && !protocols.IsValidAccountID(*op.Source) {
		return protocols.NewInvalidParameterError("source", *op.Source)
	}

	return nil
}
Exemplo n.º 7
0
// Validate validates if operation body is valid.
func (op PaymentOperationBody) Validate() error {
	if !protocols.IsValidAccountID(op.Destination) {
		return protocols.NewInvalidParameterError("destination", op.Destination)
	}

	if !protocols.IsValidAmount(op.Amount) {
		return protocols.NewInvalidParameterError("amount", op.Amount)
	}

	if !op.Asset.Validate() {
		return protocols.NewInvalidParameterError("asset", op.Asset.String())
	}

	if op.Source != nil && !protocols.IsValidAccountID(*op.Source) {
		return protocols.NewInvalidParameterError("source", *op.Source)
	}

	return nil
}
Exemplo n.º 8
0
// Validate validates if the request is correct.
func (r BuilderRequest) Validate() error {
	if !protocols.IsValidAccountID(r.Source) {
		return protocols.NewInvalidParameterError("source", r.Source)
	}

	for i, signer := range r.Signers {
		if !protocols.IsValidAccountID(signer) {
			return protocols.NewInvalidParameterError("signers["+strconv.Itoa(i)+"]", signer)
		}
	}

	for _, operation := range r.Operations {
		err := operation.Body.Validate()
		if err != nil {
			return err
		}
	}

	return nil
}
Exemplo n.º 9
0
// Validate validates if operation body is valid.
func (op ManageOfferOperationBody) Validate() error {
	if op.OfferID != nil {
		_, err := strconv.ParseUint(*op.OfferID, 10, 64)
		if err != nil {
			return protocols.NewInvalidParameterError("offer_id", *op.OfferID)
		}
	}

	if op.Source != nil && !protocols.IsValidAccountID(*op.Source) {
		return protocols.NewInvalidParameterError("source", *op.Source)
	}

	return nil
}
Exemplo n.º 10
0
// Validate validates if operation body is valid.
func (op ManageDataOperationBody) Validate() error {
	if len(op.Name) > 64 {
		return protocols.NewInvalidParameterError("name", op.Name)
	}

	data, err := base64.StdEncoding.DecodeString(op.Data)
	if err != nil || len(data) > 64 {
		return protocols.NewInvalidParameterError("data", op.Data)
	}

	if op.Source != nil && !protocols.IsValidAccountID(*op.Source) {
		return protocols.NewInvalidParameterError("source", *op.Source)
	}

	return nil
}
Exemplo n.º 11
0
// Validate validates if operation body is valid.
func (op ChangeTrustOperationBody) Validate() error {
	if !op.Asset.Validate() {
		return protocols.NewInvalidParameterError("asset", op.Asset.String())
	}

	if op.Limit != nil {
		if !protocols.IsValidAmount(*op.Limit) {
			return protocols.NewInvalidParameterError("limit", *op.Limit)
		}
	}

	if op.Source != nil && !protocols.IsValidAccountID(*op.Source) {
		return protocols.NewInvalidParameterError("source", *op.Source)
	}

	return nil
}