コード例 #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");
        }
        private static AccountMetadataTransaction ToMetadataTransaction(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 scopedMetadataKey = transaction["scopedMetadataKey"].ToObject <UInt64DTO>().ToUInt64();
            var targetKey         = new PublicAccount(transaction["targetKey"].ToObject <string>(), network);
            var valueSizeDelta    = transaction["valueSizeDelta"].ToObject <short>();
            var valueSize         = transaction["valueSize"].ToObject <ushort>();
            var value             = transaction["value"].ToObject <string>();

            var accountMetadataTransaction = new AccountMetadataTransaction(network, txVersion, type, deadline, maxFee, scopedMetadataKey, targetKey, value, valueSizeDelta, valueSize, signature, signer, txInfo);

            return(accountMetadataTransaction);
        }
        private AggregateTransaction ToAggregateTransactionTransaction(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 type              = EntityTypeExtension.GetRawValue(transaction["type"].ToObject <int>());
            var deadline          = new Deadline(transaction["deadline"].ToObject <UInt64DTO>().ToUInt64());
            var maxFee            = transaction["maxFee"]?.ToObject <UInt64DTO>().ToUInt64();
            var innerTransactions = MapInnerTransactions(tx);
            var cosignatures      = MapCosignatures(tx);
            var signature         = transaction["signature"].ToObject <string>();
            var signer            = new PublicAccount(transaction["signer"].ToObject <string>(), network);

            return(new AggregateTransaction(
                       network, TransactionMappingUtils.ExtractTransactionVersion(versionValue), type, deadline, maxFee,
                       innerTransactions, cosignatures, signature, signer, txInfo));
        }
コード例 #4
0
        private static AliasTransaction ToAliasTransaction(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 namespaceId = new NamespaceId(transaction["namespaceId"].ToObject <UInt64DTO>().ToUInt64());
            var type        = EntityTypeExtension.GetRawValue(transaction["type"].ToObject <int>());
            var actionType  = TransactionMappingHelper.ExtractActionType(tx);

            AliasTransaction aliasTransaction = null;

            switch (type)
            {
            case EntityType.ADDRESS_ALIAS:
                var addressHex = transaction["address"].ToObject <string>();
                var address    = Address.CreateFromHex(addressHex);
                aliasTransaction = new AliasTransaction(network, txVersion, deadline, maxFee, type,
                                                        namespaceId, actionType, null, address, signature, signer, txInfo);
                break;

            case EntityType.MOSAIC_ALIAS:
                var mosaic = new MosaicId(transaction["mosaicId"].ToObject <UInt64DTO>().ToUInt64());
                aliasTransaction = new AliasTransaction(network, txVersion, deadline, maxFee, type,
                                                        namespaceId, actionType, mosaic, null, signature, signer, txInfo);
                break;
            }

            return(aliasTransaction);
        }
コード例 #5
0
        public async Task Should_Add_Account_Filter_With_Allow_Entity_Type()
        {
            var company = Account.GenerateNewAccount(Fixture.NetworkType);

            var allowedTransType = EntityType.MODIFY_ACCOUNT_PROPERTY_ENTITY_TYPE;

            var accountFilter = ModifyAccountPropertyTransaction <EntityType> .CreateForEntityType(
                Deadline.Create(),
                (ulong)0,
                PropertyType.ALLOW_TRANSACTION,
                new List <AccountPropertyModification <EntityType> >()
            {
                new AccountPropertyModification <EntityType>(PropertyModificationType.ADD, allowedTransType)
            },
                Fixture.NetworkType);

            Log.WriteLine($"Going to filter the address {company.Address} ");

            await Fixture.SiriusWebSocketClient.Listener.Open();

            var tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(company.Address).Take(1)
                     .Timeout(TimeSpan.FromSeconds(1000));


            var signedTransaction = accountFilter.SignWith(company, Fixture.GenerationHash);

            Log.WriteLine($"Going to announce transaction {signedTransaction.Hash}");

            await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction);

            var result = await tx;

            Log.WriteLine($"Request confirmed with transaction {result.TransactionInfo.Hash}");


            var accountProperties = await Fixture.SiriusClient.AccountHttp.GetAccountProperty(company.PublicAccount);

            accountProperties.Should().NotBeNull();
            var allowedTransactionProperty =
                accountProperties.AccountProperties.Properties.Single(ap =>
                                                                      ap.PropertyType == PropertyType.ALLOW_TRANSACTION);
            var allowedTxType = allowedTransactionProperty.Values.Select(p =>
                                                                         EntityTypeExtension.GetRawValue((int)p) == allowedTransType);

            allowedTxType.Should().NotBeNull();
        }
