Пример #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 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
}
Пример #3
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
}
Пример #4
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
}