Пример #1
0
        public MarketAuction[] GetAuctions()
        {
            var ids      = _auctionIDs.All <string>();
            var auctions = new MarketAuction[ids.Length];

            for (int i = 0; i < auctions.Length; i++)
            {
                auctions[i] = _auctionMap.Get <string, MarketAuction>(ids[i]);
            }
            return(auctions);
        }
Пример #2
0
        public void SellToken(Address from, string baseSymbol, string quoteSymbol, BigInteger tokenID, BigInteger price, Timestamp endDate)
        {
            Runtime.Expect(Runtime.IsWitness(from), "invalid witness");
            Runtime.Expect(endDate > Runtime.Time, "invalid end date");

            var maxAllowedDate = Runtime.Time + TimeSpan.FromDays(30);

            Runtime.Expect(endDate <= maxAllowedDate, "end date is too distant");

            Runtime.Expect(Runtime.TokenExists(quoteSymbol), "invalid quote token");
            var quoteToken = Runtime.GetToken(quoteSymbol);

            Runtime.Expect(quoteToken.Flags.HasFlag(TokenFlags.Fungible), "quote token must be fungible");

            Runtime.Expect(Runtime.TokenExists(baseSymbol), "invalid base token");
            var baseToken = Runtime.GetToken(baseSymbol);

            Runtime.Expect(!baseToken.Flags.HasFlag(TokenFlags.Fungible), "base token must be non-fungible");

            var nft = Runtime.ReadToken(baseSymbol, tokenID);

            Runtime.Expect(nft.CurrentChain == Runtime.Chain.Name, "token not currently in this chain");
            Runtime.Expect(nft.CurrentOwner == from, "invalid owner");

            Runtime.Expect(Runtime.TransferToken(baseToken.Symbol, from, this.Address, tokenID), "transfer failed");

            var auction   = new MarketAuction(from, Runtime.Time, endDate, baseSymbol, quoteSymbol, tokenID, price);
            var auctionID = baseSymbol + "." + tokenID;

            _auctionMap.Set(auctionID, auction);
            _auctionIDs.Add(auctionID);

            Runtime.Notify(EventKind.OrderCreated, from, new MarketEventData()
            {
                ID = tokenID, BaseSymbol = baseSymbol, QuoteSymbol = quoteSymbol, Price = price
            });
            Runtime.Notify(EventKind.TokenSend, from, new TokenEventData()
            {
                chainAddress = this.Address, symbol = auction.BaseSymbol, value = tokenID
            });
        }