Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrorpmoleiro committed Sep 7, 2020
2 parents c99a4cb + c9ec30d commit 81b944c
Show file tree
Hide file tree
Showing 25 changed files with 634 additions and 178 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
Documentation for this API's Endpoints is available [here](https://documenter.getpostman.com/view/8998471/TVCgynHq#84bdf27c-b339-46c1-9d5b-e3d8a93e3f1b).

## Description
A scalable and lightweight REST API service that clients or external services can use to communicate with the [VOIDChain](https://github.com/pedrorpmoleiro/voidchain) platform.


## Objective
* Straightforward interface with the VOIDChain platform for external services wanting to communicate.
* Lightweight and scalable API.
* REST architecture for universal compatibility.

## Built With

Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>pt.ipleiria.estg.dei.pi</groupId>
<artifactId>voidchain-api</artifactId>
<version>0.2.2</version>
<version>1.0</version>

<properties>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
Expand All @@ -23,7 +23,7 @@

<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>

<voidchain-node.version>0.9.10</voidchain-node.version>
<voidchain-node.version>1.0</voidchain-node.version>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import java.util.List;
import java.util.StringTokenizer;

/**
* The Api configuration loads and stores the configuration variables from configuration files.
*/
public class APIConfiguration {
private static APIConfiguration INSTANCE = null;

Expand All @@ -23,15 +26,36 @@ public class APIConfiguration {

private boolean firstRun = true;

/**
* The constant CONFIG_FILES.
*/
public static final List<String> CONFIG_FILES = new ArrayList<>() {{
add("voidchain-api.config");
}};

/**
* The constant DEFAULT_ID.
*/
public static final int DEFAULT_ID = 1001;
/**
* The constant DEFAULT_BLOCK_SYNC_TIMER.
*/
public static final int DEFAULT_BLOCK_SYNC_TIMER = 30000;
/**
* The constant DEFAULT_TRANSACTION_SUBMIT_TIMER.
*/
public static final int DEFAULT_TRANSACTION_SUBMIT_TIMER = 5000;
/**
* The constant DEFAULT_MAX_TRANSACTION_SUBMIT.
*/
public static final int DEFAULT_MAX_TRANSACTION_SUBMIT = 15;
/**
* The constant DEFAULT_NODE.
*/
public static final boolean DEFAULT_NODE = false;
/**
* The constant DEFAULT_NODE_SYNC.
*/
public static final boolean DEFAULT_NODE_SYNC = false;

private int id = DEFAULT_ID;
Expand All @@ -42,38 +66,72 @@ public class APIConfiguration {
private boolean nodeSync = DEFAULT_NODE_SYNC;

private APIConfiguration() {
this.loadConfigurationFromDisk();
}

/**
* Gets instance.
*
* @return the instance
*/
public static APIConfiguration getInstance() {
if (INSTANCE == null)
INSTANCE = new APIConfiguration();
else
INSTANCE.loadConfigurationFromDisk();

INSTANCE.loadConfigurationFromDisk();

return INSTANCE;
}

/**
* Gets id.
*
* @return the id
*/
public int getId() {
return id;
}

/**
* Gets block sync timer.
*
* @return the block sync timer
*/
public int getBlockSyncTimer() {
return blockSyncTimer;
}

/**
* Gets send transactions timer.
*
* @return the send transactions timer
*/
public int getSendTransactionsTimer() {
return transactionSubmitTimer;
}

/**
* Gets max number of transaction to send.
*
* @return the max number of transaction to send
*/
public int getMaxNumberOfTransactionToSend() {
return maxTransactionSubmit;
}

/**
* Has node.
*
* @return the boolean
*/
public boolean hasNode() {
return node;
}

/**
* Has sync.
*
* @return the boolean
*/
public boolean hasSync() {
if (!hasNode())
return false;
Expand All @@ -96,9 +154,11 @@ private void loadConfigurationFromDisk() {
String aux;
switch (str.nextToken().trim()) {
case "system.voidchain.api.id":
aux = str.nextToken().trim();
if (aux != null)
this.id = Integer.parseInt(aux);
if (firstRun) {
aux = str.nextToken().trim();
if (aux != null)
this.id = Integer.parseInt(aux);
}
continue;
case "system.voidchain.api.block_sync_timer":
aux = str.nextToken().trim();
Expand Down Expand Up @@ -142,6 +202,11 @@ private void loadConfigurationFromDisk() {
}
}

/**
* Create default config files.
*
* @throws IOException the io exception
*/
public static void createDefaultConfigFiles() throws IOException {
Path configDir = Paths.get(Configuration.CONFIG_DIR);

Expand All @@ -158,7 +223,7 @@ public static void createDefaultConfigFiles() throws IOException {
if (Files.notExists(Paths.get(filePath))) {
logger.info("Creating file '" + f + "' in 'config'");

InputStream in = Storage.class.getClassLoader().getResourceAsStream(filePath);
InputStream in = Storage.class.getClassLoader().getResourceAsStream(filePathJar);
File outFile = new File(filePath);
FileOutputStream out = new FileOutputStream(outFile);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@

import java.io.Serializable;

/**
* The enum Transaction status api.
*/
public enum TransactionStatusAPI implements Serializable {
/**
* In block transaction status api.
*/
IN_BLOCK,
/**
* In network mem pool transaction status api.
*/
IN_NETWORK_MEM_POOL,
/**
* In api mem pool transaction status api.
*/
IN_API_MEM_POOL,
/**
* Unknown transaction status api.
*/
UNKNOWN
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ public class BlockDTO implements Serializable {
private final String hash;
private final int size;

/**
* Instantiates a new Block Data Transfer Object.
*
* @param transactions the transactions
* @param blockHeader the block header
* @param transactionCounter the transaction counter
* @param blockHeight the block height
* @param hash the hash
* @param size the size
*/
public BlockDTO(List<TransactionGetDTO> transactions, BlockHeaderDTO blockHeader, int transactionCounter,
int blockHeight, String hash, int size) {
this.transactions = transactions;
Expand All @@ -19,29 +29,58 @@ public BlockDTO(List<TransactionGetDTO> transactions, BlockHeaderDTO blockHeader
this.blockHeight = blockHeight;
this.hash = hash;
this.size = size;

}

/**
* Gets transactions.
*
* @return the transactions
*/
public List<TransactionGetDTO> getTransactions() {
return transactions;
}

/**
* Gets block header.
*
* @return the block header
*/
public BlockHeaderDTO getBlockHeader() {
return blockHeader;
}

/**
* Gets transaction counter.
*
* @return the transaction counter
*/
public int getTransactionCounter() {
return transactionCounter;
}

/**
* Gets block height.
*
* @return the block height
*/
public int getBlockHeight() {
return blockHeight;
}

/**
* Gets hash.
*
* @return the hash
*/
public String getHash() {
return hash;
}

/**
* Gets size.
*
* @return the size
*/
public int getSize() {
return size;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,53 @@ public class BlockHeaderDTO implements Serializable {
private final String protocolVersion;
private final String merkleRoot;

/**
* Instantiates a new Block header Data Transfer Object.
*
* @param timestamp the timestamp
* @param previousBlockHash the previous block hash
* @param protocolVersion the protocol version
* @param merkleRoot the merkle root
*/
public BlockHeaderDTO(long timestamp, String previousBlockHash, String protocolVersion, String merkleRoot) {
this.timestamp = timestamp;
this.previousBlockHash = previousBlockHash;
this.protocolVersion = protocolVersion;
this.merkleRoot = merkleRoot;
}

/**
* Gets timestamp.
*
* @return the timestamp
*/
public long getTimestamp() {
return timestamp;
}

/**
* Gets previous block hash.
*
* @return the previous block hash
*/
public String getPreviousBlockHash() {
return previousBlockHash;
}

/**
* Gets protocol version.
*
* @return the protocol version
*/
public String getProtocolVersion() {
return protocolVersion;
}

/**
* Gets merkle root.
*
* @return the merkle root
*/
public String getMerkleRoot() {
return merkleRoot;
}
Expand Down
Loading

0 comments on commit 81b944c

Please sign in to comment.