コード例 #6
0
        public async Task Should_Add_Account_Filter_With_Allow_Entity_Type()
        {
            // var company = await Fixture.GenerateAccountWithCurrency(10000);
            var company = Account.CreateFromPrivateKey("101a4dfcffe3d5abddee535c0c7fa7bb386b99eb7c19f0c73cdc3837c5844477", Fixture.NetworkType);

            Log.WriteLine($"Company Account {company.Address.Plain} \r\n Private Key: {company.PrivateKey} \r\n Public Key {company.PublicKey}");
            //    var allowedMosaic = await Fixture.CreateMosaic(company);
            var allowedTransType = EntityType.TRANSFER;

            var accountFilter = ModifyAccountPropertyTransaction <EntityType> .CreateForEntityType(
                Deadline.Create(),
                (ulong)0,
                PropertyType.BLOCK_TRANSACTION,
                new List <AccountPropertyModification <EntityType> >()
            {
                new AccountPropertyModification <EntityType>(PropertyModificationType.ADD, allowedTransType)
            },
                Fixture.NetworkType);

            Log.WriteLine($"Going to filter the address {company.Address} ");

            //   await Fixture.SiriusWebSocketClient.Listener.Open();

            //    var tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(company.Address).Take(1).Timeout(TimeSpan.FromSeconds(5000));

            var signedTransaction = accountFilter.SignWith(Fixture.SeedAccount, Fixture.GenerationHash);

            Log.WriteLine($"Going to announce transaction {signedTransaction.Hash}");
            Log.WriteLine($"Transaction Payload {signedTransaction.Payload}");

            await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction);

            //    var result = await tx;
            //   Log.WriteLine($"Request confirmed with transaction {result.TransactionInfo.Hash}");

            var accountProperties = await Fixture.SiriusClient.AccountHttp.GetAccountProperty(company.Address);

            accountProperties.Should().NotBeNull();
            var allowedTransactionProperty = accountProperties.AccountProperties.Properties.Single(ap => ap.PropertyType == PropertyType.BLOCK_TRANSACTION);
            var allowedTxType = allowedTransactionProperty.Values.Select(p =>
                                                                         EntityTypeExtension.GetRawValue((int)p) == allowedTransType);

            allowedTxType.Should().NotBeNull();
        }
