Skip to content

Commit

Permalink
testinvoke working beautifully :) closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
igormcoelho committed Feb 12, 2018
1 parent ede2559 commit 761f258
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 18 deletions.
30 changes: 21 additions & 9 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,7 @@ app.post('/deployx', function(req, res) {
//console.log(cmddocker);
outp = require('child_process').execSync(cmddocker).toString();
outp = outp.replace(/(\r\n|\n|\r)/gm,"");

//outp_str = new Buffer(outp, 'base64').toString('ascii');
//outp = new Buffer(outp_str, 'ascii').toString('base64');
//console.log(outp_str);

outp = '{"output":"'+outp+'"}';
//console.log(outp);
//res.send(JSON.stringify(outp));
//res.send(outp);
//res.send(JSON.parse(outp));
res.send(JSON.parse(outp));
});

Expand All @@ -114,6 +105,27 @@ app.post('/searchx', function(req, res) {
res.send(JSON.parse(outp));
});

app.post('/invokex', function(req, res) {
console.log("hash:"+req.body.invokehash+" params:"+req.body.invokeparams);
console.log("wallet:"+req.body.wallet_invoke);
var invokehash = new Buffer(req.body.invokehash, 'ascii').toString('base64');
var invokeparams = new Buffer(req.body.invokeparams, 'ascii').toString('base64');
var wallet_invoke = "";
if((req.body.wallet_invoke == "w1.wallet")||(req.body.wallet_invoke == "w2.wallet")||(req.body.wallet_invoke == "w3.wallet")||(req.body.wallet_invoke == "w4.wallet"))
wallet_invoke = new Buffer(req.body.wallet_invoke, 'ascii').toString('base64');

var cmddocker = 'docker exec -t neo-privnet-with-gas dash -i -c "./exectestinvokecontract.sh '+
invokehash+' '+ invokeparams + ' ' + wallet_invoke + '" | base64';
var outp = "";

console.log(cmddocker);
outp = require('child_process').execSync(cmddocker).toString();
outp = outp.replace(/(\r\n|\n|\r)/gm,"");
outp = '{"output":"'+outp+'"}';
res.send(JSON.parse(outp));
});


//docker exec -t neo-privnet-with-gas dash -i -c "./execimportcontract.sh M2ZlMTY2ZTczMzIwYTVlZDNmZTg0YTFkNjhlMmRlMmE2YTk1YmJiZAo= MDBjNTZiNjE2Yzc1NjYK IiIK MDEK RmFsc2UK RmFsc2UK" > saida.log

