Пример #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(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");

            var quoteToken = Runtime.Nexus.FindTokenBySymbol(quoteSymbol);

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

            var baseToken = Runtime.Nexus.FindTokenBySymbol(baseSymbol);

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

            var ownerships = Runtime.Chain.GetTokenOwnerships(baseToken);
            var owner      = ownerships.GetOwner(this.Storage, tokenID);

            Runtime.Expect(owner == from, "invalid owner");

            Runtime.Expect(baseToken.Transfer(this.Storage, ownerships, from, Runtime.Chain.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);

            var nft = this.Runtime.Nexus.GetNFT(baseToken, tokenID);

            nft.CurrentChain = Runtime.Chain.Address;
            nft.CurrentOwner = Runtime.Chain.Address;

            Runtime.Notify(EventKind.AuctionCreated, from, new MarketEventData()
            {
                ID = tokenID, BaseSymbol = baseSymbol, QuoteSymbol = quoteSymbol, Price = price
            });
        }
Пример #3
0
        public void SellToken(Address from, string baseSymbol, string quoteSymbol, BigInteger tokenID, BigInteger price, Timestamp endDate)
        {
            Runtime.Expect(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.Nexus.TokenExists(quoteSymbol), "invalid quote token");
            var quoteToken = Runtime.Nexus.GetTokenInfo(quoteSymbol);

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

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

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

            var ownerships = new OwnershipSheet(baseSymbol);
            var owner      = ownerships.GetOwner(this.Storage, tokenID);

            Runtime.Expect(owner == from, "invalid owner");

            Runtime.Expect(Runtime.Nexus.TransferToken(Runtime, baseToken.Symbol, from, Runtime.Chain.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.Runtime.Chain.Address, symbol = auction.BaseSymbol, value = tokenID
            });
        }