/// <summary>
        /// Load info about the Utxo
        /// </summary>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public async Task LoadInfo()
        {
            if (string.IsNullOrEmpty(Utxo.Txid))
            {
                throw new Exception("Cannot load Info. Utxo txid is empty.");
            }

            TokenInfo.Clear();
            TotalTokens = 0;
            if (Utxo.Tokens.Count > 0)
            {
                foreach (var tok in Utxo.Tokens)
                {
                    var ti = await NeblioTransactionHelpers.GetTokenMetadata(tok.TokenId);

                    if (ti != null)
                    {
                        TokenInfo.Add(ti);
                        TotalTokens += (int)tok.Amount;
                    }
                }
            }

            TxInfo = await NeblioTransactionHelpers.GetTransactionInfo(Utxo.Txid);
        }
        public async void GetSendAmount_Valid_Test()
        {
            //Arrange
            string address = "NPvfpRCmDNcJjCZvDuAB9QsFC32gVThWdh";
            var    addr    = NBitcoin.BitcoinAddress.Create(address, NeblioTransactionHelpers.Network);

            var txinfo = new GetTransactionInfoResponse()
            {
                Vin = new List <Vin>()
                {
                    new Vin()
                    {
                        Value = 10000,
                        Addr  = address
                    }
                },
                Vout = new List <Vout>()
                {
                    new Vout()
                    {
                        Value        = 5000,
                        ScriptPubKey = new ScriptPubKey()
                        {
                            Hex = addr.ScriptPubKey.ToHex()
                        }
                    }
                }
            };

            var amount = NeblioTransactionHelpers.GetSendAmount(txinfo, address);

            //Assert
            Assert.Equal(0.00005, amount);
        }
Exemple #3
0
        /// <summary>
        /// Parse Message from Doge transaction (from OP_RETURN)
        /// </summary>
        /// <param name="txinfo"></param>
        /// <returns></returns>
        public static CommonReturnTypeDto ParseDogeMessage(GetTransactionInfoResponse txinfo)
        {
            if (txinfo == null)
            {
                return(CommonReturnTypeDto.GetNew(false, "No input data provided."));
            }

            if (txinfo.Success != "success")
            {
                return(CommonReturnTypeDto.GetNew(false, "No input data provided."));
            }

            if (txinfo.Transaction.Vout == null || txinfo.Transaction.Vout.Count == 0)
            {
                return(CommonReturnTypeDto.GetNew(false, "No outputs in transaction."));
            }

            foreach (var o in txinfo.Transaction.Vout)
            {
                if (!string.IsNullOrEmpty(o.Script) && o.Script.Contains("OP_RETURN"))
                {
                    var message = o.Script.Replace("OP_RETURN ", string.Empty);
                    var bytes   = HexStringToBytes(message);
                    var msg     = Encoding.UTF8.GetString(bytes);
                    return(CommonReturnTypeDto.GetNew(true, msg));
                }
            }

            return(CommonReturnTypeDto.GetNew <string>());
        }
Exemple #4
0
        /// <summary>
        /// Parse the total sent value from Doge Tx Info. It takes all outputs together.
        /// </summary>
        /// <param name="txinfo"></param>
        /// <returns></returns>
        public static CommonReturnTypeDto ParseTotalSentValue(GetTransactionInfoResponse txinfo)
        {
            if (txinfo == null)
            {
                return(CommonReturnTypeDto.GetNew <double>());
            }

            if (txinfo.Success != "success")
            {
                return(CommonReturnTypeDto.GetNew <double>());
            }

            if (txinfo.Transaction.Vout == null || txinfo.Transaction.Vout.Count == 0)
            {
                return(CommonReturnTypeDto.GetNew <double>());
            }

            var value = 0.0;
            var vouts = txinfo.Transaction.Vout.ToList();

            for (var i = 0; i < (vouts.Count - 2); i++)
            {
                var o = vouts[i];
                if (!string.IsNullOrEmpty(o.Script) && !o.Script.Contains("OP_RETURN"))
                {
                    var v = Convert.ToDouble(o.Value, CultureInfo.InvariantCulture);
                    value += v;
                }
            }

            return(CommonReturnTypeDto.GetNew(true, value));
        }
        public async void GetSendAmount_EmptyInAndOutVectors_Test()
        {
            //Arrange
            //var transactionId = "cb2cec4a0c3c6df5bf033e7da61a58eedb9a28ff2407c11b247b35f05baff6"; //Incorrect transactionId
            string address = "NPvfpRCmDNcJjCZvDuAB9QsFC32gVThWdh";

            var emptyTransactionObject = new GetTransactionInfoResponse()
            {
                Vin  = new List <Vin>(),
                Vout = new List <Vout>()
            };

            //ACT
            double amount = NeblioTransactionHelpers.GetSendAmount(emptyTransactionObject, address);

            //Assert
            Assert.Equal(0, amount);
        }
        public async void GetSendAmount_Exception_Test()
        {
            //Arrange
            var    transactionId = "cb2cec4a0c3c6df5bf033e7da61a58eedb9a28ff2407c11b247b35f05baff6"; //Incorrect transactionId
            string address       = "NPvfpRCmDNcJjCZvDuAB9QsFC32gVThW";                               //Incorrect address
            string message       = "Cannot get amount of transaction. cannot create receiver address!";

            var transactionObject = new GetTransactionInfoResponse()
            {
                Vin  = new List <Vin>(),
                Vout = new List <Vout>()
            };

            //ACT

            //Assert
            var exception = Assert.Throws <Exception>(() => NeblioTransactionHelpers.GetSendAmount(transactionObject, address));

            Assert.Equal(message, exception.Message);
        }
Exemple #7
0
        public async void GetNeblioTransaction_Valid_Test()
        {
            NeblioTransactionHelpers.GetClient(Common.NeblioTestHelpers.Client.Object);
            NeblioTransactionHelpers.TurnOnCache = false;

            //Arrange

            #region TransactionObject

            string sampleTransactionObject = "{\"hex\":\"\",\"txid\":\"cb2cec4a0c3c6df5bf033e7da61a58eedb9a28ff2407c11b247b35f05baff6fb\",\"version\":1.0,\"locktime\":0.0,\"vin\"" +
                                             ":[{\"txid\":\"3e1fb1d4dd68fa6cfc87546d46f84700d3ec8c4ad30379aeebbefbfc846e1a0c\",\"vout\":0.0,\"scriptSig\":" +
                                             "{\"asm\":\"304402202cfb5f83b09523cbbad30c645bc7732d8f373e9db7beded80d647b5a9f7c470302203a9d3b0c8179489457d1a195449b1152dbac4a93036c041721e9043448bb693801" +
                                             " 03e295cd7e4bdc5005d185abc88b896a92aa2f32697df7255ee9a9eb4a1f121817\",\"hex\":" +
                                             "\"47304402202cfb5f83b09523cbbad30c645bc7732d8f373e9db7beded80d647b5a9f7c470302203a9d3b0c8179489457d1a195449b1152dbac4a93036c041721e9043448bb6938012103e295cd7e4bdc5005d185abc88b896a92aa2f32697df7255ee9a9eb4a1f121817\"}" +
                                             ",\"sequence\":4294967295.0,\"previousOutput\":{\"asm\":\"OP_DUP OP_HASH160 2c026bcdd04c8154d7cc73841914ffe33fcb3568 OP_EQUALVERIFY OP_CHECKSIG\"," +
                                             "\"hex\":\"76a9142c026bcdd04c8154d7cc73841914ffe33fcb356888ac\",\"reqSigs\":1.0,\"type\":\"pubkeyhash\",\"addresses\":[\"NPvfpRCmDNcJjCZvDuAB9QsFC32gVThWdh\"]}," +
                                             "\"tokens\":[{\"tokenId\":\"La58e9EeXUMx41uyfqk6kgVWAQq9yBs44nuQW8\",\"amount\":100.0,\"issueTxid\":\"49ad447c7fc9dc3b8203a42b76f80dd5b79ccaa3cb7e9723e9ac05fb4c70c32c\"," +
                                             "\"divisibility\":7.0,\"lockStatus\":true,\"aggregationPolicy\":\"aggregatable\"}],\"value\":10000.0,\"fixed\":true,\"doubleSpentTxid\":\"70db343273615e939b3a268a08f93974b13d335052059ddfa11d24f8f0533fbe\"}," +
                                             "{\"txid\":\"3e1fb1d4dd68fa6cfc87546d46f84700d3ec8c4ad30379aeebbefbfc846e1a0c\",\"vout\":2.0,\"scriptSig\":{\"asm\":" +
                                             "\"3044022058927def6c4edfeee8c69afe054762d588a18b5289a47d038805473b57aeb6bc02205f6ab7e14c62e81baab44046aea04cbbf41f56f9bbde57032289fe172fbc1ed701" +
                                             " 03e295cd7e4bdc5005d185abc88b896a92aa2f32697df7255ee9a9eb4a1f121817\",\"hex\":\"473044022058927def6c4edfeee8c69afe054762d588a18b5289a47d038805473b57aeb6bc02205f6ab7e14c62e81baab44046aea04cbbf41f56f9bbde57032289fe172fbc1ed7012103e295cd7e4bdc5005d185abc88b896a92aa2f32697df7255ee9a9eb4a1f121817\"}," +
                                             "\"sequence\":4294967295.0,\"previousOutput\":{\"asm\":\"OP_DUP OP_HASH160 2c026bcdd04c8154d7cc73841914ffe33fcb3568 OP_EQUALVERIFY OP_CHECKSIG\",\"hex\":\"76a9142c026bcdd04c8154d7cc73841914ffe33fcb356888ac\",\"reqSigs\":1.0,\"type\":\"pubkeyhash\",\"addresses\":[\"NPvfpRCmDNcJjCZvDuAB9QsFC32gVThWdh\"]}," +
                                             "\"tokens\":[],\"value\":5000000.0,\"fixed\":true,\"doubleSpentTxid\":\"70db343273615e939b3a268a08f93974b13d335052059ddfa11d24f8f0533fbe\"}],\"vout\":[{\"value\":10000.0,\"n\":0.0,\"scriptPubKey\":{\"asm\":\"OP_DUP OP_HASH160 2c026bcdd04c8154d7cc73841914ffe33fcb3568 OP_EQUALVERIFY OP_CHECKSIG\"" +
                                             ",\"hex\":\"76a9142c026bcdd04c8154d7cc73841914ffe33fcb356888ac\",\"reqSigs\":1.0,\"type\":\"pubkeyhash\",\"addresses\":[\"NPvfpRCmDNcJjCZvDuAB9QsFC32gVThWdh\"]},\"tokens\":[{\"tokenId\":\"La58e9EeXUMx41uyfqk6kgVWAQq9yBs44nuQW8\",\"amount\":1.0,\"issueTxid\":\"49ad447c7fc9dc3b8203a42b76f80dd5b79ccaa3cb7e9723e9ac05fb4c70c32c\"" +
                                             ",\"divisibility\":7.0,\"lockStatus\":true,\"aggregationPolicy\":\"aggregatable\"}],\"used\":false,\"blockheight\":3627327.0,\"usedBlockheight\":null,\"usedTxid\":null},{\"value\":10000.0,\"n\":1.0,\"scriptPubKey\":{\"asm\":\"OP_DUP OP_HASH160 2c026bcdd04c8154d7cc73841914ffe33fcb3568 OP_EQUALVERIFY OP_CHECKSIG\"," +
                                             "\"hex\":\"76a9142c026bcdd04c8154d7cc73841914ffe33fcb356888ac\",\"reqSigs\":1.0,\"type\":\"pubkeyhash\",\"addresses\":[\"NPvfpRCmDNcJjCZvDuAB9QsFC32gVThWdh\"]},\"tokens\":[{\"tokenId\":\"La58e9EeXUMx41uyfqk6kgVWAQq9yBs44nuQW8\",\"amount\":1.0,\"issueTxid\":\"49ad447c7fc9dc3b8203a42b76f80dd5b79ccaa3cb7e9723e9ac05fb4c70c32c\"" +
                                             ",\"divisibility\":7.0,\"lockStatus\":true,\"aggregationPolicy\":\"aggregatable\"}],\"used\":false,\"blockheight\":3627327.0,\"usedBlockheight\":null,\"usedTxid\":null},{\"value\":10000.0,\"n\":2.0,\"scriptPubKey\":{\"asm\":\"OP_DUP OP_HASH160 2c026bcdd04c8154d7cc73841914ffe33fcb3568 OP_EQUALVERIFY OP_CHECKSIG\",\"hex\"" +
                                             ":\"76a9142c026bcdd04c8154d7cc73841914ffe33fcb356888ac\",\"reqSigs\":1.0,\"type\":\"pubkeyhash\",\"addresses\":[\"NPvfpRCmDNcJjCZvDuAB9QsFC32gVThWdh\"]},\"tokens\":[{\"tokenId\":\"La58e9EeXUMx41uyfqk6kgVWAQq9yBs44nuQW8\",\"amount\":1.0,\"issueTxid\":\"49ad447c7fc9dc3b8203a42b76f80dd5b79ccaa3cb7e9723e9ac05fb4c70c32c\"," +
                                             "\"divisibility\":7.0,\"lockStatus\":true,\"aggregationPolicy\":\"aggregatable\"}],\"used\":false,\"blockheight\":3627327.0,\"usedBlockheight\":null,\"usedTxid\":null},{\"value\":10000.0,\"n\":3.0,\"scriptPubKey\":{\"asm\":\"\",\"hex\":\"\",\"type\":\"nulldata\"},\"tokens\":[],\"used\":false,\"blockheight\":3627327.0," +
                                             "\"usedBlockheight\":null,\"usedTxid\":null},{\"value\":4930000.0,\"n\":4.0,\"scriptPubKey\":{\"asm\":\"OP_DUP OP_HASH160 2c026bcdd04c8154d7cc73841914ffe33fcb3568 OP_EQUALVERIFY OP_CHECKSIG\",\"hex\":\"76a9142c026bcdd04c8154d7cc73841914ffe33fcb356888ac\",\"reqSigs\":1.0,\"type\":\"pubkeyhash\",\"addresses\"" +
                                             ":[\"NPvfpRCmDNcJjCZvDuAB9QsFC32gVThWdh\"]},\"tokens\":[],\"used\":false,\"blockheight\":3627327.0,\"usedBlockheight\":null,\"usedTxid\":null},{\"value\":10000.0,\"n\":5.0,\"scriptPubKey\":{\"asm\":\"OP_DUP OP_HASH160 2c026bcdd04c8154d7cc73841914ffe33fcb3568 OP_EQUALVERIFY OP_CHECKSIG\",\"hex\":\"76a9142c026bcdd04c8154d7cc73841914ffe33fcb356888ac\"" +
                                             ",\"reqSigs\":1.0,\"type\":\"pubkeyhash\",\"addresses\":[\"NPvfpRCmDNcJjCZvDuAB9QsFC32gVThWdh\"]},\"tokens\":[{\"tokenId\":\"La58e9EeXUMx41uyfqk6kgVWAQq9yBs44nuQW8\",\"amount\":97.0,\"issueTxid\":\"49ad447c7fc9dc3b8203a42b76f80dd5b79ccaa3cb7e9723e9ac05fb4c70c32c\",\"divisibility\":7.0,\"lockStatus\":true," +
                                             "\"aggregationPolicy\":\"aggregatable\"}],\"used\":false,\"blockheight\":3627327.0,\"usedBlockheight\":null,\"usedTxid\":null}],\"blocktime\":1640788684000.0,\"blockheight\":3627327.0,\"totalsent\":4980000.0,\"fee\":30000.0,\"blockhash\":\"45e0f23add155af31ffcc06304384406212465222782194866654ccf359b7ddd\",\"time\"" +
                                             ":1640788684000.0,\"confirmations\":65021.0,\"doubleSpent\":true,\"tries\":0}";

            #endregion

            GetTransactionInfoResponse transactionObject = Newtonsoft.Json.JsonConvert.DeserializeObject <GetTransactionInfoResponse>(sampleTransactionObject);

            var res = Common.FakeDataGenerator.GetKeyAndAddress();

            string address = res.Item1.ToString();
            string key     = res.Item2.ToString();

            GetAddressInfoResponse addressObject = Common.FakeDataGenerator.GetAddressWithNeblUtxos(address, 10, 1000000);

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

            Common.NeblioTestHelpers.Client.Setup(x => x.GetAddressInfoAsync(It.IsAny <string>())).ReturnsAsync(addressObject);
            Common.NeblioTestHelpers.Client.Setup(x => x.GetTransactionInfoAsync(It.IsAny <string>())).ReturnsAsync(transactionObject);

            var AccountKey = new EncryptionKey(key);

            var transaction = NeblioTransactionHelpers.GetNeblioTransactionObject(sendTxData, AccountKey, addressObject.Utxos);

            var inputCount  = transaction.Inputs.Count();
            var outputCount = transaction.Outputs.Count();

            Assert.Equal(10, inputCount);
            Assert.Equal(3, outputCount);
        }