//public ErrorDTO Error = null;
 public Contract()
 {
     //Error = null;
     Deleted = false;
     Properties = new ContractProperties();
     initLists();
 }
    public void CreateTheContract(InputField HowMuchNodes)
    {
        MasterContractID = PlayerPrefs.GetInt("mstrcontractcounter", MasterContractID);
        int howMuchNodes = int.Parse(HowMuchNodes.text);

        if (MasterContractID < 4)
        {
            //new object properties
            ContractProperties contractProperties = new ContractProperties();
            contractProperties.ContractDescription = "this is just a demo description";
            contractProperties.ContractID          = MasterContractID;//randomNewContractID;
            contractProperties.isContractStarted   = true;
            string ToJson = JsonUtility.ToJson(contractProperties);
            MasterContractID += 1;
            PlayerPrefs.SetInt("mstrcontractcounter", MasterContractID);
            reference.Child("USERS").Child(LoginAndRegisterManager.Instance.CustomMasterUserID).Child("GAMESPACE").Child("CONTRACT" + MasterContractID).SetRawJsonValueAsync(ToJson);
        }
        else
        {
            Debug.Log("can not create more than 4 contracts");
        }
    }
        /// <summary>
        /// Gets all Properties of a contract.
        /// </summary>
        /// <param name="CultureIdentifier">Culture identifier to be used to retrieve users information</param>
        /// <returns>List of TopContractsDAL10.ContractUser objects.</returns>
        public Dictionary<long, ContractProperties> GetAllContractProperties(string CultureIdentifier)
        {
            TopContractsV01Entities context = new TopContractsV01Entities(Utilities.getTestEnvName());
            Dictionary<long, ContractProperties> contractProperties = new Dictionary<long, ContractProperties>();

            foreach (TopContractsEntities.Contract contract in context.Contracts)
            {
                ContractProperties cntprop = new ContractProperties();
                cntprop.initDataFields(contract);
                Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Data Fields initialized");
                cntprop.initPrivateFields(contract, CultureIdentifier);
                Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Private Fields initialized");
                contractProperties.Add(contract.ContractID, cntprop);
            }
            return contractProperties;
        }
        /// <summary>
        /// This constructor is only used to fetch an existing contract, and not for creating a new one.
        /// </summary>
        /// <param action="ContractID">ID of contract to fetch</param>
        /// <param action="CultureIdentifier">Culture Identifier used for the selection of Fields and Field-Groups 
        /// names in the appropriate language.</param>
        /// <param name="paging">Object of ContractSectionPaging class to provide page sizes of various contract sections.</param>
        /// <param action="UserId">UserID may be passed to set the read-only value of RoleName of that user 
        /// in the selected contract</param>
        public Contract(long ContractID, string CultureIdentifier, ContractSectionPaging paging, long? UserId = null, ContractSections Content = ContractSections.All, List<long> GroupIDs = null)
        {
            Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Commencing CTOR for ContractID {0}, UserId {1}, Content {2}", ContractID, UserId, Content.ToString());
            //ErrorDTO Error = null;
            //try
            //{
            Deleted = false;
            Properties = new ContractProperties();
            initLists();
            Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Lists initialized");

            TopContractsV01Entities context = new TopContractsV01Entities(Utilities.getTestEnvName());
            TopContractsEntities.Contract efContract = context.Contracts.Where(u => u.ContractID == ContractID).SingleOrDefault();
            this.ID = efContract.ContractID;
            this.Properties.initDataFields(efContract);
            Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Data Fields initialized");
            this.Properties.initPrivateFields(efContract, CultureIdentifier, UserId);
            Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Private Fields initialized");

            if ((Content & ContractSections.Events) == ContractSections.Events)
            {
                this.ContractActivities.AddRange(efContract.ContractActivities.Select(ca => new ContractActivity(ca, CultureIdentifier)));
                Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Events added for ContractSections.Events");
            }
            if ((Content & ContractSections.Alerts) == ContractSections.Alerts)
            {
                this.ContractTodos.AddRange(efContract.ContractTodos.Select(ca => new ContractTodo(ca, CultureIdentifier)));
                Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Alerts added for ContractSections.Alerts");
            }
            if ((Content & ContractSections.AuthorizedEntities) == ContractSections.AuthorizedEntities)
            {
                bool showAllUser = false;
                long? MaxPageSizeUsers = null;

                if (paging.UsersPaging.PagingBehaviour == PagingParameter.DontPage)
                    showAllUser = true;
                else if (paging.UsersPaging.PagingBehaviour == PagingParameter.OverrideDatabaseValues)
                    MaxPageSizeUsers = paging.UsersPaging.PagingValue;
                else
                    MaxPageSizeUsers = GetPagingValueFromDB(efContract.OrganizationIdentifier, ContractSections.AuthorizedEntities);

                if (showAllUser == true || MaxPageSizeUsers == null)
                    this.ContractUsers.AddRange(efContract.ContractUsers.Select(ca => new ContractUser(ca, CultureIdentifier)));
                else
                    this.ContractUsers.AddRange(GetContractUsersByPaging(ContractID, CultureIdentifier, Convert.ToInt64(MaxPageSizeUsers)));

                Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Users added for ContractSections.AuthorizedEntities");
            }
            if ((Content & ContractSections.Applications) == ContractSections.Applications)
            {
                this.ContractApplications.AddRange(efContract.ContractApplications.Select(ca => new ContractApplication(ca)));
                Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Applications added for ContractSections.Applications");
            }
            if ((Content & ContractSections.Fields) == ContractSections.Fields)
            {
                //Code Commented By Viplav for implement sorting related to (DisplayOrder / Alphabatically)

                //long groupID = 0;
                //foreach (TopContractsEntities.ContractField field in efContract.ContractFields.OrderBy(fl => fl.FieldGroupID))
                //{
                //    if (field.FieldGroupID != groupID)
                //    {
                //        groupID = field.FieldGroupID;
                //        this.ContractFieldGroups.Add(new ContractFieldGroup(field, CultureIdentifier));
                //    }
                //}

                //Viplav

                //------------Boaz 25-July-2013-------------
                //If this "contract" is a catalog record, and it is now fetched as part of a process of
                //fetching many such catalog records of the same type, then groupFields collection should
                //be initialized only once...
                List<FieldGroup> efFieldGroups = null;
                if (Contract.initializingCatalogRecords == false || Contract.efFieldGroupsForContractInit == null)
                {
                    efFieldGroups = new List<FieldGroup>();
                    //if (efContract.ContractFields.Any(fg => fg.FieldGroup.DisplayOrder == null))
                    //{
                    //    efFieldGroups = efContract.ContractFields.Select(fg => fg.FieldGroup).Distinct().OrderBy(fgl => fgl.FieldGroupsLNGs.FirstOrDefault(cul => cul.CultureId.Trim() == CultureIdentifier).DescShort).ToList();
                    //}
                    //else
                    //{
                    //    efFieldGroups = efContract.ContractFields.Select(fg => fg.FieldGroup).Distinct().OrderBy(fgd => fgd.DisplayOrder).ToList();
                    //}

                    //List<ContractTypeFieldGroupsMap> groupsMap = new List<ContractTypeFieldGroupsMap>();
                    //groupsMap = ApplicationCachedData.ContractTypeFieldGroupsMap;
                    if (efContract.ContractType.ParentContractTypeID == Utilities.contractTypeContractsID)
                    {
                        if (ApplicationCachedData.ContractTypeFieldGroupsMap.Any(ct => ct.ContractTypeID == efContract.ContractTypeID))
                        {
                            Dictionary<string, List<FieldGroup>> FieldGroupsByLang = ApplicationCachedData.ContractTypeFieldGroupsMap.Single(ct => ct.ContractTypeID == efContract.ContractTypeID).FieldGroupsByLang;
                            if (FieldGroupsByLang.Count() > 0)
                                if (FieldGroupsByLang.Any(lng => lng.Key == CultureIdentifier))
                                    efFieldGroups = FieldGroupsByLang.Single(lng => lng.Key == CultureIdentifier).Value;
                        }
                    }
                    else
                    {
                        if (ApplicationCachedData.CatalogFieldGroupsMap.Any(ct => ct.ContractTypeID == efContract.ContractTypeID))
                        {
                            Dictionary<string, List<FieldGroup>> FieldGroupsByLang = ApplicationCachedData.CatalogFieldGroupsMap.Single(ct => ct.ContractTypeID == efContract.ContractTypeID).FieldGroupsByLang;
                            if (FieldGroupsByLang.Count() > 0)
                                if (FieldGroupsByLang.Any(lng => lng.Key == CultureIdentifier))
                                    efFieldGroups = FieldGroupsByLang.Single(lng => lng.Key == CultureIdentifier).Value;
                        }
                    }

                    Contract.efFieldGroupsForContractInit = efFieldGroups;
                }
                else
                    efFieldGroups = Contract.efFieldGroupsForContractInit;

                // if list of GroupIDs is not null
                if (GroupIDs != null)
                {
                    if (GroupIDs.Count() > 0)
                    {
                        // retrieve only those fieldgroups which are requested.
                        efFieldGroups = efFieldGroups.Where(fg => GroupIDs.Contains(fg.FieldGroupID)).ToList();
                    }
                }

                foreach (FieldGroup fieldgroup in efFieldGroups)
                {
                    this.ContractFieldGroups.Add(new ContractFieldGroup(context, fieldgroup, CultureIdentifier, ContractID));
                }
                Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Fields added for ContractSections.Fields");
            }
            if ((Content & ContractSections.Documents) == ContractSections.Documents)
            {
                this.ContractDocs.AddRange(efContract.ContractDocs.Select(ca => new ContractDoc(ca)));
                Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Documents added for ContractSections.Documents");
            }
            if ((Content & ContractSections.Gallery) == ContractSections.Gallery)
            {
                this.ContractGalleries.AddRange(efContract.ContractGalleries.OrderByDescending(cg => cg.CreatedOn).Select(cg => new ContractGallery(cg)));
                Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Galleries added for ContractSections.Gallery");
            }

            if ((Content & ContractSections.ChildContract) == ContractSections.ChildContract)   // Condition Implemented for getting only neccessary Data by Viplav on 14 May 2013
            {
                this.ChildContracts = new ChildContract(ref context, efContract).ChildContracts;
                Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Child Contracts collection initialized");
            }

            if ((Content & ContractSections.ParantContract) == ContractSections.ParantContract) // Condition Implemented for getting only neccessary Data by Viplav on 14 May 2013
            {
                if (efContract.ParentContractID != null)
                {
                    //this.ParentContract = new Contract((long)efContract.ParentContractID, CultureIdentifier, UserId, Content);
                    this.ParentContract = new Contract((long)efContract.ParentContractID, CultureIdentifier, paging, UserId, Content); // Kai Cohen - Modified code to pass paging parameters.
                    Logger.WriteGeneralVerbose("Contract class - CTOR 2", "Parent Contracts initialized");
                }
            }
        }
        /// <summary>
        /// This constructor is ONLY used for creating new contracts, not for getting information about existing contracts.
        /// </summary>
        /// <param action="ContractName">The action for the new contract being created</param>
        /// <param action="ContractTypeID">The type for the new contract being created</param>
        /// <param action="ContractStatusID">The status for the new contract being created</param>
        /// <param action="UserIdCreator">The ID of the user creating the contract</param>
        /// <param action="CultureIdentifier">Culture Identifier used for the selection of Fields and Field-Groups 
        /// names in the appropriate language, in the process of creating those for the contract. The language
        /// is not needed for the creation, so much as it is needed for the population of data in the newly created contract</param>
        public Contract(Guid OrganizationIdentifier, string ContractName, long ContractTypeID, long? ContractStatusID, long UserIdCreator, string CultureIdentifier, long RoleID = 0)
        {
            //int RoleIdCreator = (int)SpecialRoles.OwnerRoleID; //Always the "owner" is the one creating the contracts...
            long RoleIdCreator = RoleID; //RoleID is a default userid used for contractuser table
            try
            {
                Deleted = false;
                Properties = new ContractProperties();
                initLists();

                New = true;
                Properties.Name = ContractName;
                Properties.ContractTypeID = ContractTypeID;
                Properties.StatusID = (int?)ContractStatusID;
                Properties.OrganizationIdentifier = OrganizationIdentifier;

                ContractUsers.Add(new ContractUser() { New = true, EntryId = UserIdCreator, RoleID = RoleIdCreator });

                TopContractsV01Entities context = new TopContractsV01Entities(Utilities.getTestEnvName());
                //long ContractTypeContractsID = ConfigurationProvider.Default.ContractTypeContracts.ContractTypeContractsID;
                long ContractTypeContractsID = Utilities.contractTypeContractsID; // Code implemented by Viplav on 17 june 2013 for remove webconfig concept
                TopContractsDAL10.SystemTables.FieldGroups fieldGroups = new SystemTables.FieldGroups();
                if (context.ContractTypes.Any(ct => ct.ParentContractTypeID == ContractTypeContractsID && ct.ContractTypeID == ContractTypeID))
                    fieldGroups = SystemTables.FieldGroups.Get(false, false, true, CultureIdentifier);
                else
                    fieldGroups = SystemTables.FieldGroups.GetWithoutParentContractTypeID(false, false, true, CultureIdentifier);

                string logData1 = "FieldGroups created: " + Environment.NewLine;
                foreach (TopContractsDAL10.SystemTables.FieldGroup fGrp in fieldGroups.Entries)
                {
                    logData1 = logData1 + string.Format("FieldGroup info: groupID-{0}", fGrp.ID) + Environment.NewLine;
                }
                Logger.WriteGeneralVerbose("Contract class - CTOR", logData1);

                Logger.WriteGeneralVerbose("Contract class - CTOR", "Creating FieldGroups collection");
                foreach (TopContractsDAL10.SystemTables.FieldGroup fieldGroup in fieldGroups.Entries)
                {
                    //if (fieldGroup.ContractTypeIDsVisible.Any(ct => ct == ContractTypeID)) //Boaz - 7-Aug-2012
                    if (context.ContractTypes.Any(ct => ct.ParentContractTypeID == ContractTypeContractsID && ct.ContractTypeID == ContractTypeID))
                    {
                        if (fieldGroup.ContractTypeIDsVisible.Any(ct => ct == ContractTypeID) || fieldGroup.VisibleToAllContractTypes)
                            ContractFieldGroups.Add(new ContractFieldGroup(fieldGroup, CultureIdentifier));
                    }
                    else
                    {
                        if (fieldGroup.ContractTypeIDsVisible.Any(ct => ct == ContractTypeID))
                            ContractFieldGroups.Add(new ContractFieldGroup(fieldGroup, CultureIdentifier));
                    }
                }
                string logData2 = "ContractFieldGroups created: " + Environment.NewLine;
                foreach (ContractFieldGroup cFldGrp in ContractFieldGroups)
                {
                    logData2 = logData2 + string.Format("FieldGroup info: groupID-{0}", cFldGrp.EntryId) + Environment.NewLine;
                }
                Logger.WriteGeneralVerbose("Contract class - CTOR", logData2);
            }
            catch (Exception ex)
            {
                Logger.WriteExceptionError("Contract class - Contract", ex);
                ErrorDTO Error = new ErrorDTO(new ExceptionUnknownContractInit(ex));
            }
        }
    /// <summary>
    /// Creating the contract. Max contracts 4. each onctract has his own id
    /// </summary>
    /// <param name="ContractDescription"></param>
    public void GetDataBeforeCreatingContract(InputField ContractDescription)
    {
        //int howmuchnodes = int.Parse(HowMuchNodes.text);
        MasterContractID = PlayerPrefs.GetInt("mstrcontractcounter", MasterContractID);



        if (MasterContractID < 4)
        {
            if (MasterContractID == 0)
            {
                ContractProperties contractProperties = new ContractProperties();
                contractProperties.ContractDescription = ContractDescription.text;
                contractProperties.ContractID          = 0;
                contractProperties.isContractStarted   = true;
                string ToJson = JsonUtility.ToJson(contractProperties);
                reference.Child("USERS").Child(LoginAndRegisterManager.Instance.CustomMasterUserID).Child("GAMESPACE").Child("CONTRACT" + MasterContractID).SetRawJsonValueAsync(ToJson);
                MasterContractID = 1;
                PlayerPrefs.SetInt("mstrcontractcounter", MasterContractID);



                for (int i = 0; i < FirstRowPlants.Count; i++) // say here that they are only for the first row, first contrat for the first row
                {
                    FirstRowPlants[i].singlePlant.ContractID        = 0;
                    FirstRowPlants[i].singlePlant.isPlantInContract = true;
                    FirstRowPlants[i].singlePlant.FieldID           = i;
                }

                ContractIsCreatedPopUp("First Row");
            }

            else if (MasterContractID == 1)
            {
                ContractProperties contractProperties = new ContractProperties();
                contractProperties.ContractDescription = ContractDescription.text;
                contractProperties.ContractID          = 1;
                contractProperties.isContractStarted   = true;

                string ToJson = JsonUtility.ToJson(contractProperties);
                reference.Child("USERS").Child(LoginAndRegisterManager.Instance.CustomMasterUserID).Child("GAMESPACE").Child("CONTRACT" + MasterContractID).SetRawJsonValueAsync(ToJson);
                MasterContractID = 2;
                PlayerPrefs.SetInt("mstrcontractcounter", MasterContractID);
                for (int i = 0; i < SecondRowPlants.Count; i++)
                {
                    SecondRowPlants[i].singlePlant.ContractID        = 1;
                    SecondRowPlants[i].singlePlant.isPlantInContract = true;
                    SecondRowPlants[i].singlePlant.FieldID           = i;
                }
                ContractIsCreatedPopUp("Second Row");
            }

            else if (MasterContractID == 2)
            {
                ContractProperties contractProperties = new ContractProperties();
                contractProperties.ContractDescription = ContractDescription.text;
                contractProperties.ContractID          = 2;
                contractProperties.isContractStarted   = true;

                string ToJson = JsonUtility.ToJson(contractProperties);
                reference.Child("USERS").Child(LoginAndRegisterManager.Instance.CustomMasterUserID).Child("GAMESPACE").Child("CONTRACT" + MasterContractID).SetRawJsonValueAsync(ToJson);
                MasterContractID = 3;
                PlayerPrefs.SetInt("mstrcontractcounter", MasterContractID);
                for (int i = 0; i < ThirdowPlants.Count; i++)
                {
                    ThirdowPlants[i].singlePlant.ContractID        = 2;
                    ThirdowPlants[i].singlePlant.isPlantInContract = true;
                    ThirdowPlants[i].singlePlant.FieldID           = i;
                }
                ContractIsCreatedPopUp("Third Row");
            }
            else if (MasterContractID == 3)
            {
                ContractProperties contractProperties = new ContractProperties();
                contractProperties.ContractDescription = ContractDescription.text;
                contractProperties.ContractID          = 3;
                contractProperties.isContractStarted   = true;

                string ToJson = JsonUtility.ToJson(contractProperties);
                reference.Child("USERS").Child(LoginAndRegisterManager.Instance.CustomMasterUserID).Child("GAMESPACE").Child("CONTRACT" + MasterContractID).SetRawJsonValueAsync(ToJson);
                MasterContractID = 0;//3;
                PlayerPrefs.SetInt("mstrcontractcounter", MasterContractID);
                for (int i = 0; i < FourthRowPlants.Count; i++)
                {
                    FourthRowPlants[i].singlePlant.ContractID        = 3;
                    FourthRowPlants[i].singlePlant.isPlantInContract = true;
                    FourthRowPlants[i].singlePlant.FieldID           = i;
                }

                ContractIsCreatedPopUp("Fourth Row");
            }
        }

        //else
        //{
        //    MasterContractID = 0;
        //    PlayerPrefs.SetInt("mstrcontractcounter", MasterContractID);
        //}
    }
    public void DeleteContract(InputField ContractID)
    {
        MasterContractID = PlayerPrefs.GetInt("mstrcontractcounter", MasterContractID);
        int id = int.Parse(ContractID.text);

        FirebaseDatabase.DefaultInstance
        .GetReference("USERS").Child(LoginAndRegisterManager.Instance.CustomMasterUserID).Child("GAMESPACE").Child("CONTRACT" + id)
        .GetValueAsync().ContinueWith(task =>
        {
            if (task.IsFaulted)
            {
                // Handle the error...
            }
            else if (task.IsCompleted)
            {
                DataSnapshot snapshot   = task.Result;
                string ContractSnapShot = snapshot.GetRawJsonValue();
                ContractProperties contractProperties = new ContractProperties();
                contractProperties = JsonUtility.FromJson <ContractProperties>(ContractSnapShot);
                if (contractProperties != null)
                {
                    if (id == 0)
                    {
                        Debug.Log("CONTRACT ID " + contractProperties.ContractID);
                        //reference.Child("USERS").Child(LoginAndRegisterManager.Instance.CustomMasterUserID).Child("GAMESPACE").Child("CONTRACT" + contractProperties.ContractID).RemoveValueAsync();
                        reference.Child("USERS").Child(LoginAndRegisterManager.Instance.CustomMasterUserID).Child("GAMESPACE").Child("CONTRACT" + id).RemoveValueAsync();

                        MasterContractID = 0;
                        PlayerPrefs.SetInt("mstrcontractcounter", MasterContractID);
                    }
                    if (id == 1)
                    {
                        Debug.Log("CONTRACT ID " + contractProperties.ContractID);
                        //reference.Child("USERS").Child(LoginAndRegisterManager.Instance.CustomMasterUserID).Child("GAMESPACE").Child("CONTRACT" + contractProperties.ContractID).RemoveValueAsync();
                        reference.Child("USERS").Child(LoginAndRegisterManager.Instance.CustomMasterUserID).Child("GAMESPACE").Child("CONTRACT" + id).RemoveValueAsync();

                        MasterContractID = 1;
                        PlayerPrefs.SetInt("mstrcontractcounter", MasterContractID);
                    }
                    if (id == 2)
                    {
                        Debug.Log("CONTRACT ID " + contractProperties.ContractID);
                        //reference.Child("USERS").Child(LoginAndRegisterManager.Instance.CustomMasterUserID).Child("GAMESPACE").Child("CONTRACT" + contractProperties.ContractID).RemoveValueAsync();
                        reference.Child("USERS").Child(LoginAndRegisterManager.Instance.CustomMasterUserID).Child("GAMESPACE").Child("CONTRACT" + id).RemoveValueAsync();

                        MasterContractID = 2;
                        PlayerPrefs.SetInt("mstrcontractcounter", MasterContractID);
                    }
                    if (id == 3)
                    {
                        Debug.Log("CONTRACT ID " + contractProperties.ContractID);
                        //reference.Child("USERS").Child(LoginAndRegisterManager.Instance.CustomMasterUserID).Child("GAMESPACE").Child("CONTRACT" + contractProperties.ContractID).RemoveValueAsync();
                        reference.Child("USERS").Child(LoginAndRegisterManager.Instance.CustomMasterUserID).Child("GAMESPACE").Child("CONTRACT" + id).RemoveValueAsync();

                        MasterContractID = 3;
                        PlayerPrefs.SetInt("mstrcontractcounter", MasterContractID);
                    }
                }
                else
                {
                    Debug.Log("nema veke dogovori");
                }
                //else
                //{
                //    MasterContractID = 0;
                //    PlayerPrefs.SetInt("mstrcontractcounter", MasterContractID);
                //    Debug.Log("no more contracts");
                //}

                ManageContract.Instance.RetreiveDataForSelectedConract();
            }
        });
    }
