Rowan Briggs
Lab 1: Scrooge Coin
Background: Coursera, Week 1 of Cryptocurrency class
Java I and II understanding preferred
Overview: Bitcoin has been gaining a lot of interest as of late. For this lab, we will be
creating a "Bitcoin." Specifically, we will be creating the ledger. The bitcoin
will be given to you in the transaction class. As was covered in the course, a
bitcoin needs to be able to have an input, output, and a signature. The ledger
needs to be able to verify a signature and check that the bitcoin is not being
double spent (there is enough bitcoin to pay the amount).
Material: Go to the following link to download the other classes that will be needed to
complete this lab. You will also need java in order to complete this lab. I
recommend using a program like Eclipse, but feel free to use any program that
you like.
Procedure:
Step 1:
Upload the precoded programs. This includes: [Link], [Link],
[Link], and [Link].
Step 2: Download the [Link] sample program.
Step 3: You will need the following imports:
import [Link];
import [Link];
import [Link];
Step 4:
Here is the constructor. You will need to refer to the other java classes.
public TxHandler (UTXOPool utxoPool){
/** Creates a public ledger whose current UTXOPool (collection of unspent
* transaction outputs) is utxoPool. This should make a defensive copy of
* utxoPool by using the UTXOPool(UTXOPool uPool) constructor.
*/
}
Step 5:
Let's work on the TxHandler method:
What are the 5 things that the ledger will need to know from each Transaction?
1. All ______ claimed by tx are in the current UTXO pool
2. All ______ on each _____ of tx are valid.
3. No UTXO is claimed _____ times by tx
4. ALl tx's _____ values are _____ negative.
5. The sum of tx's _____ values are greater than or equal to the sum of its output values;
and _____ otherwise.
/** Returns true if
//1. All ______ claimed by tx are in the current UTXO pool
//2. All ______ on each _____ of tx are valid.
//3. No UTXO is claimed _____ times by tx
//4. ALl tx's _____ values are _____ negative.
//5. The sum of tx's _____ values is greater than or equal to the sum of its output
//values; and _____ otherwise.
*/
public boolean isValidTx (Transaction tx) {
//code
}
This method will call on other methods to check if these rules are followed. If these rules
are followed, then it will return ____ and if they are not followed, it will return _____.
Step 6:
Let’s write a method to check for the first 3 rules.
private boolean validateRuleNumber123(Transaction tx) {
HashMap<UTXO, Boolean > usedUTXO = new HashMap<UTXO, Boolean>();
for(int i = 0; i < [Link](); i++){
[Link] input = [Link](i);
if (input == null) {
return false;
}
UTXO utxo = new UTXO([Link], [Link]);
//checks rule 1
//code
//checks rule 2
//code
//checks rule 3
//code
[Link](utxo, true);
//saving this value for rule 5
[Link] += [Link];
}
//return some value
}
Step 7:
Now, we should validate rules 4 and 5.
private boolean validateRuleNumber45(Transaction tx) {
double outputSum = 0;
for (int i = 0; i < [Link](); i++) {
[Link] output = [Link](i);
if (output == null) {
//return what value?
}
if ([Link] < 0) {
//return what value?
}
outputSum += [Link];
}
return [Link] >= outputSum;
}
Step 8:
Finally, let’s complete the last method.
/** Handles each epoch by receiving an unordered array of proposed
* transactions, checking each transaction for correctness,
* returning a mutually valid array of accepted transactions,
* and updating the current UTXO pool as appropriate.
*/
public Transaction[] handleTxs (Transaction[] possibleTxs){
//code
}