Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/org/dilithium/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.dilithium.config.NodeSettings;
import org.dilithium.core.Node;
import org.dilithium.core.Wallet;
import org.dilithium.db.Context;
import org.dilithium.db.StorageContext;
import org.dilithium.util.KeyUtil;
import org.dilithium.util.Log;

Expand All @@ -38,7 +38,7 @@ public class Start {

public static NodeSettings config;
public static Wallet localWallet;
public static Context localContext;
public static StorageContext localContext;
public static Node localNode;

/* This method is run when the program first starts */
Expand All @@ -56,7 +56,7 @@ public static void main(String[] args) {

/* Get local database and storage context
* will contain the local state of blocks and accounts*/
localContext = new Context();
localContext = new StorageContext();
Log.log(Level.INFO, "\nLocalContext: " + localContext.toString());

/* Setup temp local wallet */
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/dilithium/cli/commands/NodeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.dilithium.Start;
import org.dilithium.cli.Commander;
import org.dilithium.core.Block;
import org.dilithium.db.Context;
import org.dilithium.db.StorageContext;
import org.dilithium.serialization.Json;

/**
Expand Down Expand Up @@ -76,9 +76,9 @@ public void run(String[] args) {

Commander.CommanderPrint("Fetching block...");
Commander.CommanderPrint("Searching for block with index: " + indexString);
Context context = Start.localNode.getContext();
StorageContext storageContext = Start.localNode.getStorageContext();
long index = Long.parseLong(indexString);
Block block = context.getBlock(index);
Block block = storageContext.getBlock(index);

if(block == null) {
Commander.CommanderPrint("ERROR ! block not found.");
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/dilithium/core/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
import org.dilithium.Start;
import org.dilithium.core.axiom.Axiom;
import org.dilithium.core.axiom.AxiomManager;
import org.dilithium.db.Context;
import org.dilithium.db.StorageContext;
import org.dilithium.serialization.ParcelData;
import org.dilithium.serialization.Serializer;
import org.dilithium.util.ByteUtil;
import org.dilithium.util.HashUtil;
import org.dilithium.util.JsonUtil;

/**
* This class
Expand All @@ -41,7 +42,7 @@ public class Block {
private boolean parsed = false;
private byte[] axiomID;
private Axiom axiom;
private Context context;
private StorageContext context;

public Block(BlockHeader header, Axiom axiom, List<byte[]> transactions){
this.header = header;
Expand Down Expand Up @@ -139,7 +140,11 @@ public byte[] getEncoded(){
});
return encodedBlock;
}


public String getJson(){
return JsonUtil.getJson(this);
}

@Override
public String toString(){
return header.toString();
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/dilithium/core/BlockHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.dilithium.serialization.Serializer;
import org.dilithium.util.ByteUtil;
import org.dilithium.util.Encoding;
import org.dilithium.util.JsonUtil;

/**
* This class
Expand Down Expand Up @@ -246,7 +247,9 @@ public byte[] getEncoded(){
//System.out.println("header parcel length: " + parcel.length);
return parcel;
}

public String getJson(){
return JsonUtil.getJson(this);
}
@Override
public String toString(){
return "block-header: {\n" +
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/dilithium/core/BlockProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import java.math.BigInteger;
import org.dilithium.core.axiom.Axiom;
import org.dilithium.db.Context;
import org.dilithium.db.StorageContext;
import org.dilithium.util.Log;
import java.util.logging.Level;
import org.dilithium.util.ByteArrayKey;
Expand All @@ -21,11 +21,11 @@
*/
public class BlockProcessor {

public boolean addBlock(byte[] blockParcel, Context context){
public boolean addBlock(byte[] blockParcel, StorageContext context){
return addBlock(new Block(blockParcel), context);
}

public boolean addBlock(Block block, Context context){
public boolean addBlock(Block block, StorageContext context){
BlockHeader header = block.header;

//get the axiom from the block;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/dilithium/core/Miner.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
import java.util.logging.Level;

import org.bouncycastle.util.encoders.Hex;
import org.dilithium.cli.Commander;
import org.dilithium.core.axiom.Axiom;
import org.dilithium.core.axiom.AxiomManager;
import org.dilithium.db.Context;
import org.dilithium.db.StorageContext;
import org.dilithium.util.ByteUtil;
import org.dilithium.util.Log;

Expand All @@ -35,7 +34,7 @@
*/
public class Miner {

public Context context;
public StorageContext storageContext;

private Block block;

Expand Down
36 changes: 18 additions & 18 deletions src/main/java/org/dilithium/core/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@
import org.dilithium.config.NodeSettings;
import org.dilithium.core.axiom.Axiom;
import org.dilithium.core.genesis.GenesisBlock;
import org.dilithium.db.Context;
import org.dilithium.db.StorageContext;
import org.dilithium.networking.Peer2Peer;
import org.dilithium.util.Encoding;

/**
* This Class handles the block-chain as a full-node.
*/
public class Node implements Runnable{
/* The storage and db context used by this node */
private Context context;
/* The storage and db storageContext used by this node */
private StorageContext storageContext;

/* The first block in the blockchain, via context */
/* The first block in the blockchain, via storageContext */
private Block genesisBlock;

/* The wallet that will recieve rewards for each block mined (If the current axiom supports that */
Expand All @@ -51,7 +51,7 @@ public class Node implements Runnable{
/* The current axiom in use by the latest block in the blockchain */
private Axiom axiom;

/* The header from the latest block in the blockchain, via context. */
/* The header from the latest block in the blockchain, via storageContext. */
private BlockHeader tallestHeader;

/* The block that is being mined */
Expand All @@ -65,32 +65,32 @@ public class Node implements Runnable{
private Peer2Peer p2p;
private int serverPort = 8888;

/* Checks block and updates the state and adds it to the db context */
/* Checks block and updates the state and adds it to the db storageContext */
private BlockProcessor blockProcessor;

/* Transactions to be added to block */
private Queue<Transaction> transactionPool;

//Contructor
public Node(Context context, Block genesisBlock, Miner miner, Axiom axiom){
this.context = context;
public Node(StorageContext storageContext, Block genesisBlock, Miner miner, Axiom axiom){
this.storageContext = storageContext;
this.genesisBlock = genesisBlock;
this.miner = miner;
this.minerWallet = Start.localWallet;
this.axiom = axiom;
this.tallestHeader = genesisBlock.header;
this.blockProcessor = new BlockProcessor();
blockProcessor.addBlock(genesisBlock, context);
blockProcessor.addBlock(genesisBlock, storageContext);
transactionPool = new PriorityQueue<Transaction>();
}

public Node(){
this(Start.localContext,GenesisBlock.getInstance().getBlock(), null, NodeSettings.getDefault().getAxiom() );
this(Start.localContext, GenesisBlock.getInstance().getBlock(), null, NodeSettings.getDefault().getAxiom() );
}

//getters
public long getLength(){
return this.context.calculateChainSize();
return this.storageContext.calculateChainSize();
}

public int getPort(){
Expand All @@ -105,8 +105,8 @@ public boolean isMining(){
return this.shouldMine;
}

public Context getContext(){
return this.context;
public StorageContext getStorageContext(){
return this.storageContext;
}

//Methods
Expand Down Expand Up @@ -180,12 +180,12 @@ private void mine(){
}

//block has been mined
Commander.CommanderPrint("Newly mined block is valid:" + axiom.isBlockValid(minedBlock, context));
Commander.CommanderPrint("Adding new block to context...");
Commander.CommanderPrint("Newly mined block is valid:" + axiom.isBlockValid(minedBlock, storageContext));
Commander.CommanderPrint("Adding new block to storageContext...");

//Add mined block to db:
//context.putBlock(minedBlock);
blockProcessor.addBlock(minedBlock, context);
//storageContext.putBlock(minedBlock);
blockProcessor.addBlock(minedBlock, storageContext);

//Update tallest header:
tallestHeader = minedBlock.header;
Expand All @@ -202,7 +202,7 @@ public void setPort(int number){
}

public AccountState getAccount(byte[] address){
return context.getAccount(address);
return storageContext.getAccount(address);
}

//Overrides
Expand Down
Loading