Exemplo n.º 1
0
        public void PaymentSplitContractTest()
        {
            Account     account = fluentClient.ConstructAccount(baseKeyPair);
            BaseKeyPair rec1    = BaseKeyPair.Generate();
            BaseKeyPair rec2    = BaseKeyPair.Generate();
            BaseKeyPair rec3    = BaseKeyPair.Generate();
            //map(address, int)
            Dictionary <string, int> input = new Dictionary <string, int>();

            input.Add(rec1.PublicKey, 40);
            input.Add(rec2.PublicKey, 40);
            input.Add(rec3.PublicKey, 20);
            decimal  paymentValue          = 1m.ToAettos(Unit.AE);
            string   paymentSplitterSource = File.ReadAllText(Path.Combine(ResourcePath, "contracts", "PaymentSplitter.aes"), Encoding.UTF8);
            Contract contract = account.ConstructContract(paymentSplitterSource);

            ContractReturn depReturn = contract.MeasureAndDeploy(0, 0, Constants.BaseConstants.MINIMAL_GAS_PRICE, "init", input).WaitForFinish(TimeSpan.FromSeconds(30));

            Assert.IsTrue(depReturn.Events.Any(a => a.Name == "AddingInitialRecipients"));

            ContractReturn callReturn = contract.MeasureAndCall("payAndSplit", Constants.BaseConstants.MINIMAL_GAS_PRICE, (ulong)paymentValue).WaitForFinish(TimeSpan.FromSeconds(30));

            Assert.IsTrue(callReturn.Events.Any(a => a.Name == "PaymentReceivedAndSplitted"));

            Assert.AreEqual(new BigInteger(paymentValue * 0.4m), fluentClient.ConstructAccount(rec1).Balance);
            Assert.AreEqual(new BigInteger(paymentValue * 0.4m), fluentClient.ConstructAccount(rec2).Balance);
            Assert.AreEqual(new BigInteger(paymentValue * 0.2m), fluentClient.ConstructAccount(rec3).Balance);
        }
Exemplo n.º 2
0
        public bool UpdateContractReturn(int Id, ContractReturn contract_return)
        {
            //UserDelegate existdelegateuser = GetDelegateById(Id);
            //if (existdelegateuser == null)
            //    return false;
            //existdelegateuser.Name = del.Name;
            //existdelegateuser.NationalityId = del.NationalityId;
            //existdelegateuser.DelegateTypeId = del.DelegateTypeId;
            //existdelegateuser.CommissionValue = del.CommissionValue;
            //existdelegateuser.CommissionPrecentage = del.CommissionPrecentage;
            //existdelegateuser.AccountNoTree = del.AccountNoTree;
            //existdelegateuser.DeservedAmount = del.DeservedAmount;
            //existdelegateuser.RemainderAmount = del.RemainderAmount;
            //existdelegateuser.TransferAmount = del.TransferAmount;

            ////var delegatetype = _context.DelegateTypes.SingleOrDefault(x => x.Id == existdelegateuser.DelegateTypeId);
            //////if (delegatetype != null) { existdelegateuser.DelegateTypeName = delegatetype.Name; }

            ////var nationality = _context.Nationalities.SingleOrDefault(x => x.Id == existdelegateuser.NationalityId);
            ////if (delegatetype != null) { existdelegateuser.NationalityName = nationality.Name; }


            //_context.Update(existdelegateuser);
            //_context.SaveChanges();

            return(true);
        }
Exemplo n.º 3
0
        public int AddContractReturn(ContractReturn contract_return)
        {
            _context.ContractReturns.Add(contract_return);
            _context.SaveChanges();

            // Contract Info
            var cont = _context.Contracts.Find(contract_return.ContractId);

            if (cont != null)
            {
                cont.ContractStatusId = (int)EnumHelper.ContractStatus.Return;
                _context.Update(cont);
                _context.SaveChanges();
            }



            // Adding To Contract History
            ContractHistory history = new ContractHistory();

            history.ContractId       = cont.Id;
            history.CustomerId       = cont.CustomerId;
            history.ForeignAgencyId  = cont.ForeignAgencyId;
            history.EmployeeId       = cont.EmployeeId;
            history.ActionId         = (int)EnumHelper.ContractAction.Return;
            history.ContractStatusId = cont.ContractStatusId;
            //history.ActionByName = contractSelect.SelectByName;
            history.ActionById   = contract_return.CreatedById;
            history.ActionByName = _context.Users.Where(x => x.Id.Contains(history.ActionById)).SingleOrDefault().UserName;
            var foreignAgencies = _context.ForeignAgencies.SingleOrDefault(x => x.Id == history.ForeignAgencyId);

            if (foreignAgencies != null)
            {
                history.ForeignAgencyName = foreignAgencies.OfficeName;
            }
            var cust = _context.Customers.SingleOrDefault(x => x.Id == history.CustomerId);

            if (cust != null)
            {
                history.CustomerName = cust.Name;
            }
            var emp = _context.Employees.SingleOrDefault(x => x.Id == history.EmployeeId);

            if (emp != null)
            {
                history.EmployeeName = emp.FirstName + ' ' + emp.Father;
            }
            history.ActionDate = DateTime.UtcNow.ToString("dd/MM/yyyy",
                                                          CultureInfo.InvariantCulture);

            _context.ContractHistories.Add(history);
            _context.SaveChanges();



            return(contract_return.Id);
        }
Exemplo n.º 4
0
        public async Task <(object result, bool done)> CheckForFinishAsync(object input, CancellationToken token = default(CancellationToken))
        {
            Contract     co  = (Contract)input;
            TxInfoObject res = await co.Account.Client.GetTransactionInfoByHashAsync(co.TxHash, token).ConfigureAwait(false);

            if (string.IsNullOrEmpty(co.ContractId) && !string.IsNullOrEmpty(res.CallInfo?.ContractId))
            {
                co.ContractId = res.CallInfo?.ContractId;
            }
            return(await ContractReturn.CreateAsync(co.Account, co, _function, res.CallInfo, res.TXInfo, token).ConfigureAwait(false), true);
        }
Exemplo n.º 5
0
        public bool RemoveContractReturn(int Id)
        {
            ContractReturn contract_Reason = GetContractReturnById(Id);

            if (contract_Reason == null)
            {
                return(false);
            }
            _context.Remove(contract_Reason);
            _context.SaveChanges();
            return(true);
        }
Exemplo n.º 6
0
        public void IdentityContractTest()
        {
            Account  account  = fluentClient.ConstructAccount(baseKeyPair);
            Contract contract = account.ConstructContract(TestConstants.TestContractSourceCode);

            Assert.AreEqual(TestConstants.TestContractByteCode, contract.ByteCode);

            ContractReturn ret = contract.Deploy(0, 0, 2000000000, 100000).WaitForFinish(TimeSpan.FromSeconds(30));

            ContractReturn <int> re = contract.StaticCall <int>("main", 0, 42);

            Assert.AreEqual(re.ReturnValue, 42);
        }