Skip to content

Commit

Permalink
MAST tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
spartacusrex99 committed Jan 31, 2022
1 parent ee6edcc commit 53b8883
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
10 changes: 9 additions & 1 deletion src/org/minima/system/commands/base/hash.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.minima.system.commands.base;

import org.minima.objects.base.MiniData;
import org.minima.objects.base.MiniString;
import org.minima.system.commands.Command;
import org.minima.utils.Crypto;
import org.minima.utils.json.JSONObject;
Expand All @@ -15,7 +16,14 @@ public hash() {
public JSONObject runCommand() throws Exception {
JSONObject ret = getJSONReply();

MiniData data = getDataParam("data");
String datastr = getParam("data");

MiniData data = null;
if(datastr.startsWith("0x")) {
data = new MiniData(datastr);
}else {
data = new MiniData(new MiniString(datastr).getData());
}

byte[] hash = Crypto.getInstance().hashData(data.getBytes());

Expand Down
2 changes: 1 addition & 1 deletion src/org/minima/system/commands/base/mmrcreate.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public JSONObject runCommand() throws Exception{
jobj.put("entry", leaf.mEntry);
jobj.put("input", leaf.mInput);
jobj.put("data", leaf.mData);
// jobj.put("hash", leaf.mHash);
jobj.put("hash", leaf.mHash);

//Get the proof..
MMRProof proof = mmrtree.getProof(new MMREntryNumber(leaf.mEntry));
Expand Down
2 changes: 1 addition & 1 deletion src/org/minima/system/commands/base/mmrproof.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public JSONObject runCommand() throws Exception{

JSONObject resp = new JSONObject();
resp.put("data", strdata);
// resp.put("hash", hash);
resp.put("hash", hash);
resp.put("finaldata", prfcalc.to0xString());
resp.put("valid", prfcalc.isEqual(root));

Expand Down
37 changes: 33 additions & 4 deletions src/org/minima/system/commands/base/runscript.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import java.util.ArrayList;

import org.minima.database.mmr.MMRProof;
import org.minima.kissvm.Contract;
import org.minima.kissvm.values.StringValue;
import org.minima.kissvm.values.Value;
import org.minima.objects.Address;
import org.minima.objects.ScriptProof;
import org.minima.objects.StateVariable;
import org.minima.objects.Transaction;
import org.minima.objects.Witness;
Expand All @@ -17,7 +19,7 @@
public class runscript extends Command {

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

@Override
Expand Down Expand Up @@ -48,9 +50,15 @@ public JSONObject runCommand() throws Exception{
signatures = getJSONArrayParam("signatures");
}

JSONObject extrascripts = new JSONObject();
if(existsParam("extrascripts")) {
extrascripts = getJSONObjectParam("extrascripts");
}

//The Transaction..
Transaction trans = new Transaction();

Transaction trans = new Transaction();
Witness witness = new Witness();

//Add the state variables..
for(Object key : state.keySet()) {

Expand Down Expand Up @@ -101,8 +109,29 @@ public JSONObject runCommand() throws Exception{
sigs.add(new MiniData(strsig));
}

//Any extra scripts
for(Object key : extrascripts.keySet()) {

//Get the state var..
String exscript = (String)key;

//The Key is a String
String proof = (String) extrascripts.get(key);
MiniData proofdata = new MiniData(proof);

//Make it into an MMRProof..
MMRProof scproof = MMRProof.convertMiniDataVersion(proofdata);

//Create a ScriptProof..
ScriptProof scprf = new ScriptProof(exscript, scproof);

//Add to the Witness..
witness.addScript(scprf);
}


//Create a Contract
Contract contract = new Contract(script, sigs, new Witness(), trans, pstate);
Contract contract = new Contract(script, sigs, witness, trans, pstate);

//Set trhe Script..
contract.setGlobalVariable("@SCRIPT", new StringValue(script));
Expand Down

0 comments on commit 53b8883

Please sign in to comment.