public Purchase ConvertBasketToSale(HttpContextBase context, IUserInfo user, IBasket basket, decimal taxRate, string saleCodePrefix) { UserStatus status = UserStatus.None; // if we have a user that has not yet been created, create them if (!_securityService.Exists(user.Identity.Name)) { status = _securityService.CreateUser(user); if (status != UserStatus.Success) { throw new SecurityException($"Unable to create user for sale: {_securityService.StatusMessage(status)}"); } } // save it to the datasource so it can be used in the sale SaveBasket(user, basket); // create sale SaleFlags flags = (basket.Delivery.DeliveryType == DeliveryType.Address ? SaleFlags.Delivery : SaleFlags.CollectionOnly) | SaleFlags.Created; SaleEntity sale = _productDataProvider.CreateAndReturnSale(user.GetUniqueId <Guid>(), flags, taxRate, string.Concat(saleCodePrefix, GenerateSaleCode()), null); ClearBasket(context, user, emptyDatasource: false); // clear the basket (leave the basket intact in the datasource - this binds the sale) Purchase purchase = _checkoutProvider.CreateSale(sale); purchase.UserStatus = status; return(purchase); }
public Hash CreateSale(Address from, string name, SaleFlags flags, Timestamp startDate, Timestamp endDate, string sellSymbol, string receiveSymbol, BigInteger price, BigInteger globalSoftCap, BigInteger globalHardCap, BigInteger userSoftCap, BigInteger userHardCap) { Runtime.Expect(Runtime.IsWitness(from), "invalid witness"); Runtime.Expect(Runtime.TokenExists(sellSymbol), "token must exist: " + sellSymbol); var token = Runtime.GetToken(sellSymbol); Runtime.Expect(token.IsFungible(), "token must be fungible: " + sellSymbol); Runtime.Expect(token.IsTransferable(), "token must be transferable: " + sellSymbol); Runtime.Expect(price >= 1, "invalid price"); Runtime.Expect(globalSoftCap >= 0, "invalid softcap"); Runtime.Expect(globalHardCap > 0, "invalid hard cap"); Runtime.Expect(globalHardCap >= globalSoftCap, "hard cap must be larger or equal to soft capt"); Runtime.Expect(userSoftCap >= 0, "invalid user soft cap"); Runtime.Expect(userHardCap >= userSoftCap, "invalid user hard cap"); Runtime.Expect(receiveSymbol != sellSymbol, "invalid receive token symbol: " + receiveSymbol); // TODO remove this later when Cosmic Swaps 2.0 are released Runtime.Expect(receiveSymbol == DomainSettings.StakingTokenSymbol, "invalid receive token symbol: " + receiveSymbol); Runtime.TransferTokens(sellSymbol, from, this.Address, globalHardCap); var sale = new SaleInfo() { Creator = from, Name = name, Flags = flags, StartDate = startDate, EndDate = endDate, SellSymbol = sellSymbol, ReceiveSymbol = receiveSymbol, Price = price, GlobalSoftCap = globalSoftCap, GlobalHardCap = globalHardCap, UserSoftCap = userSoftCap, UserHardCap = userHardCap, }; var bytes = Serialization.Serialize(sale); var hash = Hash.FromBytes(bytes); _saleList.Add(hash); _saleMap.Set(hash, sale); _saleSupply.Set <Hash, BigInteger>(hash, 0); Runtime.Notify(EventKind.Crowdsale, from, new SaleEventData() { kind = SaleEventKind.Creation, saleHash = hash }); return(hash); }
/// <summary> /// Some flags once set are disabled e.g. when a sale is cancelled, it cannot be 'uncancelled'. /// </summary> /// <param name="flag"></param> /// <returns></returns> public bool IsFlagDisabled(SaleFlags flag) { SaleFlags checkFlags = SaleFlags.Cancelled | SaleFlags.Refunded | SaleFlags.Created; if (!checkFlags.HasFlag(flag)) { return(false); } return(SaleFlags.HasFlag(flag)); }
/// <summary> /// Routine to handle updating the entire value of the sale flags (mainly used for order status changes) /// </summary> /// <param name="saleId"></param> /// <param name="flags"></param> public void UpdateSaleFlags(int saleId, SaleFlags flags) { _productDataProvider.SetSaleFlags(saleId, flags); }
/// <summary> /// Sets a particular sale flag. /// </summary> /// <param name="saleId"></param> /// <param name="flags"></param> /// <returns></returns> public SaleFlags SetSaleFlags(int saleId, SaleFlags flags) { return(_productDataProvider.SetSaleFlags(saleId, flags)); }
/// <summary> /// Sets a particular sale flag. /// </summary> /// <param name="sale"></param> /// <param name="flags"></param> /// <returns></returns> public void SetSaleFlags(SaleEntity sale, SaleFlags flags) { SetSaleFlags(sale.SaleId, flags); sale.SaleFlags &= flags; }
public void AddFlag(int saleId, SaleFlags flag) { _productDataProvider.AddFlag(saleId, flag); }
/// <summary> /// Routine to handle updating the entire value of the sale flags (mainly used for order status changes) /// </summary> /// <param name="sale"></param> /// <param name="flags"></param> public void UpdateSaleFlags(SaleEntity sale, SaleFlags flags) { UpdateSaleFlags(sale.SaleId, flags); }
public void UpdateSaleFlags(int saleId, SaleFlags flags) { Execute("dbo.SPUpdateSaleFlags", new { saleId, flags = (int)flags }); }
public SaleFlags SetSaleFlags(int saleId, SaleFlags flags) { IEnumerable <SaleFlags> result = QueryWithTransaction <SaleFlags>("dbo.SPSetSaleFlags", new { saleId, flags = (int)flags }); return(result.Any() ? result.First() : SaleFlags.None); }
public void AddFlag(int saleId, SaleFlags flag) { Execute("dbo.SPSaleAddFlag", new { saleId, flag = (int)flag }); }
public SaleEntity CreateAndReturnSale(Guid userKey, SaleFlags flags, decimal taxRate, string saleCode, int?shippingId) { int saleId = CreateSale(userKey, flags, taxRate, saleCode, shippingId); return(ReadSale(saleId)); }
public int CreateSale(Guid userKey, SaleFlags flags, decimal taxRate, string saleCode, int?shippingId) { return(QueryWithTransaction <int>("dbo.SPCreateSale", new { flags = (int)flags, taxRate, saleCode, userKey, shippingId }).First()); }
static byte[] GenCreateSale() { Console.Write("Sale name? "); string name = Console.ReadLine(); //Console.Write("Whitelist? "); SaleFlags flags = SaleFlags.Whitelist; Console.Write("Start date?: "); uint startDate; if (!uint.TryParse(Console.ReadLine(), out startDate)) { Console.Write("Invalid start date"); return(null); } var startTimeStamp = (Timestamp)startDate; Console.WriteLine($"Start time set to {startTimeStamp}"); Console.Write("End date?: "); uint endDate; if (!uint.TryParse(Console.ReadLine(), out endDate) || endDate <= startDate) { Console.Write("Invalid end date"); return(null); } var endTimeStamp = (Timestamp)endDate; Console.WriteLine($"End time set to {endTimeStamp}"); string receiveSymbol = "SOUL"; Console.Write("What token symbol will be sold?: "); string sellSymbol = Console.ReadLine(); if (sellSymbol == DomainSettings.StakingTokenSymbol || receiveSymbol == DomainSettings.FuelTokenSymbol || !ValidationUtils.IsValidTicker(receiveSymbol)) { Console.Write("Invalid token symbol"); return(null); } int decimals; Console.Write($"How many decimals {sellSymbol} has?: "); if (!int.TryParse(Console.ReadLine(), out decimals) || decimals < 0 || decimals > 18) { Console.Write("Invalid decimals"); return(null); } Console.Write($"Price: How many {sellSymbol} per 1 {receiveSymbol}? (must be integer number): "); int price; if (!int.TryParse(Console.ReadLine(), out price) || price <= 0) { Console.Write("Invalid decimals"); return(null); } Console.Write($"Softcap: How many {sellSymbol} to sell minimum for sale to be succesful? (Or zero if no soft-cap): "); decimal globalSoftCap; if (!decimal.TryParse(Console.ReadLine(), out globalSoftCap) || globalSoftCap < 0) { Console.Write("Invalid softcap"); return(null); } Console.Write($"Hardcap: How many {sellSymbol} maximum?: "); decimal globalHardCap; if (!decimal.TryParse(Console.ReadLine(), out globalHardCap) || globalHardCap <= 0) { Console.Write("Invalid hardcap"); return(null); } Console.Write($"How many {sellSymbol} must a user buy minimum? (Or zero if no minimum): "); decimal userSoftCap; if (!decimal.TryParse(Console.ReadLine(), out userSoftCap) || userSoftCap < 0) { Console.Write("Invalid user minimum"); return(null); } Console.Write($"What is the maximum {sellSymbol} a user can buy?: "); decimal userHardCap; if (!decimal.TryParse(Console.ReadLine(), out userHardCap) || userHardCap < userSoftCap) { Console.Write("Invalid hardcap"); return(null); } var sb = new ScriptBuilder().AllowGas(signerKeys.Address, Address.Null, 100000, 99999); sb.CallContract(NativeContractKind.Sale, nameof(SaleContract.CreateSale), signerKeys.Address, name, flags, startTimeStamp, endTimeStamp, sellSymbol, receiveSymbol, price, UnitConversion.ToBigInteger(globalSoftCap, decimals), UnitConversion.ToBigInteger(globalHardCap, decimals), UnitConversion.ToBigInteger(userSoftCap, decimals), UnitConversion.ToBigInteger(userHardCap, decimals)); var script = sb.SpendGas(signerKeys.Address). EndScript(); return(script); }