/// <summary>
 /// Creates a new transport operation.
 /// </summary>
 /// <param name="message">The message to dispatch.</param>
 /// <param name="addressTag">The address to use when routing this message.</param>
 /// <param name="requiredDispatchConsistency">The required consistency level for the dispatch operation.</param>
 /// <param name="deliveryConstraints">The delivery constraints that must be honored by the transport.</param>
 public TransportOperation(OutgoingMessage message, AddressTag addressTag, DispatchConsistency requiredDispatchConsistency = DispatchConsistency.Default, List <DeliveryConstraint> deliveryConstraints = null)
 {
     Message    = message;
     AddressTag = addressTag;
     RequiredDispatchConsistency = requiredDispatchConsistency;
     DeliveryConstraints         = deliveryConstraints ?? new List <DeliveryConstraint>(0);
 }
示例#2
0
        /// <summary>
        /// Coin to receive for the transaction.
        /// </summary>
        /// <param name="coinNumber">Number of the coin inside the transaction.</param>
        /// <param name="asset">Asset of the coin.</param>
        /// <param name="value">Coin value to receive.</param>
        /// <param name="address">Address which should receive the coin.</param>
        /// <param name="addressTag">
        /// Optional.
        /// Receiving address tag.
        /// </param>
        /// <param name="addressTagType">
        /// Optional.
        /// Type of the receiving address tag.
        /// </param>
        public CoinToReceive(
            int coinNumber,
            Asset asset,
            UMoney value,
            Address address,
            AddressTag addressTag         = null,
            AddressTagType?addressTagType = null)
        {
            if (coinNumber < 0)
            {
                throw RequestValidationException.ShouldBeZeroOrPositiveNumber(coinNumber, nameof(coinNumber));
            }

            if (addressTagType.HasValue && addressTag == null)
            {
                throw new RequestValidationException("If the tag type is specified, the tag should be specified too", new [] { nameof(addressTagType), nameof(addressTag) });
            }

            CoinNumber     = coinNumber;
            Asset          = asset ?? throw RequestValidationException.ShouldBeNotNull(nameof(asset));
            Value          = value;
            Address        = address ?? throw RequestValidationException.ShouldBeNotNull(nameof(address));
            AddressTag     = addressTag;
            AddressTagType = addressTagType;
        }
示例#3
0
        /// <summary>
        /// Received coin.
        /// </summary>
        /// <param name="coinNumber">Number of received coin in the transaction.</param>
        /// <param name="asset">Asset of the coin.</param>
        /// <param name="value">Value of the coin.</param>
        /// <param name="address">
        /// Optional.
        /// Address which received the coin.
        /// </param>
        /// <param name="addressTag">
        /// Optional.
        /// Tag of the receiving address.
        /// </param>
        /// <param name="addressTagType">
        /// Optional.
        /// Type of the receiving address tag.
        /// </param>
        /// <param name="addressNonce">
        /// Optional.
        /// Nonce number of the transaction for the receiving address.
        /// </param>
        public ReceivedCoin(
            int coinNumber,
            Asset asset,
            UMoney value,
            Address address               = null,
            AddressTag addressTag         = null,
            AddressTagType?addressTagType = null,
            long?addressNonce             = null)
        {
            if (coinNumber < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(coinNumber), coinNumber, "Should be zero or positive number");
            }

            if (addressTag != null && address == null)
            {
                throw new ArgumentException("If the tag is specified, the address should be specified too");
            }

            if (addressTagType.HasValue && addressTag == null)
            {
                throw new ArgumentException("If the tag type is specified, the tag should be specified too");
            }

            CoinNumber     = coinNumber;
            Asset          = asset ?? throw new ArgumentNullException(nameof(asset));
            Value          = value;
            Address        = address;
            AddressTag     = addressTag;
            AddressTagType = addressTagType;
            AddressNonce   = addressNonce;
        }
