public async Task GetCommonMetadataTests()
        {
            var name        = "myname";
            var description = "myname";
            var text        = "mytext";
            var imagelink   = "myimagelink";
            var price       = 10.0;

            foreach (var nft in nfts.Values)
            {
                nft.Name        = name;
                nft.Description = description;
                nft.Text        = text;
                nft.ImageLink   = imagelink;
                nft.Price       = price;

                var meta = await nft.GetCommonMetadata();

                Assert.Equal(name, meta["Name"]);
                Assert.Equal(description, meta["Description"]);
                Assert.Equal(text, meta["Text"]);
                Assert.Equal(imagelink, meta["Image"]);
                Assert.Equal(nft.TypeText, meta["Type"]);
                Assert.Equal("10.000000", meta["Price"]);
                Assert.NotEqual("10,000000", meta["Price"]);
                Assert.NotEqual("10", meta["Price"]);
                Assert.Equal(nft.Type, NFTFactory.ParseNFTType(meta));
            }
        }
        public async Task LoadNFTFromNetwork()
        {
            if (!string.IsNullOrEmpty(Utxo))
            {
                Loading = true;
                if (Utxo.Contains(':'))
                {
                    NFT = await NFTFactory.GetNFT("", Utxo.Split(':')[0], wait : true);
                }
                else
                {
                    NFT = await NFTFactory.GetNFT("", Utxo, wait : true);
                }

                if (NFT != null)
                {
                    if (nftCard != null)
                    {
                        nftCard.LoadNFT(NFT);
                    }
                }
                else
                {
                    NFT = new ImageNFT("");
                }

                Loading = false;
            }
            StateHasChanged();
        }
 public async Task <INFT> GetNFT(string utxo, int index)
 {
     if (!MainDataContext.NFTs.TryGetValue(utxo, out var nft))
     {
         nft = await NFTFactory.GetNFT(NFTHelpers.TokenId, utxo, index, 0, true);
     }
     return(nft);
 }
        public async Task FillSpecificPropertiesTest()
        {
            var random = new Random();
            var strnft = string.Empty;

            foreach (var nft in nfts)
            {
                var typeprops = nft.Value.GetType().GetProperties();
                foreach (var prop in typeprops)
                {
                    if (prop.PropertyType == typeof(string) && prop.CanWrite && prop.Name != "TypeText")
                    {
                        prop.SetValue(nft.Value, Convert.ChangeType(Guid.NewGuid().ToString(), prop.PropertyType), null);
                    }
                    if (prop.PropertyType == typeof(int) && prop.CanWrite)
                    {
                        prop.SetValue(nft.Value, Convert.ChangeType(random.Next(0, 1000), prop.PropertyType), null);
                    }
                    if (prop.PropertyType == typeof(double) && prop.CanWrite)
                    {
                        prop.SetValue(nft.Value, Convert.ChangeType(random.NextDouble(), prop.PropertyType), null);
                    }
                    if (prop.PropertyType == typeof(DateTime) && prop.CanWrite)
                    {
                        prop.SetValue(nft.Value, Convert.ChangeType(DateTime.UtcNow, prop.PropertyType), null);
                    }
                    if (prop.PropertyType == typeof(bool) && prop.CanWrite)
                    {
                        prop.SetValue(nft.Value, Convert.ChangeType(true, prop.PropertyType), null);
                    }
                }

                strnft = JsonConvert.SerializeObject(nft.Value);

                var newnft = await NFTFactory.CloneNFT(nft.Value);

                var strnewnft = JsonConvert.SerializeObject(newnft);
                try
                {
                    Assert.Equal(strnft, strnewnft);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Wrong Cloning in {nft.Value.TypeText}");
                    throw ex;
                }
            }
        }
