コード例 #1
0
        public new async Task <AddressValidationResult> ValidateAsync(
            string address,
            bool skipChecksumValidation,
            bool skipWhiteAndBlacklistCheck)
        {
            if (!IconKeys.IsValidAddress(address))
            {
                return(AddressValidationResult.AddressIsInvalid(AddressValidationError.FormatIsInvalid));
            }

            var addressObj = new Address(address);

            if (addressObj.GetPrefix() == AddressPrefix.FromString(AddressPrefix.Contract))
            {
                return(AddressValidationResult.AddressIsInvalid(AddressValidationError.FormatIsInvalid));
            }

            if (skipWhiteAndBlacklistCheck)
            {
                address = address.ToLowerInvariant();

                if (await _blockchainService.IsContractAsync(address) &&
                    !await _whitelistedAddressRepository.ContainsAsync(address) &&
                    await _blacklistedAddressRepository.ContainsAsync(address))
                {
                    return(AddressValidationResult.AddressIsInvalid(AddressValidationError.AddressIsBlacklisted));
                }
            }

            return(AddressValidationResult.AddressIsValid());
        }
コード例 #2
0
        public void GetMaxMaskLength(string s, byte expected)
        {
            var before = IPAddress.Parse(s);
            var actual = AddressPrefix.GetMaxMaskLength(before);

            Assert.Equal(expected, actual);
        }
コード例 #3
0
        /// <summary>
        ///     Encodes a Cash Address from prefix, type, and hash160
        /// </summary>
        /// <param name="prefix">Cash Address prefix</param>
        /// <param name="scriptType">Bitcoin script type</param>
        /// <param name="hash160">Byte data from bitcoin script (usually hash160)</param>
        /// <returns>cash address formatted bitcoin address</returns>
        public static string EncodeCashAddress(AddressPrefix prefix, ScriptType scriptType, byte[] hash160)
        {
            try
            {
                // validate hash length
                if (!ValidLength.Contains(hash160.Length * 8))
                {
                    throw new ArgumentException("Invalid Hash Length. Received: " + hash160.Length +
                                                ". Expected: " + string.Join(", ", ValidLength) + ".");
                }

                // validate script type
                if (!Enum.IsDefined(typeof(ScriptType), scriptType))
                {
                    throw new ArgumentException("Invalid Script Type. Received: " + hash160.Length +
                                                ". Expected: " + string.Join(", ",
                                                                             Enum.GetValues(typeof(ScriptType))).Cast <ScriptType>() + ".");
                }
                // validate prefix
                if (!Enum.IsDefined(typeof(AddressPrefix), prefix))
                {
                    throw new ArgumentException("Invalid Prefix. Received: " + prefix +
                                                ". Expected: " + string.Join(", ",
                                                                             Enum.GetValues(typeof(AddressPrefix))).Cast <AddressPrefix>() + ".");
                }

                // encode and return result
                return(EncodeWithHeaderAndChecksum(prefix.ToString(), (byte)scriptType, hash160));
            }
            catch (Exception e)
            {
                throw new CashAddressException("Error decoding cash address.", e);
            }
        }
コード例 #4
0
ファイル: IconKeys.cs プロジェクト: LykkeCity/Lykke.Icon.Sdk
        public static Address GetAddress(Bytes publicKey)
        {
            var prefix  = new AddressPrefix(AddressPrefix.Eoa);
            var pkBytes = publicKey.ToByteArray(PublicKeySize);
            var hash    = GetAddressHash(pkBytes);

            return(new Address(prefix, hash));
        }
コード例 #5
0
        public void SerializeDeserialize(string prefixString, int asn, string description, int numRisPeers)
        {
            var before = new WhoIsResponse(AddressPrefix.Parse(prefixString), asn, description, numRisPeers);
            var json   = JsonSerializer.Serialize(before);
            var after  = JsonSerializer.Deserialize <WhoIsResponse>(json);

            Assert.Equal(before, after);
        }
