Skip to content

Commit

Permalink
Merge branch 'dev-spartacus' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
spartacusrex99 committed Feb 3, 2022
2 parents 4783eb5 + 9ec4259 commit 2c99c9c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/org/minima/objects/Witness.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public ArrayList<MiniData> getAllSignatureKeys(){
/**
* MMR Functions
*/
public void clearCoinProofs() {
mCoinProofs.clear();
}

public void addCoinProof(CoinProof zProof) {
mCoinProofs.add(zProof);
}
Expand Down
11 changes: 8 additions & 3 deletions src/org/minima/system/commands/base/runscript.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class runscript extends Command {

public runscript() {
super("runscript","[script:] (state:{}) (prevstate:{}) (globals:{}) (signatures:[]) (extrascripts:{}) - Run a script with the defined parameters");
super("runscript","[script:] (clean:true|false) (state:{}) (prevstate:{}) (globals:{}) (signatures:[]) (extrascripts:{}) - Run a script with the defined parameters");
}

@Override
Expand All @@ -29,6 +29,11 @@ public JSONObject runCommand() throws Exception{
//Get the script..
String script = getParam("script","");

boolean clean = getBooleanParam("clean",true);
if(clean) {
script = Contract.cleanScript(script);
}

//What is defined..
JSONObject state = new JSONObject();
if(existsParam("state")) {
Expand Down Expand Up @@ -161,13 +166,13 @@ public JSONObject runCommand() throws Exception{

JSONObject scriptnormal = new JSONObject();
scriptnormal.put("script", script);
scriptnormal.put("address", new Address(script).getAddressData());
scriptnormal.put("address", new Address(script).getAddressData().to0xString());
resp.put("script", scriptnormal);

JSONObject scriptclean = new JSONObject();
String cleanscript = Contract.cleanScript(script);
scriptclean.put("script", cleanscript);
scriptclean.put("address", new Address(cleanscript).getAddressData());
scriptclean.put("address", new Address(cleanscript).getAddressData().to0xString());
resp.put("clean", scriptclean);

resp.put("trace", contract.getCompleteTraceLog());
Expand Down
33 changes: 19 additions & 14 deletions src/org/minima/system/commands/base/tutorial.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public JSONObject runCommand() throws Exception{
+ "Grammar\n"
+ "-------\n"
+ "\n"
+ "ADDRESS ::= KECCAK ( BLOCK )\n"
+ "ADDRESS ::= ADDRESS ( BLOCK )\n"
+ "BLOCK ::= STATEMENT_1 STATEMENT_2 ... STATEMENT_n\n"
+ "STATEMENT ::= LET VARIABLE = EXPRESSION |\n"
+ " LET ( EXPRESSION_1 EXPRESSION_2 ... EXPRESSION_n ) = EXPRESSION |\n"
Expand Down Expand Up @@ -68,15 +68,15 @@ public JSONObject runCommand() throws Exception{
+ "BOOLEAN ::= TRUE | FALSE\n"
+ "FALSE ::= 0\n"
+ "TRUE ::= NOT FALSE\n"
+ "GLOBAL ::= @BLKNUM | @BLKTIME | @INPUT | @INBLKNUM | @BLKDIFF\n"
+ " @AMOUNT | @ADDRESS | @TOKENID | @COINID |\n"
+ "GLOBAL ::= @BLOCK | @INBLOCK | @BLOCKDIFF | @INPUT |\n"
+ " @AMOUNT | @ADDRESS | @TOKENID | @COINID |\n"
+ " @SCRIPT | @TOTIN | @TOTOUT\n"
+ "FUNCTION ::= FUNC ( EXPRESSION_1 EXPRESSION_2 .. EXPRESSION_n ) \n"
+ "FUNC ::= CONCAT | LEN | REV | SUBSET | GET |\n"
+ "FUNC ::= CONCAT | LEN | REV | SUBSET | GET | OVERWRITE |\n"
+ " CLEAN | UTF8 | REPLACE | SUBSTR |\n"
+ " BOOL | HEX | NUMBER | STRING |\n"
+ " BOOL | HEX | NUMBER | STRING | ADDRESS |\n"
+ " ABS | CEIL | FLOOR | MIN | MAX | INC | DEC | SIGDIG | POW |\n"
+ " BITSET | BITGET | BITCOUNT | PROOF | KECCAK | SHA2 |\n"
+ " BITSET | BITGET | BITCOUNT | PROOF | KECCAK | SHA2 | SHA3 |\n"
+ " SIGNEDBY | MULTISIG | CHECKSIG |\n"
+ " GETOUTADDR | GETOUTAMT | GETOUTTOK | VERIFYOUT |\n"
+ " GETINADDR | GETINAMT | GETINTOK | GETINID | VERIFYIN |\n"
Expand All @@ -86,8 +86,6 @@ public JSONObject runCommand() throws Exception{
+ "-------\n"
+ "\n"
+ "@BLOCK : Block number this transaction is in\n"
// + "@BLKTIME : Block time in seconds from Jan 01 1970\n"
// + "@PREVBLKHASH : Hash of the previous Block\n"
+ "@INBLOCK : Block number when this output was created\n"
+ "@BLOCKDIFF : Difference between @BLOCK and INBLOCK\n"
+ "@INPUT : Input number in the transaction\n"
Expand All @@ -96,10 +94,8 @@ public JSONObject runCommand() throws Exception{
+ "@ADDRESS : Address of this input\n"
+ "@TOKENID : TokenID of this input\n"
+ "@SCRIPT : Script for this input\n"
// + "@TOKENSCRIPT : Script for this input\n"
+ "@TOTIN : Total number of inputs for this transaction\n"
+ "@TOTOUT : Total number of outputs for this transaction\n"
// + "@FLOATING : Is this a floating input\n"
+ "\n"
+ "Functions\n"
+ "---------\n"
Expand All @@ -116,9 +112,15 @@ public JSONObject runCommand() throws Exception{
+ "SUBSET ( HEX NUMBER NUMBER )\n"
+ "Return the HEX subset of the data - start - length\n"
+ "\n"
+ "OVERWRITE ( HEX NUMBER HEX NUMBER NUMBER)\n"
+ "Copy bytes from the first HEX and pos to the second HEX and pos, length the last NUMBER\n"
+ "\n"
+ "GET ( NUMBER NUMBER .. NUMBER )\n"
+ "Return the array value set with LET ( EXPRESSION EXPRESSION .. EXPRESSION ) \n"
+ "\n"
+ "ADDRESS ( STRING )\n"
+ "Return the address of the script\n"
+ "\n"
+ "REPLACE ( STRING STRING STRING )\n"
+ "Replace in 1st string all occurrence of 2nd string with 3rd\n"
+ "\n"
Expand Down Expand Up @@ -179,15 +181,18 @@ public JSONObject runCommand() throws Exception{
+ "BITCOUNT ( HEX ) \n"
+ "Count the number of bits set in a HEX value\n"
+ "\n"
+ "PROOF ( HEX HEX ) \n"
+ "Recursively KECCAK hash the first HEX value with the merkle proof provided in the second. Returns the final result that can be checked in script. Use the 'chainsha' function in Minima to construct Hash Trees proofs for MAST and Signature Public Keys. \n"
+ "PROOF ( HEX HEX HEX ) \n"
+ "Check the data, mmr proof, and root match. Same as mmrproof on Minima.\n"
+ "\n"
+ "KECCAK ( HEX ) \n"
+ "KECCAK ( HEX|STRING ) \n"
+ "Returns the KECCAK value of the HEX value.\n"
+ "\n"
+ "SHA2 ( HEX ) \n"
+ "SHA2 ( HEX|STRING ) \n"
+ "Returns the SHA2 value of the HEX value.\n"
+ "\n"
+ "SHA3 ( HEX|STRING ) \n"
+ "Returns the SHA3 value of the HEX value.\n"
+ "\n"
+ "SIGNEDBY ( HEX )\n"
+ "Returns true if the transaction is signed by this public key\n"
+ "\n"
Expand Down
3 changes: 3 additions & 0 deletions src/org/minima/system/commands/txn/txnutils.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public static void setMMRandScripts(Transaction zTransaction, Witness zWitness)
//Get the main Wallet
Wallet walletdb = MinimaDB.getDB().getWallet();

//Clear the MMR..
zWitness.clearCoinProofs();

//Add the MMR proofs for the coins..
for(Coin input : inputs) {

Expand Down
7 changes: 5 additions & 2 deletions src/org/minima/system/network/minima/NIOClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.minima.system.network.minima;

import java.io.IOException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
Expand Down Expand Up @@ -294,7 +295,8 @@ public void handleRead() throws IOException {
}

//Ready to read
mBufferIn.flip();
// mBufferIn.flip();
((Buffer) mBufferIn).flip();

while(mBufferIn.hasRemaining()) {

Expand Down Expand Up @@ -423,7 +425,8 @@ public void handleWrite() throws IOException {
}

//Ready to write
mBufferOut.flip();
// mBufferOut.flip();
((Buffer) mBufferOut).flip();

//Write
int write = mSocket.write(mBufferOut);
Expand Down
4 changes: 3 additions & 1 deletion src/org/minima/utils/Keccak.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.minima.utils;

import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

Expand Down Expand Up @@ -242,7 +243,8 @@ public ByteBuffer digest(int outSize) {
public ByteBuffer digest(int outSize, boolean direct) {
ByteBuffer buffer = direct ? ByteBuffer.allocateDirect(outSize) : ByteBuffer.allocate(outSize);
digest(buffer);
buffer.flip();
// buffer.flip();
((Buffer) buffer).flip();
return buffer;
}

Expand Down

0 comments on commit 2c99c9c

Please sign in to comment.