Exemplo n.º 5
0
        private static async Task WritePriceToNFT()
        {
            Console.WriteLine("Fill input NFT Utxo: ");
            var nftutxo = Console.ReadLine();
            // load existing NFT object and wait for whole data synchronisation
            var nft = await NFTFactory.GetNFT(NFTHelpers.TokenId, nftutxo, 0, 0, true);

            if (nft == null)
            {
                throw new Exception("NFT does not exists!");
            }
            // send NFT to receiver
            var res = await account.SendNFT(account.Address, nft, true, 0.05);

            Console.WriteLine("New TxId hash is: ");
            Console.WriteLine(res);
        }
        /// <summary>
        /// Load Xray device NFT
        /// </summary>
        /// <returns></returns>
        public async Task LoadXrayNFT()
        {
            if (!string.IsNullOrEmpty(XrayDeviceNFTHash))
            {
                try
                {
                    var nft = await NFTFactory.GetNFT("", XrayDeviceNFTHash, 0, 0, true, true, NFTTypes.Xray);

                    if (nft != null && !string.IsNullOrEmpty(nft.Utxo))
                    {
                        XrayDeviceNFT = nft;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Cannot load the Xray NFT: {XrayDeviceNFTHash} in XrayImageNFT: {Utxo}, exception: {ex.Message}");
                }
            }
        }
Exemplo n.º 7
0
        private static async Task SendNFTPayment()
        {
            Console.WriteLine("Fill input NFT Utxo: ");
            var nftutxo = Console.ReadLine();
            // load existing NFT object and wait for whole data synchronisation. NFT must have written price!
            var nft = await NFTFactory.GetNFT(NFTHelpers.TokenId, nftutxo, 0, 0, true);

            if (nft == null)
            {
                throw new Exception("NFT does not exists!");
            }
            // send NFT to receiver
            Console.WriteLine("Fill receiver");
            var receiver = Console.ReadLine();
            var res      = await account.SendNFTPayment(receiver, nft);

            Console.WriteLine("New TxId hash is: ");
            Console.WriteLine(res);
        }
Exemplo n.º 8
0
        private static async Task GetNFTDetails()
        {
            Console.WriteLine("Input NFT Tx Id Hash");
            var txid = Console.ReadLine();
            var nft  = await NFTFactory.GetNFT(NFTHelpers.TokenId, txid, 0, 0, true);

            // sign it with loaded account
            Console.WriteLine("Timestamp");
            Console.WriteLine(nft.Time);
            Console.WriteLine("Name: ");
            Console.WriteLine(nft.Name);
            Console.WriteLine("Author: ");
            Console.WriteLine(nft.Author);
            Console.WriteLine("Description: ");
            Console.WriteLine(nft.Description);
            Console.WriteLine("Link: ");
            Console.WriteLine(nft.Link);
            Console.WriteLine("Image Link: ");
            Console.WriteLine(nft.ImageLink);
        }
        public async Task FillCommontPropertiesTestCall(INFT nft)
        {
            var newnft = await NFTFactory.CloneNFT(nft);;

            newnft.ImageLink   = "";
            newnft.Name        = "";
            newnft.Link        = "";
            newnft.Description = "";
            newnft.Author      = "";

            nft.ImageLink   = "myimagelink";
            nft.Name        = "mynft";
            nft.Link        = "mylink";
            nft.Description = "mydescription";
            nft.Author      = "myauthor";

            await newnft.Fill(nft);

            Assert.Equal(nft.ImageLink, newnft.ImageLink);
            Assert.Equal(nft.Name, newnft.Name);
            Assert.Equal(nft.Link, newnft.Link);
            Assert.Equal(nft.Description, newnft.Description);
            Assert.Equal(nft.Author, newnft.Author);
        }
Exemplo n.º 10
0
        private async Task SendOrdersToCustomer()
        {
            if (NFTOrdersToDispatchDict.Count > 0)
            {
                int alltried = NFTOrdersToDispatchDict.Count;
                while (alltried > 0)
                {
                    var dtokp = NFTOrdersToDispatchDict.FirstOrDefault();
                    if (dtokp.Value != null)
                    {
                        if (NFTOrdersToDispatchDict.TryRemove(dtokp.Key, out var dto))
                        {
                            if (Orders.TryGetValue(dto.OrderKey, out var order))
                            {
                                if (order.statusclass == OrderStatus.processing)
                                {
                                    if (!VEDLDataContext.Accounts.TryGetValue(dto.OwnerMainAccount, out var account))
                                    {
                                        Console.WriteLine("Cannot process the order. NFT Owner Neblio Address is not imported to Accounts list.");
                                        return;
                                    }
                                    var nft = await NFTFactory.GetNFT("", dto.Utxo, dto.UtxoIndex, 0, true);

                                    if (nft == null)
                                    {
                                        Console.WriteLine($"Cannot process the order {dto.OrderKey} - {dto.OrderId}. Cannot load the NFT.");
                                        return;
                                    }
                                    var done = false;
                                    (bool, Dictionary <string, string>)res = (false, new Dictionary <string, string>());
                                    if (dto.IsCategory)
                                    {
                                        var check = false;
                                        order.meta_data.ForEach(m =>
                                        {
                                            if (m.key == dto.Category)
                                            {
                                                check = true;
                                            }
                                        });
                                        if (!check)
                                        {
                                            Console.WriteLine($"Order {order.id}, {order.order_key}. Sending NFT {dto.ShortHash} to Address https://explorer.nebl.io/address/{dto.NeblioCustomerAddress}");

                                            var attempts = 20;
                                            while (!done)
                                            {
                                                try
                                                {
                                                    var maxsupply = nft.DogeftInfo.Coppies;
                                                    nft.DogeftInfo = new DogeftInfo();
                                                    await nft.ClearPrices();

                                                    nft.SoldInfo = new NFT.Dto.NFTSoldInfo()
                                                    {
                                                        PaymentTxId         = dto.PaymentId,
                                                        Amount              = dto.TotalPriceForLineItem,
                                                        Currency            = "DOGE",
                                                        Platform            = "dogeft.com",
                                                        SellAsMultipleCopy  = true,
                                                        OriginalNFTTemplate = nft.Utxo,
                                                        MaxSupply           = maxsupply
                                                    };
                                                    if (string.IsNullOrEmpty(dto.OwnerSubAccount))
                                                    {
                                                        res = await account.MintMultiNFTLargeAmount(nft, dto.Quantity, dto.NeblioCustomerAddress);
                                                    }
                                                    else
                                                    {
                                                        res = await account.MultimintNFTLargeOnSubAccount(dto.OwnerSubAccount, nft, dto.Quantity, dto.NeblioCustomerAddress);
                                                    }
                                                    done = res.Item1;
                                                    if (!res.Item1)
                                                    {
                                                        Console.WriteLine("Some error during minting NFT for the customer: " + res.Item2);
                                                        await Task.Delay(5000);
                                                    }
                                                    else
                                                    {
                                                        order.meta_data.Add(new ProductMetadata()
                                                        {
                                                            key = dto.Category, value = res.Item2
                                                        });
                                                        Console.WriteLine($"Order {order.id}, {order.order_key}. NFT {dto.ShortHash} sent in tx: https://explorer.nebl.io/tx/{res.Item2}");
                                                    }
                                                }
                                                catch
                                                {
                                                    await Task.Delay(5000);
                                                }
                                                attempts--;
                                                if (attempts < 0)
                                                {
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    else if (dto.IsUnique)
                                    {
                                        var check = false;
                                        order.meta_data.ForEach(m =>
                                        {
                                            if (m.key == dto.ShortHash)
                                            {
                                                check = true;
                                            }
                                        });
                                        if (!check)
                                        {
                                            Console.WriteLine($"Order {order.id}, {order.order_key}. Sending NFT {dto.ShortHash} to Address https://explorer.nebl.io/address/{dto.NeblioCustomerAddress}");

                                            var attempts = 20;
                                            while (!done)
                                            {
                                                try
                                                {
                                                    nft.DogeftInfo = new DogeftInfo();
                                                    await nft.ClearPrices();

                                                    nft.SoldInfo = new NFT.Dto.NFTSoldInfo()
                                                    {
                                                        PaymentTxId = dto.PaymentId,
                                                        Amount      = dto.TotalPriceForLineItem,
                                                        Currency    = "DOGE",
                                                        Platform    = "dogeft.com"
                                                    };
                                                    var rs = (false, string.Empty);
                                                    if (string.IsNullOrEmpty(dto.OwnerSubAccount))
                                                    {
                                                        rs = await account.SendNFT(dto.NeblioCustomerAddress, nft);
                                                    }
                                                    else
                                                    {
                                                        rs = await account.SendNFTFromSubAccount(dto.OwnerSubAccount, dto.NeblioCustomerAddress, nft);
                                                    }
                                                    done = rs.Item1;
                                                    if (!rs.Item1)
                                                    {
                                                        Console.WriteLine("Some error during sending unique NFT for the customer: " + rs.Item2);
                                                        await Task.Delay(5000);
                                                    }
                                                    else
                                                    {
                                                        order.meta_data.Add(new ProductMetadata()
                                                        {
                                                            key = dto.ShortHash, value = rs.Item2
                                                        });
                                                        Console.WriteLine($"Order {order.id}, {order.order_key}. NFT {dto.ShortHash} sent in tx: https://explorer.nebl.io/tx/{rs.Item2}");
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    await Task.Delay(5000);
                                                }
                                                attempts--;
                                                if (attempts < 0)
                                                {
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    var complete = 0;
                                    order.line_items.ForEach(item =>
                                    {
                                        var sh  = string.Empty;
                                        var cat = string.Empty;
                                        if (Products.TryGetValue(item.product_id, out var product))
                                        {
                                            product.meta_data.ForEach(m =>
                                            {
                                                if (m.key == "ShortHash")
                                                {
                                                    sh = Convert.ToString(m.value);
                                                }
                                                if (m.key == "Category")
                                                {
                                                    cat = Convert.ToString(m.value);
                                                }
                                            });
                                            if (!string.IsNullOrEmpty(cat))
                                            {
                                                order.meta_data.ForEach(m =>
                                                {
                                                    if (m.key.Contains(cat))
                                                    {
                                                        complete++;
                                                    }
                                                });
                                            }
                                            else if (string.IsNullOrEmpty(cat) && !string.IsNullOrEmpty(sh))
                                            {
                                                order.meta_data.ForEach(m =>
                                                {
                                                    if (m.key.Contains(sh))
                                                    {
                                                        complete++;
                                                    }
                                                });
                                            }
                                        }
                                    });
                                    if (complete == order.line_items.Count)
                                    {
                                        Console.WriteLine($"Order {order.id}, {order.order_key}. Is complete. All items was sent.");
                                        order.statusclass = OrderStatus.completed;
                                    }
                                    var o = await UpdateOrder(order);

                                    order.Fill(o);
                                }
                            }
                        }
                    }
                    alltried--;
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Load all source NFTs
        /// </summary>
        /// <returns></returns>
        public async Task LoadSourceNFTs()
        {
            if (!string.IsNullOrEmpty(ProtocolNFTHash))
            {
                try
                {
                    var nft = await NFTFactory.GetNFT("", ProtocolNFTHash, 0, 0, true, true, NFTTypes.Protocol);

                    if (nft != null && !string.IsNullOrEmpty(nft.Utxo))
                    {
                        LoadedProtocolNFT = nft;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Cannot load the ProtocolNFT: {ProtocolNFTHash} in DeviceNFT: {Utxo}, exception: {ex.Message}");
                }
            }
            if (!string.IsNullOrEmpty(HWSrcNFTHash))
            {
                try
                {
                    var nft = await NFTFactory.GetNFT("", HWSrcNFTHash, 0, 0, true, true, NFTTypes.HWSrc);

                    if (nft != null && !string.IsNullOrEmpty(nft.Utxo))
                    {
                        HwSourceNFT = nft;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Cannot load the HWSrcNFT: {HWSrcNFTHash} in DeviceNFT: {Utxo}, exception: {ex.Message}");
                }
            }
            if (!string.IsNullOrEmpty(FWSrcNFTHash))
            {
                try
                {
                    var nft = await NFTFactory.GetNFT("", FWSrcNFTHash, 0, 0, true, true, NFTTypes.FWSrc);

                    if (nft != null && !string.IsNullOrEmpty(nft.Utxo))
                    {
                        FwSourceNFT = nft;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Cannot load the FWSrcNFT: {FWSrcNFTHash} in DeviceNFT: {Utxo}, exception: {ex.Message}");
                }
            }
            if (!string.IsNullOrEmpty(SWSrcNFTHash))
            {
                try
                {
                    var nft = await NFTFactory.GetNFT("", SWSrcNFTHash, 0, 0, true, true, NFTTypes.SWSrc);

                    if (nft != null && !string.IsNullOrEmpty(nft.Utxo))
                    {
                        SwSourceNFT = nft;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Cannot load the SWSrcNFT: {SWSrcNFTHash} in DeviceNFT: {Utxo}, exception: {ex.Message}");
                }
            }
            if (!string.IsNullOrEmpty(MechSrcNFTHash))
            {
                try
                {
                    var nft = await NFTFactory.GetNFT("", MechSrcNFTHash, 0, 0, true, true, NFTTypes.MechSrc);

                    if (nft != null && !string.IsNullOrEmpty(nft.Utxo))
                    {
                        MechSourceNFT = nft;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Cannot load the MechSrcNFT: {MechSrcNFTHash} in DeviceNFT: {Utxo}, exception: {ex.Message}");
                }
            }
        }