Esempio n. 1
0
        public void NotEqualTest()
        {
            Txid txid1 = new Txid();
            Txid txid2 = new Txid("0000000000000000000000000000000000000000000000000000000000000001");

            Assert.True((txid1 != txid2));

            ByteData data = new ByteData("773420c0ded41a55b1f1205cfb632f08f3f911a53e7338a0dac73ec6cbe3ca471907434d046185abedc5afddc2761a642bccc70af6d22b46394f1d04a8b24226");

            Assert.False(txid1.Equals(data));

            OutPoint outpoint1 = new OutPoint();

            Assert.False(outpoint1.Equals(data));
        }
Esempio n. 2
0
        public void GetTxInfoTest()
        {
            ExtPrivkey privkey = new ExtPrivkey("xprv9zt1onyw8BdEf7SQ6wUVH3bQQdGD9iy9QzXveQQRhX7i5iUN7jZgLbqFEe491LfjozztYa6bJAGZ65GmDCNcbjMdjZcgmdisPJwVjcfcDhV");
            Address    addr1   = new Address(privkey.DerivePubkey(1).GetPubkey(), CfdAddressType.P2wpkh, CfdNetworkType.Regtest);
            Address    addr2   = new Address(privkey.DerivePubkey(2).GetPubkey(), CfdAddressType.P2wpkh, CfdNetworkType.Regtest);
            Address    addr3   = new Address(privkey.DerivePubkey(3).GetPubkey(), CfdAddressType.P2wpkh, CfdNetworkType.Regtest);

            OutPoint outpoint1 = new OutPoint("0000000000000000000000000000000000000000000000000000000000000001", 2);
            OutPoint outpoint2 = new OutPoint("0000000000000000000000000000000000000000000000000000000000000001", 3);
            var      txins     = new[] {
                new TxIn(outpoint1),
                new TxIn(outpoint2),
            };
            var txouts = new[] {
                new TxOut(10000, addr1.GetLockingScript()),
                new TxOut(10000, addr2.GetLockingScript()),
            };
            Transaction tx = new Transaction("02000000000000000000", txins, txouts);

            tx.AddTxOut(50000, addr3);
            output.WriteLine("tx:\n" + tx.ToHexString());
            Assert.Equal("020000000201000000000000000000000000000000000000000000000000000000000000000200000000ffffffff01000000000000000000000000000000000000000000000000000000000000000300000000ffffffff0310270000000000001600148b756cbd98f4f55e985f80437a619d47f0732a941027000000000000160014c0a3dd0b7c1b3281be91112e16ce931dbac2a97950c3000000000000160014ad3abd3c325e40e20d89aa054dd980b97494f16c00000000",
                         tx.ToHexString());

            Privkey           privkey1    = privkey.DerivePrivkey(11).GetPrivkey();
            SignatureHashType sighashType = new SignatureHashType(CfdSighashType.All, false);

            tx.AddSignWithPrivkeySimple(outpoint1, CfdHashType.P2wpkh, privkey1, 50000, sighashType);
            // output.WriteLine("tx:\n" + tx.ToHexString());
            Assert.Equal("0200000000010201000000000000000000000000000000000000000000000000000000000000000200000000ffffffff01000000000000000000000000000000000000000000000000000000000000000300000000ffffffff0310270000000000001600148b756cbd98f4f55e985f80437a619d47f0732a941027000000000000160014c0a3dd0b7c1b3281be91112e16ce931dbac2a97950c3000000000000160014ad3abd3c325e40e20d89aa054dd980b97494f16c02473044022034db802aad655cd9be589075fc8ef325b6ffb8c24e5b27eb87bde8ad38f5fd7a0220364c916c8e8fc0adf714d7148cd1c6dc6f3e67d55471e57233b1870c65ec2727012103782f0ea892d7000e5f0f82b6ff283382a76500137a542bb0a616530094a8f54c0000000000",
                         tx.ToHexString());

            Txid txid = tx.GetTxid();

            output.WriteLine("txid: " + txid.ToHexString());
            Assert.Equal("67e1878d1621e77e166bed9d726bff27b2afcde9eb3dbb1ae3088d0387f40be4",
                         txid.ToHexString());
            Txid wtxid = tx.GetWtxid();

            output.WriteLine("wtxid: " + wtxid.ToHexString());
            Assert.Equal("24c66461b4b38c750fa4528d0cf3aea9a13d3156c0a73cfd6fca6958523b97f7",
                         wtxid.ToHexString());
            Assert.Equal((uint)295, tx.GetSize());
            Assert.Equal((uint)213, tx.GetVsize());
            Assert.Equal((uint)850, tx.GetWeight());
            Assert.Equal((uint)2, tx.GetVersion());
            Assert.Equal((uint)0, tx.GetLockTime());

            Assert.Equal((uint)2, tx.GetTxInCount());
            Assert.Equal((uint)3, tx.GetTxOutCount());
            Assert.Equal((uint)1, tx.GetTxInIndex(outpoint2));
            Assert.Equal((uint)2, tx.GetTxOutIndex(addr3));
            Assert.Equal((uint)1, tx.GetTxOutIndex(addr2.GetLockingScript()));

            Assert.True(outpoint2.Equals(tx.GetTxIn(outpoint2).OutPoint));
            Assert.True(outpoint2.Equals(tx.GetTxIn(1).OutPoint));
            Assert.True(outpoint2.Equals(tx.GetTxInList()[1].OutPoint));

            Assert.True(addr2.GetLockingScript().Equals(tx.GetTxOut(addr2).ScriptPubkey));
            Assert.True(addr2.GetLockingScript().Equals(tx.GetTxOut(addr2.GetLockingScript()).ScriptPubkey));
            Assert.True(addr2.GetLockingScript().Equals(tx.GetTxOut(1).ScriptPubkey));
            Assert.True(addr2.GetLockingScript().Equals(tx.GetTxOutList()[1].ScriptPubkey));
        }