示例#4
0
 /// <summary>
 /// Creates a new transport operation.
 /// </summary>
 /// <param name="message">The message to dispatch.</param>
 /// <param name="addressTag">The address to use when routing this message.</param>
 /// <param name="requiredDispatchConsistency">The required consistency level for the dispatch operation.</param>
 /// <param name="properties">Delivery properties of the message.</param>
 public TransportOperation(OutgoingMessage message, AddressTag addressTag, DispatchProperties properties = null, DispatchConsistency requiredDispatchConsistency = DispatchConsistency.Default)
 {
     Message    = message;
     AddressTag = addressTag;
     Properties = properties ?? new DispatchProperties();
     RequiredDispatchConsistency = requiredDispatchConsistency;
 }
 /// <summary>
 /// Creates a new transport operation.
 /// </summary>
 /// <param name="message">The message to dispatch.</param>
 /// <param name="addressTag">The address to use when routing this message.</param>
 /// <param name="requiredDispatchConsistency">The required consistency level for the dispatch operation.</param>
 /// <param name="deliveryConstraints">The delivery constraints that must be honored by the transport.</param>
 public TransportOperation(OutgoingMessage message, AddressTag addressTag, DispatchConsistency requiredDispatchConsistency = DispatchConsistency.Default, List<DeliveryConstraint> deliveryConstraints = null)
 {
     Message = message;
     AddressTag = addressTag;
     RequiredDispatchConsistency = requiredDispatchConsistency;
     DeliveryConstraints = deliveryConstraints ?? DeliveryConstraint.EmptyConstraints;
 }
示例#6
0
        /// <summary>
        /// Change of the address balance made by a transaction
        /// </summary>
        /// <param name="transferId">
        /// ID of the transfer within the transaction.
        /// Can group several balance changing operations into the single transfer,
        /// or can be just the output number.
        /// </param>
        /// <param name="asset">Asset.</param>
        /// <param name="value">
        /// Value for which the balance of the address was changed.
        /// Can be positive to increase the balance or negative to decrease the balance.
        /// </param>
        /// <param name="address">
        /// Optional.
        /// Address.
        /// </param>
        /// <param name="tag">
        /// Optional.
        /// Tag of the address.
        /// </param>
        /// <param name="tagType">
        /// Optional.
        /// Type of the address tag.
        /// </param>
        /// <param name="nonce">
        /// Optional.
        /// Nonce number of the transaction for the address.
        /// </param>
        public BalanceChange(
            string transferId,
            Asset asset,
            Money value,
            Address address        = null,
            AddressTag tag         = null,
            AddressTagType?tagType = null,
            long?nonce             = null)
        {
            if (string.IsNullOrWhiteSpace(transferId))
            {
                throw new ArgumentException("Should be not empty string", nameof(transferId));
            }

            if (tag != null && address == null)
            {
                throw new ArgumentException("If the tag is specified, the address should be specified too");
            }

            if (tagType.HasValue && tag == null)
            {
                throw new ArgumentException("If the tag type is specified, the tag should be specified too");
            }

            TransferId = transferId;
            Asset      = asset ?? throw new ArgumentNullException(nameof(asset));
            Value      = value;
            Address    = address;
            Tag        = tag;
            TagType    = tagType;
            Nonce      = nonce;
        }
    TransportOperation RouteThroughLocalEndpointInstance(RoutingStrategy routingStrategy, IRoutingContext context)
    {
        Dictionary <string, string> headers = new Dictionary <string, string>(context.Message.Headers);
        AddressTag        originalTag       = routingStrategy.Apply(headers);
        UnicastAddressTag unicastTag        = originalTag as UnicastAddressTag;

        if (unicastTag == null)
        {
            MulticastAddressTag multicastTag = originalTag as MulticastAddressTag;
            if (multicastTag != null)
            {
                headers["$.store-and-forward.eventtype"] = multicastTag.MessageType.AssemblyQualifiedName;
            }
            else
            {
                throw new Exception("Unsupported type of address tag: " + originalTag.GetType().FullName);
            }
        }
        else
        {
            headers["$.store-and-forward.destination"] = unicastTag.Destination;
        }
        OutgoingMessage message = new OutgoingMessage(context.Message.MessageId, headers, context.Message.Body);

        return(new TransportOperation(message, new UnicastAddressTag(localAddress), DispatchConsistency.Default, context.Extensions.GetDeliveryConstraints()));
    }