// catch 404 and forward to error handler
Expand Down
5 changes: 4 additions & 1 deletion docker-privnet/execsearchcontract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ if (( $# == 1 )); then
#echo "code: $2"
cd /opt/neo-python/

stropen=`echo "open wallet w1.wallet" | xxd -p`
strrebuild=`echo "wallet rebuild" | xxd -p`
strshowwallet=`echo "wallet" | xxd -p`
strexit=`echo "exit" | xxd -p`
strsearch=`echo "contract $lhash" | xxd -p -c 256`

python3 unsafeprompt.py -p -e $strexit,$strsearch
python3 unsafeprompt.py -p -e $strexit,$strsearch,$strshowwallet,$strrebuild,$stropen
fi

#example: ./execimportcontract.sh M2ZlMTY2ZTczMzIwYTVlZDNmZTg0YTFkNjhlMmRlMmE2YTk1YmJiZAo=
13 changes: 8 additions & 5 deletions docker-privnet/exectestinvokecontract.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
#!/bin/bash

# $1 == HASH
# import contract hash.avm "params" 01 False False
# $2 == PARAMS
# testinvoke $1 $2
# $3 == WALLET

if (( $# == 1 )); then
if (( $# == 3 )); then
wallet=`echo "$3" | base64 --decode`
parm=`echo $2 | base64 --decode`
lhash=`echo "$1" | base64 --decode`
#echo "HASH: $lhash"
#echo "code: $2"
cd /opt/neo-python/

stropen=`echo "open wallet w1.wallet" | xxd -p`
stropen=`echo "open wallet $wallet" | xxd -p`
strrebuild=`echo "wallet rebuild" | xxd -p`
strshowwallet=`echo "wallet" | xxd -p`
strexit=`echo "exit" | xxd -p`
strsearch=`echo "contract $lhash" | xxd -p -c 256`
strinvoke=`echo "testinvoke $lhash" | xxd -p -c 256`
strinvoke=`echo "testinvoke $lhash $parm" | xxd -p -c 256`

python3 unsafeprompt.py -p -e $strexit,$strinvoke,$strshowwallet,$strrebuild,$stropen

Expand Down
46 changes: 43 additions & 3 deletions views/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ block content
br
h4 Compile Warning/Errors:
textarea.form-control(id='codewarnerr',rows='15', cols='100', placeholder="Warning/Errors in code...")=""
p *This is beta software: ConvertTask will return "FAIL" even when everything is fine. Sorry for this. If it returns "0 errors" that's OK, just ignore this message for now :)
br

form(id='formdeploy', action='/deployx')
.form-group
h4 AVM (in hex):
textarea.form-control(id='codeavm', name='codeavm' rows='5', cols='100', placeholder="AVM (in hex)")
br
button.btn.btn-success(id='btn_download', style="visibility:hidden")="Download AVM"
button.btn.btn-success(id='btn_download', style="visibility:hidden")="Download AVM"
p *This is beta. Download AVM may be corrupt... trust in hex codes more than binary download :)
br
br

Expand Down Expand Up @@ -85,6 +87,20 @@ block content
button.btn.btn-success(type="submit")="Search by hash"
br
br
form(id='forminvoke', action='/invokex')
.form-group
h4 Invoke contract in private net:
input(id='invokehash', name='invokehash' placeholder="Script Hash")
input(id='invokeparams', name='invokeparams' placeholder="Script Params")
select(name='wallet_invoke')
option w1.wallet
option w2.wallet
option w3.wallet
option w4.wallet
button.btn.btn-success(type="submit")="Invoke by hash"
br
br




Expand All @@ -103,6 +119,7 @@ block content
return str;
}
$("#myform").submit(function(e) {
$("#codewarnerr").text("");
e.preventDefault(); // Prevents the page from refreshing
var $this = $(this); // `this` refers to the current form element
var indata = $(this).serialize();
Expand All @@ -122,6 +139,8 @@ block content
chash=JSON.parse($('#codeabi').text())["hash"];
$("#contracthash")[0].value = chash.substr(2,chash.length);
$("#contracthash_search")[0].value = $("#contracthash")[0].value;
$("#invokehash")[0].value = $("#contracthash")[0].value;
$("#invokeparams")[0].value = "\"\"";
cparams=JSON.parse($('#codeabi').text())["functions"][0]["parameters"];
$("#contractparams")[0].value = '""';
rettype=JSON.parse($('#codeabi').text())["functions"][0]["returntype"];
Expand Down Expand Up @@ -158,6 +177,25 @@ block content
});

$("#formsearch").submit(function(e) {
$("#contractmessages").text("");
e.preventDefault(); // Prevents the page from refreshing
var $this = $(this); // `this` refers to the current form element
var indata = $(this).serialize();
$.post(
$this.attr("action"), // Gets the URL to sent the post to
indata, // Serializes form data in standard format
function(data) {
//console.log("output="+data);
var deploymsg = atob(data.output);
$("#contractmessages").text(deploymsg);
},
"json" // The format the response should be in
);
alert("the search action in private net can take up to 30 seconds... time for a coffee :)");
});

$("#forminvoke").submit(function(e) {
$("#contractmessages").text("");
e.preventDefault(); // Prevents the page from refreshing
var $this = $(this); // `this` refers to the current form element
var indata = $(this).serialize();
Expand All @@ -171,9 +209,11 @@ block content
},
"json" // The format the response should be in
);
alert("the search action in private net can take up to 5 seconds...");
alert("the invoke action in private net can take up to 30 seconds... time for a coffee :)");
});

$("#formdeploy").submit(function(e) {
$("#contractmessages").text("");
e.preventDefault(); // Prevents the page from refreshing
var $this = $(this); // `this` refers to the current form element
var indata = $(this).serialize();
Expand All @@ -187,7 +227,7 @@ block content
},
"json" // The format the response should be in
);
alert("the deploy action in private net can take up to 10 seconds...");
alert("the deploy action in private net can take up to 30 seconds... time for a coffee :)");
});

$("#btn_cs_ex1").click(function (e) {
Expand Down

0 comments on commit 761f258

Please sign in to comment.