Beispiel #1
0
        public void SendNeblioTransaction_CannotSignTransaction_Error_Test()
        {
            //Arrange

            var res = Common.FakeDataGenerator.GetKeyAndAddress();

            string address    = res.Item1.ToString();
            string key        = res.Item2.ToString();
            var    AccountKey = new EncryptionKey(key);

            // to load to the API which are requested during sign procedure - wrong not spendable coins
            GetAddressInfoResponse addressObject = Common.FakeDataGenerator.GetAddressWithNeblUtxos(address, 10, 1000000);
            // to load to the Send tx command as input utxos - fake actual spendable utxos on the address
            GetAddressInfoResponse addressObject1 = Common.FakeDataGenerator.GetAddressWithNeblUtxos(address, 10, 1000000);

            SendTxData sendTxData = new SendTxData()
            {
                ReceiverAddress = address,
                SenderAddress   = address,
                Amount          = 100,
                CustomMessage   = "test",
                Password        = ""
            };

            var k    = NeblioTransactionHelpers.GetAddressAndKey(AccountKey);
            var key1 = k.Item2;

            string message     = "Exception during signing tx";
            var    transaction = NeblioTransactionHelpers.GetNeblioTransactionObject(sendTxData, AccountKey, addressObject1.Utxos);

            var exception = Assert.ThrowsAsync <Exception>(async() => await NeblioTransactionHelpers.SignAndBroadcastTransaction(transaction, key1));

            Assert.Contains(message, exception.Result.Message);
        }
Beispiel #2
0
        /// <summary>
        /// This function will change Coruzant Post NFT
        /// You can use this function for sending the NFT when you will fill receiver parameter
        /// </summary>
        /// <param name="address">sender address</param>
        /// <param name="ekey">Encryption Key object of the address</param>
        /// <param name="NFT">Input NFT object with data to save to metadata. Must contain Utxo hash</param>
        /// <param name="nutxos">List of spendable neblio utxos if you have it loaded.</param>
        /// <param name="receiver">Fill when you want to send NFT to another address</param>
        /// <returns>New Tx Id Hash</returns>
        public static async Task <string> ChangeCoruzantPostNFT(string address, EncryptionKey ekey, INFT NFT, ICollection <Utxos> nutxos, NBitcoin.BitcoinSecret secret, string receiver = "")
        {
            var cnft = NFT as CoruzantArticleNFT;
            // create token metadata
            var metadata = new Dictionary <string, string>();

            metadata.Add("NFT", "true");
            metadata.Add("Type", "NFT CoruzantPost");
            metadata.Add("Name", NFT.Name);
            metadata.Add("Author", NFT.Author);
            metadata.Add("AuthorProfileUtxo", cnft.AuthorProfileUtxo);
            metadata.Add("Description", NFT.Description);
            metadata.Add("Image", NFT.ImageLink);
            metadata.Add("Link", NFT.Link);
            metadata.Add("Tags", NFT.Tags);
            metadata.Add("FullPostLink", cnft.FullPostLink);
            metadata.Add("LastComment", cnft.LastComment);
            metadata.Add("LastCommentBy", cnft.LastCommentBy);
            if (NFT.Price > 0)
            {
                metadata.Add("Price", NFT.Price.ToString(CultureInfo.InvariantCulture));
            }

            var rec = address;

            if (!string.IsNullOrEmpty(receiver))
            {
                rec = receiver;
            }

            // fill input data for sending tx
            var dto = new SendTokenTxData() // please check SendTokenTxData for another properties such as specify source UTXOs
            {
                Id       = CoruzantTokenId, // id of token
                Metadata = metadata,
                Amount   = 1,
                sendUtxo = new List <string>()
                {
                    NFT.Utxo
                },
                SenderAddress   = address,
                ReceiverAddress = rec
            };

            try
            {
                // send tx

                var transaction = await NeblioTransactionHelpers.SendNFTTokenAsync(dto, nutxos);

                var rtxid = await NeblioTransactionHelpers.SignAndBroadcastTransaction(transaction, secret);

                if (rtxid != null)
                {
                    return(rtxid);
                }
                else
                {
                    return(string.Empty);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }