Esempio n. 1
0
 private async Task InsertTXAsync()
 {
     var txList = new List <Tx>()
     {
         CreateNewTx(txC0Hash, txC0Hex, false, null, true)
     };
     await TxRepositoryPostgres.InsertTxsAsync(txList, false);
 }
        public async Task SubmitAndCheckMultipleDSRead()
        {
            var address = BitcoinAddress.Create(testAddress, Network.RegTest);

            var tx1 = BCash.Instance.Regtest.CreateTransaction();

            tx1.Inputs.Add(new TxIn(new OutPoint(new uint256(txC1Hash), 0)));
            tx1.Inputs.Add(new TxIn(new OutPoint(new uint256(txC1Hash), 1)));
            tx1.Outputs.Add(new TxOut(new Money(1000L), address));

            var tx2 = BCash.Instance.Regtest.CreateTransaction();

            tx2.Inputs.Add(new TxIn(new OutPoint(new uint256(txC2Hash), 0)));
            tx2.Inputs.Add(new TxIn(new OutPoint(new uint256(txC2Hash), 1)));
            tx2.Outputs.Add(new TxOut(new Money(100L), address));


            var txList = new List <Tx>()
            {
                CreateNewTx(tx1.GetHash().ToString(), tx1.ToHex(), false, null, true),
                CreateNewTx(tx2.GetHash().ToString(), tx2.ToHex(), false, null, true)
            };
            await TxRepositoryPostgres.InsertTxsAsync(txList, false);

            var txs = await TxRepositoryPostgres.GetTxsForDSCheckAsync(new List <byte[]> {
                tx1.GetHash().ToBytes(), tx2.GetHash().ToBytes()
            }, true);

            Assert.AreEqual(2, txs.Count());
            Assert.AreEqual(2, txs.First().TxIn.Count);
            Assert.AreEqual(2, txs.Last().TxIn.Count);

            var readTx1 = txs.SingleOrDefault(x => x.TxIn.Any(y => new uint256(y.PrevTxId) == new uint256(txC1Hash)));

            Assert.IsNotNull(readTx1);
            Assert.AreEqual(0, readTx1.OrderderInputs.First().N);
            Assert.AreEqual(1, readTx1.OrderderInputs.Last().N);

            var readTx2 = txs.SingleOrDefault(x => x.TxIn.Any(y => new uint256(y.PrevTxId) == new uint256(txC2Hash)));

            Assert.IsNotNull(readTx2);
            Assert.AreEqual(0, readTx2.OrderderInputs.First().N);
            Assert.AreEqual(1, readTx2.OrderderInputs.Last().N);
        }
        protected async Task <List <Tx> > CreateAndInsertTxAsync(bool merkleProof, bool dsCheck, int?limit = null)
        {
            string[] hashes = new string[] { Tx1Hash, Tx2Hash, Tx3Hash, Tx4Hash, Tx5Hash };
            string[] hexes  = new string[] { Tx1Hex, Tx2Hex, Tx3Hex, Tx4Hex, Tx5Hex };
            if (limit == null)
            {
                limit = hashes.Length;
            }
            List <Tx> txList = new List <Tx>();

            for (int i = 0; i < limit; i++)
            {
                txList.Add(CreateNewTx(hashes[i], hexes[i], merkleProof, dsCheck));
            }

            await TxRepositoryPostgres.InsertTxsAsync(txList);

            return(txList);
        }