@@ -47,8 +47,10 @@ int main() {
4747 std::cout << " \n Creating first group of transactions..." << std::endl;
4848
4949 // Alice sends 10 coins to Bob
50+
51+ std::cout << " \n Alice sends 10 coins to Bob" << std::endl;
5052 Transaction tx1 (alicePublicKey, bobPublicKey, 10.0 );
51- std::cout << " tx1 : " << tx1.getTransactionId () << std::endl;
53+ std::cout << " \n tx1 : " << tx1.getTransactionId () << std::endl;
5254 auto aliceUTXOs = blockchain.getUTXOsForAddress (alicePublicKey);
5355 std::cout << " aliceUTXOs: " << aliceUTXOs.size () << std::endl;
5456 std::string tx1Signature = aliceWallet->sign (tx1.getTransactionId ());
@@ -59,29 +61,31 @@ int main() {
5961 }
6062 tx1.addOutput (TransactionOutput (10.0 , bobPublicKey));
6163 if (blockchain.getBalance (alicePublicKey) > 10.0 ) {
62- std::cout << " addOutput alicePublicKey: " << blockchain.getBalance (alicePublicKey) - 10.0 << std::endl;
64+ std::cout << " addOutput alicePublicKey balance : " << blockchain.getBalance (alicePublicKey) - 10.0 << std::endl;
6365 tx1.addOutput (TransactionOutput (blockchain.getBalance (alicePublicKey) - 10.0 , alicePublicKey));
6466 }
6567
6668 // Bob sends 5 coins to Charlie
69+ std::cout << " \n Bob sends 5 coins to Charlie" << std::endl;
6770 Transaction tx2 (bobPublicKey, charliePublicKey, 5.0 );
68- std::cout << " tx2 : " << tx2.getTransactionId () << std::endl;
71+ std::cout << " \n tx2 : " << tx2.getTransactionId () << std::endl;
6972 auto bobUTXOs = blockchain.getUTXOsForAddress (bobPublicKey);
7073 std::cout << " bobUTXOs: " << bobUTXOs.size () << std::endl;
7174 std::string tx2Signature = bobWallet->sign (tx2.getTransactionId ());
7275 tx2.setSignature (tx2Signature);
7376 for (const auto & utxo : bobUTXOs) {
74- std::cout << " addInput utxo: " << utxo.getTxId () << " , " << utxo.getOutputIndex () << std::endl;
7577 tx2.addInput (TransactionInput (utxo.getTxId (), utxo.getOutputIndex (), tx2Signature));
7678 }
7779 tx2.addOutput (TransactionOutput (5.0 , charliePublicKey));
7880 if (blockchain.getBalance (bobPublicKey) > 5.0 ) {
79- std::cout << " addOutput bobPublicKey: " << blockchain.getBalance (bobPublicKey) - 5.0 << std::endl;
81+ std::cout << " addOutput bobPublicKey balance : " << blockchain.getBalance (bobPublicKey) - 5.0 << std::endl;
8082 tx2.addOutput (TransactionOutput (blockchain.getBalance (bobPublicKey) - 5.0 , bobPublicKey));
8183 }
8284
8385 // Charlie sends 2.5 coins to Alice
86+ std::cout << " \n Charlie sends 2.5 coins to Alice" << std::endl;
8487 Transaction tx3 (charliePublicKey, alicePublicKey, 2.5 );
88+ std::cout << " \n tx3: " << tx3.getTransactionId () << std::endl;
8589 auto charlieUTXOs = blockchain.getUTXOsForAddress (charliePublicKey);
8690 std::cout << " charlieUTXOs: " << charlieUTXOs.size () << std::endl;
8791 std::string tx3Signature = charlieWallet->sign (tx3.getTransactionId ());
@@ -92,19 +96,20 @@ int main() {
9296 }
9397 tx3.addOutput (TransactionOutput (2.5 , alicePublicKey));
9498 if (blockchain.getBalance (charliePublicKey) > 2.5 ) {
95- std::cout << " addOutput charliePublicKey: " << blockchain.getBalance (charliePublicKey) - 2.5 << std::endl;
99+ std::cout << " addOutput charliePublicKey balance : " << blockchain.getBalance (charliePublicKey) - 2.5 << std::endl;
96100 tx3.addOutput (TransactionOutput (blockchain.getBalance (charliePublicKey) - 2.5 , charliePublicKey));
97101 }
98102
99103 // Add transactions to pool
100- std::cout << " addTransactionToPool tx1" << std::endl;
104+ std::cout << " \n addTransactionToPool tx1" << std::endl;
101105 blockchain.addTransactionToPool (tx1);
102- std::cout << " addTransactionToPool tx2" << std::endl;
106+ std::cout << " \n addTransactionToPool tx2" << std::endl;
103107 blockchain.addTransactionToPool (tx2);
104- std::cout << " addTransactionToPool tx3" << std::endl;
108+ std::cout << " \n addTransactionToPool tx3" << std::endl;
105109 blockchain.addTransactionToPool (tx3);
106110
107111 // Add block (includes transactions from pool)
112+ std::cout << " \n main: addBlock" << std::endl;
108113 blockchain.addBlock ({});
109114
110115 // Print balances
@@ -117,34 +122,49 @@ int main() {
117122 std::cout << " \n Creating second group of transactions..." << std::endl;
118123
119124 // Alice sends 7.5 coins to Charlie
125+ std::cout << " \n Alice sends 7.5 coins to Charlie" << std::endl;
120126 Transaction tx4 (alicePublicKey, charliePublicKey, 7.5 );
127+ std::cout << " \n tx4: " << tx4.getTransactionId () << std::endl;
121128 aliceUTXOs = blockchain.getUTXOsForAddress (alicePublicKey);
129+ std::cout << " aliceUTXOs: " << aliceUTXOs.size () << std::endl;
122130 std::string tx4Signature = aliceWallet->sign (tx4.getTransactionId ());
131+ tx4.setSignature (tx4Signature);
123132 for (const auto & utxo : aliceUTXOs) {
133+ std::cout << " addInput utxo: " << utxo.getTxId () << " , " << utxo.getOutputIndex () << std::endl;
124134 tx4.addInput (TransactionInput (utxo.getTxId (), utxo.getOutputIndex (), tx4Signature));
125135 }
126136 tx4.addOutput (TransactionOutput (7.5 , charliePublicKey));
127137 if (blockchain.getBalance (alicePublicKey) > 7.5 ) {
138+ std::cout << " addOutput alicePublicKey balance: " << blockchain.getBalance (alicePublicKey) - 7.5 << std::endl;
128139 tx4.addOutput (TransactionOutput (blockchain.getBalance (alicePublicKey) - 7.5 , alicePublicKey));
129140 }
130141
131142 // Charlie sends 3 coins to Bob
143+ std::cout << " \n Charlie sends 3 coins to Bob" << std::endl;
132144 Transaction tx5 (charliePublicKey, bobPublicKey, 3.0 );
145+ std::cout << " \n tx5: " << tx5.getTransactionId () << std::endl;
133146 charlieUTXOs = blockchain.getUTXOsForAddress (charliePublicKey);
147+ std::cout << " charlieUTXOs: " << charlieUTXOs.size () << std::endl;
134148 std::string tx5Signature = charlieWallet->sign (tx5.getTransactionId ());
149+ tx5.setSignature (tx5Signature);
135150 for (const auto & utxo : charlieUTXOs) {
151+ std::cout << " addInput utxo: " << utxo.getTxId () << " , " << utxo.getOutputIndex () << std::endl;
136152 tx5.addInput (TransactionInput (utxo.getTxId (), utxo.getOutputIndex (), tx5Signature));
137153 }
138154 tx5.addOutput (TransactionOutput (3.0 , bobPublicKey));
139155 if (blockchain.getBalance (charliePublicKey) > 3.0 ) {
156+ std::cout << " addOutput charliePublicKey balance: " << blockchain.getBalance (charliePublicKey) - 3.0 << std::endl;
140157 tx5.addOutput (TransactionOutput (blockchain.getBalance (charliePublicKey) - 3.0 , charliePublicKey));
141158 }
142159
143160 // Add transactions to pool
161+ std::cout << " \n addTransactionToPool tx4" << std::endl;
144162 blockchain.addTransactionToPool (tx4);
163+ std::cout << " \n addTransactionToPool tx5" << std::endl;
145164 blockchain.addTransactionToPool (tx5);
146165
147166 // Add block
167+ std::cout << " \n main: addBlock" << std::endl;
148168 blockchain.addBlock ({});
149169
150170 // Print balances
0 commit comments