示例#1
0
        /// <summary>
        /// Get list with all documents
        /// </summary>
        /// <returns></returns>
        private async Task <DocumentList> GetDocumentList()
        {
            try
            {
                Error = null;

                if (IsDfinityNetwork)
                {
                    string?json = await dfinityService.GetValueForUser(listDataKey.Key);

                    if (string.IsNullOrEmpty(json))
                    {
                        return(new());
                    }

                    var loadedList = JsonSerializer.Deserialize <List <DocumentSummary> >(json) ?? new List <DocumentSummary>();
                    var list       = new DocumentList(loadedList.Where(x => x != null).ToList());
                    return(list);
                }
                else if (publicKey != null)
                {
                    var encryptedJson = await client.SkyDbGet(publicKey, listDataKey, TimeSpan.FromSeconds(5));

                    if (!encryptedJson.HasValue)
                    {
                        return(new DocumentList());
                    }
                    else if (privateKey != null)
                    {
                        //Decrypt data
                        var jsonBytes = Utils.Decrypt(encryptedJson.Value.file, privateKey);
                        var json      = Encoding.UTF8.GetString(jsonBytes);

                        var loadedList = JsonSerializer.Deserialize <List <DocumentSummary> >(json) ?? new List <DocumentSummary>();
                        var list       = new DocumentList(loadedList.Where(x => x != null).ToList());
                        list.Revision = encryptedJson.Value.registryEntry?.Revision ?? 0;
                        return(list);
                    }
                }
            }
            catch
            {
                Error = $"Unable to get list of documents from {CurrentNetwork}. Please try again.";
            }
            return(new DocumentList());
        }
示例#2
0
        public async Task TestForcedRevision()
        {
            string      data     = Guid.NewGuid().ToString();
            var         key      = SiaSkynetClient.GenerateKeys("my private key seed");
            RegistryKey dataKey  = new RegistryKey("datakey" + Guid.NewGuid());
            int         revision = 5;

            var success = await _client.SkyDbSet(key.privateKey, key.publicKey, dataKey, Encoding.UTF8.GetBytes(data), revision);

            var result = await _client.SkyDbGet(key.publicKey, dataKey);

            Assert.IsTrue(success);
            Assert.AreEqual(revision, result.Value.registryEntry.Revision);


            var stringResult = Encoding.UTF8.GetString(result.Value.file);

            Assert.AreEqual(data, stringResult);
        }