コード例 #6
0
        private PSVirtualNetwork CreateVirtualNetwork()
        {
            var vnet = new PSVirtualNetwork
            {
                Name = Name,
                ResourceGroupName = ResourceGroupName,
                Location          = Location,
                AddressSpace      = new PSAddressSpace {
                    AddressPrefixes = AddressPrefix?.ToList()
                }
            };

            if (DnsServer != null)
            {
                vnet.DhcpOptions = new PSDhcpOptions {
                    DnsServers = DnsServer?.ToList()
                };
            }

            vnet.Subnets = this.Subnet?.ToList();
            vnet.EnableDdosProtection = EnableDdosProtection;

            if (!string.IsNullOrEmpty(DdosProtectionPlanId))
            {
                vnet.DdosProtectionPlan = new PSResourceId {
                    Id = DdosProtectionPlanId
                };
            }

            if (!string.IsNullOrWhiteSpace(BgpCommunity))
            {
                vnet.BgpCommunities = new PSVirtualNetworkBgpCommunities {
                    VirtualNetworkCommunity = this.BgpCommunity
                };
            }

            // Map to the sdk object
            var vnetModel = NetworkResourceManagerProfile.Mapper.Map <MNM.VirtualNetwork>(vnet);

            vnetModel.Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true);

            if (this.IpAllocation != null)
            {
                foreach (var ipAllocation in this.IpAllocation)
                {
                    var ipAllocationReference = new MNM.SubResource(ipAllocation.Id);
                    vnetModel.IpAllocations.Add(ipAllocationReference);
                }
            }

            // Execute the Create VirtualNetwork call
            VirtualNetworkClient.CreateOrUpdate(ResourceGroupName, Name, vnetModel);

            var getVirtualNetwork = GetVirtualNetwork(ResourceGroupName, Name);

            return(getVirtualNetwork);
        }
コード例 #7
0
        public override void Execute()
        {
            base.Execute();

            var staticRoute = new PSStaticRoute
            {
                Name             = Name,
                NextHopIpAddress = NextHopIpAddress,
                AddressPrefixes  = AddressPrefix?.ToList()
            };

            WriteObject(staticRoute);
        }
コード例 #8
0
        public static WhoIsResponse ParseWhoIsResponse(string text)
        {
            var lines = text.Split(new[] { '\r', '\n', }, StringSplitOptions.RemoveEmptyEntries);

            var dictionary = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase);

            foreach (var line in lines)
            {
                var kvp   = line.Split(':', count: 2);
                var key   = kvp[0].Trim();
                var value = kvp[1].Trim();
                dictionary.Add(key, value);
            }

            var prefix      = AddressPrefix.Parse(dictionary.GetFirst("route", "route6"));
            var asn         = int.Parse(dictionary["origin"][2..]);
コード例 #9
0
ファイル: IconKeys.cs プロジェクト: LykkeCity/Lykke.Icon.Sdk
 public static AddressPrefix GetAddressHexPrefix(string input)
 {
     return(AddressPrefix.FromString(input.Substring(0, 2)));
 }
コード例 #10
0
        public void ToStringTests(string?s)
        {
            var prefix = new AddressPrefix(s);

            Assert.Equal("127.0.0.1/32", prefix.ToString());
        }
コード例 #11
0
        public async Task <IEnumerable <TransactionReceipt> > ExecuteAsync(
            BigInteger blockNumber)
        {
            var block = await _iconService.GetBlock(blockNumber);

            var transactions = block?.GetTransactions();

            var transactionReceipts = new List <TransactionReceipt>();

            if (transactions != null)
            {
                foreach (var blockTransaction in transactions)
                {
                    var txHash   = blockTransaction.GetTxHash().ToHexString(true);
                    var bytes    = new Bytes(txHash);
                    var txResult = await _iconService.GetTransactionResult(bytes);

                    if (txResult == null)
                    {
                        throw new InvalidOperationException(
                                  $"Block[{blockNumber}] contains confirmed transaction " +
                                  $"which results can not be retrieved as transaction results: txHash[{txHash}]");
                    }

                    var error = await _tryGetTransactionErrorStrategy.ExecuteAsync(txResult.GetStatus(), txHash);

                    if (error != null)
                    {
                        continue;
                    }

                    if (blockTransaction.GetTo() != null &&
                        blockTransaction.GetTo().GetPrefix() == AddressPrefix.FromString(AddressPrefix.Contract))
                    {
                        transactionReceipts.AddRange
                        (
                            GetInternalTransactionReceipts
                            (
                                blockTransaction.GetTxHash().ToHexString(true),
                                txResult,
                                block.GetTimestamp()
                            )
                        );
                    }

                    var transactionTransferValue = blockTransaction.GetValue();

                    if (transactionTransferValue != null &&
                        transactionTransferValue != BigInteger.Zero)
                    {
                        transactionReceipts.Add(new TransactionReceipt
                                                (
                                                    amount: transactionTransferValue.Value,
                                                    blockNumber: blockNumber,
                                                    from: blockTransaction.GetFrom().ToString(),
                                                    hash: blockTransaction.GetTxHash().ToHexString(true),
                                                    index: 0,
                                                    timestamp: block.GetTimestamp(),
                                                    to: blockTransaction.GetTo().ToString()
                                                ));
                    }
                }
            }

            return(transactionReceipts);
        }