Exemple #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
                                         )
                               )));
        }
Exemple #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()));
        }