コード例 #1
0
        /// <summary>
        ///     Gets the namespace.
        /// </summary>
        /// <param name="namespaceId">The namespace Id</param>
        /// <returns>IObservable&lt;NamespaceInfo&gt;</returns>
        public IObservable <NamespaceInfo> GetNamespace(NamespaceId namespaceId)
        {
            var route = $"{BasePath}/namespace/{namespaceId.HexId}";

            if (namespaceId == null)
            {
                throw new ArgumentNullException(nameof(namespaceId));
            }

            var networkType = GetNetworkTypeObservable().Take(1);

            return(Observable.FromAsync(async ar => await route.GetJsonAsync <NamespaceInfoDTO>())
                   .Select(info => new NamespaceInfo(
                               info.Meta.Active,
                               info.Meta.Index,
                               info.Meta.Id,
                               NamespaceTypeExtension.GetRawValue((int)info.Namespace.Type),
                               info.Namespace.Depth,
                               ExtractLevels(info.Namespace.Level0, info.Namespace.Level1, info.Namespace.Level2),
                               info.Namespace.ParentId.ToUInt64() == 0
                        ? null
                        : new NamespaceId(info.Namespace.ParentId.ToUInt64()),
                               PublicAccount.CreateFromPublicKey(info.Namespace.Owner, networkType.Wait()),
                               info.Namespace.StartHeight.ToUInt64(),
                               info.Namespace.EndHeight.ToUInt64(),
                               new Alias(AliasTypeExtension.GetRawValue((int)info.Namespace.Alias.Type),
                                         info.Namespace.Alias.Address != null
                            ? Address.CreateFromHex(info.Namespace.Alias.Address)
                            : null,
                                         info.Namespace.Alias.MosaicId != null
                            ? new MosaicId(info.Namespace.Alias.MosaicId.ToUInt64())
                            : null
                                         )
                               )));
        }
コード例 #2
0
        /// <summary>
        /// </summary>
        /// <param name="accounts"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public IObservable <List <NamespaceInfo> > GetNamespacesFromAccount(List <Address> accounts, QueryParams query)
        {
            if (accounts.Count < 0)
            {
                throw new ArgumentNullException(nameof(accounts));
            }


            var addresses = new Addresses
            {
                _Addresses = accounts.Select(a => a.Plain).ToList()
            };

            var route = $"{BasePath}/account/namespaces";

            if (query != null)
            {
                if (query.PageSize > 0)
                {
                    route.SetQueryParam("pageSize", query.PageSize);
                }

                if (!string.IsNullOrEmpty(query.Id))
                {
                    route.SetQueryParam("id", query.Id);
                }
            }

            var networkType = GetNetworkTypeObservable().Take(1);

            return(Observable.FromAsync(async ar =>
                                        await route.PostJsonAsync(addresses).ReceiveJson <List <NamespaceInfoDTO> >())
                   .Select(i => i.Select(info => new NamespaceInfo(
                                             info.Meta.Active,
                                             info.Meta.Index,
                                             info.Meta.Id,
                                             NamespaceTypeExtension.GetRawValue((int)info.Namespace.Type),
                                             info.Namespace.Depth,
                                             ExtractLevels(info.Namespace.Level0, info.Namespace.Level1, info.Namespace.Level2),
                                             new NamespaceId(info.Namespace.ParentId.ToUInt64()),
                                             PublicAccount.CreateFromPublicKey(info.Namespace.Owner, networkType.Wait()),
                                             info.Namespace.StartHeight.ToUInt64(),
                                             info.Namespace.EndHeight.ToUInt64(),
                                             new Alias(AliasTypeExtension.GetRawValue((int)info.Namespace.Alias.Type),
                                                       info.Namespace.Alias.Address != null
                            ? Address.CreateFromRawAddress(info.Namespace.Alias.Address)
                            : null,
                                                       info.Namespace.Alias.MosaicId != null
                            ? new MosaicId(info.Namespace.Alias.MosaicId.ToUInt64())
                            : null
                                                       )
                                             )).ToList()));
        }
        private static RegisterNamespaceTransaction ToRegisterNamespaceTransaction(JObject tx, TransactionInfo txInfo)
        {
            var transaction = tx["transaction"].ToObject <JObject>();
            var version     = transaction["version"];

            //Bug - It seems the dotnetcore does not
            //understand the Integer.
            //The workaround it to double cast the version
            int versionValue;

            try
            {
                versionValue = (int)((uint)version);
            }
            catch (Exception)
            {
                versionValue = (int)version;
            }

            var network       = TransactionMappingUtils.ExtractNetworkType(versionValue);
            var txVersion     = TransactionMappingUtils.ExtractTransactionVersion(versionValue);
            var deadline      = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64());
            var maxFee        = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64();
            var namespaceName = transaction["name"].ToObject <string>();
            var namespaceType = NamespaceTypeExtension.GetRawValue(transaction["namespaceType"].ToObject <int>());
            var namespaceId   = new NamespaceId(transaction["namespaceId"].ToObject <UInt64DTO>().ToUInt64());
            var duration      = namespaceType == NamespaceType.ROOT_NAMESPACE
                ? transaction["duration"].ToObject <UInt64DTO>().ToUInt64()
                : 0;
            var parentId = namespaceType == NamespaceType.SUB_NAMESPACE
                ? new NamespaceId(transaction["parentId"].ToObject <UInt64DTO>()
                                  .ToUInt64())
                : null;
            var signature = transaction["signature"].ToObject <string>();
            var signer    = new PublicAccount(transaction["signer"].ToObject <string>(), network);

            return(new RegisterNamespaceTransaction(network, txVersion, deadline, maxFee,
                                                    namespaceName, namespaceId, namespaceType, duration, parentId,
                                                    signature, signer, txInfo));
        }