コード例 #7
0
        /// <summary>
        ///     Apply mapping for transaction
        /// </summary>
        /// <param name="input">The return transaction</param>
        /// <returns>Transaction</returns>
        public virtual Transaction Apply(JObject input)
        {
            var transType = 0;

            input.TryGetValue("transaction", out var transToken);

            if (transToken != null)
            {
                transType = transToken["type"].ToObject <int>();
            }

            switch (EntityTypeExtension.GetRawValue(transType))
            {
            case EntityType.TRANSFER:
                return(new TransferTransactionMapping().Apply(input));

            case EntityType.REGISTER_NAMESPACE:
                return(new RegisterNamespaceTransactionMapping().Apply(input));

            case EntityType.MOSAIC_DEFINITION:
                return(new MosaicDefinitionTransactionMapping().Apply(input));

            case EntityType.MOSAIC_SUPPLY_CHANGE:
                return(new MosaicSupplyChangeTransactionMapping().Apply(input));

            case EntityType.AGGREGATE_COMPLETE:
            case EntityType.AGGREGATE_BONDED:
                return(new AggregateTransactionMapping().Apply(input));

            case EntityType.ADDRESS_ALIAS:
            case EntityType.MOSAIC_ALIAS:
                return(new AliasTransactionMapping().Apply(input));

            case EntityType.MODIFY_MULTISIG_ACCOUNT:
                return(new ModifyMultisigAccountTransactionMapping().Apply(input));

            case EntityType.LOCK:
                return(new LockFundsTransactionMapping().Apply(input));

            case EntityType.SECRET_LOCK:
                return(new SecretLockTransactionMapping().Apply(input));

            case EntityType.SECRET_PROOF:
                return(new SecretProofTransactionMapping().Apply(input));

            case EntityType.MODIFY_ADDRESS_METADATA:
            case EntityType.MODIFY_MOSAIC_METADATA:
            case EntityType.MODIFY_NAMESPACE_METADATA:
                return(new ModifyMetadataTransactionMapping().Apply(input));

            case EntityType.MODIFY_ACCOUNT_PROPERTY_ADDRESS:
                return(new ModifyAccountPropertyTransactionAddressMapping().Apply(input));

            case EntityType.MODIFY_ACCOUNT_PROPERTY_MOSAIC:
                return(new ModifyAccountPropertyTransactionMosaicMapping().Apply(input));

            case EntityType.MODIFY_ACCOUNT_PROPERTY_ENTITY_TYPE:
                return(new ModifyAccountPropertyTransactionEntityTypeMapping().Apply(input));

            case EntityType.LINK_ACCOUNT:
                return(new AccountLinkTransactionMapping().Apply(input));

            case EntityType.EXCHANGE_OFFER_ADD:
                return(new ExchangeOfferAddTransactionMapping().Apply(input));

            case EntityType.EXCHANGE_OFFER_REMOVE:
                return(new ExchangeOfferRemoveTransactionMapping().Apply(input));

            case EntityType.EXCHANGE_OFFER:
                return(new ExchangeOfferTransactionMapping().Apply(input));

            case EntityType.MODIFY_MOSAIC_LEVY:
                return(new ModifyMosaicLevyTransactionMapping().Apply(input));

            case EntityType.REMOVE_MOSAIC_LEVY:
                return(new RemoveMosaicLevyTransactionMapping().Apply(input));

            case EntityType.MOSAIC_METADATA_V2:
                return(new MosaicMetadataV2TransactionMapping().Apply(input));

            case EntityType.NAMESPACE_METADATA_V2:
                return(new NamespaceMetadataV2TransactionMapping().Apply(input));

            case EntityType.ACCOUNT_METADATA_V2:
                return(new AccountMetadataV2TransactionMapping().Apply(input));

            default:
                throw new Exception("Unsupported transaction");
            }
        }
コード例 #8
0
        private static ModifyMetadataTransaction ToModifyMetadataTransaction(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 metaType  = MetadataTypeExtension.GetRawValue(transaction["metadataType"].ToObject <int>());


            var modifications    = transaction["modifications"];
            var modificationList = modifications == null
                ? new List <MetadataModification>()
                : modifications.Select(e =>
            {
                var modificationType =
                    MetadataModificationTypeExtension.GetRawValue(e["modificationType"].ToObject <int>());
                var key   = e["key"].ToObject <string>();
                var value = e["value"]?.ToObject <string>();
                MetadataModification metadataModification = null;
                switch (modificationType)
                {
                case MetadataModificationType.ADD:
                    metadataModification = MetadataModification.Add(key, value);
                    break;

                case MetadataModificationType.REMOVE:
                    metadataModification = MetadataModification.Remove(key);
                    break;
                }

                return(metadataModification);
            }).ToList();

            ModifyMetadataTransaction modifyMetadataTransaction = null;

            switch (type)
            {
            case EntityType.MODIFY_ADDRESS_METADATA:
                var address = Address.CreateFromHex(transaction["metadataId"].ToObject <string>());
                modifyMetadataTransaction = new ModifyMetadataTransaction(
                    network, txVersion, type, deadline, maxFee, metaType, null, address,
                    modificationList, signature, signer, txInfo);
                break;

            case EntityType.MODIFY_MOSAIC_METADATA:
                var mosaicId = transaction["metadataId"].ToObject <UInt64DTO>().ToUInt64();
                modifyMetadataTransaction = new ModifyMetadataTransaction(
                    network, txVersion, type, deadline, maxFee, metaType, mosaicId, null,
                    modificationList, signature, signer, txInfo);
                break;

            case EntityType.MODIFY_NAMESPACE_METADATA:
                var namespaceId = transaction["metadataId"].ToObject <UInt64DTO>().ToUInt64();
                modifyMetadataTransaction = new ModifyMetadataTransaction(
                    network, txVersion, type, deadline, maxFee, metaType, namespaceId, null,
                    modificationList, signature, signer, txInfo);
                break;
            }

            return(modifyMetadataTransaction);
        }