示例#8
0
 string Read(AddressTag addressTag)
 {
     if (addressTag is UnicastAddressTag u)
     {
         return($"Unicast: {u.Destination}");
     }
     if (addressTag is MulticastAddressTag m)
     {
         return($"Multicast: {m.MessageType}");
     }
     throw new ArgumentException(
               message: "addressTag is not a recognized address type",
               paramName: nameof(addressTag));
 }
        static void SerializeAddressTag(AddressTag addressTag, Dictionary <string, string> options)
        {
            if (addressTag is UnicastAddressTag direct)
            {
                options["Destination"] = direct.Destination;
                return;
            }

            if (addressTag is MulticastAddressTag)
            {
                throw new Exception("Token-based deduplication cannot be used with multicast routing.");
            }

            throw new Exception($"Unknown routing strategy {addressTag.GetType().FullName}");
        }
        static void SerializeRoutingStrategy(AddressTag addressTag, Dictionary <string, string> options)
        {
            if (addressTag is MulticastAddressTag indirect)
            {
                options["EventType"] = indirect.MessageType.AssemblyQualifiedName;
                return;
            }

            if (addressTag is UnicastAddressTag direct)
            {
                options["Destination"] = direct.Destination;
                return;
            }

            throw new Exception($"Unknown routing strategy {addressTag.GetType().FullName}");
        }
        public async Task <ActionResult <AddressValidityResponse> > Validate(
            [FromRoute] Address address,
            [FromQuery] AddressTagType?tagType = null,
            [FromQuery] AddressTag tag         = null)
        {
            if (address == null)
            {
                throw RequestValidationException.ShouldBeNotNull(nameof(address));
            }

            if (tagType.HasValue && tag == null)
            {
                throw new RequestValidationException("If the tag type is specified, the tag should be specified too", new [] { nameof(tagType), nameof(tag) });
            }

            var response = await _addressValidator.ValidateAsync(address, tagType, tag);

            if (response == null)
            {
                throw new InvalidOperationException("Not null response object expected");
            }

            return(Ok(response));
        }
示例#12
0
        /// <summary>
        /// Transfer of the transaction.
        /// </summary>
        /// <param name="asset">Asset to transfer.</param>
        /// <param name="amount">Amount to transfer from the source address to the destination address.</param>
        /// <param name="sourceAddress">Address to transfer from.</param>
        /// <param name="destinationAddress">Address to transfer to.</param>
        /// <param name="sourceAddressContext">
        /// Optional.
        /// Source address context associated with the address.
        /// </param>
        /// <param name="sourceAddressNonce">
        /// Optional.
        /// Nonce number of the transaction for the source address.
        /// </param>
        /// <param name="destinationAddressTag">
        /// Optional.
        /// Destination address tag.
        /// </param>
        /// <param name="destinationAddressTagType">
        /// Optional.
        /// Type of the destination address tag.
        /// </param>
        public Transfer(
            Asset asset,
            UMoney amount,
            Address sourceAddress,
            Address destinationAddress,
            Base64String sourceAddressContext        = null,
            long?sourceAddressNonce                  = null,
            AddressTag destinationAddressTag         = null,
            AddressTagType?destinationAddressTagType = null)
        {
            if (destinationAddressTagType.HasValue && destinationAddressTag == null)
            {
                throw new RequestValidationException("If the tag type is specified, the tag should be specified too", new [] { nameof(destinationAddressTagType), nameof(destinationAddressTag) });
            }

            Asset                     = asset ?? throw RequestValidationException.ShouldBeNotNull(nameof(asset));
            Amount                    = amount;
            SourceAddress             = sourceAddress ?? throw RequestValidationException.ShouldBeNotNull(nameof(sourceAddress));
            SourceAddressContext      = sourceAddressContext;
            SourceAddressNonce        = sourceAddressNonce;
            DestinationAddress        = destinationAddress ?? throw RequestValidationException.ShouldBeNotNull(nameof(destinationAddress));
            DestinationAddressTag     = destinationAddressTag;
            DestinationAddressTagType = destinationAddressTagType;
        }
示例#13
0
 public void TagInput_ShouldHaveCorrectTagPriorities(string word, AddressTag expectedTag)
 {
     Assert.Equal(expectedTag, (AddressTag)Tagger.TagInput(new string[1] {
         word
     }).First());
 }
示例#14
0
 public void TagInput_ShouldTagWordIfContainedInReferenceArray(string word, AddressTag expectedTag)
 {
     Assert.Equal(expectedTag, (AddressTag)Tagger.TagInput(new string[1] {
         word
     }).First());
 }
 /// <summary>
 /// Endpoint: [POST] /api/addresses/{address}/tags
 /// </summary>
 /// <param name="tag">Generated address tag.</param>
 /// <param name="tagContext">
 /// Optional.
 /// Any non security sensitive, implementation specific information associated with the address tag.
 /// </param>
 public CreateAddressTagResponse(AddressTag tag, Base64String tagContext = null)
 {
     Tag        = tag ?? throw new ArgumentNullException(nameof(tag));
     TagContext = tagContext;
 }