示例#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 override void OnUse(ref CPet user, ref CMonster opponent)
        {
            var dmg = BattleManager.CalDamage(
                this.Damage,
                EntityTypeExtension.CheckCompacity(user.Type, opponent.Type),
                user.Info.AdAtk,
                user.Info.ApAtk,
                DmgType.ATTACK_DAMAGE
                );

            opponent.Info.DealDmg(dmg);
            this.Point--;
        }
        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();
        }
        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();
        }
        /// <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");
            }
        }
        public void ReverseEngineerCodeFirstMain(Project project)
        {
            DebugCheck.NotNull(project);
            targetProject = project;

            try
            {
                var startTime = DateTime.Now;

                var _storeMetadataFilters = new List <EntityStoreSchemaFilterEntry>
                {
                    new EntityStoreSchemaFilterEntry(null, null, "EdmMetadata", EntityStoreSchemaFilterObjectTypes.Table, EntityStoreSchemaFilterEffect.Exclude),
                    new EntityStoreSchemaFilterEntry(null, null, "__MigrationHistory", EntityStoreSchemaFilterObjectTypes.Table, EntityStoreSchemaFilterEffect.Exclude),
                    new EntityStoreSchemaFilterEntry(null, null, "sysdiagrams", EntityStoreSchemaFilterObjectTypes.Table, EntityStoreSchemaFilterEffect.Exclude),
                    //new EntityStoreSchemaFilterEntry(null, null, null, EntityStoreSchemaFilterObjectTypes.View, EntityStoreSchemaFilterEffect.Exclude),
                    new EntityStoreSchemaFilterEntry(null, null, null, EntityStoreSchemaFilterObjectTypes.Function, EntityStoreSchemaFilterEffect.Exclude)
                };

                //build.txt不存在或者空文本生成所有实体,有文本按设置生成
                var buildFilename = Path.Combine(targetProject.GetProjectDir(), "build.txt");
                if (File.Exists(buildFilename))
                {
                    var content = File.ReadAllText(buildFilename);
                    if (!string.IsNullOrWhiteSpace(content))
                    {
                        var allowFilterEntrys = content.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
                                                .Select(p => new EntityStoreSchemaFilterEntry(null, null, p, EntityStoreSchemaFilterObjectTypes.Table, EntityStoreSchemaFilterEffect.Allow));

                        _storeMetadataFilters.AddRange(allowFilterEntrys);
                    }
                }

                var connectionStringSettings = DoConnectionStringSettings(targetProject);
                var entityFrameworkVersion   = GetEntityFrameworkVersion(package, targetProject);

                // Load store schema
                var storeGenerator = new EntityStoreSchemaGenerator(connectionStringSettings.ProviderName, connectionStringSettings.ConnectionString, "dbo");
                storeGenerator.GenerateForeignKeyProperties = true;
                var errors = storeGenerator.GenerateStoreMetadata(_storeMetadataFilters).Where(e => e.Severity == EdmSchemaErrorSeverity.Error);
                errors.HandleErrors(Strings.ReverseEngineer_SchemaError);

                if (storeGenerator.EntityContainer.BaseEntitySets == null || storeGenerator.EntityContainer.BaseEntitySets.Count() == 0)
                {
                    package.LogError("生成中断,没有找到对应的表", new Exception("生成中断,没有找到对应的表"));
                    return;
                }

                // Generate default mapping
                package.LogInfo(Strings.ReverseEngineer_GenerateMapping);
                var modelGenerator = new EntityModelSchemaGenerator(storeGenerator.EntityContainer, "DefaultNamespace", connectionStringSettings.Name);
                modelGenerator.PluralizationService         = PluralizationService.CreateService(new CultureInfo("en"));
                modelGenerator.GenerateForeignKeyProperties = true;
                modelGenerator.GenerateMetadata();

                var entityTypes = modelGenerator.EdmItemCollection.OfType <EntityType>().ToArray();
                EdmPropertyExtension.ColumnModels = new DocumentionExtension().GenerateDocumentation(entityTypes, connectionStringSettings);
                EntityTypeExtension.GetTableDescriptions(connectionStringSettings);

                var solutionProjects = targetProject.DTE.Solution.Projects.OfType <Project>();

                Action <IEnumerable <Project> > loopProjectsAction = null;
                loopProjectsAction = projects =>
                {
                    foreach (var item in projects)
                    {
                        if (item.FullName.EndsWith(".csproj"))
                        {
                            ReverseEngineerCodeFirst(item, modelGenerator, entityTypes, storeGenerator.StoreItemCollection, entityFrameworkVersion);
                            continue;
                        }

                        if (item.ProjectItems.Count > 0)
                        {
                            var subProjects = new List <Project>();
                            foreach (EnvDTE.ProjectItem subProject in item.ProjectItems)
                            {
                                subProjects.Add(subProject.SubProject);
                            }

                            loopProjectsAction(subProjects);
                        }
                    }
                };
                loopProjectsAction(solutionProjects);

                var duration = DateTime.Now - startTime;
                package.LogInfo(Strings.ReverseEngineer_Complete(duration.ToString(@"h\:mm\:ss")));
            }
            catch (Exception exception)
            {
                package.LogError(exception.Message, exception);
            }
        }
示例#10
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);
        }