Ejemplo n.º 1
0
        /// <summary>
        ///     ToModifyAccountPropertyTransaction
        /// </summary>
        /// <param name="tx"></param>
        /// <param name="txInfo"></param>
        /// <returns></returns>
        private static ModifyAccountPropertyTransaction <IUInt64Id> ToModifyAccountPropertyTransaction(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 signature    = transaction["signature"].ToObject <string>();
            var signer       = new PublicAccount(transaction["signer"].ToObject <string>(), network);
            var type         = EntityTypeExtension.GetRawValue(transaction["type"].ToObject <int>());
            var propertyType = PropertyTypeExtension.GetRawValue(transaction["propertyType"].ToObject <int>());

            var modifications    = transaction["modifications"];
            var modificationList = modifications == null
                ? new List <AccountPropertyModification <IUInt64Id> >()
                : modifications.Select(e =>
            {
                var mt = e["modificationType"] ?? e["type"];
                var modificationType =
                    PropertyModificationTypeExtension.GetRawValue(mt.ToObject <int>());
                var mosaicId     = new MosaicId(e["value"].ToObject <UInt64DTO>().ToUInt64());
                var modification = new AccountPropertyModification <IUInt64Id>(modificationType,
                                                                               mosaicId);
                return(modification);
            }).ToList();

            if (type == EntityType.MODIFY_ACCOUNT_PROPERTY_MOSAIC)
            {
                return(new MosaicModification(
                           network,
                           txVersion,
                           deadline,
                           propertyType,
                           modificationList,
                           maxFee,
                           signature,
                           signer,
                           txInfo
                           ));
            }

            throw new Exception("Unsupported transaction type");
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Gets account property by public account
        /// </summary>
        /// <param name="account">The public account</param>
        /// <returns>IObservable&lt;AccountPropertiesInfo&gt;</returns>
        public IObservable <AccountPropertiesInfo> GetAccountProperty(PublicAccount account)
        {
            if (account == null)
            {
                throw new ArgumentNullException(nameof(account));
            }

            var route = $"{BasePath}/account/{account.PublicKey}/properties";

            return(Observable.FromAsync(async ar => await route.GetJsonAsync <AccountPropertiesInfoDTO>())
                   .Select(info => new AccountPropertiesInfo(
                               new AccountProperties(
                                   Address.CreateFromHex(info.AccountProperties.Address),
                                   info.AccountProperties.Properties
                                   .Select(ap =>
                                           new AccountProperty(PropertyTypeExtension.GetRawValue((int)ap.PropertyType), ap.Values))
                                   .OrderBy(pt => pt.PropertyType).ToList())
                               )));
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Get the account properties by list of addresses
        /// </summary>
        /// <param name="addresses">The list of address</param>
        /// <returns>IObservable&lt;List&lt;AccountPropertiesInfo&gt;&gt;</returns>
        public IObservable <List <AccountPropertiesInfo> > GetAccountProperties(List <Address> addresses)
        {
            if (addresses.Count < 0)
            {
                throw new ArgumentNullException(nameof(addresses));
            }

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

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

            return(Observable.FromAsync(async ar =>
                                        await route.PostJsonAsync(addressList).ReceiveJson <List <AccountPropertiesInfoDTO> >())
                   .Select(apl => apl.Select(info => new AccountPropertiesInfo(
                                                 new AccountProperties(
                                                     Address.CreateFromHex(info.AccountProperties.Address),
                                                     info.AccountProperties.Properties.Select(ap =>
                                                                                              new AccountProperty(PropertyTypeExtension.GetRawValue((int)ap.PropertyType), ap.Values))
                                                     .OrderBy(pt => pt.PropertyType).ToList()
                                                     )
                                                 )).OrderBy(l => l.AccountProperties.Address.Plain).ToList()));
        }