コード例 #1
0
        private static void GetPriceByProvider(UInt160 provider, byte[] recordKey, Map <UInt160, string> priceMap)
        {
            StorageMap priceList = new(Storage.CurrentContext, provider);

            if (priceList[recordKey] is null)
            {
                throw new Exception("The price of the symbol and blockIndex does not exist");
            }
            PriceState price = (PriceState)StdLib.Deserialize(priceList[recordKey]);

            price.EnsureNotExpired();
            priceMap[provider] = price.CurrentPrice;
        }
コード例 #2
0
        public static void UpdatePriceByProvider(string blockIndex, string symbol, string currentPrice)
        {
            if (Symbols[symbol] is null)
            {
                throw new Exception("Symbol has not registered.");
            }
            UInt160 provider = Runtime.CallingScriptHash;

            if (Providers[provider] is null)
            {
                throw new Exception("No such provider registered");
            }
            StorageMap priceList = new(Storage.CurrentContext, provider);
            PriceState state     = new PriceState
            {
                CurrentPrice = currentPrice,
                Expiration   = Runtime.Time + OneYear
            };

            byte[] key = Helper.Concat((byte[])GetKey(symbol), (byte[])GetKey(blockIndex));
            Storage.Put(Storage.CurrentContext, new byte[] { Prefix_Block }, blockIndex);
            priceList.Put(key, StdLib.Serialize(state));
        }