Example #8
0
        public Transaction DeployContract(KeyPair keys, byte[] script, byte[] parameter_list, byte return_type, ContractProperties properties, string name, string version, string author, string email, string description)
        {
            if (script.Length > 1024 * 1024)
            {
                return(null);
            }

            byte[] gen_script;
            using (var sb = new ScriptBuilder())
            {
                sb.EmitPush(description);
                sb.EmitPush(email);
                sb.EmitPush(author);
                sb.EmitPush(version);
                sb.EmitPush(name);
                sb.EmitPush((byte)properties);
                sb.EmitPush(return_type);
                sb.EmitPush(parameter_list);
                sb.EmitPush(script);

                sb.EmitSysCall("Neo.Contract.Create");

                gen_script = sb.ToArray();

                //string hex = bytes.ByteToHex();
                //System.IO.File.WriteAllBytes(@"D:\code\Crypto\neo-debugger-tools\ICO-Template\bin\Debug\inputs.avm", bytes);
            }

            decimal fee = 100;

            if (properties.HasFlag(ContractProperties.HasStorage))
            {
                fee += 400;
            }

            if (properties.HasFlag(ContractProperties.HasDynamicInvoke))
            {
                fee += 500;
            }

            fee -= 10; // first 10 GAS is free

            List <Transaction.Input>  inputs;
            List <Transaction.Output> outputs;

            GenerateInputsOutputs(keys, "GAS", null, out inputs, out outputs, fee);

            Transaction tx = new Transaction()
            {
                type    = TransactionType.InvocationTransaction,
                version = 0,
                script  = gen_script,
                gas     = fee,
                inputs  = inputs.ToArray(),
                outputs = outputs.ToArray()
            };

            tx.Sign(keys);

            var ok = SendTransaction(tx);

            return(ok ? tx : null);
        }
Example #9
0
 /// <summary>
 /// Gets a collection of <see cref="MemoryProperty"/> objects that <see cref="DataType"/>s inheriting this <see cref="DataContract"/> are expected to have. This only includes publicly visible properties.
 /// </summary>
 public IEnumerable <MemoryProperty> GetProperties()
 {
     return(ContractProperties.Concat(InheritedContracts.SelectMany(c => c.GetProperties())));
 }
Example #10
0
 /// <summary>
 /// Creates a <see cref="DataContract"/> with the specified name and initializes properties and inheritance.
 /// </summary>
 /// <param name="typeName">The full namespace of the <see cref="DataContract"/>.</param>
 /// <param name="properties">A collection of <see cref="MemoryProperty"/> objects included in this <see cref="DataContract"/>.</param>
 /// <param name="inheritedContracts">A collection of parent <see cref="DataContract"/>s.</param>
 public DataContract(Namespace typeName, IEnumerable <MemoryProperty> properties, IEnumerable <DataContract> inheritedContracts = null)
     : this(typeName)
 {
     InheritedContracts.AddRange(inheritedContracts);
     ContractProperties.AddRange(properties);
 }