Exemple #1
0
        /// <summary>
        /// Save list with all documents
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public async Task <bool> SaveDocumentList(DocumentList list)
        {
            var  json    = JsonSerializer.Serialize(list);
            bool success = false;

            try
            {
                if (IsDfinityNetwork)
                {
                    await dfinityService.SetValueForUser(listDataKey.Key, json);

                    success = true;
                }
                else if (publicKey != null && privateKey != null)
                {
                    var data          = Encoding.UTF8.GetBytes(json);
                    var encryptedData = Utils.Encrypt(data, privateKey);
                    list.Revision++;

                    success = await client.SkyDbSet(privateKey, publicKey, listDataKey, encryptedData, list.Revision);
                }
            }
            catch
            {
                success = false;
            }
            return(success);
        }
Exemple #2
0
        /// <summary>
        /// Save list with all documents
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        private async Task <bool> SaveDocumentList(List <DocumentSummary> list)
        {
            var  json    = JsonSerializer.Serialize(list);
            bool success = false;

            try
            {
                success = await client.SkyDbSet(privateKey, publicKey, listDataKey, json);
            }
            catch
            {
                success = false;
            }
            return(success);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Invalid args - should only be the datakey and the file containing the data you want to put");
                return;
            }

            SiaSkynet.SiaSkynetClient c = new SiaSkynetClient();
            bool   seedFileExists       = File.Exists(@".\seed.txt");
            string seed = "";

            if (seedFileExists)
            {
                Console.WriteLine("seed.txt found, generating keys off it");
                seed = System.IO.File.ReadAllText(@".\seed.txt");
            }
            else
            {
                string generatedSeed = GetUniqueString(64);
                System.IO.File.WriteAllText(@".\seed.txt", generatedSeed);
                seed = generatedSeed;
                Console.WriteLine("seed.txt not found, generating a seed randomly and writing it to seed.txt");
            }
            var keys = SiaSkynetClient.GenerateKeys(seed).Result;

            Console.WriteLine("Updating registry at " + args[0] + " with content in " + args[1]);
            string content = System.IO.File.ReadAllText(args[1]);
            bool   r       = c.SkyDbSet(keys.privateKey, keys.publicKey, args[0], content).Result;

            Console.WriteLine("Registry now contains:");
            string actualContent = c.SkyDbGetAsString(keys.publicKey, args[0]).Result;

            Console.WriteLine(actualContent);
        }