diff --git a/build.gradle b/build.gradle index 8d3cd3bfb..09599e7aa 100644 --- a/build.gradle +++ b/build.gradle @@ -124,12 +124,12 @@ publishing { } docker { - name 'minimaglobal/minima:latest' + name 'minimaglobal/minima:dev' dockerfile project.file('docker/Dockerfile') - //buildx true - //push true - //platform 'linux/amd64,linux/arm64,linux/arm/v7' + buildx true + push true + platform 'linux/amd64,linux/arm64,linux/arm/v7' files tasks.shadowJar, "$rootDir/docker/dapps" copySpec.from("$buildDir/lib/minima-all.jar",).into(".") diff --git a/docker/minima b/docker/minima index 8fa994819..6cbb63dbf 100644 --- a/docker/minima +++ b/docker/minima @@ -1,3 +1,4 @@ -#!/bin/bash +#!/bin/sh -java -cp /usr/local/minima/minima.jar org.minima.utils.MinimaRPCClient \ No newline at end of file +#Start the docker container Minima RPC Client +java -cp /usr/local/minima/minima.jar org.minima.utils.MinimaRPCClient diff --git a/gradlew b/gradlew old mode 100755 new mode 100644 diff --git a/jar/minima-0.103.20.apk b/jar/minima-0.103.22.apk similarity index 92% rename from jar/minima-0.103.20.apk rename to jar/minima-0.103.22.apk index 391ad6d9b..4bfb5b8b0 100644 Binary files a/jar/minima-0.103.20.apk and b/jar/minima-0.103.22.apk differ diff --git a/jar/minima-nolibs.jar b/jar/minima-nolibs.jar index afdd68998..c1a9c1853 100644 Binary files a/jar/minima-nolibs.jar and b/jar/minima-nolibs.jar differ diff --git a/jar/minima.jar b/jar/minima.jar index 176b19ae6..221ddf018 100644 Binary files a/jar/minima.jar and b/jar/minima.jar differ diff --git a/lib/junit-4.13.jar b/lib/junit-4.13.jar old mode 100755 new mode 100644 diff --git a/mds/code/testhub/index.html b/mds/code/testhub/index.html new file mode 100644 index 000000000..86430288e --- /dev/null +++ b/mds/code/testhub/index.html @@ -0,0 +1,120 @@ + + + + + MDS HUB + + + + + + +
+ + +
MDS
+
+
+ +
+ + + + \ No newline at end of file diff --git a/mydaatafolder/0.103/databases/archivesql/archive.mv.db b/mydaatafolder/0.103/databases/archivesql/archive.mv.db new file mode 100644 index 000000000..dc5faee8f Binary files /dev/null and b/mydaatafolder/0.103/databases/archivesql/archive.mv.db differ diff --git a/mydaatafolder/0.103/databases/cascade.db b/mydaatafolder/0.103/databases/cascade.db new file mode 100644 index 000000000..180cf4bf9 Binary files /dev/null and b/mydaatafolder/0.103/databases/cascade.db differ diff --git a/mydaatafolder/0.103/databases/chaintree.db b/mydaatafolder/0.103/databases/chaintree.db new file mode 100644 index 000000000..180cf4bf9 Binary files /dev/null and b/mydaatafolder/0.103/databases/chaintree.db differ diff --git a/mydaatafolder/0.103/databases/maximasql/maxima.mv.db b/mydaatafolder/0.103/databases/maximasql/maxima.mv.db new file mode 100644 index 000000000..57022d735 Binary files /dev/null and b/mydaatafolder/0.103/databases/maximasql/maxima.mv.db differ diff --git a/mydaatafolder/0.103/databases/mdssql/mds.mv.db b/mydaatafolder/0.103/databases/mdssql/mds.mv.db new file mode 100644 index 000000000..4e68dadff Binary files /dev/null and b/mydaatafolder/0.103/databases/mdssql/mds.mv.db differ diff --git a/mydaatafolder/0.103/databases/p2p.db b/mydaatafolder/0.103/databases/p2p.db new file mode 100644 index 000000000..92da0ccdb Binary files /dev/null and b/mydaatafolder/0.103/databases/p2p.db differ diff --git a/mydaatafolder/0.103/databases/txpowsql/txpow.mv.db b/mydaatafolder/0.103/databases/txpowsql/txpow.mv.db new file mode 100644 index 000000000..57d4be15b Binary files /dev/null and b/mydaatafolder/0.103/databases/txpowsql/txpow.mv.db differ diff --git a/mydaatafolder/0.103/databases/userprefs.db b/mydaatafolder/0.103/databases/userprefs.db new file mode 100644 index 000000000..270185216 Binary files /dev/null and b/mydaatafolder/0.103/databases/userprefs.db differ diff --git a/mydaatafolder/0.103/databases/walletsql/wallet.mv.db b/mydaatafolder/0.103/databases/walletsql/wallet.mv.db new file mode 100644 index 000000000..95ed41796 Binary files /dev/null and b/mydaatafolder/0.103/databases/walletsql/wallet.mv.db differ diff --git a/mydaatafolder/0.103/databases/walletsql/wallet.trace.db b/mydaatafolder/0.103/databases/walletsql/wallet.trace.db new file mode 100644 index 000000000..e000dc706 --- /dev/null +++ b/mydaatafolder/0.103/databases/walletsql/wallet.trace.db @@ -0,0 +1,12 @@ +2022-11-14 12:55:25 jdbc[3]: exception +org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "SCRIPT TO '/mnt/c/Users/user/Documents/Oscar's work folder/Minima-dev/Minima-dev/mydaatafolder/0.103/backup/wallet.sql[*]'"; SQL statement: +SCRIPT TO '/mnt/c/Users/user/Documents/Oscar's work folder/Minima-dev/Minima-dev/mydaatafolder/0.103/backup/wallet.sql' [42000-200] +2022-11-14 12:55:25 jdbc[3]: exception +org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "SCRIPT TO '/mnt/c/Users/user/Documents/Oscar's work folder/Minima-dev/Minima-dev/mydaatafolder/0.103/backup/wallet.sql[*]'"; SQL statement: +SCRIPT TO '/mnt/c/Users/user/Documents/Oscar's work folder/Minima-dev/Minima-dev/mydaatafolder/0.103/backup/wallet.sql' [42000-200] +2022-11-14 13:58:03 jdbc[3]: exception +org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "SCRIPT TO '/mnt/c/Users/user/Documents/Oscar's work folder/Minima-dev/Minima-dev - Copy/mydaatafolder/0.103/backup/wallet.sql[*]'"; SQL statement: +SCRIPT TO '/mnt/c/Users/user/Documents/Oscar's work folder/Minima-dev/Minima-dev - Copy/mydaatafolder/0.103/backup/wallet.sql' [42000-200] +2022-11-14 13:58:03 jdbc[4]: exception +org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "SCRIPT TO '/mnt/c/Users/user/Documents/Oscar's work folder/Minima-dev/Minima-dev - Copy/mydaatafolder/0.103/backup/wallet.sql[*]'"; SQL statement: +SCRIPT TO '/mnt/c/Users/user/Documents/Oscar's work folder/Minima-dev/Minima-dev - Copy/mydaatafolder/0.103/backup/wallet.sql' [42000-200] diff --git a/scripts/multihtop.sh b/scripts/multihtop.sh old mode 100755 new mode 100644 diff --git a/src/org/minima/database/MinimaDB.java b/src/org/minima/database/MinimaDB.java index 2470241a3..dd99676c4 100644 --- a/src/org/minima/database/MinimaDB.java +++ b/src/org/minima/database/MinimaDB.java @@ -15,6 +15,7 @@ import org.minima.database.wallet.Wallet; import org.minima.system.network.p2p.P2PDB; import org.minima.system.params.GeneralParams; +import org.minima.utils.MiniFile; import org.minima.utils.MinimaLogger; public class MinimaDB { @@ -188,7 +189,31 @@ public void loadAllDB() { //Set the Archive folder File archsqlfolder = new File(basedb,"archivesql"); - mArchive.loadDB(new File(archsqlfolder,"archive")); + try { + + //Try and load the Archive DB + mArchive.loadDB(new File(archsqlfolder,"archive")); + +// throw new Exception("TEST CRASH ARCHIVEDB!"); + + }catch(Exception exc) { + + //Log the complete error + MinimaLogger.log(exc); + + //There wqas an issue.. wipe it.. and resync.. + MinimaLogger.log("ERROR loading ArchiveDB.. WIPE and RESYNC.. "); + + //Close the DB + mArchive.hardCloseDB(); + + //Delete the ArchiveDB folder + MiniFile.deleteFileOrFolder(archsqlfolder.getAbsolutePath(), archsqlfolder); + + //And reload.. + mArchive = new ArchiveManager(); + mArchive.loadDB(new File(archsqlfolder,"archive")); + } //Are we Storing in a MySQL.. if(!GeneralParams.MYSQL_HOST.equals("")) { @@ -199,14 +224,38 @@ public void loadAllDB() { GeneralParams.MYSQL_PASSWORD); } + //Load the SQL DB + File txpowsqlfolder = new File(basedb,"txpowsql"); + try { + + //Try and load the Archive DB + mTxPoWDB.loadSQLDB(new File(txpowsqlfolder,"txpow")); + +// throw new Exception("TEST CRASH TXPOWDB!"); + + }catch(Exception exc) { + + //Log the complete error + MinimaLogger.log(exc); + + //There wqas an issue.. wipe it.. and resync.. + MinimaLogger.log("ERROR loading TxPoWSQLDB.. WIPE and RESYNC.. "); + + //Close the DB + mTxPoWDB.hardCloseSQLDB(); + + //Delete the ArchiveDB folder + MiniFile.deleteFileOrFolder(txpowsqlfolder.getAbsolutePath(), txpowsqlfolder); + + //And reload.. + mTxPoWDB = new TxPoWDB(); + mTxPoWDB.loadSQLDB(new File(txpowsqlfolder,"txpow")); + } + //Load the wallet File walletsqlfolder = new File(basedb,"walletsql"); mWallet.loadDB(new File(walletsqlfolder,"wallet")); - //Load the SQL DB - File txpowsqlfolder = new File(basedb,"txpowsql"); - mTxPoWDB.loadSQLDB(new File(txpowsqlfolder,"txpow")); - //Load the MaximaDB File maxsqlfolder = new File(basedb,"maximasql"); mMaximaDB.loadDB(new File(maxsqlfolder,"maxima")); diff --git a/src/org/minima/database/archive/ArchiveManager.java b/src/org/minima/database/archive/ArchiveManager.java index d539fe042..21c55c16f 100644 --- a/src/org/minima/database/archive/ArchiveManager.java +++ b/src/org/minima/database/archive/ArchiveManager.java @@ -17,6 +17,7 @@ import org.minima.objects.base.MiniNumber; import org.minima.system.Main; import org.minima.system.params.GeneralParams; +import org.minima.utils.MiniFile; import org.minima.utils.MinimaLogger; import org.minima.utils.SqlDB; import org.minima.utils.json.JSONObject; @@ -160,6 +161,9 @@ protected void createSQL() throws SQLException { public synchronized int getSize() { try { + //Make sure.. + checkOpen(); + //Run the query ResultSet rs = SQL_TOTAL_COUNT.executeQuery(); @@ -178,48 +182,42 @@ public synchronized int getSize() { } public synchronized boolean saveBlock(TxBlock zBlock) throws SQLException { -// try { - - //get the MiniData version.. - MiniData syncdata = MiniData.getMiniDataVersion(zBlock); - - //Get the Query ready - SQL_INSERT_SYNCBLOCK.clearParameters(); - //Set main params - SQL_INSERT_SYNCBLOCK.setString(1, zBlock.getTxPoW().getTxPoWID()); - SQL_INSERT_SYNCBLOCK.setLong(2, zBlock.getTxPoW().getBlockNumber().getAsLong()); - SQL_INSERT_SYNCBLOCK.setLong(3, System.currentTimeMillis()); - - //And finally the actual bytes - SQL_INSERT_SYNCBLOCK.setBytes(4, syncdata.getBytes()); - - //Do it. - SQL_INSERT_SYNCBLOCK.execute(); + //Make sure.. + checkOpen(); + + //get the MiniData version.. + MiniData syncdata = MiniData.getMiniDataVersion(zBlock); - //Do we MySQL - if(mStoreMySQL) { - mMySQL.saveBlock(zBlock); - } - - return true; - -// } catch (SQLException e) { -// MinimaLogger.log(e); -// } -// -// return false; - } + //Get the Query ready + SQL_INSERT_SYNCBLOCK.clearParameters(); - public synchronized TxBlock loadBlock(String zTxPoWID) { + //Set main params + SQL_INSERT_SYNCBLOCK.setString(1, zBlock.getTxPoW().getTxPoWID()); + SQL_INSERT_SYNCBLOCK.setLong(2, zBlock.getTxPoW().getBlockNumber().getAsLong()); + SQL_INSERT_SYNCBLOCK.setLong(3, System.currentTimeMillis()); + + //And finally the actual bytes + SQL_INSERT_SYNCBLOCK.setBytes(4, syncdata.getBytes()); - //Are we shutting down.. - if(Main.getInstance().isShuttingDown()) { - return new TxBlock(new TxPoW()); + //Do it. + SQL_INSERT_SYNCBLOCK.execute(); + + //Do we MySQL + if(mStoreMySQL) { + mMySQL.saveBlock(zBlock); } + return true; + } + + public synchronized TxBlock loadBlock(String zTxPoWID) { + try { + //Make sure.. + checkOpen(); + //Set search params SQL_FIND_SYNCBLOCK.clearParameters(); SQL_FIND_SYNCBLOCK.setString(1, zTxPoWID); @@ -251,13 +249,11 @@ public synchronized TxBlock loadBlock(String zTxPoWID) { public synchronized TxBlock loadLastBlock() { - //Are we shutting down.. - if(Main.getInstance().isShuttingDown()) { - return new TxBlock(new TxPoW()); - } - try { + //Make sure.. + checkOpen(); + //Set search params SQL_SELECT_LAST.clearParameters(); @@ -288,15 +284,13 @@ public synchronized TxBlock loadLastBlock() { public synchronized JSONObject loadLastBlockJSON() { - //Are we shutting down.. - if(Main.getInstance().isShuttingDown()) { - return new JSONObject(); - } - JSONObject ret = new JSONObject(); try { + //Make sure.. + checkOpen(); + //Set search params SQL_SELECT_LAST.clearParameters(); @@ -331,6 +325,9 @@ public synchronized ArrayList loadSyncBlockRange(MiniNumber zStartBlock try { + //Make sure.. + checkOpen(); + //Set Search params SQL_SELECT_SYNC_LIST.clearParameters(); SQL_SELECT_SYNC_LIST.setLong(1,zStartBlock.getAsLong()); @@ -384,6 +381,8 @@ public int compare(TxBlock zBlk1, TxBlock zBlk2) { public synchronized MiniNumber exists(String zTxPoWID) { try { + //Make sure.. + checkOpen(); //Set search params SQL_EXISTS_SYNCBLOCK.clearParameters(); @@ -413,6 +412,9 @@ public synchronized ArrayList loadBlockRange(MiniNumber zStartBlock, Mi try { + //Make sure.. + checkOpen(); + //Set Search params SQL_SELECT_RANGE.clearParameters(); SQL_SELECT_RANGE.setLong(1,zStartBlock.getAsLong()); @@ -456,6 +458,9 @@ public synchronized TxBlock loadFirstBlock() { try { + //Make sure.. + checkOpen(); + //Set search params SQL_SELECT_FIRST.clearParameters(); @@ -486,6 +491,9 @@ public synchronized TxBlock loadFirstBlock() { public synchronized int cleanDB() { try { + //Make sure.. + checkOpen(); + //Set search params SQL_SELECT_FIRST.clearParameters(); @@ -528,50 +536,57 @@ public synchronized int cleanDB() { return 0; } + public void hackShut() throws SQLException { + mSQLConnection.close(); + } + public static void main(String[] zArgs) throws SQLException { + File testdbfolder = new File(System.getProperty("user.home"),"testfolder"); + File testdb = new File(testdbfolder,"sqlsync"); + + //Wipe the old.. + MiniFile.deleteFileOrFolder(testdbfolder.getAbsolutePath(), testdbfolder); + ArchiveManager arch = new ArchiveManager(); + arch.loadDB(testdb); + + //test insert.. + TxPoW txp = new TxPoW(); + txp.setBlockNumber(MiniNumber.ONE); + txp.setTimeMilli(); + txp.calculateTXPOWID(); + txp.setSuperParent(0, new MiniData("0xFFEEFF")); + + arch.hackShut(); + + //Create a SyncBlock + TxBlock sb = new TxBlock(txp); + + arch.saveBlock(sb); + + arch.hackShut(); + + int rows = arch.getSize(); + + System.out.println("DB Size : "+rows); + + arch.hackShut(); + + String txpid = sb.getTxPoW().getTxPoWID(); + + TxBlock lsb = arch.loadBlock(txpid); + + arch.hackShut(); + + System.out.println("Sync Loaded : "+lsb.getTxPoW().toString()); + + //Load a range.. + ArrayList blocks = arch.loadBlockRange(MiniNumber.ZERO, MiniNumber.ONE); + System.out.println("Sync Range : "+blocks.size()); -// long timenow = System.currentTimeMillis(); -// System.out.println(new Date(timenow)); -// long timethen = timenow - arch.MAX_SQL_MILLI; -// System.out.println(new Date(1662646695127L)); - -// File testdbfolder = new File(System.getProperty("user.home"),"testfolder"); -// File testdb = new File(testdbfolder,"sqlsync"); -// -// ArchiveManager arch = new ArchiveManager(); -// arch.loadDB(testdb); -// -// //test insert.. -// TxPoW txp = new TxPoW(); -// txp.setBlockNumber(MiniNumber.ONE); -// txp.setTimeMilli(); -// txp.calculateTXPOWID(); -// txp.setSuperParent(0, new MiniData("0xFFEEFF")); -// -// //Create a SyncBlock -// TxBlock sb = new TxBlock(txp); -// -// arch.saveBlock(sb); -// arch.saveBlock(sb); -// -// int rows = arch.getSize(); -// -// System.out.println("DB Size : "+rows); -// -// String txpid = sb.getTxPoW().getTxPoWID(); -// -// TxBlock lsb = arch.loadBlock(txpid); -// -// System.out.println("Sync Loaded : "+lsb.getTxPoW().toString()); -// -// //Load a range.. -// ArrayList blocks = arch.loadBlockRange(MiniNumber.ZERO, MiniNumber.ONE); -// System.out.println("Sync Range : "+blocks.size()); -// -// //Shut down -// arch.saveDB(); + //Shut down + arch.saveDB(); } diff --git a/src/org/minima/database/txpowdb/TxPoWDB.java b/src/org/minima/database/txpowdb/TxPoWDB.java index 2b97d9ef7..6b325d877 100644 --- a/src/org/minima/database/txpowdb/TxPoWDB.java +++ b/src/org/minima/database/txpowdb/TxPoWDB.java @@ -39,6 +39,10 @@ public void loadSQLDB(File zFile) throws SQLException { mSqlDB.loadDB(zFile); } + public void hardCloseSQLDB() { + mSqlDB.hardCloseDB(); + } + public void saveDB() { //Shut down the SQL DB cleanly mSqlDB.saveDB(); @@ -65,11 +69,8 @@ public void addTxPoW(TxPoW zTxPoW) { } public void addSQLTxPoW(TxPoW zTxPoW) { - //Get the ID - String txpid = zTxPoW.getTxPoWID(); - //Is it in the SQL - if(!mSqlDB.exists(txpid)) { + if(!mSqlDB.exists(zTxPoW.getTxPoWID())) { //Add it to the SQL.. mSqlDB.addTxPoW(zTxPoW); } @@ -86,12 +87,6 @@ public TxPoW getTxPoW(String zTxPoWID) { if(txp == null) { //Check the SQL.. txp = mSqlDB.getTxPoW(zTxPoWID); - - //If found add to RamDB - if(txp != null) { - //For fast access next time - mRamDB.addTxPoW(txp); - } } //Could still be null @@ -170,8 +165,11 @@ public TxPoWSqlDB getSQLDB() { * When you access a txpow it's record is updated * and will not be deleted for another time period */ - public void cleanDB() { + public void cleanDBRAM() { mRamDB.cleanDB(); + } + + public void cleanDBSQL() { mSqlDB.cleanDB(); } diff --git a/src/org/minima/database/userprefs/UserDB.java b/src/org/minima/database/userprefs/UserDB.java index ecbd28cec..a4ab285de 100644 --- a/src/org/minima/database/userprefs/UserDB.java +++ b/src/org/minima/database/userprefs/UserDB.java @@ -2,6 +2,7 @@ import java.util.ArrayList; +import org.minima.objects.Magic; import org.minima.objects.base.MiniData; import org.minima.objects.base.MiniNumber; import org.minima.system.params.GlobalParams; @@ -171,4 +172,31 @@ public void setAutoBackup(boolean zAuto) { setBoolean("autobackup", zAuto); } + /** + * Desired Magic Numbers + */ + public MiniNumber getMagicDesiredKISSVM() { + return getNumber("magic_kissvm", Magic.DEFAULT_KISSVM_OPERATIONS); + } + + public void setMagicDesiredKISSVM(MiniNumber zKISSVM) { + setNumber("magic_kissvm", zKISSVM); + } + + public MiniNumber getMagicMaxTxPoWSize() { + return getNumber("magic_txpowsize", Magic.DEFAULT_TXPOW_SIZE); + } + + public void setMagicMaxTxPoWSize(MiniNumber zMaxSize) { + setNumber("magic_txpowsize", zMaxSize); + } + + public MiniNumber getMagicMaxTxns() { + return getNumber("magic_txns", Magic.DEFAULT_TXPOW_TXNS); + } + + public void setMagicMaxTxns(MiniNumber zMaxTxns) { + setNumber("magic_txns", zMaxTxns); + } + } diff --git a/src/org/minima/database/wallet/Wallet.java b/src/org/minima/database/wallet/Wallet.java index e56f088a9..8a1a502b6 100644 --- a/src/org/minima/database/wallet/Wallet.java +++ b/src/org/minima/database/wallet/Wallet.java @@ -224,6 +224,10 @@ public boolean initDefaultKeys() { } public boolean initDefaultKeys(int zMaxNum) { + return initDefaultKeys(zMaxNum, false); + } + + public boolean initDefaultKeys(int zMaxNum, boolean zLog) { //Get all the keys.. ArrayList allscripts = getAllDefaultAddresses(); @@ -243,6 +247,10 @@ public boolean initDefaultKeys(int zMaxNum) { for(int i=0;i= x0.5 and <= x2 + * Desired calculated as >= x0.5 and <= x2 * */ public Magic calculateNewCurrent() { diff --git a/src/org/minima/objects/TxHeader.java b/src/org/minima/objects/TxHeader.java index 3a75fd136..68970cd42 100644 --- a/src/org/minima/objects/TxHeader.java +++ b/src/org/minima/objects/TxHeader.java @@ -54,7 +54,7 @@ public class TxHeader implements Streamable { /** * MAGIC numbers that set the chain parameters */ - public Magic mMagic = new Magic(); + public Magic mMagic = new Magic(); /** * The MMR Root! diff --git a/src/org/minima/system/Main.java b/src/org/minima/system/Main.java index 5ece1dab4..1b994f501 100644 --- a/src/org/minima/system/Main.java +++ b/src/org/minima/system/Main.java @@ -68,8 +68,16 @@ public static void setMinimaListener(MessageListener zListener) { * Main loop messages */ public static final String MAIN_TXPOWMINED = "MAIN_TXPOWMINED"; - public static final String MAIN_CLEANDB = "MAIN_CLEANDB"; public static final String MAIN_PULSE = "MAIN_PULSE"; + + /** + * Clean DB - RamDB every 30 mins.. the TxPoW and Archive every 12 hours + */ + public static final String MAIN_CLEANDB_RAM = "MAIN_CLEANDB_RAM"; + long CLEANDB_RAM_TIMER = 1000 * 60 * 30; + + public static final String MAIN_CLEANDB_SQL = "MAIN_CLEANDB_SQL"; + long CLEANDB_SQL_TIMER = 1000 * 60 * 60 * 12; /** * Auto backup every 24 hrs.. @@ -156,11 +164,6 @@ public static void setMinimaListener(MessageListener zListener) { */ boolean mRestoring = false; - /** - * Timer delay for CleanDB messages - every 30 mins - */ - long CLEANDB_TIMER = 1000 * 60 * 30; - /** * Timer for the automine message */ @@ -269,10 +272,12 @@ public Main() { //Clean the DB (delete old records) if(GeneralParams.GENESIS) { - PostTimerMessage(new TimerMessage(5 * 1000, MAIN_CLEANDB)); + //Do sooner as stores the genesis Txn.. + PostTimerMessage(new TimerMessage(10 * 1000, MAIN_CLEANDB_RAM)); }else { - PostTimerMessage(new TimerMessage(60 * 1000, MAIN_CLEANDB)); + PostTimerMessage(new TimerMessage(60 * 1000, MAIN_CLEANDB_RAM)); } + PostTimerMessage(new TimerMessage(60 * 1000, MAIN_CLEANDB_SQL)); //Store the IC User - do fast first time - 30 seconds in.. then every 8 hours PostTimerMessage(new TimerMessage(1000*30, MAIN_INCENTIVE)); @@ -561,23 +566,31 @@ protected void processMessage(Message zMessage) throws Exception { //Post to the NIOManager - which will check it and forward if correct getNetworkManager().getNIOManager().PostMessage(newniomsg); - }else if(zMessage.getMessageType().equals(MAIN_CLEANDB)) { + }else if(zMessage.getMessageType().equals(MAIN_CLEANDB_RAM)) { - //Do some house keeping on the DB - MinimaDB.getDB().getTxPoWDB().cleanDB(); + //Clean up the RAM Memory + System.gc(); - //Same with the ArchiveDB - MinimaDB.getDB().getArchive().cleanDB(); + //Do some house keeping on the DB + MinimaDB.getDB().getTxPoWDB().cleanDBRAM(); //Now save the state - in case system crashed.. MinimaDB.getDB().saveState(); - //Clean up the RAM Memory - System.gc(); - //Do it again.. - PostTimerMessage(new TimerMessage(CLEANDB_TIMER, MAIN_CLEANDB)); + PostTimerMessage(new TimerMessage(CLEANDB_RAM_TIMER, MAIN_CLEANDB_RAM)); + }else if(zMessage.getMessageType().equals(MAIN_CLEANDB_SQL)) { + + //Do some house keeping on the DB + MinimaDB.getDB().getTxPoWDB().cleanDBSQL(); + + //Same with the ArchiveDB + MinimaDB.getDB().getArchive().cleanDB(); + + //Do it again.. + PostTimerMessage(new TimerMessage(CLEANDB_SQL_TIMER, MAIN_CLEANDB_SQL)); + }else if(zMessage.getMessageType().equals(MAIN_PULSE)) { //Create Pulse Message diff --git a/src/org/minima/system/brains/TxPoWGenerator.java b/src/org/minima/system/brains/TxPoWGenerator.java index f123ea7ab..5d0fd0488 100644 --- a/src/org/minima/system/brains/TxPoWGenerator.java +++ b/src/org/minima/system/brains/TxPoWGenerator.java @@ -10,7 +10,9 @@ import org.minima.database.MinimaDB; import org.minima.database.mmr.MMRData; +import org.minima.database.txpowdb.TxPoWDB; import org.minima.database.txpowtree.TxPoWTreeNode; +import org.minima.database.userprefs.UserDB; import org.minima.objects.Coin; import org.minima.objects.CoinProof; import org.minima.objects.Magic; @@ -84,7 +86,12 @@ public static TxPoW generateTxPoW(Transaction zTransaction, Witness zWitness, Tr } //Set the correct Magic Numbers.. + UserDB udb = MinimaDB.getDB().getUserDB(); + Magic txpowmagic = tip.getTxPoW().getMagic().calculateNewCurrent(); + txpowmagic.setDesiredKISSVM(udb.getMagicDesiredKISSVM()); + txpowmagic.setDesiredMaxTxPoWSize(udb.getMagicMaxTxPoWSize()); + txpowmagic.setDesiredMaxTxns(udb.getMagicMaxTxns()); txpow.setMagic(txpowmagic); //Set the parents.. @@ -141,6 +148,25 @@ public int compare(TxPoW o1, TxPoW o2) { } }); + //MAX number of transactions in mempool.. 1 hrs worth of blocks.. + int max = tip.getTxPoW().getMagic().getMaxNumTxns().getAsInt() * 12 * 6; + int counter = 0; + ArrayList newmempool = new ArrayList<>(); + TxPoWDB txpdb = MinimaDB.getDB().getTxPoWDB(); + for(TxPoW memtxp : mempool) { + if(counter chosentxns = new ArrayList<>(); diff --git a/src/org/minima/system/brains/TxPoWMiner.java b/src/org/minima/system/brains/TxPoWMiner.java index 4847445a0..478b66e2d 100644 --- a/src/org/minima/system/brains/TxPoWMiner.java +++ b/src/org/minima/system/brains/TxPoWMiner.java @@ -134,7 +134,7 @@ protected void processMessage(Message zMessage) throws Exception { //Make a log.. if(txpow.isTransaction()) { - MinimaLogger.log("Transaction Mined : "+txpow.getTxPoWID()); + MinimaLogger.log("ASYNC Transaction Mined : "+txpow.getTxPoWID()); } //Post a message.. Mining Finished @@ -234,13 +234,16 @@ public boolean checkForMiningCoin(String zCoinID) { /** * Mine a TxPoW - Used to Mine Maxima Messages */ - public boolean MineMaxTxPoW(TxPoW zTxPoW, long zTimeLimit) { + public boolean MineMaxTxPoW(boolean zMaxima, TxPoW zTxPoW, long zTimeLimit) { //What is the time.. long timenow = System.currentTimeMillis(); - + + //Add these coins to our Mining list + addMiningCoins(zTxPoW); + //Are we logging.. - if(GeneralParams.MINING_LOGS) { + if(GeneralParams.MINING_LOGS && zMaxima) { MinimaLogger.log("MINING MAXIMA START"); } @@ -310,6 +313,11 @@ public boolean MineMaxTxPoW(TxPoW zTxPoW, long zTimeLimit) { //Calculate TxPoWID zTxPoW.calculateTXPOWID(); + //Make a log.. + if(zTxPoW.isTransaction()) { + MinimaLogger.log("SYNC Transaction Mined : "+zTxPoW.getTxPoWID()); + } + //Post it on.. Main.getInstance().PostMessage(new Message(Main.MAIN_TXPOWMINED).addObject("txpow", zTxPoW)); @@ -317,7 +325,7 @@ public boolean MineMaxTxPoW(TxPoW zTxPoW, long zTimeLimit) { removeMiningCoins(zTxPoW); //Are we logging.. - if(GeneralParams.MINING_LOGS) { + if(GeneralParams.MINING_LOGS && zMaxima) { //Time diff.. long timediff = System.currentTimeMillis() - timenow; diff --git a/src/org/minima/system/brains/TxPoWSearcher.java b/src/org/minima/system/brains/TxPoWSearcher.java index 89cb0c8d8..56ab7c17f 100644 --- a/src/org/minima/system/brains/TxPoWSearcher.java +++ b/src/org/minima/system/brains/TxPoWSearcher.java @@ -242,6 +242,40 @@ public static TxPoW getTxPoWBlock(MiniNumber zBlockNumber) { return null; } + public static TxPoW searchChainForTxPoW(MiniData zTxPoWID) { + + //Start node position + TxPoWTreeNode tip = MinimaDB.getDB().getTxPoWTree().getTip(); + + //Now cycle through and get all your coins.. + while(tip != null) { + + //The Block + TxPoW txblock = tip.getTxPoW(); + + //Is this block the txn + if(txblock.getTxPoWIDData().isEqual(zTxPoWID)) { + return txblock; + } + + //Check all the transactions.. + ArrayList txns = txblock.getBlockTransactions(); + for(MiniData txn : txns) { + + //Is this the one.. + if(txn.isEqual(zTxPoWID)) { + return txblock; + } + } + + + //And move back up the tree + tip = tip.getParent(); + } + + return null; + } + public static ArrayList searchTxPoWviaAddress(MiniData zAddress) { ArrayList ret = new ArrayList<>(); diff --git a/src/org/minima/system/commands/Command.java b/src/org/minima/system/commands/Command.java index 3be6c2060..aae4534fe 100644 --- a/src/org/minima/system/commands/Command.java +++ b/src/org/minima/system/commands/Command.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Set; import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -24,19 +25,19 @@ import org.minima.system.commands.base.cointrack; import org.minima.system.commands.base.consolidate; import org.minima.system.commands.base.debugflag; +import org.minima.system.commands.base.file; import org.minima.system.commands.base.getaddress; import org.minima.system.commands.base.hash; import org.minima.system.commands.base.hashtest; import org.minima.system.commands.base.healthcheck; import org.minima.system.commands.base.incentivecash; import org.minima.system.commands.base.logs; +import org.minima.system.commands.base.magic; import org.minima.system.commands.base.mempool; import org.minima.system.commands.base.missingcmd; import org.minima.system.commands.base.mmrcreate; import org.minima.system.commands.base.mmrproof; import org.minima.system.commands.base.newaddress; -import org.minima.system.commands.base.p2pstate; -import org.minima.system.commands.base.peers; import org.minima.system.commands.base.printmmr; import org.minima.system.commands.base.printtree; import org.minima.system.commands.base.quit; @@ -52,17 +53,19 @@ import org.minima.system.commands.base.vault; import org.minima.system.commands.maxima.maxcontacts; import org.minima.system.commands.maxima.maxima; +import org.minima.system.commands.maxima.maxsign; +import org.minima.system.commands.maxima.maxverify; import org.minima.system.commands.mds.mds; import org.minima.system.commands.network.connect; import org.minima.system.commands.network.disconnect; import org.minima.system.commands.network.message; import org.minima.system.commands.network.network; import org.minima.system.commands.network.nodecount; +import org.minima.system.commands.network.p2pstate; +import org.minima.system.commands.network.peers; import org.minima.system.commands.network.ping; import org.minima.system.commands.network.rpc; import org.minima.system.commands.network.webhooks; -import org.minima.system.commands.persistent.file; -import org.minima.system.commands.persistent.sql; import org.minima.system.commands.scripts.newscript; import org.minima.system.commands.scripts.runscript; import org.minima.system.commands.scripts.scripts; @@ -70,6 +73,9 @@ import org.minima.system.commands.search.keys; import org.minima.system.commands.search.tokens; import org.minima.system.commands.search.txpow; +import org.minima.system.commands.send.sendnosign; +import org.minima.system.commands.send.sendpost; +import org.minima.system.commands.send.sendsign; import org.minima.system.commands.signatures.sign; import org.minima.system.commands.signatures.verify; import org.minima.system.commands.txn.txnauto; @@ -106,10 +112,14 @@ public abstract class Command { new mds(), new sendpoll(), new healthcheck(), new mempool(), + new sendsign(), new sendnosign(), new sendpost(), + new magic(), + + new maxsign(), new maxverify(), new archive(), new logs(), - new ping(), new random(), - new sql(),new file(), + new ping(), new random(),new file(), + new vault(), new consolidate(), new backup(), new restore(), new test(), new runscript(), new tutorial(),new keys(), @@ -144,6 +154,10 @@ public void setCompleteCommand(String zCommand) { mCompleteCommand = zCommand; } + public ArrayList getValidParams(){ + return new ArrayList<>(); + } + public String getCompleteCommand() { return mCompleteCommand; } @@ -252,6 +266,14 @@ public JSONArray getJSONArrayParam(String zParamName) throws CommandException { return (JSONArray) mParams.get(zParamName); } + public String getAddressParam(String zParamName, String zDefault) throws CommandException { + if(existsParam(zParamName)) { + return getAddressParam(zParamName); + } + + return zDefault; + } + public String getAddressParam(String zParamName) throws CommandException { if(!existsParam(zParamName)) { throw new CommandException("param not specified : "+zParamName); @@ -320,6 +342,37 @@ public static JSONArray runMultiCommand(String zMiniDAPPID, String zCommand) { //The final result JSONObject result = null; + //Check the Parameters + ArrayList validparams = cmd.getValidParams(); + JSONObject allparams = cmd.getParams(); + Set keys = allparams.keySet(); + + boolean validp=true; + for(String key : keys) { + if(!validparams.contains(key)) { + + //Invalid Param + result= new JSONObject(); + result.put("command", command); + result.put("params", allparams); + result.put("status", false); + result.put("pending", false); + result.put("error", "Invalid parameter : "+key); + + //Add to the List.. + res.add(result); + + //And that's all folks.. + validp=false; + break; + } + } + + //Are we valid.. + if(!validp) { + break; + } + //Is this a MiniDAPP.. if(!zMiniDAPPID.equals("0x00")) { @@ -385,6 +438,20 @@ public static JSONArray runMultiCommand(String zMiniDAPPID, String zCommand) { return res; } + public static Command getCommandOnly(String zCommandName) { + int commandlen = ALL_COMMANDS.length; + + Command comms = null; + for(int i=0;i getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"action","host","phrase","keys","keyuses"})); + } + + @Override + public String getFullHelp() { + return "\narchive\n" + + "\n" + + "Resync your node using an archive node. You need to set the host.\n" + + "\n" + + "Optionally you can set the seed phrase and this will wipe your wallet and reset it with the data.\n" + + "\n" + + "action:\n" + + " resync : do a resync\n" + + " integrity : check the integrity of your Archive DB if you are running an archive node yourself. No host required.\n" + + "\n" + + "host:\n" + + " ip:port of the archive node\n" + + "\n" + + "phrase:\n" + + " Your seed phrase. This will wipe your wallet. You do NOT have to do this. Just resync and you get on the correct chain.\n" + + "\n" + + "keys:\n" + + " Number of keys to create, if you seed phrase sync. Defaults to the 64 you normally have + 16 extra incase you used newaddress\n" + + "\n" + + "keyuses:\n" + + " How many times at most did you use your keys.. Every time you resync with seed phrase this needs to be higher as Minima Signatures are stateful. Defaults to 1000 - the max is 262144 for normal keys\n" + + "\n" + + "Examples:\n" + + "\n" + + "archive action:resync host:89.98.89.98:8888\n"; } @Override @@ -150,10 +185,10 @@ public JSONObject runCommand() throws Exception { int port = connectdata.getInteger("port"); //How many Keys do we need to generate - int keys = getNumberParam("keys", new MiniNumber(Wallet.NUMBER_GETADDRESS_KEYS + 10)).getAsInt(); + int keys = getNumberParam("keys", new MiniNumber(Wallet.NUMBER_GETADDRESS_KEYS + 16)).getAsInt(); //Set the key uses to this.. - int keyuses = getNumberParam("keyuses", new MiniNumber(10000)).getAsInt(); + int keyuses = getNumberParam("keyuses", new MiniNumber(1000)).getAsInt(); //Before we start deleting - check connection.. IBD ibdtest = sendArchiveReq(host, port, MiniNumber.MINUSONE); diff --git a/src/org/minima/system/commands/backup/backup.java b/src/org/minima/system/commands/backup/backup.java index fbb1dc13a..4ff4344ee 100644 --- a/src/org/minima/system/commands/backup/backup.java +++ b/src/org/minima/system/commands/backup/backup.java @@ -5,6 +5,8 @@ import java.io.FileOutputStream; import java.security.SecureRandom; import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.Locale; import java.util.zip.GZIPOutputStream; @@ -32,6 +34,35 @@ public backup() { super("backup","(password:) (file:) (auto:) (complete:false|true) - Backup the system. Uses a timestamped name by default"); } + @Override + public String getFullHelp() { + return "\nbackup\n" + + "\n" + + "Backup your node. Uses a timestamped name by default.\n" + + "\n" + + "password: (optional)\n" + + " Set a password using uppercase, lowercase characters and numbers only.\n" + + "\n" + + "file: (optional)\n" + + " Specify a filename or local path for the backup.\n" + + "\n" + + "auto: (optional)\n" + + " true or false, true will schedule a default, non-password protected backup every 24 hours.\n" + + "\n" + + "Examples:\n" + + "\n" + + "backup password:Longsecurepassword456\n" + + "\n" + + "backup password:Longsecurepassword456 file:my-full-backup-01-Jan-22\n" + + "\n" + + "backup auto:true\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"password","file","auto","complete"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/backup/restore.java b/src/org/minima/system/commands/backup/restore.java index 4d203f73c..8561b6dba 100644 --- a/src/org/minima/system/commands/backup/restore.java +++ b/src/org/minima/system/commands/backup/restore.java @@ -4,6 +4,8 @@ import java.io.DataInputStream; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; import java.util.zip.GZIPInputStream; import javax.crypto.Cipher; @@ -27,6 +29,28 @@ public restore() { super("restore","[file:] (password:) - Restore the entire system."); } + @Override + public String getFullHelp() { + return "\nrestore\n" + + "\n" + + "Restore your node from a backup.\n" + + "\n" + + "file:\n" + + " Specify the filename or local path of the backup to restore\n" + + "\n" + + "password: (optional)\n" + + " Enter the password of the backup \n" + + "\n" + + "Examples:\n" + + "\n" + + "restore file:my-full-backup-01-Jan-22 password:Longsecurepassword456\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"file","password"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/balance.java b/src/org/minima/system/commands/base/balance.java index 948625d0a..0dcbea6e7 100644 --- a/src/org/minima/system/commands/base/balance.java +++ b/src/org/minima/system/commands/base/balance.java @@ -1,6 +1,7 @@ package org.minima.system.commands.base; import java.util.ArrayList; +import java.util.Arrays; import java.util.Hashtable; import org.minima.database.MinimaDB; @@ -23,12 +24,41 @@ public balance() { super("balance","(address:) (tokenid:) (confirmations:) - Show your total balance of Minima and tokens"); } + @Override + public String getFullHelp() { + return "\nbalance\n" + + "\n" + + "Show your total balance of Minima and tokens.\n" + + "\n" + + "address: (optional)\n" + + " Show the balance for a specific 0x or Mx address.\n" + + "\n" + + "tokenid: (optional)\n" + + " Show the balance for a specific tokenid. Minima is 0x00.\n" + + "\n" + + "confirmations: (optional)\n" + + " Set the number of block confirmations required before a coin is considered confirmed in your balance. Default is 3.\n" + + "\n" + + "Examples:\n" + + "\n" + + "balance\n" + + "\n" + + "balance tokenid:0xFED5.. confirmations:10\n" + + "\n" + + "balance address:0xFF..\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"address","tokenid","confirmations"})); + } + @Override public JSONObject runCommand() throws Exception{ JSONObject ret = getJSONReply(); //Is there a specified address - String address = getParam("address",""); + String address = getAddressParam("address",""); MiniNumber confirmations = getNumberParam("confirmations", GlobalParams.MINIMA_CONFIRM_DEPTH); //Are we in debug mode diff --git a/src/org/minima/system/commands/base/burn.java b/src/org/minima/system/commands/base/burn.java index 4c1a0ec25..b5264d749 100644 --- a/src/org/minima/system/commands/base/burn.java +++ b/src/org/minima/system/commands/base/burn.java @@ -37,6 +37,19 @@ public burn() { super("burn","View Burn metrics"); } + @Override + public String getFullHelp() { + return "\nburn\n" + + "\n" + + "View the number of burn transactions and the maximum, median, average and minimum burn metrics for the last 1, 10 and 50 blocks.\n" + + "\n" + + "Use as an indicator for an appropriate burn amount for transactions.\n" + + "\n" + + "Examples:\n" + + "\n" + + "burn\n"; + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/coincheck.java b/src/org/minima/system/commands/base/coincheck.java index 8c040053d..c63cd9f88 100644 --- a/src/org/minima/system/commands/base/coincheck.java +++ b/src/org/minima/system/commands/base/coincheck.java @@ -1,5 +1,8 @@ package org.minima.system.commands.base; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.MinimaDB; import org.minima.database.txpowtree.TxPoWTreeNode; import org.minima.objects.Coin; @@ -15,6 +18,27 @@ public coincheck() { super("coincheck","[data:] - Check a coin exists"); } + @Override + public String getFullHelp() { + return "\ncoincheck\n" + + "\n" + + "Check a coin exists and is valid. Can only check unspent coins.\n" + + "\n" + + "Returns the coin details and whether the MMR proof is valid.\n" + + "\n" + + "data:\n" + + " The data of a coin. Can be found using the 'coinexport' command.\n" + + "\n" + + "Examples:\n" + + "\n" + + "coincheck data:0x00000..\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"data"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/coinexport.java b/src/org/minima/system/commands/base/coinexport.java index d393b9e52..df5a8bd88 100644 --- a/src/org/minima/system/commands/base/coinexport.java +++ b/src/org/minima/system/commands/base/coinexport.java @@ -1,5 +1,8 @@ package org.minima.system.commands.base; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.MinimaDB; import org.minima.database.mmr.MMRProof; import org.minima.database.txpowtree.TxPoWTreeNode; @@ -19,6 +22,28 @@ public coinexport() { super("coinexport","[coinid:] - Export a coin"); } + @Override + public String getFullHelp() { + return "\ncoinexport\n" + + "\n" + + "Export a coin including its MMR proof.\n" + + "\n" + + "A coin can then be imported and tracked on another node using the 'coinimport' command.\n" + + "\n" + + "coinid:\n" + + " The id of a coin. Can be found using the 'coins' command.\n" + + "\n" + + "Examples:\n" + + "\n" + + "coinexport coinid:0xCD34..\n"; + } + + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"coinid"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/coinimport.java b/src/org/minima/system/commands/base/coinimport.java index 4524dc023..ea7013f57 100644 --- a/src/org/minima/system/commands/base/coinimport.java +++ b/src/org/minima/system/commands/base/coinimport.java @@ -1,5 +1,8 @@ package org.minima.system.commands.base; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.MinimaDB; import org.minima.database.mmr.MMRData; import org.minima.database.mmr.MMRProof; @@ -19,6 +22,30 @@ public coinimport() { super("coinimport","[data:] (track:true|false) - Import a coin, and keep tracking it"); } + @Override + public String getFullHelp() { + return "\ncoinimport\n" + + "\n" + + "Import a coin including its MMR proof.\n" + + "\n" + + "Optionally you can track the coin to add it to your relevant coins list and know when it becomes spent.\n" + + "\n" + + "data:\n" + + " The data of a coin. Can be found using the 'coinexport' command.\n" + + "\n" + + "track: (optional)\n" + + " true or false, true will create an MMR entry for the coin and add it to your relevant coins.\n" + + "\n" + + "Examples:\n" + + "\n" + + "coinimport data:0x00000..\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"data","track"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/cointrack.java b/src/org/minima/system/commands/base/cointrack.java index 227a087d8..078befaf9 100644 --- a/src/org/minima/system/commands/base/cointrack.java +++ b/src/org/minima/system/commands/base/cointrack.java @@ -1,5 +1,8 @@ package org.minima.system.commands.base; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.txpowtree.TxPoWTreeNode; import org.minima.objects.Coin; import org.minima.objects.base.MiniData; @@ -14,6 +17,30 @@ public cointrack() { super("cointrack","[enable:true|false] [coinid:] - Track or untrack a coin"); } + @Override + public String getFullHelp() { + return "\ncointrack\n" + + "\n" + + "Track or untrack a coin.\n" + + "\n" + + "Track a coin to keep its MMR proof up-to-date and know when it becomes spent. Stop tracking to remove it from your relevant coins list.\n" + + "\n" + + "enable:\n" + + " true or false, true will add the coin to your relevant coins, false will remove it from your relevant coins.\n" + + "\n" + + "coinid:\n" + + " The id of a coin. Can be found using the 'coins' command.\n" + + "\n" + + "Examples:\n" + + "\n" + + "cointrack enable:true coinid:0xCD34..\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"file","password"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/consolidate.java b/src/org/minima/system/commands/base/consolidate.java index ad07e0b36..f0483fe29 100644 --- a/src/org/minima/system/commands/base/consolidate.java +++ b/src/org/minima/system/commands/base/consolidate.java @@ -1,6 +1,7 @@ package org.minima.system.commands.base; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; @@ -37,6 +38,58 @@ public consolidate() { super("consolidate","[tokenid:] (coinage:) (maxcoins:) (maxsigs:) (burn:) (debug:) (dryrun:) - Consolidate coins by sending them back to yourself"); } + @Override + public String getFullHelp() { + return "\nconsolidate\n" + + "\n" + + "Consolidate multiple coins (UTxOs) into one by sending them back to yourself. Must have at least 3 coins.\n" + + "\n" + + "Useful to prevent having many coins of tiny value and to manage the number of coins you are tracking.\n" + + "\n" + + "Optionally set the minimum coin age (in blocks), maximum number of coins and maximum number of signatures for the transaction.\n" + + "\n" + + "tokenid:\n" + + " The tokenid for Minima or custom token to consolidate coins for. Minima is 0x00.\n" + + "\n" + + "coinage: (optional)\n" + + " The minimum number of blocks deep (confirmations) a coin needs to be. Default is 3.\n" + + "\n" + + "maxcoins: (optional)\n" + + " The maximum number of coins to consolidate. Minimum 3, up to 20.\n" + + " Coins are first sorted by value (smallest first) before adding to the transaction.\n" + + "\n" + + "maxsigs: (optional)\n" + + " The maximum number of signatures for the transaction, up to 5.\n" + + " Coins are then sorted by address to minimize the number of signatures required.\n" + + "\n" + + "burn: (optional)\n" + + " Amount of Minima to burn with the transaction.\n" + + "\n" + + "debug: (optional)\n" + + " true or false, true will print more detailed logs.\n" + + "\n" + + "dryrun: (optional)\n" + + " true or false, true will simulate the consolidate transaction but not execute it.\n" + + "\n" + + "Examples:\n" + + "\n" + + "consolidate tokenid:0x00\n" + + "\n" + + "consolidate tokenid:0x77.. coinage:10\n" + + "\n" + + "consolidate tokenid:0x00 maxcoins:5\n" + + "\n" + + "consolidate tokenid:0x00 coinage:10 maxcoins:8 burn:1\n" + + "\n" + + "consolidate tokenid:0x00 coinage:10 maxcoins:8 maxsigs:3 burn:1 dryrun:true\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"tokenid","coinage","maxcoins", + "maxsigs","burn","debug","dryrun"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/debugflag.java b/src/org/minima/system/commands/base/debugflag.java index 2621848fc..fcae01434 100644 --- a/src/org/minima/system/commands/base/debugflag.java +++ b/src/org/minima/system/commands/base/debugflag.java @@ -1,5 +1,8 @@ package org.minima.system.commands.base; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.system.commands.Command; import org.minima.system.params.GeneralParams; import org.minima.utils.json.JSONObject; @@ -10,6 +13,11 @@ public debugflag() { super("debugflag","(activate:true|false) (var:) - Set DEBUG flag for testing code.."); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"activate","var"})); + } + @Override public JSONObject runCommand() throws Exception{ JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/file.java b/src/org/minima/system/commands/base/file.java index f9c72c624..b0ec98b0a 100644 --- a/src/org/minima/system/commands/base/file.java +++ b/src/org/minima/system/commands/base/file.java @@ -1,6 +1,8 @@ package org.minima.system.commands.base; import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; import org.minima.objects.base.MiniData; import org.minima.system.commands.Command; @@ -16,6 +18,11 @@ public file() { super("file","[action:list|load|save|delete] [file:] (data:)- Load, save, delete or list files. / is root. Data is in 0xHEX format"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"action","file","data"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/getaddress.java b/src/org/minima/system/commands/base/getaddress.java index 6e921f935..7ea014044 100644 --- a/src/org/minima/system/commands/base/getaddress.java +++ b/src/org/minima/system/commands/base/getaddress.java @@ -1,15 +1,48 @@ package org.minima.system.commands.base; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.MinimaDB; import org.minima.database.wallet.ScriptRow; import org.minima.database.wallet.Wallet; import org.minima.system.commands.Command; +import org.minima.utils.MinimaLogger; import org.minima.utils.json.JSONObject; public class getaddress extends Command { public getaddress() { - super("getaddress","Get one of your default Minima addresses"); + super("getaddress","(createall:true) Get one of your default Minima addresses"); + } + + @Override + public String getFullHelp() { + return "\ngetaddress\n" + + "\n" + + "Returns an existing default Minima address to receive funds, use as a change address etc.\n" + + "\n" + + "Each address can be used securely 262144 (64^3) times.\n" + + "\n" + + "Optionally, force create all 64 default keys immediately when starting a new node.\n" + + "\n" + + "Create all if you want to make a backup and transfer your keys to an offline device for signing transactions.\n" + + "\n" + + "Then you can wipe the private keys from your online node using the 'vault' command.\n" + + "\n" + + "createall: (optional)\n" + + " true only. To force create all 64 default keys immediately when starting a new node.\n" + + "\n" + + "Examples:\n" + + "\n" + + "getaddress\n" + + "\n" + + "getaddress createall:true\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"createall"})); } @Override @@ -19,13 +52,26 @@ public JSONObject runCommand() throws Exception{ //Get the wallet.. Wallet wallet = MinimaDB.getDB().getWallet(); - String type = getParam("type","single"); + //Are we creating them all.. + if(existsParam("createall")) { + + MinimaLogger.log("Creating all remaining keys.."); + + //Create all remaining addresses.. + wallet.initDefaultKeys(Wallet.NUMBER_GETADDRESS_KEYS, true); + + ret.put("response", "All keys created.."); + + }else { - //Get an existing address - ScriptRow scrow = wallet.getDefaultAddress(); + String type = getParam("type","single"); - //Put the details in the response.. - ret.put("response", scrow.toJSON()); + //Get an existing address + ScriptRow scrow = wallet.getDefaultAddress(); + + //Put the details in the response.. + ret.put("response", scrow.toJSON()); + } return ret; } diff --git a/src/org/minima/system/commands/base/hash.java b/src/org/minima/system/commands/base/hash.java index 373cc2e29..9e9fc7344 100644 --- a/src/org/minima/system/commands/base/hash.java +++ b/src/org/minima/system/commands/base/hash.java @@ -1,5 +1,8 @@ package org.minima.system.commands.base; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.objects.base.MiniData; import org.minima.objects.base.MiniString; import org.minima.system.commands.Command; @@ -13,6 +16,34 @@ public hash() { super("hash","[data:] (type:keccak|sha2|sha3)- Hash the data - default KECCAK"); } + @Override + public String getFullHelp() { + return "\nhash\n" + + "\n" + + "Hash the data - default KECCAK.\n" + + "\n" + + "Returns the hash of the data provided using the algorithm specified.\n" + + "\n" + + "data:\n" + + " The data to hash. Can be HEX (0x) or a string in quotes.\n" + + " String data will return the the byte representation of the string.\n" + + "\n" + + "type: (optional)\n" + + " keccak, sha2 or sha3. The hashing algorithm to use, default is KECCAK.\n" + + " BTC and ETH support sha2 or sha3.\n" + + "\n" + + "Examples:\n" + + "\n" + + "hash data:0x1C8AFF950685C2ED4BC3174F3472287B56D9517B9C948127319A09A7A36DEAC8\n" + + "\n" + + "hash data:\"this is my secret\" type:sha2\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"data","type"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/hashtest.java b/src/org/minima/system/commands/base/hashtest.java index e211cfa4d..9684fbdbc 100644 --- a/src/org/minima/system/commands/base/hashtest.java +++ b/src/org/minima/system/commands/base/hashtest.java @@ -1,8 +1,14 @@ package org.minima.system.commands.base; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.objects.base.MiniData; +import org.minima.objects.base.MiniNumber; +import org.minima.system.brains.TxPoWMiner; import org.minima.system.commands.Command; import org.minima.utils.Crypto; +import org.minima.utils.MinimaLogger; import org.minima.utils.json.JSONObject; public class hashtest extends Command { @@ -11,31 +17,50 @@ public hashtest() { super("hashtest","(amount:) - Check the speed of hashing of this device. Defaults to 1 million hashes"); } + @Override + public String getFullHelp() { + return "\nhashtest\n" + + "\n" + + "Check the speed of hashing of this device. Defaults to 1 million hashes.\n" + + "\n" + + "Returns the time taken in milliseconds and speed in megahashes/second.\n" + + "\n" + + "E.g. A speed of 0.5 MH/s indicates 500000 hashes per second.\n" + + "\n" + + "amount: (optional)\n" + + " Number of hashes to execute.\n" + + "\n" + + "Examples:\n" + + "\n" + + "hashtest\n" + + "\n" + + "hashtest amount:2000000\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"amount"})); + } + @Override public JSONObject runCommand() throws Exception{ JSONObject ret = getJSONReply(); //How many hashes to perform - int hashes = Integer.parseInt(getParam("amount", "1000000")); - - long timestart = System.currentTimeMillis(); - - MiniData data = MiniData.getRandomData(32); - for(int i=0;i getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"uid"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/logs.java b/src/org/minima/system/commands/base/logs.java index 363b6f96e..7c5fa1639 100644 --- a/src/org/minima/system/commands/base/logs.java +++ b/src/org/minima/system/commands/base/logs.java @@ -1,5 +1,8 @@ package org.minima.system.commands.base; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.system.commands.Command; import org.minima.system.params.GeneralParams; import org.minima.utils.json.JSONObject; @@ -10,6 +13,30 @@ public logs() { super("logs","(scripts:true|false) (mining:true|false) - Enable full logs for various parts of Minima"); } + @Override + public String getFullHelp() { + return "\nlogs\n" + + "\n" + + "Enable detailed logs for script errors or mining activity.\n" + + "\n" + + "scripts: (optional)\n" + + " true or false, true turns on detailed logs for script errors.\n" + + "\n" + + "mining: (optional)\n" + + " true or false, true turns on detailed logs for mining start/end activity.\n" + + "\n" + + "Examples:\n" + + "\n" + + "logs scripts:true\n" + + "\n" + + "logs scripts:false mining:true\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"scripts","mining"})); + } + @Override public JSONObject runCommand() throws Exception{ JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/magic.java b/src/org/minima/system/commands/base/magic.java new file mode 100644 index 000000000..efdaa937b --- /dev/null +++ b/src/org/minima/system/commands/base/magic.java @@ -0,0 +1,69 @@ +package org.minima.system.commands.base; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.minima.database.MinimaDB; +import org.minima.database.txpowtree.TxPoWTreeNode; +import org.minima.database.userprefs.UserDB; +import org.minima.objects.base.MiniNumber; +import org.minima.system.commands.Command; +import org.minima.system.params.GeneralParams; +import org.minima.utils.json.JSONObject; + +public class magic extends Command { + + public magic() { + super("magic","(kissvm:) (txpowsize:) (txnsperblock:) - Set the Magic numbers that define the Minima network overall capacity"); + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"kissvm","txpowsize","txnsperblock"})); + } + + @Override + public JSONObject runCommand() throws Exception{ + JSONObject ret = getJSONReply(); + + JSONObject resp = new JSONObject(); + + UserDB udb = MinimaDB.getDB().getUserDB(); + + if(existsParam("kissvm")) { + //Set this as your KISSVM opcodes.. + udb.setMagicDesiredKISSVM(getNumberParam("kissvm")); + } + + if(existsParam("txpowsize")) { + //Set this as your KISSVM opcodes.. + udb.setMagicMaxTxPoWSize(getNumberParam("txpowsize")); + } + + if(existsParam("txnsperblock")) { + //Set this as your KISSVM opcodes.. + udb.setMagicMaxTxns(getNumberParam("txnsperblock")); + } + + //Get the Tip.. + TxPoWTreeNode tip = MinimaDB.getDB().getTxPoWTree().getTip(); + resp.put("lastblock", tip.getTxPoW().getMagic().toJSON()); + + JSONObject desired = new JSONObject(); + desired.put("kissvm", udb.getMagicDesiredKISSVM()); + desired.put("txpowsize", udb.getMagicMaxTxPoWSize()); + desired.put("txnsperblock", udb.getMagicMaxTxns()); + resp.put("desired", desired); + + //Add balance.. + ret.put("response", resp); + + return ret; + } + + @Override + public Command getFunction() { + return new magic(); + } + +} diff --git a/src/org/minima/system/commands/base/mmrcreate.java b/src/org/minima/system/commands/base/mmrcreate.java index 744ee99b4..fade73261 100644 --- a/src/org/minima/system/commands/base/mmrcreate.java +++ b/src/org/minima/system/commands/base/mmrcreate.java @@ -1,6 +1,7 @@ package org.minima.system.commands.base; import java.util.ArrayList; +import java.util.Arrays; import org.minima.database.mmr.MMR; import org.minima.database.mmr.MMRData; @@ -29,6 +30,35 @@ public mmrcreate() { super("mmrcreate","[nodes:[]] - Create an MMR Tree of data. Nodes can be STRING / HEX"); } + @Override + public String getFullHelp() { + return "\nmmrcreate\n" + + "\n" + + "Create an MMR Tree of data. Can be used in MAST contracts.\n" + + "\n" + + "Must specify a JSON array of string/HEX data for the leaf nodes.\n" + + "\n" + + "They could be a list of public keys.. and then in a script you can check if the given key is one in the set.\n" + + "\n" + + "OR you can have different scripts.. and then you can execute any number of scripts from the same UTXO.\n" + + "\n" + + "Returns the MMR data and proof for each leaf node and the MMR root hash.\n" + + "\n" + + "nodes:\n" + + " JSON array of string/HEX data for the leaf nodes.\n" + + "\n" + + "Examples:\n" + + "\n" + + "mmrcreate nodes:[\"RETURN TRUE\",\"RETURN FALSE\"]\n" + + "\n" + + "mmrcreate nodes:[\"0xFF..\",\"0xEE..\"]\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"nodes"})); + } + @Override public JSONObject runCommand() throws Exception{ JSONObject ret = getJSONReply(); @@ -74,7 +104,7 @@ public JSONObject runCommand() throws Exception{ //Increment counter++; - //Add to thew MMR + //Add to the MMR mmrtree.addEntry(new MMRData(hash)); } diff --git a/src/org/minima/system/commands/base/mmrproof.java b/src/org/minima/system/commands/base/mmrproof.java index 585af807b..00a908fb0 100644 --- a/src/org/minima/system/commands/base/mmrproof.java +++ b/src/org/minima/system/commands/base/mmrproof.java @@ -1,5 +1,8 @@ package org.minima.system.commands.base; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.mmr.MMRData; import org.minima.database.mmr.MMRProof; import org.minima.objects.base.MiniData; @@ -23,6 +26,35 @@ public mmrproof() { super("mmrproof","[data:] [proof:] [root:] - Check an MMR proof"); } + @Override + public String getFullHelp() { + return "\nmmrproof\n" + + "\n" + + "Check an MMR Proof.\n" + + "\n" + + "Can be used to check MMR Proof of coins, scripts or a custom MMR tree created with the 'mmrcreate' command.\n" + + "\n" + + "Returns true if the proof is valid or false if not.\n" + + "\n" + + "data:\n" + + " String/HEX data of an MMR leaf node.\n" + + "\n" + + "proof:\n" + + " The MMR proof of the data from the 'mmrcreate' command.\n" + + "\n" + + "root:\n" + + " The root hash of the MMR tree from the 'mmrcreate' command.\n" + + "\n" + + "Examples:\n" + + "\n" + + "mmrproof data:0xCD34.. proof:0xFED5.. root:0xDAE6..\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"data","proof","root"})); + } + @Override public JSONObject runCommand() throws Exception{ JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/newaddress.java b/src/org/minima/system/commands/base/newaddress.java index e3aa82dee..d5fec2d32 100644 --- a/src/org/minima/system/commands/base/newaddress.java +++ b/src/org/minima/system/commands/base/newaddress.java @@ -12,6 +12,19 @@ public newaddress() { super("newaddress","Create a new address that will not be not used for anything else (not a default change address)"); } + @Override + public String getFullHelp() { + return "\nnewaddress\n" + + "\n" + + "Create a new address that will not be not used for anything else (not one of the 64 default change address).\n" + + "\n" + + "Can be used for a specific use case or for improved privacy.\n" + + "\n" + + "Examples:\n" + + "\n" + + "newaddress\n"; + } + @Override public JSONObject runCommand() throws Exception{ JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/peers.java b/src/org/minima/system/commands/base/peers.java deleted file mode 100644 index 5583ba9cb..000000000 --- a/src/org/minima/system/commands/base/peers.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.minima.system.commands.base; - -import org.minima.system.Main; -import org.minima.system.commands.Command; -import org.minima.system.commands.CommandException; -import org.minima.system.network.p2p.P2PManager; -import org.minima.system.network.p2p.messages.InetSocketAddressIO; -import org.minima.system.params.GeneralParams; -import org.minima.utils.json.JSONObject; - -public class peers extends Command { - - public peers() { - super("peers","prints the peers list this node has"); - } - - @Override - public JSONObject runCommand() throws Exception{ - JSONObject ret = getJSONReply(); - - //Is the P2P Enable.. - if(!GeneralParams.P2P_ENABLED) { - throw new CommandException("P2P System not enabled"); - } - - - P2PManager p2PManager = (P2PManager) Main.getInstance().getNetworkManager().getP2PManager(); - - JSONObject resp = new JSONObject(); - resp.put("peers-list", InetSocketAddressIO.addressesListToJSONArray(p2PManager.getPeersCopy())); - ret.put("response", resp); - - return ret; - } - - @Override - public Command getFunction() { - return new peers(); - } - -} diff --git a/src/org/minima/system/commands/base/printmmr.java b/src/org/minima/system/commands/base/printmmr.java index 45cf00134..6ea30b2e6 100644 --- a/src/org/minima/system/commands/base/printmmr.java +++ b/src/org/minima/system/commands/base/printmmr.java @@ -8,7 +8,24 @@ public class printmmr extends Command { public printmmr() { - super("printmmr", ""); + super("printmmr", "Print the MMR set of the tip block"); + } + + @Override + public String getFullHelp() { + return "\nprintmmr\n" + + "\n" + + "Print the MMR set of the tip block and the total number of entries in the MMR.\n" + + "\n" + + "Returns the tip block number, latest entrynumber and latest set of MMR entries.\n" + + "" + + "For each entry, details of its row, entry number, data and value of all new and updated MMR entries for the tip block.\n" + + "\n" + + "Row 1 represents the leaf nodes, entry 0 represents the first entry on a row.\n" + + "\n" + + "Examples:\n" + + "\n" + + "printmmr\n"; } @Override @@ -17,7 +34,7 @@ public JSONObject runCommand() throws Exception { MMR mmr = MinimaDB.getDB().getTxPoWTree().getTip().getMMR(); - ret.put("responsse", mmr.toJSON()); + ret.put("response", mmr.toJSON()); return ret; } diff --git a/src/org/minima/system/commands/base/printtree.java b/src/org/minima/system/commands/base/printtree.java index 8e38e5217..434fc8684 100644 --- a/src/org/minima/system/commands/base/printtree.java +++ b/src/org/minima/system/commands/base/printtree.java @@ -1,5 +1,8 @@ package org.minima.system.commands.base; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.MinimaDB; import org.minima.system.commands.Command; import org.minima.utils.json.JSONObject; @@ -10,6 +13,37 @@ public printtree() { super("printtree", "(depth:) (cascade:true|false) - Print a tree representation of the blockchain. Depth default 32, Cascade false."); } + @Override + public String getFullHelp() { + return "\nprinttree\n" + + "\n" + + "Print a tree representation of the blockchain.\n" + + "\n" + + "Default depth 32 blocks, can be increased to see more of the txpow tree.\n" + + "\n" + + "Optionally show the cascading chain, default is false.\n" + + "\n" + + "depth: (optional)\n" + + " Number of blocks back from the tip to show in the txpow tree.\n" + + "\n" + + "cascade: (optional)\n" + + " true or false, true shows the cascade.\n" + + "\n" + + "Examples:\n" + + "\n" + + "printtree\n" + + "\n" + + "printtree depth:500\n" + + "\n" + + "printtree cascade:true\n"; + + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"depth","cascade"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/quit.java b/src/org/minima/system/commands/base/quit.java index da984bb86..68473d030 100644 --- a/src/org/minima/system/commands/base/quit.java +++ b/src/org/minima/system/commands/base/quit.java @@ -10,6 +10,19 @@ public quit() { super("quit","Shutdown Minima"); } + @Override + public String getFullHelp() { + return "\nquit\n" + + "\n" + + "Shutdown Minima safely.\n" + + "\n" + + "Ensure you have a backup before shutting down.\n" + + "\n" + + "Examples:\n" + + "\n" + + "quit\n"; + } + @Override public JSONObject runCommand() { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/random.java b/src/org/minima/system/commands/base/random.java index 1427a7ade..9b64e66dd 100644 --- a/src/org/minima/system/commands/base/random.java +++ b/src/org/minima/system/commands/base/random.java @@ -1,5 +1,8 @@ package org.minima.system.commands.base; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.objects.base.MiniData; import org.minima.objects.base.MiniNumber; import org.minima.system.commands.Command; @@ -11,6 +14,27 @@ public random() { super("random","(size:) - Generate a random hash value, defaults to 32 bytes"); } + @Override + public String getFullHelp() { + return "\nrandom\n" + + "\n" + + "Generate a random hash value, defaults to 32 bytes.\n" + + "\n" + + "size: (optional)\n" + + " Integer number of bytes for the hash value.\n" + + "\n" + + "Examples:\n" + + "\n" + + "random\n" + + "\n" + + "random size:64\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"size"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/send.java b/src/org/minima/system/commands/base/send.java index a773db650..851300387 100644 --- a/src/org/minima/system/commands/base/send.java +++ b/src/org/minima/system/commands/base/send.java @@ -1,6 +1,7 @@ package org.minima.system.commands.base; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; @@ -59,7 +60,66 @@ public MiniNumber getAmount() { } public send() { - super("send","(address:Mx..|0x..) (amount:) (multi:[address:amount,..]) (tokenid:) (state:{}) (burn:) (split:) (debug:) (dryrun:) - Send Minima or Tokens to an address"); + super("send","(address:Mx..|0x..) (amount:) (multi:[address:amount,..]) (tokenid:) (state:{}) (burn:) (split:) (mine:) (debug:) (dryrun:) - Send Minima or Tokens to an address"); + } + + @Override + public String getFullHelp() { + return "\nsend\n" + + "\n" + + "Send Minima or custom tokens to a wallet or custom script address.\n" + + "\n" + + "Optionally, send to multiple addresses in one transaction; split UTxOs; add state variables or include a burn.\n" + + "\n" + + "address: (optional)\n" + + " A Minima 0x or Mx wallet address or custom script address. Must also specify amount.\n" + + "\n" + + "amount: (optional)\n" + + " The amount of Minima or custom tokens to send to the specified address.\n" + + "\n" + + "multi: (optional)\n" + + " JSON Array listing addresses and amounts to send in one transaction.\n" + + " Takes the format [address:amount,address2:amount2,..], with each set in double quotes.\n" + + "\n" + + "tokenid: (optional)\n" + + " If sending a custom token, you must specify its tokenid. Defaults to Minima (0x00).\n" + + "\n" + + "state: (optional)\n" + + " List of state variables, if sending coins to a script. A JSON object in the format {\"port\":\"value\",..}\n" + + "\n" + + "burn: (optional)\n" + + " The amount of Minima to burn with this transaction.\n" + + "\n" + + "split: (optional)\n" + + " You can set the number of coins the recipient will receive, between 1 and 20. Default is 1.\n" + + " The amount being sent will be split into multiple coins of equal value.\n" + + " You can split your own coins by sending to your own address.\n" + + " Useful if you want to send multiple transactions without waiting for change to be confirmed.\n" + + "\n" + + "debug: (optional)\n" + + " true or false, true will print more detailed logs.\n" + + "\n" + + "dryrun: (optional)\n" + + " true or false, true will simulate the send transaction but not execute it.\n" + + "\n" + + "Examples:\n" + + "\n" + + "send address:0xFF.. amount:10\n" + + "\n" + + "send address:0xFF.. amount:10 tokenid:0xFED5.. burn:0.1\n" + + "\n" + + "send address:0xFF.. amount:10 split:5 burn:0.1\n" + + "\n" + + "send multi:[\"0xFF..:10\",\"0xEE..:10\",\"0xDD..:10\"] split:20\n" + + "\n" + + "send amount:1 address:0xFF.. state:{\"0\":\"0xEE..\",\"1\":\"0xDD..\"}\n"; + + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"action","uid", + "address","amount","multi","tokenid","state","burn","split","debug","dryrun","mine"})); } @Override @@ -69,7 +129,7 @@ public JSONObject runCommand() throws Exception { //Who are we sending to ArrayList recipients = new ArrayList<>(); - //What is the toal amount we are sending.. + //What is the total amount we are sending.. MiniNumber totalamount = MiniNumber.ZERO; //Is it a MULTI send.. @@ -149,6 +209,9 @@ public JSONObject runCommand() throws Exception { state = getJSONObjectParam("state"); } + //Are we Mining synchronously + boolean minesync = getBooleanParam("mine", false); + //get the tip.. TxPoWTreeNode tip = MinimaDB.getDB().getTxPoWTree().getTip(); @@ -501,17 +564,28 @@ public JSONObject runCommand() throws Exception { //Calculate the txpowid / size.. txpow.calculateTXPOWID(); - //All good.. - ret.put("dryrun", dryrun); - ret.put("response", txpow.toJSON()); - if(!dryrun) { - //Send it to the Miner.. - Main.getInstance().getTxPoWMiner().mineTxPoWAsync(txpow); + + //Sync or Asyn mining.. + if(minesync) { + boolean success = Main.getInstance().getTxPoWMiner().MineMaxTxPoW(false, txpow, 120000); + + if(!success) { + throw new CommandException("FAILED TO MINE txn in 120 seconds !?"); + } + + }else { + Main.getInstance().getTxPoWMiner().mineTxPoWAsync(txpow); + } + }else { MinimaLogger.log("DRY RUN - not sending"); } + //All good.. + ret.put("dryrun", dryrun); + ret.put("response", txpow.toJSON()); + return ret; } @@ -528,11 +602,11 @@ public Command getFunction() { * Expects all the coins to be of the same tokenid */ - private static ArrayList selectCoins(ArrayList zAllCoins, MiniNumber zAmountRequired){ + public static ArrayList selectCoins(ArrayList zAllCoins, MiniNumber zAmountRequired){ return selectCoins(zAllCoins, zAmountRequired, false); } - private static ArrayList selectCoins(ArrayList zAllCoins, MiniNumber zAmountRequired, boolean zDebug){ + public static ArrayList selectCoins(ArrayList zAllCoins, MiniNumber zAmountRequired, boolean zDebug){ ArrayList ret = new ArrayList<>(); //Get the TxPoWDB @@ -541,14 +615,6 @@ private static ArrayList selectCoins(ArrayList zAllCoins, MiniNumber //First sort the coins by size and address.. ArrayList coinlist = orderCoins(zAllCoins); -// Collections.sort(zAllCoins, new Comparator() { -// @Override -// public int compare(Coin zCoin1, Coin zCoin2) { -// MiniNumber amt1 = zCoin1.getAmount(); -// MiniNumber amt2 = zCoin2.getAmount(); -// return amt2.compareTo(amt1); -// } -// }); //Are we debugging.. if(zDebug) { @@ -679,4 +745,4 @@ public static void main(String[] zArgs) { System.out.println(cc.toJSON().toString()); } } -} +} \ No newline at end of file diff --git a/src/org/minima/system/commands/base/sendpoll.java b/src/org/minima/system/commands/base/sendpoll.java index e5f934fce..42da0945e 100644 --- a/src/org/minima/system/commands/base/sendpoll.java +++ b/src/org/minima/system/commands/base/sendpoll.java @@ -1,6 +1,7 @@ package org.minima.system.commands.base; import java.util.ArrayList; +import java.util.Arrays; import org.minima.system.Main; import org.minima.system.commands.Command; @@ -15,6 +16,38 @@ public sendpoll() { super("sendpoll","(action:add|list|remove) (uid:) - Send function that is added to a list and polls until complete"); } + @Override + public String getFullHelp() { + return "\nsendpoll\n" + + "\n" + + "Send function that adds 'send' commands to a list and polls every 30 seconds until the return status is 'true'.\n" + + "\n" + + "Accepts the same parameters as the 'send' function.\n" + + "\n" + + "action: (optional)\n" + + " list : list all the 'send' commands in the polling list.\n" + + " remove : remove a 'send' command from the polling list.\n" + + "\n" + + "uid: (optional)\n" + + " The uid of a 'send' command you wish to remove from the polling list. Use with 'action:remove'.\n" + + "\n" + + "Examples:\n" + + "\n" + + "sendpoll address:0xFF.. amount:10\n" + + "\n" + + "sendpoll address:0xFF.. amount:10 tokenid:0xFED5.. burn:0.1\n" + + "\n" + + "sendpoll action:list\n" + + "\n" + + "sendpoll action:remove uid:0x..\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"action","uid", + "address","amount","multi","tokenid","state","burn","split","debug","dryrun","mine"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); @@ -70,4 +103,4 @@ public Command getFunction() { return new sendpoll(); } -} +} \ No newline at end of file diff --git a/src/org/minima/system/commands/base/status.java b/src/org/minima/system/commands/base/status.java index 4c653aaeb..c4900ef92 100644 --- a/src/org/minima/system/commands/base/status.java +++ b/src/org/minima/system/commands/base/status.java @@ -4,6 +4,8 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.math.MathContext; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import org.minima.database.MinimaDB; @@ -35,6 +37,29 @@ public status() { super("status","(clean:true) - Show general status for Minima and clean RAM"); } + @Override + public String getFullHelp() { + return "\nstatus\n" + + "\n" + + "Show the general status for Minima and your node. Optionally clean the RAM.\n" + + "\n" + + "Prints details for general status, memory used, chain info, stored txpow units, network connections, p2p connections and traffic.\n" + + "\n" + + "clean: (optional)\n" + + " true only, clear the RAM.\n" + + "\n" + + "Examples:\n" + + "\n" + + "status\n" + + "\n" + + "status clean:true\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"clean"})); + } + @Override public JSONObject runCommand() throws Exception{ JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/test.java b/src/org/minima/system/commands/base/test.java index 3c74c8b7b..e6c9f4e3b 100644 --- a/src/org/minima/system/commands/base/test.java +++ b/src/org/minima/system/commands/base/test.java @@ -26,38 +26,9 @@ public JSONObject runCommand() throws Exception { //Get the Archive DB ArchiveManager arch = MinimaDB.getDB().getArchive(); - //Get the current lowest block - TxBlock txbbefore = arch.loadLastBlock(); + arch.hackShut(); - JSONObject resp = new JSONObject(); - - TxBlock firstblock = arch.loadFirstBlock(); - TxBlock lastblock = arch.loadLastBlock(); - resp.put("xfirstblock", firstblock.getTxPoW().getBlockNumber()); - resp.put("xlastblock", lastblock.getTxPoW().getBlockNumber()); - - resp.put("archivesizebefore", arch.getSize()); - resp.put("lastblock", txbbefore.getTxPoW().getBlockNumber().toString()); - resp.put("lasttime", new Date(txbbefore.getTxPoW().getTimeMilli().getAsLong())); - resp.put("lastjson", arch.loadLastBlockJSON()); - - //Now do a cleanDB - int del = arch.cleanDB(); - MinimaLogger.log("DELETED : "+del); - - txbbefore = arch.loadLastBlock(); - - resp.put("archiveafter", arch.getSize()); - resp.put("aftlastblock", txbbefore.getTxPoW().getBlockNumber().toString()); - resp.put("aftlasttime", new Date(txbbefore.getTxPoW().getTimeMilli().getAsLong())); - resp.put("afterjson", arch.loadLastBlockJSON()); - - ArrayList blocks = arch.loadBlockRange(new MiniNumber(2000), new MiniNumber(2010)); - for(TxBlock block : blocks) { - MinimaLogger.log(block.getTxPoW().getBlockNumber().toString()); - } - - ret.put("response", resp); + ret.put("response", "Archive DB Closed for test"); return ret; } diff --git a/src/org/minima/system/commands/base/tokencreate.java b/src/org/minima/system/commands/base/tokencreate.java index 1813b357d..99a6f28b2 100644 --- a/src/org/minima/system/commands/base/tokencreate.java +++ b/src/org/minima/system/commands/base/tokencreate.java @@ -1,6 +1,7 @@ package org.minima.system.commands.base; import java.util.ArrayList; +import java.util.Arrays; import org.minima.database.MinimaDB; import org.minima.database.mmr.MMRProof; @@ -29,6 +30,7 @@ import org.minima.system.commands.CommandException; import org.minima.system.commands.txn.txnutils; import org.minima.system.params.GlobalParams; +import org.minima.utils.MinimaLogger; import org.minima.utils.json.JSONObject; public class tokencreate extends Command { @@ -37,6 +39,58 @@ public tokencreate() { super("tokencreate","[name:] [amount:] (decimals:) (script:) (state:{}) (signtoken:) (webvalidate:) (burn:) - Create a token. 'name' can be a JSON Object"); } + @Override + public String getFullHelp() { + return "\ntokencreate\n" + + "\n" + + "Create (mint) custom tokens or NFTs.\n" + + "\n" + + "You must have some sendable Minima in your wallet as tokens are 'colored coins', a fraction of 1 Minima.\n" + + "\n" + + "name:\n" + + " The name of the token. Can be a string or JSON Object.\n" + + "\n" + + "amount: \n" + + " The amount of total supply to create for the token. Between 1 and 1 Trillion.\n" + + "\n" + + "decimals: (optional)\n" + + " The number of decimal places for the token. Default is 8, maximum 16.\n" + + " To create NFTs, use 0.\n" + + "\n" + + "script: (optional)\n" + + " Add a custom script that must return 'true' when spending the token.\n" + + "\n" + + "state: (optional)\n" + + " List of state variables, if adding a script. A JSON object in the format {\"port\":\"value\",..}\n" + + "\n" + + "signtoken: (optional)\n" + + " Provide a public key to sign the token with.\n" + + " Useful for proving you are the creator of the token/NFT.\n" + + "\n" + + "webvalidate: (optional)\n" + + " Provide a URL to a publicly viewable .txt file you are hosting which stores the tokenid for validation purposes.\n" + + " Create the file in advance and get the tokenid after the token has been minted.\n" + + "\n" + + "burn: (optional)\n" + + " Amount to burn with the tokencreate minting transaction.\n" + + "\n" + + "Examples:\n" + + "\n" + + "tokencreate name:newtoken amount:1000000\n" + + "\n" + + "tokencreate amount:10 name:{\"name\":\"newcoin\",\"link\":\"http:mysite.com\",\"description\":\"A very cool token\"}\n" + + "\n" + + "tokencreate name:mynft amount:10 decimals:0 webvalidate:https://www.mysite.com/nftvalidation.txt signtoken:0xFF.. burn:0.1\n" + + "\n" + + "tokencreate name:charitycoin amount:1000 script:\"ASSERT VERIFYOUT(@TOTOUT-1 0xMyAddress 1 0x00 TRUE)\"\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"name","amount","decimals","script", + "state","signtoken","webvalidate","burn"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); @@ -117,8 +171,8 @@ public JSONObject runCommand() throws Exception { //What is the scale.. int scale = MiniNumber.MAX_DECIMAL_PLACES - decimals; - //The actual amount of Minima that needs to be sent - MiniNumber sendamount = new MiniNumber(colorminima); + //The actual amount of Minima that needs to be sent - add the burn if any + MiniNumber sendamount = colorminima.add(burn); //Send it to ourselves ScriptRow sendkey = MinimaDB.getDB().getWallet().getDefaultAddress(); @@ -259,7 +313,7 @@ public JSONObject runCommand() throws Exception { } //Now add the output.. - Coin recipient = new Coin(Coin.COINID_OUTPUT, sendaddress, sendamount, Token.TOKENID_CREATE, true); + Coin recipient = new Coin(Coin.COINID_OUTPUT, sendaddress, colorminima, Token.TOKENID_CREATE, true); //Is there a Web Validation URL if(existsParam("webvalidate")) { @@ -350,21 +404,7 @@ public JSONObject runCommand() throws Exception { } //The final TxPoW - TxPoW txpow = null; - - //Is there a BURN.. - if(burn.isMore(MiniNumber.ZERO)) { - - //Create a Burn Transaction - TxnRow burntxn = txnutils.createBurnTransaction(addedcoinid,transaction.getTransactionID(),burn); - - //Now create a complete TxPOW - txpow = TxPoWGenerator.generateTxPoW(transaction, witness, burntxn.getTransaction(), burntxn.getWitness()); - - }else { - //Now create a complete TxPOW - txpow = TxPoWGenerator.generateTxPoW(transaction, witness); - } + TxPoW txpow = TxPoWGenerator.generateTxPoW(transaction, witness); //Calculate the size.. txpow.calculateTXPOWID(); diff --git a/src/org/minima/system/commands/base/tokenvalidate.java b/src/org/minima/system/commands/base/tokenvalidate.java index ad984b24f..1e70c0fb3 100644 --- a/src/org/minima/system/commands/base/tokenvalidate.java +++ b/src/org/minima/system/commands/base/tokenvalidate.java @@ -1,6 +1,7 @@ package org.minima.system.commands.base; import java.util.ArrayList; +import java.util.Arrays; import org.minima.objects.Token; import org.minima.objects.base.MiniData; @@ -19,6 +20,25 @@ public tokenvalidate() { super("tokenvalidate","[tokenid:] - validate the signature and web link in a token"); } + @Override + public String getFullHelp() { + return "\ntokenvalidate\n" + + "\n" + + "Validate the signature and webvalidate link in a token.\n" + + "\n" + + "tokenid:\n" + + " The tokenid of the custom token/NFT to validate.\n" + + "\n" + + "Examples:\n" + + "\n" + + "tokenvalidate tokenid:0xFED5..\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"tokenid"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/trace.java b/src/org/minima/system/commands/base/trace.java index d18f70450..afc33da37 100644 --- a/src/org/minima/system/commands/base/trace.java +++ b/src/org/minima/system/commands/base/trace.java @@ -1,5 +1,8 @@ package org.minima.system.commands.base; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.system.commands.Command; import org.minima.system.network.minima.NIOClient; import org.minima.system.network.minima.NIOServer; @@ -12,6 +15,40 @@ public trace() { super("trace","[enable:true|false] (filter:) - Show the message stacks of the internal Minima Engine with optional filter string. Only works on terminal."); } + @Override + public String getFullHelp() { + return "\ntrace\n" + + "\n" + + "Show the message stacks of the internal Minima Engine with optional filter string.\n" + + "\n" + + "enable:\n" + + " true or false, true to enable or false to disable.\n" + + "\n" + + "filter: (optional)\n" + + " A case sensitive string to filter the messages by.\n" + + "\n" + + "Examples:\n" + + "\n" + + "trace enable:true\n" + + "\n" + + "trace enable:true filter:MAIN\n" + + "\n" + + "trace enable:true filter:MINER\n" + + "\n" + + "trace enable:true filter:MDS\n" + + "\n" + + "trace enable:true filter:NOTIFYMANAGER\n" + + "\n" + + "trace enable:true filter:TXPOWPROCESSOR\n" + + "\n" + + "trace enable:false\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"enable","filter"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/tutorial.java b/src/org/minima/system/commands/base/tutorial.java index edb4655f2..5af47f58e 100644 --- a/src/org/minima/system/commands/base/tutorial.java +++ b/src/org/minima/system/commands/base/tutorial.java @@ -9,6 +9,19 @@ public tutorial() { super("tutorial","Show the complete Grammar for Minima KISSVM scripting"); } + @Override + public String getFullHelp() { + return "\ntutorial\n" + + "\n" + + "Show the complete Grammar for Minima KISSVM scripting.\n" + + "\n" + + "KISS is the scripting language used to write Minima scripts/smart contracts.\n" + + "\n" + + "Examples:\n" + + "\n" + + "tutorial\n"; + } + @Override public JSONObject runCommand() throws Exception{ JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/base/vault.java b/src/org/minima/system/commands/base/vault.java index 8377a6be2..c10f64706 100644 --- a/src/org/minima/system/commands/base/vault.java +++ b/src/org/minima/system/commands/base/vault.java @@ -1,5 +1,8 @@ package org.minima.system.commands.base; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.MinimaDB; import org.minima.objects.base.MiniData; import org.minima.system.commands.Command; @@ -13,6 +16,11 @@ public vault() { super("vault","[action:seed|lock|unlock] (seed:) (phrase:) - BE CAREFUL. Wipe / Restore your private keys"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"action","seed","phrase"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/help.java b/src/org/minima/system/commands/help.java index c9d8fef13..66ca3b67c 100644 --- a/src/org/minima/system/commands/help.java +++ b/src/org/minima/system/commands/help.java @@ -1,5 +1,8 @@ package org.minima.system.commands; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.system.commands.backup.archive; import org.minima.system.commands.backup.backup; import org.minima.system.commands.backup.restore; @@ -65,7 +68,12 @@ public class help extends Command { public help() { - super("help","Show Help. [] are required. () are optional. Chain multiple commands with ;"); + super("help","Show Help. [] are required. () are optional. Use 'help command:' for full help. Chain multiple commands with ;"); + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"command"})); } @Override @@ -74,87 +82,105 @@ public JSONObject runCommand() throws Exception{ JSONObject details = new JSONObject(); - addCommand(details, new help()); - - addCommand(details, new status()); - addCommand(details, new printtree()); - addCommand(details, new burn()); - addCommand(details, new trace()); - addCommand(details, new logs()); -// addCommand(details, new automine()); - addCommand(details, new hashtest()); -// addCommand(details, new debugflag()); - - addCommand(details, new txpow()); - addCommand(details, new coins()); - addCommand(details, new tokens()); - addCommand(details, new keys()); - - addCommand(details, new getaddress()); - addCommand(details, new newaddress()); - addCommand(details, new send()); - addCommand(details, new sendpoll()); - addCommand(details, new balance()); - addCommand(details, new tokencreate()); - addCommand(details, new tokenvalidate()); - addCommand(details, new consolidate()); - - addCommand(details, new hash()); - addCommand(details, new random()); - -// addCommand(details, new file()); -// addCommand(details, new sql()); - - addCommand(details, new scripts()); - addCommand(details, new newscript()); - addCommand(details, new runscript()); - addCommand(details, new tutorial()); - - addCommand(details, new mmrcreate()); - addCommand(details, new mmrproof()); - - addCommand(details, new coinimport()); - addCommand(details, new coinexport()); - addCommand(details, new cointrack()); - - addCommand(details, new sign()); - addCommand(details, new verify()); - - addCommand(details, new txnlist()); - addCommand(details, new txncreate()); - addCommand(details, new txnbasics()); - addCommand(details, new txndelete()); - addCommand(details, new txncheck()); - addCommand(details, new txninput()); - addCommand(details, new txnoutput()); - addCommand(details, new txnstate()); - addCommand(details, new txnscript()); - addCommand(details, new txnsign()); - addCommand(details, new txnclear()); - addCommand(details, new txnpost()); - addCommand(details, new txnimport()); - addCommand(details, new txnexport()); - - addCommand(details, new network()); - addCommand(details, new maxima()); - addCommand(details, new maxcontacts()); - addCommand(details, new message()); - addCommand(details, new connect()); - addCommand(details, new disconnect()); - addCommand(details, new rpc()); - addCommand(details, new webhooks()); - - addCommand(details, new mds()); - - addCommand(details, new backup()); - addCommand(details, new restore()); - addCommand(details, new archive()); - addCommand(details, new vault()); - - addCommand(details, new incentivecash()); - - //addCommand(details, new nodecount()); - addCommand(details, new quit()); + String command = getParam("command",""); + + if(!command.equals("")) { + + //Get the command.. + Command cmd = Command.getCommandOnly(command); + if(cmd == null) { + throw new CommandException("Command not found : "+command); + } + + //Otherwise get the Full help.. + details.put("command", command); + details.put("help", cmd.getHelp()); + details.put("fullhelp", cmd.getFullHelp()); + + }else{ + + addCommand(details, new help()); + + addCommand(details, new status()); + addCommand(details, new printtree()); + addCommand(details, new burn()); + addCommand(details, new trace()); + addCommand(details, new logs()); + // addCommand(details, new automine()); + addCommand(details, new hashtest()); + // addCommand(details, new debugflag()); + + addCommand(details, new txpow()); + addCommand(details, new coins()); + addCommand(details, new tokens()); + addCommand(details, new keys()); + + addCommand(details, new getaddress()); + addCommand(details, new newaddress()); + addCommand(details, new send()); + addCommand(details, new sendpoll()); + addCommand(details, new balance()); + addCommand(details, new tokencreate()); + addCommand(details, new tokenvalidate()); + addCommand(details, new consolidate()); + + addCommand(details, new hash()); + addCommand(details, new random()); + + // addCommand(details, new file()); + // addCommand(details, new sql()); + + addCommand(details, new scripts()); + addCommand(details, new newscript()); + addCommand(details, new runscript()); + addCommand(details, new tutorial()); + + addCommand(details, new mmrcreate()); + addCommand(details, new mmrproof()); + + addCommand(details, new coinimport()); + addCommand(details, new coinexport()); + addCommand(details, new cointrack()); + + addCommand(details, new sign()); + addCommand(details, new verify()); + + addCommand(details, new txnlist()); + addCommand(details, new txncreate()); + addCommand(details, new txnbasics()); + addCommand(details, new txndelete()); + addCommand(details, new txncheck()); + addCommand(details, new txninput()); + addCommand(details, new txnoutput()); + addCommand(details, new txnstate()); + addCommand(details, new txnscript()); + addCommand(details, new txnsign()); + addCommand(details, new txnclear()); + addCommand(details, new txnpost()); + addCommand(details, new txnimport()); + addCommand(details, new txnexport()); + + addCommand(details, new network()); + addCommand(details, new maxima()); + addCommand(details, new maxcontacts()); + addCommand(details, new message()); + addCommand(details, new connect()); + addCommand(details, new disconnect()); + addCommand(details, new rpc()); + addCommand(details, new webhooks()); + + addCommand(details, new mds()); + + addCommand(details, new backup()); + addCommand(details, new restore()); + addCommand(details, new archive()); + addCommand(details, new vault()); + + addCommand(details, new incentivecash()); + + //addCommand(details, new nodecount()); + addCommand(details, new quit()); + } ret.put("response", details); diff --git a/src/org/minima/system/commands/maxima/maxcontacts.java b/src/org/minima/system/commands/maxima/maxcontacts.java index 09c0312c6..73f4e4e61 100644 --- a/src/org/minima/system/commands/maxima/maxcontacts.java +++ b/src/org/minima/system/commands/maxima/maxcontacts.java @@ -1,6 +1,7 @@ package org.minima.system.commands.maxima; import java.util.ArrayList; +import java.util.Arrays; import org.minima.database.MinimaDB; import org.minima.database.maxima.MaximaContact; @@ -26,6 +27,46 @@ public maxcontacts() { super("maxcontacts","[action:list|mls|add|remove|search] (contact:) (id:) (publickey:) - Manage your Maxima contacts"); } + @Override + public String getFullHelp() { + return "\nmaxcontacts\n" + + "\n" + + "Manage your Maxima contacts. List, refresh, add, remove or search contacts.\n" + + "\n" + + "action:\n" + + " list : List your Maxima contacts to see their id, address details, MLS and if they are on the same chain.\n" + + " mls : Send a message to your contacts to refresh your MLS (Minima Location Service) details.\n" + + " add : Add a new contact. Use with the 'contact' parameter.\n" + + " remove : Remove a Maxima contact. Will also remove you from their contacts. Use with the 'id' parameter.\n" + + " search : Search for a contact. Use with the 'id' or 'publickey' parameter.\n" + + "\n" + + "contact: (optional)\n" + + " The Maxima contact address of another node. Can be found using the 'maxima' command.\n" + + "\n" + + "id: (optional)\n" + + " The id of an existing contact to remove or search for.\n" + + "\n" + + "publickey: (optional)\n" + + " The Maxima public key of an existing contact to remove or search for.\n" + + "\n" + + "Examples:\n" + + "\n" + + "maxcontacts action:list\n" + + "\n" + + "maxcontacts action:mls\n" + + "\n" + + "maxcontacts action:add contact:MxG18H..\n" + + "\n" + + "maxcontacts action:remove id:1\n" + + "\n" + + "maxcontacts action:search publickey:0x3081..\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"action","contact","id","publickey"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); @@ -45,8 +86,11 @@ public JSONObject runCommand() throws Exception { //Get the Tree tip - to check the contacts TxPoWTreeNode tip = MinimaDB.getDB().getTxPoWTree().getTip(); - MiniNumber topblock = tip.getBlockNumber(); - + MiniNumber topblock = MiniNumber.ZERO; + if(tip != null) { + topblock = tip.getBlockNumber(); + } + JSONObject details = new JSONObject(); if(func.equals("list")) { diff --git a/src/org/minima/system/commands/maxima/maxima.java b/src/org/minima/system/commands/maxima/maxima.java index 80bd5a0e6..863134b5a 100644 --- a/src/org/minima/system/commands/maxima/maxima.java +++ b/src/org/minima/system/commands/maxima/maxima.java @@ -1,6 +1,7 @@ package org.minima.system.commands.maxima; import java.util.ArrayList; +import java.util.Arrays; import org.minima.database.MinimaDB; import org.minima.database.maxima.MaximaContact; @@ -12,6 +13,7 @@ import org.minima.system.Main; import org.minima.system.commands.Command; import org.minima.system.commands.CommandException; +import org.minima.system.commands.network.connect; import org.minima.system.network.maxima.MaxMsgHandler; import org.minima.system.network.maxima.MaximaManager; import org.minima.system.network.maxima.message.MaximaMessage; @@ -29,7 +31,60 @@ public maxima() { @Override public String getFullHelp() { - return "Maxima is an information transport layer running ontop of Minima"; + return "\nmaxima\n" + + "\n" + + "Check your Maxima details, send a message / data, enable logs.\n" + + "\n" + + "Maxima is an information transport layer running on top of Minima.\n" + + "\n" + + "action:\n" + + " info : Show your Maxima details - name, publickey, staticmls, mls, local identity and contact address.\n" + + " setname : Set your Maxima name so your contacts recognise you. Default 'noname'.\n" + + " hosts : List your Maxima hosts and see their Maxima public key, contact address, last seen time and if you are connected.\n" + + " send : Send a message to a contact. Must specify 'id|to|publickey', 'application' and 'data' parameters.\n" + + " refresh : Refresh your contacts by sending them a network message. \n" + + "\n" + + "name: (optional)\n" + + " Set your name. Use with 'action:setname'.\n" + + "\n" + + "id|to|publickey: (optional)\n" + + " The id, contact address or public key of the recipient of the message. Use with 'action:send'.\n" + + "\n" + + "application: (optional)\n" + + " The ip:port to send a message to. Use with 'action:send'.\n" + + "\n" + + "data: (optional)\n" + + " The data to send. Can be HEX or a JSON object. Use with 'action:send'.\n" + + "\n" + + "logs: (optional)\n" + + " true or false, true turns on detailed logs for Maxima.\n" + + "\n" + + "poll: (optional)\n" + + " true or false, true will poll the send action until successful. Use with 'action:send'.\n" + + "\n" + + "Examples:\n" + + "\n" + + "maxima action:info\n" + + "\n" + + "maxima action:setname name:myname\n" + + "\n" + + "maxima action:hosts\n" + + "\n" + + "maxima action:send id:1 application:ip:port data:0xFED5..\n" + + "\n" + + "maxima action:send to:MxG18H.. application:ip:port data:0xFED5..\n" + + "\n" + + "maxima action:send publickey:0xCD34.. application:ip:port data:0xFED5.. poll:true\n" + + "\n" + + "maxima action:refresh\n" + + "\n" + + "maxima logs:true\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"action","name","id","to", + "publickey","application","data","logs","poll","host"})); } @Override @@ -67,12 +122,33 @@ public JSONObject runCommand() throws Exception { details.put("logs", max.mMaximaLogs); details.put("name", MinimaDB.getDB().getUserDB().getMaximaName()); details.put("publickey", max.getPublicKey().to0xString()); + details.put("staticmls", max.isStaticMLS()); details.put("mls", max.getMLSHost()); details.put("localidentity", max.getLocalMaximaAddress()); details.put("contact", max.getRandomMaximaAddress()); ret.put("response", details); + }else if(func.equals("staticmls")) { + + String host = getParam("host"); + + //Check is valid.. + Message conn = connect.createConnectMessage(host); + if(conn == null) { + throw new CommandException("Invalid host.. must be host:port : "+host); + } + + if(host.equals("clear")) { + max.setStaticMLS(false, ""); + }else { + max.setStaticMLS(true, host); + } + + details.put("staticmls", max.isStaticMLS()); + details.put("mls", max.getMLSHost()); + ret.put("response", details); + }else if(func.equals("setname")) { String name = getParam("name"); @@ -89,6 +165,21 @@ public JSONObject runCommand() throws Exception { //Refresh max.PostMessage(MaximaManager.MAXIMA_REFRESH); + }else if(func.equals("statichost")) { + + String id = getParam("host"); + if(id.equals("random")) { + details.put("static", false); + max.setStaticAddress(false, ""); + }else { + details.put("static", true); + max.setStaticAddress(true, id); + } + + details.put("contact", max.getRandomMaximaAddress()); + + ret.put("response", details); + }else if(func.equals("hosts")) { //Add ALL Hosts diff --git a/src/org/minima/system/commands/maxima/maxsign.java b/src/org/minima/system/commands/maxima/maxsign.java new file mode 100644 index 000000000..2efb8886e --- /dev/null +++ b/src/org/minima/system/commands/maxima/maxsign.java @@ -0,0 +1,68 @@ +package org.minima.system.commands.maxima; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.minima.objects.base.MiniData; +import org.minima.system.Main; +import org.minima.system.commands.Command; +import org.minima.system.network.maxima.MaximaManager; +import org.minima.utils.encrypt.SignVerify; +import org.minima.utils.json.JSONObject; + +public class maxsign extends Command { + + public maxsign() { + super("maxsign","[data:] - Sign a piece of data with your Maxima ID"); + } + + @Override + public String getFullHelp() { + return "\nmaxsign\n" + + "\n" + + "Sign a piece of data with your Maxima ID.\n" + + "\n" + + "Returns the signature of the data, signed with your Maxima private key.\n" + + "\n" + + "data:\n" + + " The 0x HEX data to sign.\n" + + "\n" + + "Examples:\n" + + "\n" + + "maxsign data:0xCD34..\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"data"})); + } + + @Override + public JSONObject runCommand() throws Exception { + JSONObject ret = getJSONReply(); + + MiniData data = getDataParam("data"); + + MaximaManager max = Main.getInstance().getMaxima(); + + //get the Private Key.. + MiniData priv = max.getPrivateKey(); + + byte[] sigBytes = SignVerify.sign(priv.getBytes(), data.getBytes()); + MiniData sign = new MiniData(sigBytes); + + JSONObject resp = new JSONObject(); + + resp.put("signature", sign.to0xString()); + + ret.put("response", resp); + + return ret; + } + + @Override + public Command getFunction() { + return new maxsign(); + } + +} diff --git a/src/org/minima/system/commands/maxima/maxverify.java b/src/org/minima/system/commands/maxima/maxverify.java new file mode 100644 index 000000000..ec2a4e0b6 --- /dev/null +++ b/src/org/minima/system/commands/maxima/maxverify.java @@ -0,0 +1,68 @@ +package org.minima.system.commands.maxima; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.minima.objects.base.MiniData; +import org.minima.system.Main; +import org.minima.system.commands.Command; +import org.minima.system.network.maxima.MaximaManager; +import org.minima.utils.encrypt.SignVerify; +import org.minima.utils.json.JSONObject; + +public class maxverify extends Command { + + public maxverify() { + super("maxverify","[data:] [publickey:] [signature:] - Verify data with a Maxima Public key"); + } + + @Override + public String getFullHelp() { + return "\nmaxverify\n" + + "\n" + + "Verify data with a Maxima public key. Returns valid true or false.\n" + + "\n" + + "data:\n" + + " The 0x HEX data to verify the signature for.\n" + + "\n" + + "publickey:\n" + + " The Maxima public key of the signer.\n" + + "\n" + + "signature:\n" + + " The signature of the data.\n" + + "\n" + + "Examples:\n" + + "\n" + + "maxverify data:0xCD34.. publickey:0xFED5 signature:0x4827..\n"; + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"data","publickey","signature"})); + } + + @Override + public JSONObject runCommand() throws Exception { + JSONObject ret = getJSONReply(); + + MiniData data = getDataParam("data"); + MiniData pubk = getDataParam("publickey"); + MiniData sign = getDataParam("signature"); + + boolean valid = SignVerify.verify(pubk.getBytes(), data.getBytes(), sign.getBytes()); + + JSONObject resp = new JSONObject(); + + resp.put("valid", valid); + + ret.put("response", resp); + + return ret; + } + + @Override + public Command getFunction() { + return new maxverify(); + } + +} diff --git a/src/org/minima/system/commands/mds/mds.java b/src/org/minima/system/commands/mds/mds.java index 7f234bd92..33207e57f 100644 --- a/src/org/minima/system/commands/mds/mds.java +++ b/src/org/minima/system/commands/mds/mds.java @@ -3,6 +3,7 @@ import java.io.File; import java.io.FileInputStream; import java.util.ArrayList; +import java.util.Arrays; import org.minima.database.MinimaDB; import org.minima.database.minidapps.MDSDB; @@ -29,6 +30,11 @@ public mds() { super("mds","(action:list|install|update|uninstall|pending|accept|deny|permission) (file:) (uid:) (trust:read|write)- MiniDAPP System management"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"action","file","uid","trust"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/network/connect.java b/src/org/minima/system/commands/network/connect.java index b57b92ac4..9c9061e78 100644 --- a/src/org/minima/system/commands/network/connect.java +++ b/src/org/minima/system/commands/network/connect.java @@ -1,5 +1,8 @@ package org.minima.system.commands.network; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.system.Main; import org.minima.system.commands.Command; import org.minima.system.network.minima.NIOManager; @@ -12,6 +15,11 @@ public connect() { super("connect","[host:ip:port] - Connect to a network Minima instance"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"host"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/network/disconnect.java b/src/org/minima/system/commands/network/disconnect.java index 27a1ec565..d8eed6fc3 100644 --- a/src/org/minima/system/commands/network/disconnect.java +++ b/src/org/minima/system/commands/network/disconnect.java @@ -1,5 +1,8 @@ package org.minima.system.commands.network; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.system.Main; import org.minima.system.commands.Command; import org.minima.system.network.minima.NIOManager; @@ -12,6 +15,11 @@ public disconnect() { super("disconnect","[uid:uid] - Disconnect from a connected or connecting host"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"uid"})); + } + @Override public JSONObject runCommand() throws Exception{ JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/network/message.java b/src/org/minima/system/commands/network/message.java index 29072d0bb..29728c195 100644 --- a/src/org/minima/system/commands/network/message.java +++ b/src/org/minima/system/commands/network/message.java @@ -1,5 +1,8 @@ package org.minima.system.commands.network; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.objects.base.MiniString; import org.minima.system.Main; import org.minima.system.commands.Command; @@ -9,7 +12,12 @@ public class message extends Command { public message() { - super("message","(uid:uid) [data:message] - Send a message over the network to one of your direct peers"); + super("message","[data:message] (uid:uid) - Send a message over the network to one of your direct peers"); + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"uid","data"})); } @Override diff --git a/src/org/minima/system/commands/network/network.java b/src/org/minima/system/commands/network/network.java index 85174c203..e5ebbdaf9 100644 --- a/src/org/minima/system/commands/network/network.java +++ b/src/org/minima/system/commands/network/network.java @@ -1,6 +1,7 @@ package org.minima.system.commands.network; import java.util.ArrayList; +import java.util.Arrays; import org.minima.system.Main; import org.minima.system.commands.Command; @@ -15,6 +16,11 @@ public network() { super("network","(action:list|reset) - Show network status or reset traffic counter"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"action"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/network/nodecount.java b/src/org/minima/system/commands/network/nodecount.java index d7dec4390..ef4ad7978 100644 --- a/src/org/minima/system/commands/network/nodecount.java +++ b/src/org/minima/system/commands/network/nodecount.java @@ -3,6 +3,8 @@ import java.io.File; import java.io.PrintWriter; import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -23,6 +25,11 @@ public nodecount() { super("nodecount","(file:) (complete:false|true) - Enumerate the network to count all participating nodes"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"file","complete"})); + } + @Override public JSONObject runCommand() throws Exception { boolean saveCSV = true; diff --git a/src/org/minima/system/commands/base/p2pstate.java b/src/org/minima/system/commands/network/p2pstate.java similarity index 93% rename from src/org/minima/system/commands/base/p2pstate.java rename to src/org/minima/system/commands/network/p2pstate.java index 12b0aa716..071a5003c 100644 --- a/src/org/minima/system/commands/base/p2pstate.java +++ b/src/org/minima/system/commands/network/p2pstate.java @@ -1,4 +1,4 @@ -package org.minima.system.commands.base; +package org.minima.system.commands.network; import org.minima.system.Main; import org.minima.system.commands.Command; diff --git a/src/org/minima/system/commands/network/peers.java b/src/org/minima/system/commands/network/peers.java new file mode 100644 index 000000000..97071e4d5 --- /dev/null +++ b/src/org/minima/system/commands/network/peers.java @@ -0,0 +1,89 @@ +package org.minima.system.commands.network; + +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.Arrays; + +import org.minima.database.MinimaDB; +import org.minima.system.Main; +import org.minima.system.commands.Command; +import org.minima.system.commands.CommandException; +import org.minima.system.network.p2p.P2PDB; +import org.minima.system.network.p2p.P2PManager; +import org.minima.system.network.p2p.P2PPeersChecker; +import org.minima.system.network.p2p.messages.InetSocketAddressIO; +import org.minima.system.params.GeneralParams; +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.messages.Message; + +public class peers extends Command { + + public peers() { + super("peers","(action:list|addpeers) (peerslist:[]) - Prints the peers list this node has"); + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"action","peerslist"})); + } + + @Override + public JSONObject runCommand() throws Exception{ + JSONObject ret = getJSONReply(); + + //Is the P2P Enable.. + if(!GeneralParams.P2P_ENABLED) { + throw new CommandException("P2P System not enabled"); + } + + //Are we adding a peer.. + String action = getParam("action","list"); + if(action.equals("list")) { + + P2PManager p2PManager = (P2PManager) Main.getInstance().getNetworkManager().getP2PManager(); + + JSONObject resp = new JSONObject(); + resp.put("peers-list", InetSocketAddressIO.addressesListToJSONArray(p2PManager.getPeersCopy())); + ret.put("response", resp); + + + }else if(action.equals("addpeers")) { + + P2PManager p2pmanager = (P2PManager)Main.getInstance().getNetworkManager().getP2PManager(); + P2PPeersChecker p2pchecker = p2pmanager.getPeersChecker(); + + JSONArray peers = getJSONArrayParam("peerslist"); + for(Object peerobj : peers) { + + String peer = (String)peerobj; + + //Check is a valid host:port + Message checker = connect.createConnectMessage(peer); + if(checker == null) { + throw new CommandException("Invalid peer : "+peer); + } + + //Create an address + InetSocketAddress addr = new InetSocketAddress(checker.getString("host"), checker.getInteger("port")); + + //Otherwise add + Message msg = new Message(P2PPeersChecker.PEERS_CHECKPEERS).addObject("address", addr); + msg.addBoolean("force", true); + + p2pchecker.PostMessage(msg); + } + + }else { + throw new CommandException("Invalid action : "+action); + } + + return ret; + } + + @Override + public Command getFunction() { + return new peers(); + } + +} diff --git a/src/org/minima/system/commands/network/ping.java b/src/org/minima/system/commands/network/ping.java index bd1999a5c..0f04f0fa7 100644 --- a/src/org/minima/system/commands/network/ping.java +++ b/src/org/minima/system/commands/network/ping.java @@ -1,5 +1,8 @@ package org.minima.system.commands.network; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.objects.Greeting; import org.minima.system.Main; import org.minima.system.commands.Command; @@ -12,6 +15,11 @@ public ping() { super("ping","[host:] - Ping a host and get back Minima Node info"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"host"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/network/rpc.java b/src/org/minima/system/commands/network/rpc.java index cf49b6df5..4cc7bbcb3 100644 --- a/src/org/minima/system/commands/network/rpc.java +++ b/src/org/minima/system/commands/network/rpc.java @@ -1,5 +1,8 @@ package org.minima.system.commands.network; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.MinimaDB; import org.minima.system.Main; import org.minima.system.commands.Command; @@ -12,6 +15,11 @@ public rpc() { super("rpc","[enable:true|false] - Enable and disable RPC on port "+GeneralParams.RPC_PORT+" (default is off)"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"enable"})); + } + @Override public JSONObject runCommand() throws Exception{ JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/network/webhooks.java b/src/org/minima/system/commands/network/webhooks.java index 57e0f2450..6740baa90 100644 --- a/src/org/minima/system/commands/network/webhooks.java +++ b/src/org/minima/system/commands/network/webhooks.java @@ -1,6 +1,7 @@ package org.minima.system.commands.network; import java.util.ArrayList; +import java.util.Arrays; import org.minima.system.Main; import org.minima.system.commands.Command; @@ -14,6 +15,11 @@ public webhooks() { super("webhooks","(action:list|add|remove|clear) (hook:url) - Add a web hook that is called with Minima events as they happen"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"action","hook"})); + } + @Override public JSONObject runCommand() throws Exception{ JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/persistent/file.java b/src/org/minima/system/commands/persistent/file.java deleted file mode 100644 index 8698322b4..000000000 --- a/src/org/minima/system/commands/persistent/file.java +++ /dev/null @@ -1,120 +0,0 @@ -package org.minima.system.commands.persistent; - -import java.io.File; - -import org.minima.objects.base.MiniData; -import org.minima.system.commands.Command; -import org.minima.system.commands.CommandException; -import org.minima.system.params.GeneralParams; -import org.minima.utils.MiniFile; -import org.minima.utils.json.JSONArray; -import org.minima.utils.json.JSONObject; - -public class file extends Command { - - public file() { - super("file","[action:list|load|save|delete] [file:] (data:)- Load, save, delete or list files. / is root. Data is in 0xHEX format"); - } - - @Override - public JSONObject runCommand() throws Exception { - JSONObject ret = getJSONReply(); - - String action = getParam("action"); - String thefile = getParam("file"); - - //Check no back.. - if(thefile.indexOf("..")!=-1) { - throw new CommandException("No .. parent allowed in filename"); - } - - //The Root.. - File root = new File(GeneralParams.DATA_FOLDER,"minifiles"); - if(!root.exists()) { - root.mkdir(); - } - - //Which file are we listing.. - File touchfile = new File(root,thefile); - - if(action.equals("list")) { - - //Get the list of files.. - JSONArray allfiles = new JSONArray(); - File[] files = touchfile.listFiles(); - if(files!=null) { - - for(File ff : files) { - - JSONObject fjson = new JSONObject(); - fjson.put("name", ff.getName()); - fjson.put("directory", ff.isDirectory()); - fjson.put("size", ff.length()); - - allfiles.add(fjson); - } - } - - //Now get the details.. - JSONObject resp = new JSONObject(); - resp.put("found", allfiles.size()); - resp.put("files", allfiles); - ret.put("response", resp); - - }else if(action.equals("save")) { - - //Make sure the parent exists.. - File parent = touchfile.getParentFile(); - parent.mkdirs(); - - //Get the adta param.. - MiniData data = getDataParam("data"); - - //Save this data.. - MiniFile.writeDataToFile(touchfile, data.getBytes()); - - //Now get the details.. - JSONObject resp = new JSONObject(); - resp.put("name", thefile); - resp.put("size", touchfile.length()); - ret.put("response", resp); - - }else if(action.equals("load")) { - - //Load the file.. - byte[] datafile = MiniFile.readCompleteFile(touchfile); - - //The MinData object - MiniData filedata = new MiniData(datafile); - - //Now get the details.. - JSONObject resp = new JSONObject(); - resp.put("name", thefile); - resp.put("size", touchfile.length()); - resp.put("data", filedata.to0xString()); - ret.put("response", resp); - - }else if(action.equals("delete")) { - - //Delete the file.. - MiniFile.deleteFileOrFolder(root.getAbsolutePath(), touchfile); - - //Now get the details.. - JSONObject resp = new JSONObject(); - resp.put("name", thefile); - resp.put("status", "deleted"); - ret.put("response", resp); - - }else { - throw new CommandException("Invalid file function : "+action); - } - - return ret; - } - - @Override - public Command getFunction() { - return new file(); - } - -} diff --git a/src/org/minima/system/commands/persistent/sql.java b/src/org/minima/system/commands/persistent/sql.java deleted file mode 100644 index 38f6e6caf..000000000 --- a/src/org/minima/system/commands/persistent/sql.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.minima.system.commands.persistent; - -import org.minima.system.commands.Command; -import org.minima.utils.json.JSONObject; - -public class sql extends Command { - - public sql() { - super("sql","[sql:..] - Run SQL on a shared Database"); - } - - @Override - public JSONObject runCommand() throws Exception { - JSONObject ret = getJSONReply(); - -// //Get the SQL -// String sql = getParam("sql"); -// -// //Get the MiniDAPP DB -// MiniDAPPDB db = MinimaDB.getDB().getMiniDAPPDB(); -// -// //Run the SQL.. -// JSONObject results = db.executeSQL(sql); -// -// //Add them.. -// ret.put("response", results); - - - return ret; - } - - @Override - public Command getFunction() { - return new sql(); - } - -} diff --git a/src/org/minima/system/commands/scripts/newscript.java b/src/org/minima/system/commands/scripts/newscript.java index 49132bb54..98f255f2d 100644 --- a/src/org/minima/system/commands/scripts/newscript.java +++ b/src/org/minima/system/commands/scripts/newscript.java @@ -1,5 +1,8 @@ package org.minima.system.commands.scripts; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.MinimaDB; import org.minima.database.wallet.ScriptRow; import org.minima.database.wallet.Wallet; @@ -14,6 +17,11 @@ public newscript() { super("newscript","[script:] [trackall:false|true] (clean:false|true) - Add a new custom script. Track ALL addresses or just ones with relevant state variables."); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"script","trackall","clean"})); + } + @Override public JSONObject runCommand() throws Exception{ JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/scripts/runscript.java b/src/org/minima/system/commands/scripts/runscript.java index 8247189f7..574c8ca52 100644 --- a/src/org/minima/system/commands/scripts/runscript.java +++ b/src/org/minima/system/commands/scripts/runscript.java @@ -1,6 +1,7 @@ package org.minima.system.commands.scripts; import java.util.ArrayList; +import java.util.Arrays; import org.minima.database.mmr.MMRProof; import org.minima.kissvm.Contract; @@ -23,6 +24,11 @@ public runscript() { super("runscript","[script:] (state:{}) (prevstate:{}) (globals:{}) (signatures:[]) (extrascripts:{}) - Run a script with the defined parameters"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"script","state","prevstate","globals","signatures","extrascreipt"})); + } + @Override public JSONObject runCommand() throws Exception{ JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/scripts/scripts.java b/src/org/minima/system/commands/scripts/scripts.java index 4ede1f1db..5196d086f 100644 --- a/src/org/minima/system/commands/scripts/scripts.java +++ b/src/org/minima/system/commands/scripts/scripts.java @@ -1,6 +1,7 @@ package org.minima.system.commands.scripts; import java.util.ArrayList; +import java.util.Arrays; import org.minima.database.MinimaDB; import org.minima.database.wallet.ScriptRow; @@ -17,6 +18,11 @@ public scripts() { super("scripts","(address:) - Search scripts / addresses"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"address"})); + } + @Override public JSONObject runCommand() throws Exception{ JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/search/coins.java b/src/org/minima/system/commands/search/coins.java index 512c9f34f..c89f398d6 100644 --- a/src/org/minima/system/commands/search/coins.java +++ b/src/org/minima/system/commands/search/coins.java @@ -1,6 +1,7 @@ package org.minima.system.commands.search; import java.util.ArrayList; +import java.util.Arrays; import org.minima.database.MinimaDB; import org.minima.database.txpowtree.TxPoWTreeNode; @@ -18,6 +19,11 @@ public coins() { super("coins","(relevant:true) (sendable:true) (coinid:) (amount:) (address:) (tokenid:) - Search for coins"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"relevant","sendable","coinid","amount","address","tokenid"})); + } + @Override public JSONObject runCommand() throws Exception{ JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/search/keys.java b/src/org/minima/system/commands/search/keys.java index 6de1ca875..1b9ef9888 100644 --- a/src/org/minima/system/commands/search/keys.java +++ b/src/org/minima/system/commands/search/keys.java @@ -1,6 +1,7 @@ package org.minima.system.commands.search; import java.util.ArrayList; +import java.util.Arrays; import org.minima.database.MinimaDB; import org.minima.database.wallet.KeyRow; @@ -16,6 +17,11 @@ public keys() { super("keys","(action:list|new) - Get a list of all your public keys or create a new key"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"action"})); + } + @Override public JSONObject runCommand() throws Exception{ JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/search/tokens.java b/src/org/minima/system/commands/search/tokens.java index 86d25044c..f7552a601 100644 --- a/src/org/minima/system/commands/search/tokens.java +++ b/src/org/minima/system/commands/search/tokens.java @@ -1,6 +1,7 @@ package org.minima.system.commands.search; import java.util.ArrayList; +import java.util.Arrays; import org.minima.objects.Token; import org.minima.objects.base.MiniData; @@ -17,6 +18,11 @@ public tokens() { super("tokens","(tokenid:) (action:import|export) (data:) - List, import or export tokens on the chain"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"tokenid","action","data"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/search/txpow.java b/src/org/minima/system/commands/search/txpow.java index 9f30a5092..0a84b8a8f 100644 --- a/src/org/minima/system/commands/search/txpow.java +++ b/src/org/minima/system/commands/search/txpow.java @@ -1,8 +1,10 @@ package org.minima.system.commands.search; import java.util.ArrayList; +import java.util.Arrays; import org.minima.database.MinimaDB; +import org.minima.database.txpowtree.TxPoWTreeNode; import org.minima.objects.TxPoW; import org.minima.objects.base.MiniData; import org.minima.objects.base.MiniNumber; @@ -15,7 +17,12 @@ public class txpow extends Command { public txpow() { - super("txpow","(txpowid:txpowid) (block:) (address:) - Search for a specific TxPoW"); + super("txpow","(txpowid:txpowid) (onchain:) (block:) (address:) - Search for a specific TxPoW or check for onchain"); + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"txpowid","block","address","onchain"})); } @Override @@ -24,7 +31,7 @@ public JSONObject runCommand() throws Exception{ //Get the txpowid if(existsParam("txpowid")) { - String txpowid = getParam("txpowid", "0x01"); + String txpowid = getParam("txpowid"); //Search for a given txpow TxPoW txpow = MinimaDB.getDB().getTxPoWDB().getTxPoW(txpowid); @@ -34,6 +41,29 @@ public JSONObject runCommand() throws Exception{ ret.put("response", txpow.toJSON()); + }else if(existsParam("onchain")) { + MiniData txpowid = getDataParam("onchain"); + + JSONObject resp = new JSONObject(); + + TxPoW block = TxPoWSearcher.searchChainForTxPoW(txpowid); + if(block == null) { + resp.put("found", false); + }else { + + TxPoWTreeNode tip = MinimaDB.getDB().getTxPoWTree().getTip(); + + resp.put("found", true); + resp.put("block", block.getBlockNumber().toString()); + resp.put("blockid", block.getTxPoWID()); + resp.put("tip", tip.getBlockNumber().toString()); + + MiniNumber depth = tip.getBlockNumber().sub(block.getBlockNumber()); + resp.put("confirmations", depth.toString()); + } + + ret.put("response", resp); + }else if(existsParam("block")) { MiniNumber block = getNumberParam("block"); diff --git a/src/org/minima/system/commands/send/sendnosign.java b/src/org/minima/system/commands/send/sendnosign.java new file mode 100644 index 000000000..2cde85915 --- /dev/null +++ b/src/org/minima/system/commands/send/sendnosign.java @@ -0,0 +1,507 @@ +package org.minima.system.commands.send; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.StringTokenizer; + +import org.minima.database.MinimaDB; +import org.minima.database.mmr.MMRProof; +import org.minima.database.txpowdb.TxPoWDB; +import org.minima.database.txpowtree.TxPoWTreeNode; +import org.minima.database.userprefs.txndb.TxnRow; +import org.minima.database.wallet.ScriptRow; +import org.minima.database.wallet.Wallet; +import org.minima.objects.Address; +import org.minima.objects.Coin; +import org.minima.objects.CoinProof; +import org.minima.objects.ScriptProof; +import org.minima.objects.StateVariable; +import org.minima.objects.Token; +import org.minima.objects.Transaction; +import org.minima.objects.TxPoW; +import org.minima.objects.Witness; +import org.minima.objects.base.MiniData; +import org.minima.objects.base.MiniNumber; +import org.minima.system.Main; +import org.minima.system.brains.TxPoWGenerator; +import org.minima.system.brains.TxPoWMiner; +import org.minima.system.brains.TxPoWSearcher; +import org.minima.system.commands.Command; +import org.minima.system.commands.CommandException; +import org.minima.system.commands.base.send; +import org.minima.system.commands.txn.txnutils; +import org.minima.system.params.GlobalParams; +import org.minima.utils.MiniFile; +import org.minima.utils.MinimaLogger; +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; + +public class sendnosign extends Command { + + public class AddressAmount { + + MiniData mAddress; + MiniNumber mAmount; + + public AddressAmount(MiniData zAddress, MiniNumber zAmount) { + mAddress = zAddress; + mAmount = zAmount; + } + + public MiniData getAddress(){ + return mAddress; + } + + public MiniNumber getAmount() { + return mAmount; + } + } + + public sendnosign() { + super("sendnosign","(address:Mx..|0x..) (amount:) (multi:[address:amount,..]) (tokenid:) (state:{}) (burn:) (split:) (debug:) - Create a txn but don't sign it"); + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"address","amount","multi", + "tokenid","state","burn","split","debug","dryrun"})); + } + + @Override + public JSONObject runCommand() throws Exception { + JSONObject ret = getJSONReply(); + + //Who are we sending to + ArrayList recipients = new ArrayList<>(); + + //What is the toal amount we are sending.. + MiniNumber totalamount = MiniNumber.ZERO; + + //Is it a MULTI send.. + if(existsParam("multi")) { + + //Convert the list.. + JSONArray allrecips = getJSONArrayParam("multi"); + Iterator it = allrecips.iterator(); + while(it.hasNext()) { + String sendto = it.next(); + + StringTokenizer strtok = new StringTokenizer(sendto,":"); + + //Get the address + String address = strtok.nextToken(); + MiniData addr = null; + if(address.toLowerCase().startsWith("mx")) { + //Convert back to normal hex.. + try { + addr = Address.convertMinimaAddress(address); + }catch(IllegalArgumentException exc) { + throw new CommandException(exc.toString()); + } + }else { + addr = new MiniData(address); + } + + //Get the amount + MiniNumber amount = new MiniNumber(strtok.nextToken()); + totalamount = totalamount.add(amount); + + //Add to our List + recipients.add(new AddressAmount(addr, amount)); + } + + }else { + //Get the address + MiniData sendaddress = new MiniData(getAddressParam("address")); + + //How much to send + MiniNumber sendamount = getNumberParam("amount"); + totalamount = sendamount; + + recipients.add(new AddressAmount(sendaddress, sendamount)); + } + + //What is the Token + String tokenid = getParam("tokenid", "0x00"); + + //Show extra info.. + boolean debug = getBooleanParam("debug", false); + + //Is there a burn.. + MiniNumber burn = getNumberParam("burn",MiniNumber.ZERO); + if(burn.isLess(MiniNumber.ZERO)) { + throw new CommandException("Cannot have negative burn "+burn.toString()); + } + + //Are we splitting the outputs + MiniNumber split = getNumberParam("split", MiniNumber.ONE); + if(split.isLess(MiniNumber.ONE) || split.isMore(MiniNumber.TWENTY)) { + throw new CommandException("Split outputs from 1 to 20"); + } + + //Are we doing a Minima burn + if(tokenid.equals("0x00")) { + totalamount = totalamount.add(burn); + } + + //Get the State + JSONObject state = new JSONObject(); + if(existsParam("state")) { + state = getJSONObjectParam("state"); + } + + //get the tip.. + TxPoWTreeNode tip = MinimaDB.getDB().getTxPoWTree().getTip(); + + //Get the parent deep enough for valid confirmed coins + int confdepth = GlobalParams.MINIMA_CONFIRM_DEPTH.getAsInt(); + for(int i=0;i foundcoins = TxPoWSearcher.getRelevantUnspentCoins(tip,tokenid,true); + ArrayList relcoins = new ArrayList<>(); + + //Now make sure they are old enough + MiniNumber mincoinblock = tip.getBlockNumber().sub(coinage); + for(Coin relc : foundcoins) { + if(relc.getBlockCreated().isLessEqual(mincoinblock)) { + relcoins.add(relc); + } + } + + //Are there any coins at all.. + if(relcoins.size()<1) { + throw new CommandException("No Coins of tokenid:"+tokenid+" available!"); + } + + //Lets select the correct coins.. + MiniNumber findamount = totalamount; + if(!tokenid.equals("0x00")) { + findamount = relcoins.get(0).getToken().getScaledMinimaAmount(totalamount); + } + + //Now search for the best coin selection.. leave for Now!.. + relcoins = send.selectCoins(relcoins, findamount, debug); + + //The current total + MiniNumber currentamount = MiniNumber.ZERO; + ArrayList currentcoins = new ArrayList<>(); + + if(debug) { + MinimaLogger.log("Coins that will be checked for transaction"); + for(Coin coin : relcoins) { + MinimaLogger.log("Coin : "+coin.getAmount()+" "+coin.getCoinID().to0xString()); + } + } + + //Now cycle through.. + Token token = null; + for(Coin coin : relcoins) { + + //Check if we are already using thewm in another Transaction that is being mined + if(txminer.checkForMiningCoin(coin.getCoinID().to0xString())) { + if(debug) { + MinimaLogger.log("Coin being mined : "+coin.getAmount()+" "+coin.getCoinID().to0xString()); + } + continue; + } + + //Check if in mempool.. + if(txpdb.checkMempoolCoins(coin.getCoinID())) { + if(debug) { + MinimaLogger.log("Coin in mempool : "+coin.getAmount()+" "+coin.getCoinID().to0xString()); + } + continue; + } + + //Add this coin.. + currentcoins.add(coin); + + //Get the actual ammount.. + if(tokenid.equals("0x00")) { + currentamount = currentamount.add(coin.getAmount()); + }else { + //Store it.. + if(token == null) { + token = coin.getToken(); + } + + //Calculate the Token Amount.. + MiniNumber amt = coin.getToken().getScaledTokenAmount(coin.getAmount()); + + //Add that to the total + currentamount = currentamount.add(amt); + } + + if(debug) { + MinimaLogger.log("Coin added : "+coin.getAmount()+" "+coin.getCoinID().to0xString()+" total:"+currentamount); + } + + //Do we have enough.. + if(currentamount.isMoreEqual(totalamount)) { + break; + } + } + + //Check the token script + if(token != null) { + String script = token.getTokenScript().toString(); + if(!script.equals("RETURN TRUE")) { + //Not enough funds.. + ret.put("status", false); + ret.put("message", "Token script is not simple : "+script); + return ret; + } + } + + //Did we add enough + if(currentamount.isLess(totalamount)) { + //Not enough funds.. + ret.put("status", false); + ret.put("message", "Insufficient funds.. you only have "+currentamount+" require:"+totalamount); + return ret; + } + + if(debug) { + MinimaLogger.log("Total Coins used : "+currentcoins.size()); + } + + //What is the change.. + MiniNumber change = currentamount.sub(totalamount); + + //Lets construct a txn.. + Transaction transaction = new Transaction(); + Witness witness = new Witness(); + + //Min depth of a coin + MiniNumber minblock = MiniNumber.ZERO; + + //Add the inputs.. + for(Coin inputs : currentcoins) { + + //Add this input to our transaction + transaction.addInput(inputs); + + //How deep + if(inputs.getBlockCreated().isMore(minblock)) { + minblock = inputs.getBlockCreated(); + } + } + + //Get the block.. + MiniNumber currentblock = tip.getBlockNumber(); + MiniNumber blockdiff = currentblock.sub(minblock); + if(blockdiff.isMore(GlobalParams.MINIMA_MMR_PROOF_HISTORY)) { + blockdiff = GlobalParams.MINIMA_MMR_PROOF_HISTORY; + } + + //Now get that Block + TxPoWTreeNode mmrnode = tip.getPastNode(tip.getBlockNumber().sub(blockdiff)); + if(mmrnode == null) { + //Not enough blocks.. + throw new CommandException("Not enough blocks in chain to make valid MMR Proofs.."); + } + + //Get the main Wallet + Wallet walletdb = MinimaDB.getDB().getWallet(); + + //Create a list of the required signatures + ArrayList reqsigs = new ArrayList<>(); + + //Which Coins are added + ArrayList addedcoinid = new ArrayList<>(); + + //Add the MMR proofs for the coins.. + for(Coin input : currentcoins) { + + //May need it for BURN + addedcoinid.add(input.getCoinID().to0xString()); + + //Get the proof.. + MMRProof proof = mmrnode.getMMR().getProofToPeak(input.getMMREntryNumber()); + + //Create the CoinProof.. + CoinProof cp = new CoinProof(input, proof); + + //Add it to the witness data + witness.addCoinProof(cp); + + //Add the script proofs + String scraddress = input.getAddress().to0xString(); + + //Get the ScriptRow.. + ScriptRow srow = walletdb.getScriptFromAddress(scraddress); + if(srow == null) { + throw new CommandException("SERIOUS ERROR script missing for simple address : "+scraddress); + } + ScriptProof pscr = new ScriptProof(srow.getScript()); + witness.addScript(pscr); + + //Add this address / public key to the list we need to sign as.. + String pubkey = srow.getPublicKey(); + if(!reqsigs.contains(pubkey)) { + reqsigs.add(pubkey); + } + } + + //Now make the sendamount correct + if(!tokenid.equals("0x00")) { + + //Convert back and forward to make sure is a valid amount + MiniNumber tokenamount = token.getScaledMinimaAmount(totalamount); + MiniNumber prectest = token.getScaledTokenAmount(tokenamount); + + if(!prectest.isEqual(totalamount)) { + throw new CommandException("Invalid Token amount to send.. "+totalamount); + } + + totalamount = tokenamount; + + }else { + //Check valid - for Minima.. + if(!totalamount.isValidMinimaValue()) { + throw new CommandException("Invalid Minima amount to send.. "+totalamount); + } + } + + //Are we splitting the outputs + int isplit = split.getAsInt(); + + //Cycle through all the recipients + for(AddressAmount user : recipients) { + + MiniNumber splitamount = user.getAmount().div(split); + MiniData address = user.getAddress(); + + if(!tokenid.equals("0x00")) { + //Use the token object we previously found + splitamount = token.getScaledMinimaAmount(splitamount); + } + + for(int i=0;i getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"file"})); + } + + @Override + public JSONObject runCommand() throws Exception { + JSONObject ret = getJSONReply(); + + String txnfile = getParam("file"); + + //Load the txn + byte[] data = MiniFile.readCompleteFile(MiniFile.createBaseFile(txnfile)); + + //Create the MininData + MiniData txndata = new MiniData(data); + + //Now convert back into a TxPoW + TxPoW txp = TxPoW.convertMiniDataVersion(txndata); + + //Calculate the TxPOWID + txp.calculateTXPOWID(); + + JSONObject sigtran = new JSONObject(); + sigtran.put("txpow", txp.toJSON()); + + JSONObject resp = new JSONObject(); + ret.put("response", sigtran); + + //Post It..! + Main.getInstance().getTxPoWMiner().mineTxPoWAsync(txp); + + return ret; + } + + @Override + public Command getFunction() { + return new sendpost(); + } +} \ No newline at end of file diff --git a/src/org/minima/system/commands/send/sendsign.java b/src/org/minima/system/commands/send/sendsign.java new file mode 100644 index 000000000..70159c977 --- /dev/null +++ b/src/org/minima/system/commands/send/sendsign.java @@ -0,0 +1,144 @@ +package org.minima.system.commands.send; + +import java.io.File; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Arrays; + +import org.minima.database.MinimaDB; +import org.minima.database.wallet.ScriptRow; +import org.minima.database.wallet.Wallet; +import org.minima.objects.Coin; +import org.minima.objects.ScriptProof; +import org.minima.objects.Transaction; +import org.minima.objects.TxPoW; +import org.minima.objects.Witness; +import org.minima.objects.base.MiniData; +import org.minima.objects.keys.Signature; +import org.minima.system.commands.Command; +import org.minima.system.commands.CommandException; +import org.minima.utils.MiniFile; +import org.minima.utils.json.JSONObject; + +public class sendsign extends Command { + + public sendsign() { + super("sendsign","[file:] - Sign a previously created txn"); + } + + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"file"})); + } + + @Override + public JSONObject runCommand() throws Exception { + JSONObject ret = getJSONReply(); + + String filename = getParam("file"); + + //Load the data + byte[] data = MiniFile.readCompleteFile(MiniFile.createBaseFile(filename)); + + //Create the MiniData + MiniData sendtxpow = new MiniData(data); + + //Now convert back into a TxPoW + TxPoW txp = TxPoW.convertMiniDataVersion(sendtxpow); + + //Get the main Wallet + Wallet walletdb = MinimaDB.getDB().getWallet(); + + //Create a list of the required signatures + ArrayList reqsigs = new ArrayList<>(); + + //Get the sigs required.. for the main transaction + Transaction trans = txp.getTransaction(); + Witness witness = txp.getWitness(); + ArrayList inputs = trans.getAllInputs(); + for(Coin input : inputs) { + + //Add the script proofs + String scraddress = input.getAddress().to0xString(); + + //Get the ScriptRow.. + ScriptRow srow = walletdb.getScriptFromAddress(scraddress); + if(srow == null) { + throw new CommandException("SERIOUS ERROR script missing for simple address : "+scraddress); + } + ScriptProof pscr = new ScriptProof(srow.getScript()); + witness.addScript(pscr); + + //Add this address / public key to the list we need to sign as.. + String pubkey = srow.getPublicKey(); + if(!reqsigs.contains(pubkey)) { + //Use the wallet.. + Signature signature = walletdb.signData(pubkey, trans.getTransactionID()); + + //Add it.. + witness.addSignature(signature); + } + } + + //Get the sigs required.. for the BURN transaction + trans = txp.getBurnTransaction(); + witness = txp.getBurnWitness(); + inputs = trans.getAllInputs(); + for(Coin input : inputs) { + + //Add the script proofs + String scraddress = input.getAddress().to0xString(); + + //Get the ScriptRow.. + ScriptRow srow = walletdb.getScriptFromAddress(scraddress); + if(srow == null) { + throw new CommandException("SERIOUS ERROR script missing for simple address : "+scraddress); + } + ScriptProof pscr = new ScriptProof(srow.getScript()); + witness.addScript(pscr); + + //Add this address / public key to the list we need to sign as.. + String pubkey = srow.getPublicKey(); + if(!reqsigs.contains(pubkey)) { + //Use the wallet.. + Signature signature = walletdb.signData(pubkey, trans.getTransactionID()); + + //Add it.. + witness.addSignature(signature); + } + } + + //Create the file.. + File txnfile = MiniFile.createBaseFile("signedtransaction-"+System.currentTimeMillis()+".txn"); + + //Write it to a file.. + MiniFile.writeObjectToFile(txnfile, txp); + + JSONObject sigtran = new JSONObject(); + sigtran.put("txpow", txnfile.getAbsolutePath()); + + JSONObject resp = new JSONObject(); + ret.put("response", sigtran); + + return ret; + } + + @Override + public Command getFunction() { + return new sendsign(); + } + + public static void main(String[] zArgs) { + + for(int i=0;i<512;i++) { + + MiniData data = new MiniData(new BigInteger(Integer.toString(i))); + + System.out.println(data.to0xString()); + + } + + + + } +} \ No newline at end of file diff --git a/src/org/minima/system/commands/signatures/sign.java b/src/org/minima/system/commands/signatures/sign.java index 357bc83cb..f2474cb3c 100644 --- a/src/org/minima/system/commands/signatures/sign.java +++ b/src/org/minima/system/commands/signatures/sign.java @@ -1,5 +1,8 @@ package org.minima.system.commands.signatures; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.MinimaDB; import org.minima.database.wallet.Wallet; import org.minima.objects.base.MiniData; @@ -13,6 +16,11 @@ public sign() { super("sign","[publickey:] [data:] - Sign the data with the publickey"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"publickey","data"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/signatures/verify.java b/src/org/minima/system/commands/signatures/verify.java index 445077bcc..34c2d9dd8 100644 --- a/src/org/minima/system/commands/signatures/verify.java +++ b/src/org/minima/system/commands/signatures/verify.java @@ -1,5 +1,8 @@ package org.minima.system.commands.signatures; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.objects.base.MiniData; import org.minima.objects.keys.Signature; import org.minima.objects.keys.TreeKey; @@ -13,6 +16,11 @@ public verify() { super("verify","[publickey:] [data:] [signature:] - Verify a signature"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"publickey","data","signature"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/txn/txnauto.java b/src/org/minima/system/commands/txn/txnauto.java index 8a777f60c..9c2942548 100644 --- a/src/org/minima/system/commands/txn/txnauto.java +++ b/src/org/minima/system/commands/txn/txnauto.java @@ -1,6 +1,7 @@ package org.minima.system.commands.txn; import java.util.ArrayList; +import java.util.Arrays; import org.minima.database.MinimaDB; import org.minima.database.mmr.MMRProof; @@ -34,6 +35,11 @@ public txnauto() { super("txnauto","[id:] [amount:] [address:] - Create a send transaction automatically"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"id","amount","address"})); + } + @Override public JSONObject runCommand() throws Exception { diff --git a/src/org/minima/system/commands/txn/txnbasics.java b/src/org/minima/system/commands/txn/txnbasics.java index 3772edf78..f52f96990 100644 --- a/src/org/minima/system/commands/txn/txnbasics.java +++ b/src/org/minima/system/commands/txn/txnbasics.java @@ -1,5 +1,8 @@ package org.minima.system.commands.txn; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.MinimaDB; import org.minima.database.userprefs.txndb.TxnDB; import org.minima.database.userprefs.txndb.TxnRow; @@ -16,6 +19,11 @@ public txnbasics() { super("txnbasics","[id:] - Automatically set the MMR proofs and scripts for a txn"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"id"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/txn/txncheck.java b/src/org/minima/system/commands/txn/txncheck.java index 4d3c15cf4..7f977273d 100644 --- a/src/org/minima/system/commands/txn/txncheck.java +++ b/src/org/minima/system/commands/txn/txncheck.java @@ -1,6 +1,7 @@ package org.minima.system.commands.txn; import java.util.ArrayList; +import java.util.Arrays; import org.minima.database.MinimaDB; import org.minima.database.txpowtree.TxPoWTreeNode; @@ -26,6 +27,11 @@ public txncheck() { super("txncheck","[id:] - Show details about the transaction"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"id"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/txn/txnclear.java b/src/org/minima/system/commands/txn/txnclear.java index fc7209401..d0f5281a4 100644 --- a/src/org/minima/system/commands/txn/txnclear.java +++ b/src/org/minima/system/commands/txn/txnclear.java @@ -1,5 +1,8 @@ package org.minima.system.commands.txn; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.MinimaDB; import org.minima.database.userprefs.txndb.TxnDB; import org.minima.database.userprefs.txndb.TxnRow; @@ -13,6 +16,11 @@ public txnclear() { super("txnclear","[id:] - Clear ALL the Witness data"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"id"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/txn/txncreate.java b/src/org/minima/system/commands/txn/txncreate.java index 5ad0f21e7..a88f6fc1d 100644 --- a/src/org/minima/system/commands/txn/txncreate.java +++ b/src/org/minima/system/commands/txn/txncreate.java @@ -1,5 +1,8 @@ package org.minima.system.commands.txn; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.MinimaDB; import org.minima.database.userprefs.txndb.TxnDB; import org.minima.system.commands.Command; @@ -12,6 +15,11 @@ public txncreate() { super("txncreate","[id:] - Create a transaction"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"id"})); + } + @Override public JSONObject runCommand() throws Exception { diff --git a/src/org/minima/system/commands/txn/txndelete.java b/src/org/minima/system/commands/txn/txndelete.java index 877c006d7..7590fac3c 100644 --- a/src/org/minima/system/commands/txn/txndelete.java +++ b/src/org/minima/system/commands/txn/txndelete.java @@ -1,5 +1,8 @@ package org.minima.system.commands.txn; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.MinimaDB; import org.minima.database.userprefs.txndb.TxnDB; import org.minima.system.commands.Command; @@ -11,6 +14,11 @@ public txndelete() { super("txndelete","[id:] - Delete this custom transaction"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"id"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/txn/txnexport.java b/src/org/minima/system/commands/txn/txnexport.java index 1df79b50e..15019b20c 100644 --- a/src/org/minima/system/commands/txn/txnexport.java +++ b/src/org/minima/system/commands/txn/txnexport.java @@ -1,6 +1,8 @@ package org.minima.system.commands.txn; import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; import org.minima.database.MinimaDB; import org.minima.database.userprefs.txndb.TxnDB; @@ -18,6 +20,11 @@ public txnexport() { super("txnexport","[id:] (file:) - Export a transaction as HEX or to a file"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"id","file"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/txn/txnimport.java b/src/org/minima/system/commands/txn/txnimport.java index d24e842d6..8b4fcdd84 100644 --- a/src/org/minima/system/commands/txn/txnimport.java +++ b/src/org/minima/system/commands/txn/txnimport.java @@ -1,6 +1,8 @@ package org.minima.system.commands.txn; import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; import org.minima.database.MinimaDB; import org.minima.database.userprefs.txndb.TxnDB; @@ -17,6 +19,11 @@ public txnimport() { super("txnimport","(id:) (file:) (data:) - Import a transaction as a file or HEX data. Optionally specify the ID"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"id","file","data"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/txn/txninput.java b/src/org/minima/system/commands/txn/txninput.java index 64707aa6a..ff1f35c0d 100644 --- a/src/org/minima/system/commands/txn/txninput.java +++ b/src/org/minima/system/commands/txn/txninput.java @@ -1,5 +1,8 @@ package org.minima.system.commands.txn; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.MinimaDB; import org.minima.database.userprefs.txndb.TxnDB; import org.minima.database.userprefs.txndb.TxnRow; @@ -19,6 +22,12 @@ public txninput() { super("txninput","[id:] (coinid:) (coindata:) (floating:) (address:) (amount:) (tokenid:) (sciptmmr:true)- Add a coin as an input to a transaction"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"id","coinid", + "coindata","floating","address","amount","tokenid","scriptmmr"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/txn/txnlist.java b/src/org/minima/system/commands/txn/txnlist.java index cd114ee91..39d23b7aa 100644 --- a/src/org/minima/system/commands/txn/txnlist.java +++ b/src/org/minima/system/commands/txn/txnlist.java @@ -1,6 +1,7 @@ package org.minima.system.commands.txn; import java.util.ArrayList; +import java.util.Arrays; import org.minima.database.MinimaDB; import org.minima.database.userprefs.txndb.TxnDB; @@ -16,6 +17,11 @@ public txnlist() { super("txnlist","(id:) - List current custom transactions"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"id"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/txn/txnoutput.java b/src/org/minima/system/commands/txn/txnoutput.java index e9dd27bc4..00b8aaf4e 100644 --- a/src/org/minima/system/commands/txn/txnoutput.java +++ b/src/org/minima/system/commands/txn/txnoutput.java @@ -1,5 +1,8 @@ package org.minima.system.commands.txn; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.MinimaDB; import org.minima.database.userprefs.txndb.TxnDB; import org.minima.database.userprefs.txndb.TxnRow; @@ -20,6 +23,11 @@ public txnoutput() { super("txnoutput","[id:] [amount:] [address:] (tokenid:) (storestate:) - Create a transaction output"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"id","amount","address","tokenid","storestate"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/txn/txnpost.java b/src/org/minima/system/commands/txn/txnpost.java index a490616e4..061e36c92 100644 --- a/src/org/minima/system/commands/txn/txnpost.java +++ b/src/org/minima/system/commands/txn/txnpost.java @@ -1,6 +1,7 @@ package org.minima.system.commands.txn; import java.util.ArrayList; +import java.util.Arrays; import org.minima.database.MinimaDB; import org.minima.database.userprefs.txndb.TxnDB; @@ -22,6 +23,11 @@ public txnpost() { super("txnpost","[id:] (auto:true) (burn:) - Post a transaction. Automatically set the Scripts and MMR"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"id","auto","burn"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/txn/txnscript.java b/src/org/minima/system/commands/txn/txnscript.java index 82d626d79..6e2e33790 100644 --- a/src/org/minima/system/commands/txn/txnscript.java +++ b/src/org/minima/system/commands/txn/txnscript.java @@ -1,5 +1,8 @@ package org.minima.system.commands.txn; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.MinimaDB; import org.minima.database.mmr.MMRProof; import org.minima.database.userprefs.txndb.TxnDB; @@ -17,6 +20,11 @@ public txnscript() { super("txnscript","[id:] [scripts:{}] - Add scripts to a txn"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"id","scripts"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/txn/txnsign.java b/src/org/minima/system/commands/txn/txnsign.java index 8f972053b..cccbbb7a2 100644 --- a/src/org/minima/system/commands/txn/txnsign.java +++ b/src/org/minima/system/commands/txn/txnsign.java @@ -1,6 +1,7 @@ package org.minima.system.commands.txn; import java.util.ArrayList; +import java.util.Arrays; import org.minima.database.MinimaDB; import org.minima.database.userprefs.txndb.TxnDB; @@ -24,6 +25,11 @@ public txnsign() { super("txnsign","[id:] [publickey:0x..|auto] - Sign a transaction"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"id","publickey"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/txn/txnstate.java b/src/org/minima/system/commands/txn/txnstate.java index a34b72f2f..10130c4c7 100644 --- a/src/org/minima/system/commands/txn/txnstate.java +++ b/src/org/minima/system/commands/txn/txnstate.java @@ -1,5 +1,8 @@ package org.minima.system.commands.txn; +import java.util.ArrayList; +import java.util.Arrays; + import org.minima.database.MinimaDB; import org.minima.database.userprefs.txndb.TxnDB; import org.minima.database.userprefs.txndb.TxnRow; @@ -15,6 +18,11 @@ public txnstate() { super("txnstate","[id:] [port:] [value:] - Add a state variable"); } + @Override + public ArrayList getValidParams(){ + return new ArrayList<>(Arrays.asList(new String[]{"id","port","value"})); + } + @Override public JSONObject runCommand() throws Exception { JSONObject ret = getJSONReply(); diff --git a/src/org/minima/system/commands/txn/txnutils.java b/src/org/minima/system/commands/txn/txnutils.java index 132f5d3a5..bde8db183 100644 --- a/src/org/minima/system/commands/txn/txnutils.java +++ b/src/org/minima/system/commands/txn/txnutils.java @@ -171,8 +171,14 @@ public static void setMMRandScripts(Coin zCoin, Witness zWitness) throws Excepti zWitness.addScript(pscr); } - public static TxnRow createBurnTransaction(ArrayList zExcludeCoins, MiniData zLinkTransactionID, MiniNumber zAmount) throws CommandException { - + public static TxnRow createBurnTransaction(ArrayList zExcludeCoins, + MiniData zLinkTransactionID, MiniNumber zAmount) throws CommandException { + return createBurnTransaction(zExcludeCoins, zLinkTransactionID, zAmount, true); + } + + public static TxnRow createBurnTransaction(ArrayList zExcludeCoins, + MiniData zLinkTransactionID, MiniNumber zAmount, boolean zSign) throws CommandException { + //The Full Txn.. TxnRow txnrow = new TxnRow("temp", new Transaction(), new Witness()); @@ -328,15 +334,19 @@ public static TxnRow createBurnTransaction(ArrayList zExcludeCoins, Mini transaction.calculateTransactionID(); //Now that we have constructed the transaction - lets sign it.. - for(String pubk : reqsigs) { - - //Use the wallet.. - Signature signature = walletdb.signData(pubk, transaction.getTransactionID()); + if(zSign) { - //Add it.. - witness.addSignature(signature); + //Run through the sigs + for(String pubk : reqsigs) { + + //Use the wallet.. + Signature signature = walletdb.signData(pubk, transaction.getTransactionID()); + + //Add it.. + witness.addSignature(signature); + } } return txnrow; } -} +} \ No newline at end of file diff --git a/src/org/minima/system/mds/MDSFileHandler.java b/src/org/minima/system/mds/MDSFileHandler.java index de92981e0..c4b2382a9 100644 --- a/src/org/minima/system/mds/MDSFileHandler.java +++ b/src/org/minima/system/mds/MDSFileHandler.java @@ -166,9 +166,6 @@ public void run() { //Get the password.. String pass = getPasswordFromPost(data); - //PAUSE - this prevents fast checking of passwords - Thread.sleep(1000); - //Check this is the correct password.. String webpage = null; if(!mMDS.checkMiniHUBPasword(pass)) { diff --git a/src/org/minima/system/mds/MDSManager.java b/src/org/minima/system/mds/MDSManager.java index 99a25bda5..afad55e18 100644 --- a/src/org/minima/system/mds/MDSManager.java +++ b/src/org/minima/system/mds/MDSManager.java @@ -155,7 +155,14 @@ public String getMiniHUBPasword() { return mMiniHUBPassword; } - public boolean checkMiniHUBPasword(String zPassword) { + /** + * One check at a time + * @throws InterruptedException + */ + public synchronized boolean checkMiniHUBPasword(String zPassword) throws InterruptedException { + //PAUSE - this prevents fast checking of passwords + Thread.sleep(1000); + if(GeneralParams.MDS_PASSWORD.equals("")) { return mMiniHUBPassword.replace("-", "").equalsIgnoreCase(zPassword.replace("-", "").trim()); } diff --git a/src/org/minima/system/mds/handler/FILEcommand.java b/src/org/minima/system/mds/handler/FILEcommand.java index 9f0901f1f..ca5807b6c 100644 --- a/src/org/minima/system/mds/handler/FILEcommand.java +++ b/src/org/minima/system/mds/handler/FILEcommand.java @@ -6,12 +6,9 @@ import org.minima.system.mds.MDSManager; import org.minima.utils.MiniFile; import org.minima.utils.MinimaLogger; -import org.minima.utils.RPCClient; import org.minima.utils.json.JSONArray; import org.minima.utils.json.JSONObject; -import com.sun.media.sound.FFT; - public class FILEcommand { public static final String FILECOMMAND_LIST = "LIST"; diff --git a/src/org/minima/system/mds/handler/MDSCompleteHandler.java b/src/org/minima/system/mds/handler/MDSCompleteHandler.java index 09527d40d..b815182c8 100644 --- a/src/org/minima/system/mds/handler/MDSCompleteHandler.java +++ b/src/org/minima/system/mds/handler/MDSCompleteHandler.java @@ -5,6 +5,7 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.Socket; +import java.net.SocketException; import java.net.URLDecoder; import java.util.Date; import java.util.StringTokenizer; @@ -283,6 +284,17 @@ public void run() { }catch(SSLHandshakeException exc) { }catch(SSLException exc) { + }catch(SocketException exc) { + + // send HTTP Headers + out.println("HTTP/1.1 500 OK"); + out.println("Server: HTTP MDS Server from Minima : 1.3"); + out.println("Date: " + new Date()); + out.println("Content-type: text/plain"); + out.println("Access-Control-Allow-Origin: *"); + out.println(); // blank line between headers and content, very important ! + out.flush(); // flush character output stream buffer + }catch(IllegalArgumentException exc) { MinimaLogger.log(exc.toString()); diff --git a/src/org/minima/system/mds/hub/MDSHub.java b/src/org/minima/system/mds/hub/MDSHub.java index 4d9d97f8b..3ab9a39fa 100644 --- a/src/org/minima/system/mds/hub/MDSHub.java +++ b/src/org/minima/system/mds/hub/MDSHub.java @@ -9,105 +9,108 @@ public class MDSHub { - public static final String HUB_START ="\r\n" - + "\r\n" - + "\r\n" - + " MDS HUB\r\n" - + "\r\n" - + "" - + "\r\n" - + "\r\n" - + "\r\n" - + "
\r\n" - + " \r\n" - + " \r\n" - + "
MDS
\r\n" - + "
\r\n" - + "
\r\n" + + "\n" + + "\n" + + "\n" + + "
\n" + + " \n" + + " \n" + + "
MDS
\n" + + "
\n" + + "
\n" + "
    "; - public static final String HUB_END ="
\r\n" - + "
\r\n" - + "\r\n" - + "\r\n" - + "\r\n" + public static final String HUB_END ="\n" + + "
\n" + + "\n" + + "\n" + + "\n" + ""; public static String createHubPage(MDSManager zMDS, String zPassword) { @@ -129,16 +132,16 @@ public static String createHubPage(MDSManager zMDS, String zPassword) { String base = "./"+dapp.getUID()+"/"; - page += "
  • \r\n" - + " \r\n" - + " \r\n" - + "\r\n" - + "
    \r\n" - + "
    "+dapp.getName()+"
    \r\n" - + "
    "+dapp.getDescription()+"
    \r\n" - + "
    "+dapp.getVersion()+"
    \r\n" - + "
    \r\n" - + "
    \r\n" + page += "
  • \n" + + " \n" + + " \n" + + "\n" + + "
    \n" + + "
    "+dapp.getName()+"
    \n" + + "
    "+dapp.getDescription()+"
    \n" + + "
    "+dapp.getVersion()+"
    \n" + + "
    \n" + + "
    \n" + "
  • "; } } @@ -148,21 +151,21 @@ public static String createHubPage(MDSManager zMDS, String zPassword) { } //And the Install MiniDAPP - page += "
  • \r\n" - + "
    \r\n" - + " \r\n" - + "\r\n" - + "
    \r\n" - + "
    Install a MiniDAPP
    \r\n" + page += "
  • \n" + + "
    \n" + + " \n" + + "\n" + + "
    \n" + + "
    Install a MiniDAPP
    \n" + "

    " - + "
    \r\n" - + " \r\n" - + " \r\n" - + " \r\n" + + "\n" + + " \n" + + " \n" + + " \n" + "
    " - + "
    \r\n" - + "
    \r\n" - + "
    \r\n" + + " \n" + + " \n" + + " \n" + "
  • "; //End the HTML diff --git a/src/org/minima/system/network/maxima/MaximaContactManager.java b/src/org/minima/system/network/maxima/MaximaContactManager.java index 0f65c528c..5747d58dd 100644 --- a/src/org/minima/system/network/maxima/MaximaContactManager.java +++ b/src/org/minima/system/network/maxima/MaximaContactManager.java @@ -132,6 +132,9 @@ protected void processMessage(Message zMessage) throws Exception { MinimaLogger.log("DELETED contact request from : "+publickey); if(checkcontact != null) { maxdb.deleteContact(checkcontact.getUID()); + + //Contacts have changed + mManager.NotifyMaximaContactsChanged(); } return; @@ -170,7 +173,10 @@ protected void processMessage(Message zMessage) throws Exception { maxdb.updateContact(mxcontact); } - + + //Send a message that Tells there has been an update.. + mManager.NotifyMaximaContactsChanged(); + //Send them a contact message aswell.. if(intro || checkcontact == null) { Message msg = new Message(MAXCONTACTS_UPDATEINFO); @@ -201,6 +207,9 @@ protected void processMessage(Message zMessage) throws Exception { maxdb.updateContact(mxcontact); } + //There has been an Update + mManager.NotifyMaximaContactsChanged(); + MiniString str = new MiniString(mycontactinfo.toString()); MiniData mdata = new MiniData(mycontactinfo.toString().getBytes(MiniString.MINIMA_CHARSET)); @@ -241,6 +250,9 @@ protected void processMessage(Message zMessage) throws Exception { //Delete the contact maxdb.deleteContact(id); + //Contacts have changed + mManager.NotifyMaximaContactsChanged(); + //Tell them NIOClient nioc = Main.getInstance().getNIOManager().getNIOClient(host); if(nioc != null) { diff --git a/src/org/minima/system/network/maxima/MaximaManager.java b/src/org/minima/system/network/maxima/MaximaManager.java index c3aa3cfc3..e08a75a7b 100644 --- a/src/org/minima/system/network/maxima/MaximaManager.java +++ b/src/org/minima/system/network/maxima/MaximaManager.java @@ -96,6 +96,9 @@ public class MaximaManager extends MessageProcessor { private static final String MAXIMA_MLSTIME = "maxima_mlstime"; private static final String MAXIMA_OLDMLSHOST = "maxima_oldmlshost"; + private static final String MAXIMA_ISSTATICMLS = "maxima_isstaticmls"; + private static final String MAXIMA_STATICMLS = "maxima_staticmls"; + /** * The Response message for a Maxima Message */ @@ -130,6 +133,12 @@ public class MaximaManager extends MessageProcessor { private boolean mInited = false; public boolean mMaximaLogs = false; + /** + * Are you a static Maxima ID + */ + boolean mStaticMaxima = false; + String mStaticMaximaID = ""; + /** * The Contacts Manager */ @@ -140,6 +149,15 @@ public class MaximaManager extends MessageProcessor { */ MaxMsgHandler mMaxSender; + /** + * Are we using a STATIC MLS + */ + boolean mIsStaticMLS = false; + String mStaticMLS = ""; + + /** + * Main Constructor + */ public MaximaManager() { super("MAXIMA"); @@ -185,7 +203,28 @@ public String getLocalMaximaAddress() { return getMaximaMLSIdentity()+"@"+GeneralParams.MINIMA_HOST+":"+GeneralParams.MINIMA_PORT; } + public boolean isStaticMLS() { + return mIsStaticMLS; + } + + public void setStaticMLS(boolean zStatic, String zStaticAddress) { + mIsStaticMLS = zStatic; + mStaticMLS = zStaticAddress; + + //Get the UserDB + UserDB udb = MinimaDB.getDB().getUserDB(); + udb.setBoolean(MAXIMA_ISSTATICMLS, mIsStaticMLS); + udb.setString(MAXIMA_STATICMLS, mStaticMLS); + + //Save this.. + MinimaDB.getDB().saveUserDB(); + } + public String getMLSHost() { + if(mIsStaticMLS) { + return mStaticMLS; + } + String mls = mMLSService.getMLSServer(); if(mls.equals("")) { return mMaximaMLSAddress+"@"+GeneralParams.MINIMA_HOST+":"+GeneralParams.MINIMA_PORT; @@ -195,6 +234,10 @@ public String getMLSHost() { } public String getOldMLSHost() { + if(mIsStaticMLS) { + return mStaticMLS; + } + String mls = mMLSService.getOldMLSServer(); if(mls.equals("")) { return mMaximaMLSAddress+"@"+GeneralParams.MINIMA_HOST+":"+GeneralParams.MINIMA_PORT; @@ -221,6 +264,11 @@ public ArrayList getAllConnectedHosts(){ public String getRandomMaximaAddress() { + //Are we a static address.. + if(mStaticMaxima) { + return mMaximaMLSAddress+"@"+mStaticMaximaID; + } + //Who are we connected to ArrayList connctedhosts = getAllConnectedHosts(); @@ -232,6 +280,10 @@ public String getRandomMaximaAddress() { return connctedhosts.get(new Random().nextInt(connctedhosts.size())).getMaximaAddress(); } + public void setStaticAddress(boolean zStatic, String zAddress) { + mStaticMaxima = zStatic; + mStaticMaximaID = zAddress; + } public MaximaMessage createMaximaMessage(String zTo, String zApplication, MiniData zData) { MaximaMessage maxima = new MaximaMessage(); @@ -279,6 +331,13 @@ protected void processMessage(Message zMessage) throws Exception { mMaximaMLSAddress = Address.makeMinimaAddress(mMLSPublic); } + //Are we using a Static MLS + mIsStaticMLS = udb.getBoolean(MAXIMA_ISSTATICMLS, false); + mStaticMLS = udb.getString(MAXIMA_STATICMLS, ""); + if(mIsStaticMLS) { + MinimaLogger.log("Static MLS found : "+mStaticMLS); + } + //Hard set the MLSService String oldserver = udb.getString(MAXIMA_OLDMLSHOST, ""); String server = udb.getString(MAXIMA_MLSHOST, ""); @@ -930,12 +989,16 @@ public void updateMLSServers(){ if(allcontacts.size() > 0) { //Send the message - to BOTH hosts.. old and new PostMessage(maxima.createSendMessage(getMLSHost(),MAXIMA_MLS_SETAPP,mlspackdata)); - PostMessage(maxima.createSendMessage(getOldMLSHost(),MAXIMA_MLS_SETAPP,mlspackdata)); + if(!mIsStaticMLS) { + PostMessage(maxima.createSendMessage(getOldMLSHost(),MAXIMA_MLS_SETAPP,mlspackdata)); + } mHaveContacts = true; }else { if(mHaveContacts) { PostMessage(maxima.createSendMessage(getMLSHost(),MAXIMA_MLS_SETAPP,mlspackdata)); - PostMessage(maxima.createSendMessage(getOldMLSHost(),MAXIMA_MLS_SETAPP,mlspackdata)); + if(!mIsStaticMLS) { + PostMessage(maxima.createSendMessage(getOldMLSHost(),MAXIMA_MLS_SETAPP,mlspackdata)); + } } mHaveContacts = false; } @@ -951,4 +1014,10 @@ public void NotifyMaximaHostsChanged(String zFullAddress, boolean zConnected) { data.put("connected", zConnected); Main.getInstance().PostNotifyEvent("MAXIMAHOSTS", data); } + + public void NotifyMaximaContactsChanged() { + //Post a Notify Message + JSONObject data = new JSONObject(); + Main.getInstance().PostNotifyEvent("MAXIMACONTACTS", data); + } } diff --git a/src/org/minima/system/network/maxima/message/MaxTxPoW.java b/src/org/minima/system/network/maxima/message/MaxTxPoW.java index e792b6047..d5d29e3f6 100644 --- a/src/org/minima/system/network/maxima/message/MaxTxPoW.java +++ b/src/org/minima/system/network/maxima/message/MaxTxPoW.java @@ -112,7 +112,7 @@ public static MaxTxPoW createMaxTxPoW(MaximaPackage zMaxima) { txpow.setTxDifficulty(minhash); //Now Mine it.. - boolean valid = Main.getInstance().getTxPoWMiner().MineMaxTxPoW(txpow,mMaxTimeMilli); + boolean valid = Main.getInstance().getTxPoWMiner().MineMaxTxPoW(true, txpow, mMaxTimeMilli); if(!valid) { return null; } diff --git a/src/org/minima/system/network/minima/NIOManager.java b/src/org/minima/system/network/minima/NIOManager.java index a9fba4dfc..d4ea5fd24 100644 --- a/src/org/minima/system/network/minima/NIOManager.java +++ b/src/org/minima/system/network/minima/NIOManager.java @@ -527,6 +527,12 @@ protected void processMessage(Message zMessage) throws Exception { }else if(zMessage.getMessageType().equals(NIO_SYNCTXBLOCK)) { + //Check we have a chain.. + if(MinimaDB.getDB().getTxPoWTree().getRoot() == null) { + MinimaLogger.log("No TxPoWTree yet.. requited for NIO_SYNCTXBLOCK"); + return; + } + //Which client.. String clientid = zMessage.getString("client"); diff --git a/src/org/minima/system/network/p2p/P2PManager.java b/src/org/minima/system/network/p2p/P2PManager.java index 34540ffcc..631c1c826 100644 --- a/src/org/minima/system/network/p2p/P2PManager.java +++ b/src/org/minima/system/network/p2p/P2PManager.java @@ -76,6 +76,10 @@ public P2PManager() { PostTimerMessage(new TimerMessage(P2PParams.SAVE_DATA_DELAY, P2P_SAVE_DATA)); } + public P2PPeersChecker getPeersChecker() { + return mPeersChecker; + } + public ArrayList getPeersCopy(){ return state.getKnownPeersCopy(); } @@ -145,7 +149,14 @@ protected List init(P2PState state) { private void doDiscoveryPing(){ - while (state.isDoingDiscoveryConnection() && isRunning()){ + + //Check how many nodes there are.. + if(P2PParams.DEFAULT_NODE_LIST.size()==0) { + MinimaLogger.log("There are NO DEFAULT PEERS - please use command 'peers' to add a valid peer.."); + return; + } + + while (state.isDoingDiscoveryConnection() && isRunning()){ InetSocketAddress address = P2PParams.DEFAULT_NODE_LIST.get(rand.nextInt(P2PParams.DEFAULT_NODE_LIST.size())); Greeting greet = NIOManager.sendPingMessage(address.getHostString(), address.getPort(), true); if (greet != null) { diff --git a/src/org/minima/system/network/p2p/P2PPeersChecker.java b/src/org/minima/system/network/p2p/P2PPeersChecker.java index 18a6b871e..312563058 100644 --- a/src/org/minima/system/network/p2p/P2PPeersChecker.java +++ b/src/org/minima/system/network/p2p/P2PPeersChecker.java @@ -77,6 +77,8 @@ public P2PPeersChecker(P2PManager manager) { @Override protected void processMessage(Message zMessage) throws Exception { +// MinimaLogger.log("PEERSCHECKER:"+zMessage.toString()); + if (zMessage.getMessageType().equals(PEERS_INIT)) { @@ -101,7 +103,13 @@ protected void processMessage(Message zMessage) throws Exception { } else if (zMessage.getMessageType().equals(PEERS_CHECKPEERS)) { InetSocketAddress address = (InetSocketAddress) zMessage.getObject("address"); - if (P2PFunctions.getAllConnectedConnections().size() > 0) { + + boolean force = false; + if(zMessage.exists("force")) { + force = zMessage.getBoolean("force"); + } + + if (force || P2PFunctions.getAllConnectedConnections().size() > 0) { //Get a Greeting if possible Greeting greet = NIOManager.sendPingMessage(address.getHostString(), address.getPort(), true); diff --git a/src/org/minima/system/network/p2p/params/P2PParams.java b/src/org/minima/system/network/p2p/params/P2PParams.java index 7a75a0911..2f29ca29d 100644 --- a/src/org/minima/system/network/p2p/params/P2PParams.java +++ b/src/org/minima/system/network/p2p/params/P2PParams.java @@ -81,5 +81,6 @@ public class P2PParams { new InetSocketAddress("34.151.221.133", 9001), // v101-southamerica-east new InetSocketAddress("34.67.254.187", 9001) // v101-usa-central ); - + +// public static List DEFAULT_NODE_LIST = Arrays.asList(); } diff --git a/src/org/minima/system/params/GlobalParams.java b/src/org/minima/system/params/GlobalParams.java index 5e94bde33..f55676202 100644 --- a/src/org/minima/system/params/GlobalParams.java +++ b/src/org/minima/system/params/GlobalParams.java @@ -8,7 +8,7 @@ public class GlobalParams { * Which Version fo Minima are we running */ public static String MINIMA_BASE_VERSION = "0.103"; - public static String MINIMA_BUILD_NUMBER = "20"; + public static String MINIMA_BUILD_NUMBER = "25"; public static String MINIMA_VERSION = MINIMA_BASE_VERSION+"."+MINIMA_BUILD_NUMBER; /** diff --git a/src/org/minima/utils/SqlDB.java b/src/org/minima/utils/SqlDB.java index 69a1d2fa0..01665b66d 100644 --- a/src/org/minima/utils/SqlDB.java +++ b/src/org/minima/utils/SqlDB.java @@ -23,6 +23,7 @@ public abstract class SqlDB { * The actual File used.. */ protected File mSQLFile; + protected File mSQLDBNoMV; public SqlDB() {} @@ -39,6 +40,9 @@ public File getSQLFile() { */ public void loadDB(File zFile) throws SQLException { + //Store this for open checks + mSQLDBNoMV = zFile; + //Make sure the parent files exist zFile.getParentFile().mkdirs(); @@ -50,23 +54,10 @@ public void loadDB(File zFile) throws SQLException { //The H2 JDBC URL String h2db = "jdbc:h2:"+path+";MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE"; -// String h2db = "jdbc:h2:"+path+";MODE=MySQL"; //Create the connection mSQLConnection = DriverManager.getConnection(h2db, "SA", ""); -// //Save and compact the DB! -// Statement stmt = mSQLConnection.createStatement(); -// -// //Shut down.. this saves and closes all the data -// stmt.execute("SHUTDOWN COMPACT"); -// -// //Close the connection -// mSQLConnection.close(); -// -// //Now open a NEW Connection.. -// mSQLConnection = DriverManager.getConnection(h2db, "SA", ""); - //Auto commit changes mSQLConnection.setAutoCommit(true); @@ -74,6 +65,66 @@ public void loadDB(File zFile) throws SQLException { createSQL(); } + public boolean checkOpen() throws SQLException { + + //Check not NULL + boolean reopen = false; + if(mSQLConnection==null) { + reopen = true; + + }else if(mSQLConnection.isClosed()) { + reopen = true; + } + + //Do we need to restart.. + if(reopen) { + + //Notify User + MinimaLogger.log("SQLDB RE-OPEN : "+mSQLDBNoMV.getName()); + + //Clean memory + System.gc(); + + //Get the full db path + String path = mSQLDBNoMV.getAbsolutePath(); + + //The H2 JDBC URL + String h2db = "jdbc:h2:"+path+";MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE"; + + //Create the connection + mSQLConnection = DriverManager.getConnection(h2db, "SA", ""); + + //Auto commit changes + mSQLConnection.setAutoCommit(true); + + //Perform Create SQL + createSQL(); + } + + return reopen; + } + + public void hardCloseDB() { + try { + + //Check not NULL + if(mSQLConnection==null) { + return; + } + + //Are we already closed.. + if(mSQLConnection.isClosed()) { + return; + } + + //Close the connection + mSQLConnection.close(); + + } catch (SQLException e) { + MinimaLogger.log(e); + } + } + public void saveDB() { try { @@ -86,7 +137,8 @@ public void saveDB() { Statement stmt = mSQLConnection.createStatement(); //Shut down.. this saves and closes all the data - stmt.execute("SHUTDOWN COMPACT"); +// stmt.execute("SHUTDOWN COMPACT"); + stmt.execute("SHUTDOWN"); //Close the connection mSQLConnection.close(); diff --git a/test/org/minima/tests/cli/MinimaCliTest.java b/test/org/minima/tests/cli/MinimaCliTest.java new file mode 100644 index 000000000..76c956964 --- /dev/null +++ b/test/org/minima/tests/cli/MinimaCliTest.java @@ -0,0 +1,29 @@ +package org.minima.tests.cli; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; +import org.junit.Test; +import org.junit.After; +import static org.junit.Assert.*; + +public class MinimaCliTest { + + public void runBaseTests (String output) throws Exception { + System.out.println("Printing the output of the command:"); + System.out.println(output); + + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be true: " + json.get("status")); + assertTrue((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} + diff --git a/test/org/minima/tests/cli/MinimaTestNode.java b/test/org/minima/tests/cli/MinimaTestNode.java new file mode 100644 index 000000000..ff35a4f62 --- /dev/null +++ b/test/org/minima/tests/cli/MinimaTestNode.java @@ -0,0 +1,148 @@ +package org.minima.tests.cli; + +import java.util.ArrayList; + +import org.minima.Minima; +import org.minima.system.Main; +import org.minima.system.network.webhooks.NotifyManager; +import org.minima.utils.MiniFormat; +import org.minima.utils.MinimaLogger; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; +import org.minima.utils.messages.Message; +import org.minima.utils.messages.MessageListener; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; + +import org.minima.system.params.*; +import org.minima.objects.base.MiniNumber; + + +public class MinimaTestNode { + + static String command = ""; + public Minima minima; + + public MinimaTestNode() { + + //New Instance of Minima + minima = new Minima(); + + //Add a listener + Main.setMinimaListener(new MessageListener() { + + @Override + public void processMessage(Message zMessage) { + if(zMessage.getMessageType().equals(MinimaLogger.MINIMA_LOG)){ + + }else if(zMessage.getMessageType().equals(NotifyManager.NOTIFY_POST)){ + //Get the JSON.. + JSONObject notify = (JSONObject) zMessage.getObject("notify"); + + //What is the Event.. + String event = (String) notify.get("event"); + JSONObject data = (JSONObject) notify.get("data"); + + if(event.equals("NEWBLOCK")) { + //Get the TxPoW + JSONObject mTxPowJSON = (JSONObject) data.get("txpow"); + + }else if(event.equals("NEWBALANCE")) { + //Balance change.. + } + } + } + }); + + + //Now start her up.. + ArrayList vars = new ArrayList<>(); + + vars.add("-daemon"); + vars.add("-nop2p"); + vars.add("-test"); + vars.add("-genesis"); + + //Set a data dir.. + //vars.add("-data"); + //vars.add(""); + + //No shut down hook for CTRL C + //vars.add("-noshutdownhook"); + + //Auto connect + //vars.add("-connect"); + //vars.add("127.0.0.1:9001"); + TestParams.MINIMA_BLOCK_SPEED = new MiniNumber("0.2"); //faster blockspeed for testing + + minima.mainStarter(vars.toArray(new String[0])); + + //Catch error.. + try { + + //Now wait for valid.. + Thread.sleep(1000); + + //Run status + String status = minima.runMinimaCMD("status",false); + + //Make a JSON + JSONObject json = (JSONObject) new JSONParser().parse(status); + + //Get the status.. + while(!(boolean)json.get("status")){ + Thread.sleep(2000); + + //Run Status.. + status = minima.runMinimaCMD("status"); + + //Make a JSON + json = (JSONObject) new JSONParser().parse(status); + + MinimaLogger.log("Waiting for Status .. "+json.toString()); + } + + + + }catch(Exception exc) { + exc.printStackTrace(); + } + } + + public void setCommand(String _command){ + command = _command; + } + + public String runCommand(){ + String output = minima.runMinimaCMD(command, false); + return output.toString(); + } + + public String runCommand(String command) throws Exception{ + this.setCommand(command); + String output = this.runCommand(); + return output; + } + + public boolean waitForMinimaBlockConfirmation() throws Exception { + + long balance = 0; + int attempts = 0; + while(balance == 0 && attempts <= 250){ + Thread.sleep(1000); + + this.setCommand("balance"); + String balanceOutput = this.runCommand(); + + var jsonObject = (JSONObject) new JSONParser().parse(balanceOutput.toString()); + JSONArray innerJson = (JSONArray) jsonObject.get("response"); + JSONObject innerJsonObj = (JSONObject) innerJson.get(0); + + balance = Long.valueOf(innerJsonObj.get("confirmed").toString()).longValue(); + attempts++; + } + return attempts != 250; + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/balance/BalanceTest.java b/test/org/minima/tests/cli/balance/BalanceTest.java new file mode 100644 index 000000000..a4f771148 --- /dev/null +++ b/test/org/minima/tests/cli/balance/BalanceTest.java @@ -0,0 +1,324 @@ +package org.minima.tests.cli.balance; +import java.io.BufferedReader; +import java.io.FileReader; +import java.lang.StringBuilder; +import java.math.BigDecimal; +import org.junit.Test; +import org.junit.After; +import static org.junit.Assert.*; +import org.minima.system.commands.CommandException; +import org.minima.database.MinimaDB; +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; +import java.nio.charset.Charset; +import java.util.Random; + +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; +import org.minima.system.Main; + +public class BalanceTest extends MinimaCliTest { + + public MinimaTestNode minimaTestNode = new MinimaTestNode(); + + public BigDecimal ZERO = new BigDecimal("0"); + + public void runBaseTests (String output) throws Exception + { + super.runBaseTests(output); + + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + var responseAttr = json.get("response"); + + //The response body must be valid JSON + var jsonArray = (JSONArray) new JSONParser().parse(responseAttr.toString()); + JSONObject responseInnerJson = (JSONObject) jsonArray.get(0); + + //make sure sendable, unconfirmed and confirmed are all >= 0 + + BigDecimal confirmed = new BigDecimal(responseInnerJson.get("confirmed").toString()); + BigDecimal unconfirmed = new BigDecimal(responseInnerJson.get("unconfirmed").toString()); + BigDecimal sendable = new BigDecimal(responseInnerJson.get("sendable").toString()); + BigDecimal total = new BigDecimal(responseInnerJson.get("total").toString()); + + //Confirmed coins cannot be negative + System.out.println("confirmed must be gte 0"); + assertTrue(confirmed.compareTo(ZERO) >= 0); + + //Unconfirmed coins cannot be negative + System.out.println("unconfirmed must be gte 0"); + assertTrue(unconfirmed.compareTo(ZERO) >= 0); + + //Spendable coins cannot be negative + System.out.println("sendable must be gte 0"); + assertTrue(sendable.compareTo(ZERO) >= 0); + + //Total coins cannot be negative + System.out.println("total must be gte 0"); + assertTrue(total.compareTo(ZERO) >= 0); + + //confirmed, unconfirmed and spendable must not be gt total + System.out.println("confirmed must be lte total"); + assertTrue(confirmed.compareTo(total) < 1); + + System.out.println("sendable must be lte total"); + assertTrue(sendable.compareTo(total) < 1); + + System.out.println("unconfirmed must be lte total"); + assertTrue(unconfirmed.compareTo(total) < 1); + } + + @Test + public void testBalanceWithNoArgs() throws Exception { + + minimaTestNode.setCommand("balance"); + + String output = minimaTestNode.runCommand(); + + //tests that apply to every balance command + runBaseTests (output); + + killMinima(); + } + + @Test + public void testBalanceWithAddressArg() throws Exception { + + //First get the 0x address and the miniaddress + minimaTestNode.setCommand("getaddress"); + + String myAddress = ""; + String myMiniAddress = ""; + + String output = minimaTestNode.runCommand(); + + JSONObject json = (JSONObject) new JSONParser().parse(output); + + var responseAttr = json.get("response"); + + JSONObject responseObj = (JSONObject) new JSONParser().parse(responseAttr.toString()); + + myAddress = responseObj.get("address").toString(); + myMiniAddress = responseObj.get("miniaddress").toString(); + + //Run tests with 0x address + minimaTestNode.setCommand("balance address: " + myAddress); + + output = minimaTestNode.runCommand(); + + System.out.println("Regular 0x address\n"); + System.out.println(output); + + runBaseTests (output); + + //Run tests with Mx address + minimaTestNode.setCommand("balance address:" + myMiniAddress); + + output = minimaTestNode.runCommand(); + + System.out.println("Mx address\n"); + System.out.println(output); + + runBaseTests (output); + + /* + ---------------------------- + !!! THIS TEST IS FAILING !!! + ---------------------------- + */ + + //Try an invalid address of 1,000,000 characters + byte[] array = new byte[1000000]; + new Random().nextBytes(array); + String aMillionRandomCharacters = new String(array, Charset.forName("UTF-8")); + + minimaTestNode.setCommand("balance address:" + aMillionRandomCharacters); + + output = minimaTestNode.runCommand(); + + System.out.println("The output is "); + System.out.println(output.toString()); + + runBaseTests (output); + + System.out.println("Testing with garbage ZALGO text. He comes. \n"); + + String zalgo = " ̵̨̨͕̥̼̤̪͉̬̟̪͙̮͙̳͈͉̹̗̳̳͍͔̤͐̆̓͊̃̒̿̈́̽͌̀̎̃̓̎͛̌̓̒̾͑͆͘͘͜͝ ̶̢̨̢̪̯̩̙̗̫͕̘̦͉̮̗̹̼̳̭̱͈̭̮̠͙̻̫̆̎̎̈́̈̒̂͗̐̏͆̓̿̐͒͂͌̍͜͝ͅͅ"; + + minimaTestNode.setCommand("balance address:" + zalgo); + + output = minimaTestNode.runCommand(); + + runBaseTests (output); + + //Test with extra garbage arguments + + minimaTestNode.setCommand("balance address:0x422033899FD23B3B8EFECCBDE05D1D40D1550E8BB27798C12820C0D2CFC83689 garbage:garble"); + + output = minimaTestNode.runCommand(); + + json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false"); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:"); + assertFalse((boolean)json.get("pending")); + + } + + @Test + public void testBalanceWithGarbageArg() throws Exception { + + System.out.println("Testing with garbage argument"); + + minimaTestNode.setCommand("balance garbage:mygarbage"); + + String output = minimaTestNode.runCommand(); + + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false"); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:"); + assertFalse((boolean)json.get("pending")); + + } + + @Test + public void testBalanceWithEvilQuotes() throws Exception { + + minimaTestNode.setCommand("balance \""); + String output = minimaTestNode.runCommand(); + JSONObject json = (JSONObject) new JSONParser().parse(output); + assertFalse((boolean)json.get("status")); + assertFalse((boolean)json.get("pending")); + + minimaTestNode.setCommand("balance \"\""); + output = minimaTestNode.runCommand(); + json = (JSONObject) new JSONParser().parse(output); + assertFalse((boolean)json.get("status")); + assertFalse((boolean)json.get("pending")); + + System.out.println("Testing balance with evil quotes"); + + /* + ---------------------------- + !!! THIS TEST IS FAILING !!! + ---------------------------- + */ + + minimaTestNode.setCommand("balance \"\"\""); + output = minimaTestNode.runCommand(); + json = (JSONObject) new JSONParser().parse(output); + assertFalse((boolean)json.get("status")); + assertFalse((boolean)json.get("pending")); + + minimaTestNode.setCommand("balance \'"); + output = minimaTestNode.runCommand(); + json = (JSONObject) new JSONParser().parse(output); + assertFalse((boolean)json.get("status")); + assertFalse((boolean)json.get("pending")); + + minimaTestNode.setCommand("balance \'\'"); + output = minimaTestNode.runCommand(); + json = (JSONObject) new JSONParser().parse(output); + assertFalse((boolean)json.get("status")); + assertFalse((boolean)json.get("pending")); + + minimaTestNode.setCommand("balance \'\'\'"); + output = minimaTestNode.runCommand(); + json = (JSONObject) new JSONParser().parse(output); + assertFalse((boolean)json.get("status")); + assertFalse((boolean)json.get("pending")); + + minimaTestNode.setCommand("balance \'\'\'\'"); + output = minimaTestNode.runCommand(); + json = (JSONObject) new JSONParser().parse(output); + assertFalse((boolean)json.get("status")); + assertFalse((boolean)json.get("pending")); + + } + + @Test + public void testBalanceWithMultipleArg() throws Exception { + + System.out.println("Testing with garbage argument"); + + minimaTestNode.setCommand("balance address:0x7F234423354BF8E172F1019C7ED64310FB2EE7C9F5AFDA640F28D49F8D64DCDC confirmations:1"); + + String output = minimaTestNode.runCommand(); + + runBaseTests (output); + + } + + @Test + public void testBalanceWithDuplicateAddressArg() throws Exception { + + System.out.println("Testing with garbage argument"); + + minimaTestNode.setCommand("balance address:0x7F234423354BF8E172F1019C7ED64310FB2EE7C9F5AFDA640F28D49F8D64DCDC address:0x7F234423354BF8E172F1019C7ED64310FB2EE7C9F5AFDA640F28D49F8D64DCDC"); + + String output = minimaTestNode.runCommand(); + + runBaseTests (output); + + } + + @Test + public void testBalanceWithConfirmationsArg() throws Exception { + + System.out.println("Testing balance with confirmation argument \n"); + minimaTestNode.setCommand("balance confirmations:0"); + String output = minimaTestNode.runCommand(); + runBaseTests (output); + + + System.out.println("Test with 1000000000000000000000000000000000000000000000000000000000000000000000 confirmations"); + minimaTestNode.setCommand("balance confirmations:1000000000000000000000000000000000000000000000000000000000000000000000"); + output = minimaTestNode.runCommand(); + JSONObject json = (JSONObject) new JSONParser().parse(output); + assertFalse((boolean)json.get("status")); + assertFalse((boolean)json.get("pending")); + + System.out.println("Test with floating point confirmations"); + minimaTestNode.setCommand("balance confirmations:0.01"); + output = minimaTestNode.runCommand(); + json = (JSONObject) new JSONParser().parse(output); + assertFalse((boolean)json.get("status")); + assertFalse((boolean)json.get("pending")); + + /* + ---------------------------- + !!! THIS TEST IS FAILING !!! + ---------------------------- + */ + System.out.println("Test with non numeric confirmations"); + minimaTestNode.setCommand("balance confirmations:a"); + output = minimaTestNode.runCommand(); + json = (JSONObject) new JSONParser().parse(output); + assertFalse((boolean)json.get("status")); + assertFalse((boolean)json.get("pending")); + + System.out.println("Test with extra garbage args"); + minimaTestNode.setCommand("balance confirmations:1 garble:garble"); + output = minimaTestNode.runCommand(); + json = (JSONObject) new JSONParser().parse(output); + assertFalse((boolean)json.get("status")); + assertFalse((boolean)json.get("pending")); + + } + + public void killMinima(){ + minimaTestNode.minima.runMinimaCMD("quit",false); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/burn/DoBurnTest.java b/test/org/minima/tests/cli/burn/DoBurnTest.java new file mode 100644 index 000000000..587bce40b --- /dev/null +++ b/test/org/minima/tests/cli/burn/DoBurnTest.java @@ -0,0 +1,262 @@ +package org.minima.tests.cli.burn; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.lang.StringBuilder; +import java.math.BigDecimal; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; + +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; +import org.minima.database.MinimaDB; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class DoBurnTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testBurnWithSend() throws Exception { + + String output = runCommand("burn"); + + System.out.println(output); + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + assertTrue((boolean)json.get("status")); + + //cmd response pending should be false + assertFalse((boolean)json.get("pending")); + + var responseAttr = json.get("response"); + + //The response body must be valid JSON + var obj = (JSONObject) new JSONParser().parse(responseAttr.toString()); + JSONObject responseInnerJson = (JSONObject) obj.get(0); + + String newAddress = getNewAddress(); + String newAddress2 = getNewAddress(); + String newAddress3 = getNewAddress(); + + boolean confirmed = waitForMinimaBlockConfirmation(); + + //send to new addresses, each triggering burn event + String sendOutput = runCommand("send address:"+newAddress+" amount:30 burn:10"); + Thread.sleep(30000);//waiting 30 seconds for transaction finality so we can see if tx is picked up with burn + String sendOutput2 = runCommand("send address:"+newAddress2+" amount:40 burn:20"); + Thread.sleep(30000);//waiting 30 seconds for transaction finality so we can see if tx is picked up with burn + String sendOutput3 = runCommand("send address:"+newAddress3+" amount:50 burn:30"); + Thread.sleep(30000);//waiting 30 seconds for transaction finality so we can see if tx is picked up with burn + + System.out.println("Send response: "); + System.out.println(sendOutput); + + System.out.println("Send response 2: "); + System.out.println(sendOutput2); + + System.out.println("Send response 3: "); + System.out.println(sendOutput3); + + output = runCommand("burn"); + + System.out.println("second burn result: "); + System.out.println(output); + + json = (JSONObject) new JSONParser().parse(output); + JSONObject burnInnerResponseJSON = (JSONObject) json.get("response"); + JSONObject fiftyBlockResponse = (JSONObject) burnInnerResponseJSON.get("50block"); + assertTrue((long)fiftyBlockResponse.get("txns") == 4); //initial minting of coins on genesis block + 3 send events is 4 txns + + } + + //burn using consolidate + + @Test + public void testBurnWithConsolidate() throws Exception { + + boolean confirmed = waitForMinimaBlockConfirmation(); + + String newAddress1 = getAddress(); + String addressAmount = "["+'"'+newAddress1+":10"+'"'+","; + addressAmount += '"'+newAddress1+":20"+'"'+","; + addressAmount += '"'+newAddress1+":30"+'"'+"]"; + + System.out.println("address amount array: "); + System.out.println(addressAmount); + + String sendOutput = runCommand("send multi:"+addressAmount+" burn:50"); + System.out.println("sendOutput output: "); + System.out.println(sendOutput); + + Thread.sleep(90000);//waiting 1.5 minute for transaction finality so we can see if tx is picked up with burn + + String balanceResponse = runCommand("balance"); + System.out.println(balanceResponse); + + String coinsResponse = runCommand("coins"); + System.out.println("coins output: "); + System.out.println(coinsResponse); + + String output = runCommand("consolidate tokenid:0x00"); + + System.out.println("consolidate output: "); + System.out.println(output); + + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + assertTrue((boolean)json.get("status")); + + } + + //burn using tokencreate + @Test + public void testBurnWithTokencreate() throws Exception { + + boolean confirmed = waitForMinimaBlockConfirmation(); + + String newAddress = getNewAddress(); + String sendOutput = runCommand("send address:"+newAddress+" amount:1000"); + Thread.sleep(60000);//waiting 1 minute for transaction finality so we can see if tx is picked up with burn + + String tokenCreateOutput = runCommand("tokencreate name:testtoken amount:100 burn:1"); + Thread.sleep(60000);//waiting 1 minute for transaction finality so we can see if tx is picked up with burn + + String output = runCommand("burn"); + + JSONObject json = (JSONObject) new JSONParser().parse(output); + JSONObject burnInnerResponseJSON = (JSONObject) json.get("response"); + JSONObject fiftyBlockResponse = (JSONObject) burnInnerResponseJSON.get("50block"); + + assertTrue((long)fiftyBlockResponse.get("txns") == 3); //3 burns have happened, one when initial token supply was made, one for the send command and one for the tokencreate command + + } + + //burn using txnpost + @Test + public void testBurnWithTxnpost() throws Exception { + } + + @Test + public void testMinMaxAvgBurnStats() throws Exception { + + String newAddress = getNewAddress(); + String newAddress2 = getNewAddress(); + String newAddress3 = getNewAddress(); + + boolean confirmed = waitForMinimaBlockConfirmation(); + + //burn using send + //send to random address, in this case 0xA202C7C... + String sendOutput = runCommand("send address:"+newAddress+" amount:30 burn:10"); + Thread.sleep(30000);//waiting 1 minute for transaction finality so we can see if tx is picked up with burn + String sendOutput2 = runCommand("send address:"+newAddress2+" amount:40 burn:20"); + Thread.sleep(30000);//waiting 1 minute for transaction finality so we can see if tx is picked up with burn + String sendOutput3 = runCommand("send address:"+newAddress3+" amount:50 burn:30"); + Thread.sleep(30000);//waiting 1 minute for transaction finality so we can see if tx is picked up with burn + + System.out.println("Send response: "); + System.out.println(sendOutput); + + System.out.println("Send response 2: "); + System.out.println(sendOutput2); + + System.out.println("Send response 3: "); + System.out.println(sendOutput3); + + String output = runCommand("burn"); + + System.out.println("second burn result: "); + System.out.println(output); + + JSONObject json = (JSONObject) new JSONParser().parse(output); + JSONObject burnInnerResponseJSON = (JSONObject) json.get("response"); + JSONObject fiftyBlockResponse = (JSONObject) burnInnerResponseJSON.get("50block"); + assertTrue((long)fiftyBlockResponse.get("max") == 30); + assertTrue((long)fiftyBlockResponse.get("med") == 10); + assertTrue((long)fiftyBlockResponse.get("avg") == 15); + assertTrue((long)fiftyBlockResponse.get("min") == 0); + + } + + + + + + + + + @After public void killMinima() throws Exception { + test.minima.runMinimaCMD("quit",false); + } + + boolean waitForMinimaBlockConfirmation() throws Exception { + + long balance = 0; + int attempts = 0; + while(balance == 0 && attempts <= 250){ + Thread.sleep(1000); + String balanceOutput = runCommand("balance"); + + var jsonObject = (JSONObject) new JSONParser().parse(balanceOutput.toString()); + JSONArray innerJson = (JSONArray) jsonObject.get("response"); + JSONObject innerJsonObj = (JSONObject) innerJson.get(0); + + balance = Long.valueOf(innerJsonObj.get("confirmed").toString()).longValue(); + attempts++; + } + return attempts != 250; + } + + String runCommand(String command) throws Exception{ + test.setCommand(command); + String output = test.runCommand(); + return output; + } + + String getNewAddress() throws Exception{ + //get my new address + String getaddressResponse = runCommand("newaddress"); + + System.out.println("Response Object: "); + System.out.println(getaddressResponse); + + var stringResponseObj = (JSONObject) new JSONParser().parse(getaddressResponse); + JSONObject stringResponseResponseObj = (JSONObject) stringResponseObj.get("response"); + String address = stringResponseResponseObj.get("address").toString(); + + System.out.println("address: "); + System.out.println(address); + return address; + } + + String getAddress() throws Exception{ + //get my new address + String getaddressResponse = runCommand("getaddress"); + + System.out.println("Response Object: "); + System.out.println(getaddressResponse); + + var stringResponseObj = (JSONObject) new JSONParser().parse(getaddressResponse); + JSONObject stringResponseResponseObj = (JSONObject) stringResponseObj.get("response"); + String address = stringResponseResponseObj.get("address").toString(); + + System.out.println("address: "); + System.out.println(address); + return address; + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/coinexport/CoinexportTest.java b/test/org/minima/tests/cli/coinexport/CoinexportTest.java new file mode 100644 index 000000000..7b6b001ef --- /dev/null +++ b/test/org/minima/tests/cli/coinexport/CoinexportTest.java @@ -0,0 +1,53 @@ +package org.minima.tests.cli.coinimport; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class CoinexportTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + + public void baseTests (String output) throws Exception + { + super.runBaseTests(output); + } + + @Test + public void coinImportWithCoinid() throws Exception + { + boolean confirmed = test.waitForMinimaBlockConfirmation(); + + //run coins + String coinsOutput = test.runCommand("coins"); + + JSONObject json = (JSONObject) new JSONParser().parse(coinsOutput); + var responseAttr = json.get("response"); + + var jsonArray = (JSONArray) new JSONParser().parse(responseAttr.toString()); + JSONObject responseInnerJson = (JSONObject) jsonArray.get(0); + + var coinid = responseInnerJson.get("coinid"); + + //coinexport with coinid + String output = test.runCommand("coinexport coinid:"+coinid.toString()); + + System.out.println("output: "); + System.out.println(output); + + baseTests(output); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/coinimport/CoinimportTest.java b/test/org/minima/tests/cli/coinimport/CoinimportTest.java new file mode 100644 index 000000000..a4d7337ed --- /dev/null +++ b/test/org/minima/tests/cli/coinimport/CoinimportTest.java @@ -0,0 +1,69 @@ +package org.minima.tests.cli.coinimport; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class CoinimportTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + public void baseTests (String output) throws Exception + { + super.runBaseTests(output); + } + + @Test + public void coinImportWithData () throws Exception + { + boolean confirmed = test.waitForMinimaBlockConfirmation(); + + //run coins + String coinsOutput = test.runCommand("coins"); + + System.out.println("coinsOutput: "); + System.out.println(coinsOutput); + + JSONObject json = (JSONObject) new JSONParser().parse(coinsOutput); + var responseAttr = json.get("response"); + + var jsonArray = (JSONArray) new JSONParser().parse(responseAttr.toString()); + JSONObject responseInnerJson = (JSONObject) jsonArray.get(0); + + var coinid = responseInnerJson.get("coinid"); + + test.runCommand("cointrack enable:false coinid:"+coinid); + + //coinexport with coinid + String exported = test.runCommand("coinexport coinid:"+coinid.toString()); + + JSONObject exportjson = (JSONObject) new JSONParser().parse(exported); + + System.out.println("exported: "); + System.out.println(exportjson.get("response")); + + String output = test.runCommand("coinimport data:"+exportjson.get("response")); + +//{"command":"coinimport","params":{"data":{"command":"coinexport","params":{"coinid":"0x4A53698FC9721731817BAB4488ED58F5B6CBEF110AD951F6F53374EB9F30C5F9"},"status":true,"pending":false,"response":"0x000000204A53698FC9721731817BAB4488ED58F5B6CBEF110AD951F6F53374EB9F30C5F9000000205EC75319945DED777D1B7B8A4603484D5E2D2D1C92F9BF6CA8D34FC950C32C4FF70101000000010001000100000000010100000101000100000001010001010100000020A53AD6A229F11DAD05FD0D9164F8EEE96501FA67ED9FEF7087EEA5C43E293357000100"}},"status":false,"pending":false,"error":"class org.minima.utils.json.JSONObject cannot be cast to class java.lang.String (org.minima.utils.json.JSONObject is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')"} + + System.out.println("output: "); + System.out.println(output); + + json = (JSONObject) new JSONParser().parse(output); + + assertFalse((boolean)json.get("status")); //MMR proof already tracked + //baseTests(output); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/coins/CoinsTest.java b/test/org/minima/tests/cli/coins/CoinsTest.java new file mode 100644 index 000000000..c8f19b26e --- /dev/null +++ b/test/org/minima/tests/cli/coins/CoinsTest.java @@ -0,0 +1,32 @@ +package org.minima.tests.cli.coins; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class CoinsTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void runBaseTests () throws Exception + { + boolean confirmed = test.waitForMinimaBlockConfirmation(); + + //run coins + String coinsOutput = test.runCommand("coins"); + super.runBaseTests(coinsOutput); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/cointrack/CointrackTest.java b/test/org/minima/tests/cli/cointrack/CointrackTest.java new file mode 100644 index 000000000..25a0816d2 --- /dev/null +++ b/test/org/minima/tests/cli/cointrack/CointrackTest.java @@ -0,0 +1,45 @@ +package org.minima.tests.cli.cointrack; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class CointrackTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testCointrackWithNoArgs () throws Exception + { + //run coins + String output = test.runCommand("cointrack"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/connect/ConnectTest.java b/test/org/minima/tests/cli/connect/ConnectTest.java new file mode 100644 index 000000000..f46583218 --- /dev/null +++ b/test/org/minima/tests/cli/connect/ConnectTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.connect; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class ConnectTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("connect"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/consolidate/ConsolidateTest.java b/test/org/minima/tests/cli/consolidate/ConsolidateTest.java new file mode 100644 index 000000000..0bba94d0b --- /dev/null +++ b/test/org/minima/tests/cli/consolidate/ConsolidateTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.consolidate; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class ConsolidateTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("consolidate"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/disconnect/DisconnectTest.java b/test/org/minima/tests/cli/disconnect/DisconnectTest.java new file mode 100644 index 000000000..9918570f8 --- /dev/null +++ b/test/org/minima/tests/cli/disconnect/DisconnectTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.disconnect; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class DisconnectTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("disconnect"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/getaddress/GetaddressTest.java b/test/org/minima/tests/cli/getaddress/GetaddressTest.java new file mode 100644 index 000000000..539a6be88 --- /dev/null +++ b/test/org/minima/tests/cli/getaddress/GetaddressTest.java @@ -0,0 +1,36 @@ +package org.minima.tests.cli.getaddress; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class GetaddressTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("getaddress"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + super.runBaseTests(output); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/hash/HashTest.java b/test/org/minima/tests/cli/hash/HashTest.java new file mode 100644 index 000000000..9463f331f --- /dev/null +++ b/test/org/minima/tests/cli/hash/HashTest.java @@ -0,0 +1,64 @@ +package org.minima.tests.cli.hash; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class HashTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("hash"); + + runBaseTests(output); + } + + @Test + public void runKeccakTest() throws Exception { + String output = test.runCommand("hash data:0xB291E3A6D546E1D5E61A3EF08D01474386749D267774D718E8E07280F678A628 type:keccak"); + System.out.println("keccak output: "); + System.out.println(output); + } + + @Test + public void runSha2Test() throws Exception { + String output = test.runCommand("hash data:0xB291E3A6D546E1D5E61A3EF08D01474386749D267774D718E8E07280F678A628 type:sha2"); + System.out.println("sha2 output: "); + System.out.println(output); + } + + @Test + public void runSha3Test() throws Exception { + String output = test.runCommand("hash data:0xB291E3A6D546E1D5E61A3EF08D01474386749D267774D718E8E07280F678A628 type:sha3"); + System.out.println("sha3 output: "); + System.out.println(output); + } +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/hashtest/HashtestTest.java b/test/org/minima/tests/cli/hashtest/HashtestTest.java new file mode 100644 index 000000000..f197f7c41 --- /dev/null +++ b/test/org/minima/tests/cli/hashtest/HashtestTest.java @@ -0,0 +1,35 @@ +package org.minima.tests.cli.hashtest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class HashtestTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("hashtest"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + super.runBaseTests(output); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/help/HelpTest.java b/test/org/minima/tests/cli/help/HelpTest.java new file mode 100644 index 000000000..2d0638b73 --- /dev/null +++ b/test/org/minima/tests/cli/help/HelpTest.java @@ -0,0 +1,35 @@ +package org.minima.tests.cli.help; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class HelpTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("help"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + super.runBaseTests(output); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/incentivecash/IncentivecashTest.java b/test/org/minima/tests/cli/incentivecash/IncentivecashTest.java new file mode 100644 index 000000000..6dc372013 --- /dev/null +++ b/test/org/minima/tests/cli/incentivecash/IncentivecashTest.java @@ -0,0 +1,35 @@ +package org.minima.tests.cli.incentivecash; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class IncentivecashTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("incentivecash"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + super.runBaseTests(output); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/keys/KeysTest.java b/test/org/minima/tests/cli/keys/KeysTest.java new file mode 100644 index 000000000..9ec15a804 --- /dev/null +++ b/test/org/minima/tests/cli/keys/KeysTest.java @@ -0,0 +1,35 @@ +package org.minima.tests.cli.keys; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class KeysTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("keys"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + super.runBaseTests(output); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/maxcontacts/MaxContactsTest.java b/test/org/minima/tests/cli/maxcontacts/MaxContactsTest.java new file mode 100644 index 000000000..7d4507726 --- /dev/null +++ b/test/org/minima/tests/cli/maxcontacts/MaxContactsTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.maxcontacts; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class MaxContactsTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("maxcontacts"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/maxima/MaximaTest.java b/test/org/minima/tests/cli/maxima/MaximaTest.java new file mode 100644 index 000000000..e0c2f4328 --- /dev/null +++ b/test/org/minima/tests/cli/maxima/MaximaTest.java @@ -0,0 +1,48 @@ +package org.minima.tests.cli.maxima; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class MaximaTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + /* + ERROR: Maxima is meant to require an action: parameter + */ + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("maxima"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/mds/MdsTest.java b/test/org/minima/tests/cli/mds/MdsTest.java new file mode 100644 index 000000000..59bc445f3 --- /dev/null +++ b/test/org/minima/tests/cli/mds/MdsTest.java @@ -0,0 +1,36 @@ +package org.minima.tests.cli.mds; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class MdsTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("mds"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + super.runBaseTests(output); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/message/MessageTest.java b/test/org/minima/tests/cli/message/MessageTest.java new file mode 100644 index 000000000..5f2cdb7d3 --- /dev/null +++ b/test/org/minima/tests/cli/message/MessageTest.java @@ -0,0 +1,48 @@ +package org.minima.tests.cli.message; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class MessageTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + /* + ERROR: Maxima is meant to require an action: parameter + */ + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("message"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/mmrcreate/MmrCreate.java b/test/org/minima/tests/cli/mmrcreate/MmrCreate.java new file mode 100644 index 000000000..446fe9149 --- /dev/null +++ b/test/org/minima/tests/cli/mmrcreate/MmrCreate.java @@ -0,0 +1,48 @@ +package org.minima.tests.cli.mmrcreate; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class MmrCreate extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + /* + ERROR: Maxima is meant to require an action: parameter + */ + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("mmrcreate"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/mmrproof/MmrProof.java b/test/org/minima/tests/cli/mmrproof/MmrProof.java new file mode 100644 index 000000000..d66ddb8ba --- /dev/null +++ b/test/org/minima/tests/cli/mmrproof/MmrProof.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.mmrproof; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class MmrProof extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("mmrproof"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/network/NetworkTest.java b/test/org/minima/tests/cli/network/NetworkTest.java new file mode 100644 index 000000000..3efd79b36 --- /dev/null +++ b/test/org/minima/tests/cli/network/NetworkTest.java @@ -0,0 +1,35 @@ +package org.minima.tests.cli.network; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class NetworkTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("network"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + super.runBaseTests(output); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/newaddress/NewaddressTest.java b/test/org/minima/tests/cli/newaddress/NewaddressTest.java new file mode 100644 index 000000000..607214a4a --- /dev/null +++ b/test/org/minima/tests/cli/newaddress/NewaddressTest.java @@ -0,0 +1,35 @@ +package org.minima.tests.cli.newaddress; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class NewaddressTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("newaddress"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + super.runBaseTests(output); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/newscript/NewscriptTest.java b/test/org/minima/tests/cli/newscript/NewscriptTest.java new file mode 100644 index 000000000..3d87562d2 --- /dev/null +++ b/test/org/minima/tests/cli/newscript/NewscriptTest.java @@ -0,0 +1,48 @@ +package org.minima.tests.cli.newscript; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class NewscriptTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + /* + ERROR: Maxima is meant to require an action: parameter + */ + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("newscript"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/printtree/PrinttreeTest.java b/test/org/minima/tests/cli/printtree/PrinttreeTest.java new file mode 100644 index 000000000..a00bdd8fa --- /dev/null +++ b/test/org/minima/tests/cli/printtree/PrinttreeTest.java @@ -0,0 +1,36 @@ +package org.minima.tests.cli.printtree; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class PrinttreeTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("printtree"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + super.runBaseTests(output); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/quit/QuitTest.java b/test/org/minima/tests/cli/quit/QuitTest.java new file mode 100644 index 000000000..2d0acdeea --- /dev/null +++ b/test/org/minima/tests/cli/quit/QuitTest.java @@ -0,0 +1,36 @@ +package org.minima.tests.cli.quit; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class QuitTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("quit"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + super.runBaseTests(output); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/restore/RestoreTest.java b/test/org/minima/tests/cli/restore/RestoreTest.java new file mode 100644 index 000000000..3f89f953f --- /dev/null +++ b/test/org/minima/tests/cli/restore/RestoreTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.restore; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class RestoreTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("restore"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/rpc/RpcTest.java b/test/org/minima/tests/cli/rpc/RpcTest.java new file mode 100644 index 000000000..233a25604 --- /dev/null +++ b/test/org/minima/tests/cli/rpc/RpcTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.rpc; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class RpcTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("rpc"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/runscript/RunscriptTest.java b/test/org/minima/tests/cli/runscript/RunscriptTest.java new file mode 100644 index 000000000..13e873ae8 --- /dev/null +++ b/test/org/minima/tests/cli/runscript/RunscriptTest.java @@ -0,0 +1,48 @@ +package org.minima.tests.cli.runscript; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class RunscriptTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + /* + ERROR: runscript is meant to require an script: parameter + */ + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("runscript"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/scripts/ScriptsTest.java b/test/org/minima/tests/cli/scripts/ScriptsTest.java new file mode 100644 index 000000000..47b4aefa5 --- /dev/null +++ b/test/org/minima/tests/cli/scripts/ScriptsTest.java @@ -0,0 +1,36 @@ +package org.minima.tests.cli.scripts; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class ScriptsTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("scripts"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + super.runBaseTests(output); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/send/SendTest.java b/test/org/minima/tests/cli/send/SendTest.java new file mode 100644 index 000000000..bd2441bcb --- /dev/null +++ b/test/org/minima/tests/cli/send/SendTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.send; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class SendTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("send"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/sendpoll/SendpollTest.java b/test/org/minima/tests/cli/sendpoll/SendpollTest.java new file mode 100644 index 000000000..fe1bca423 --- /dev/null +++ b/test/org/minima/tests/cli/sendpoll/SendpollTest.java @@ -0,0 +1,51 @@ +package org.minima.tests.cli.sendpoll; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class SendpollTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + /* + + ERROR: returns status:true with no arguments + + */ + + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("sendpoll"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/sign/SignTest.java b/test/org/minima/tests/cli/sign/SignTest.java new file mode 100644 index 000000000..0a3d75fa4 --- /dev/null +++ b/test/org/minima/tests/cli/sign/SignTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.sign; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class SignTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testConnectWithNoArgs () throws Exception + { + String output = test.runCommand("sign"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/status/StatusTest.java b/test/org/minima/tests/cli/status/StatusTest.java new file mode 100644 index 000000000..0b977b68e --- /dev/null +++ b/test/org/minima/tests/cli/status/StatusTest.java @@ -0,0 +1,36 @@ +package org.minima.tests.cli.status; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class StatusTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testStatusWithNoArgs () throws Exception + { + String output = test.runCommand("status"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + super.runBaseTests(output); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/tokencreate/TokencreateTest.java b/test/org/minima/tests/cli/tokencreate/TokencreateTest.java new file mode 100644 index 000000000..c98fa40bc --- /dev/null +++ b/test/org/minima/tests/cli/tokencreate/TokencreateTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.tokencreatetest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TokencreateTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTokencreateWithNoArgs () throws Exception + { + String output = test.runCommand("tokencreate"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/tokens/TokensTest.java b/test/org/minima/tests/cli/tokens/TokensTest.java new file mode 100644 index 000000000..fd9d2283a --- /dev/null +++ b/test/org/minima/tests/cli/tokens/TokensTest.java @@ -0,0 +1,35 @@ +package org.minima.tests.cli.tokenstest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TokensTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTokensWithNoArgs () throws Exception + { + String output = test.runCommand("tokens"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + super.runBaseTests(output); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/tokenvalidate/TokenvalidateTest.java b/test/org/minima/tests/cli/tokenvalidate/TokenvalidateTest.java new file mode 100644 index 000000000..ee4f5cf34 --- /dev/null +++ b/test/org/minima/tests/cli/tokenvalidate/TokenvalidateTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.tokenvalidatetest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TokenvalidateTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTokenvalidateWithNoArgs () throws Exception + { + String output = test.runCommand("tokenvalidate"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/trace/TraceTest.java b/test/org/minima/tests/cli/trace/TraceTest.java new file mode 100644 index 000000000..98c09f3ed --- /dev/null +++ b/test/org/minima/tests/cli/trace/TraceTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.tracetest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TraceTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTraceWithNoArgs () throws Exception + { + String output = test.runCommand("trace"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/tutorial/TutorialTest.java b/test/org/minima/tests/cli/tutorial/TutorialTest.java new file mode 100644 index 000000000..55d1fffc1 --- /dev/null +++ b/test/org/minima/tests/cli/tutorial/TutorialTest.java @@ -0,0 +1,35 @@ +package org.minima.tests.cli.tutorialtest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TutorialTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTutorialWithNoArgs () throws Exception + { + String output = test.runCommand("tutorial"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + super.runBaseTests(output); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/txnbasics/TxnbasicsTest.java b/test/org/minima/tests/cli/txnbasics/TxnbasicsTest.java new file mode 100644 index 000000000..bf6880766 --- /dev/null +++ b/test/org/minima/tests/cli/txnbasics/TxnbasicsTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.txnbasicstest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TxnbasicsTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTxnbasicsWithNoArgs () throws Exception + { + String output = test.runCommand("txnbasics"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/txncheck/TxncheckTest.java b/test/org/minima/tests/cli/txncheck/TxncheckTest.java new file mode 100644 index 000000000..1cdcb1620 --- /dev/null +++ b/test/org/minima/tests/cli/txncheck/TxncheckTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.txnchecktest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TxncheckTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTxncheckWithNoArgs () throws Exception + { + String output = test.runCommand("txncheck"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/txnclear/TxnclearTest.java b/test/org/minima/tests/cli/txnclear/TxnclearTest.java new file mode 100644 index 000000000..822ed944b --- /dev/null +++ b/test/org/minima/tests/cli/txnclear/TxnclearTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.txncleartest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TxnclearTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTxnclearWithNoArgs () throws Exception + { + String output = test.runCommand("txnclear"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/txncreate/TxncreateTest.java b/test/org/minima/tests/cli/txncreate/TxncreateTest.java new file mode 100644 index 000000000..f8ab1d6ac --- /dev/null +++ b/test/org/minima/tests/cli/txncreate/TxncreateTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.txncreatetest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TxncreateTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTxncreateWithNoArgs () throws Exception + { + String output = test.runCommand("txncreate"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/txndelete/TxndeleteTest.java b/test/org/minima/tests/cli/txndelete/TxndeleteTest.java new file mode 100644 index 000000000..8a5ad5578 --- /dev/null +++ b/test/org/minima/tests/cli/txndelete/TxndeleteTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.txndeletetest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TxndeleteTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTxndeleteWithNoArgs () throws Exception + { + String output = test.runCommand("txndelete"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/txnexport/TxnexportTest.java b/test/org/minima/tests/cli/txnexport/TxnexportTest.java new file mode 100644 index 000000000..5e56a1abf --- /dev/null +++ b/test/org/minima/tests/cli/txnexport/TxnexportTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.txnexporttest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TxnexportTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTxnexportWithNoArgs () throws Exception + { + String output = test.runCommand("txnexport"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/txnimport/TxnimportTest.java b/test/org/minima/tests/cli/txnimport/TxnimportTest.java new file mode 100644 index 000000000..0d80716a1 --- /dev/null +++ b/test/org/minima/tests/cli/txnimport/TxnimportTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.txnimporttest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TxnimportTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTxnimportWithNoArgs () throws Exception + { + String output = test.runCommand("txnimport"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/txninput/TxninputTest.java b/test/org/minima/tests/cli/txninput/TxninputTest.java new file mode 100644 index 000000000..5a20ef3c4 --- /dev/null +++ b/test/org/minima/tests/cli/txninput/TxninputTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.txninputtest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TxninputTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTxninputWithNoArgs () throws Exception + { + String output = test.runCommand("txninput"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/txnlist/TxnlistTest.java b/test/org/minima/tests/cli/txnlist/TxnlistTest.java new file mode 100644 index 000000000..013bcfa4a --- /dev/null +++ b/test/org/minima/tests/cli/txnlist/TxnlistTest.java @@ -0,0 +1,35 @@ +package org.minima.tests.cli.txnlisttest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TxnlistTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTxnlistWithNoArgs () throws Exception + { + String output = test.runCommand("txnlist"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + super.runBaseTests(output); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/txnoutput/TxnoutputTest.java b/test/org/minima/tests/cli/txnoutput/TxnoutputTest.java new file mode 100644 index 000000000..0b0388dad --- /dev/null +++ b/test/org/minima/tests/cli/txnoutput/TxnoutputTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.txnoutputtest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TxnoutputTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTxnoutputWithNoArgs () throws Exception + { + String output = test.runCommand("txnoutput"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/txnpost/TxnpostTest.java b/test/org/minima/tests/cli/txnpost/TxnpostTest.java new file mode 100644 index 000000000..4736a18f3 --- /dev/null +++ b/test/org/minima/tests/cli/txnpost/TxnpostTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.txnposttest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TxnpostTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTxnpostWithNoArgs () throws Exception + { + String output = test.runCommand("txnpost"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/txnscript/TxnscriptTest.java b/test/org/minima/tests/cli/txnscript/TxnscriptTest.java new file mode 100644 index 000000000..da4826e53 --- /dev/null +++ b/test/org/minima/tests/cli/txnscript/TxnscriptTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.txnscripttest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TxnscriptTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTxnscriptWithNoArgs () throws Exception + { + String output = test.runCommand("txnscript"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/txnsign/TxnsignTest.java b/test/org/minima/tests/cli/txnsign/TxnsignTest.java new file mode 100644 index 000000000..54d7c6945 --- /dev/null +++ b/test/org/minima/tests/cli/txnsign/TxnsignTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.txnsigntest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TxnsignTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTxnsignWithNoArgs () throws Exception + { + String output = test.runCommand("txnsign"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/txnstate/TxnstateTest.java b/test/org/minima/tests/cli/txnstate/TxnstateTest.java new file mode 100644 index 000000000..b2de1dd8f --- /dev/null +++ b/test/org/minima/tests/cli/txnstate/TxnstateTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.txnstatetest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TxnstateTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTxnstateWithNoArgs () throws Exception + { + String output = test.runCommand("txnstate"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/txpow/TxpowTest.java b/test/org/minima/tests/cli/txpow/TxpowTest.java new file mode 100644 index 000000000..b1378e91b --- /dev/null +++ b/test/org/minima/tests/cli/txpow/TxpowTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.txpowtest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class TxpowTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testTxpowWithNoArgs () throws Exception + { + String output = test.runCommand("txpow"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/vault/VaultTest.java b/test/org/minima/tests/cli/vault/VaultTest.java new file mode 100644 index 000000000..831a20937 --- /dev/null +++ b/test/org/minima/tests/cli/vault/VaultTest.java @@ -0,0 +1,35 @@ +package org.minima.tests.cli.vaulttest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class VaultTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testVaultWithNoArgs () throws Exception + { + String output = test.runCommand("vault"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + super.runBaseTests(output); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/verify/VerifyTest.java b/test/org/minima/tests/cli/verify/VerifyTest.java new file mode 100644 index 000000000..e95ef75ab --- /dev/null +++ b/test/org/minima/tests/cli/verify/VerifyTest.java @@ -0,0 +1,44 @@ +package org.minima.tests.cli.verifytest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class VerifyTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testVerifyWithNoArgs () throws Exception + { + String output = test.runCommand("verify"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + //The cmd response should be valid JSON + JSONObject json = (JSONObject) new JSONParser().parse(output); + + //status of the cmd request must be true + System.out.println("status must be false: " + json.get("status")); + assertFalse((boolean)json.get("status")); + + //cmd response pending should be false + System.out.println("pending must be false:" + json.get("pending").toString()); + assertFalse((boolean)json.get("pending")); + } + +} \ No newline at end of file diff --git a/test/org/minima/tests/cli/webhooks/WebhooksTest.java b/test/org/minima/tests/cli/webhooks/WebhooksTest.java new file mode 100644 index 000000000..26636bdb9 --- /dev/null +++ b/test/org/minima/tests/cli/webhooks/WebhooksTest.java @@ -0,0 +1,35 @@ +package org.minima.tests.cli.webhookstest; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import static org.junit.Assert.*; + +import org.minima.system.commands.CommandException; + +import org.minima.utils.json.JSONArray; +import org.minima.utils.json.JSONObject; +import org.minima.utils.json.parser.JSONParser; + +import org.minima.system.Main; +import org.minima.tests.cli.MinimaTestNode; +import org.minima.tests.cli.MinimaCliTest; + +public class WebhooksTest extends MinimaCliTest { + + public MinimaTestNode test = new MinimaTestNode(); + + @Test + public void testWebhooksWithNoArgs () throws Exception + { + String output = test.runCommand("webhooks"); + + runBaseTests(output); + } + + public void runBaseTests (String output) throws Exception + { + super.runBaseTests(output); + } + +} \ No newline at end of file