Skip to content
Snippets Groups Projects
Commit 055bb214 authored by Robert Martin-Legene's avatar Robert Martin-Legene
Browse files

A bit closer, but still fails in the EVM

parent eba899d7
No related branches found
No related tags found
No related merge requests found
...@@ -8,15 +8,18 @@ var web3 = new Web3( 'http://localhost:8545/' ); ...@@ -8,15 +8,18 @@ var web3 = new Web3( 'http://localhost:8545/' );
var myArgs = process.argv.slice(2); var myArgs = process.argv.slice(2);
var myaccount = myArgs[0]; var myaccount = myArgs[0];
var proof = myArgs[1]; var proof = myArgs[1];
var password = myArgs[2] || '';
var contractaddr; var contractaddr;
var networkid; var networkid;
var chainid; var chainid;
var rawdata; var rawdata;
var estimate; var estimate;
if ( myArgs.length != 2 ) if ( myArgs.length < 2 || myArgs.length > 3 )
{ {
console.error( "Wrong number of arguments: "+process.argv[1]+" <account> <proof>"); let myname = process.argv[1].replace(/^.*\//, '');;
console.error( "Wrong number of arguments.");
console.error( "Usage: " + myname + " <account> <proof> [<privatekeypassword>]");
process.exit( 1 ); process.exit( 1 );
} }
...@@ -98,7 +101,7 @@ function loadaccount( path ) ...@@ -98,7 +101,7 @@ function loadaccount( path )
} }
let w; let w;
try { try {
w = web3.eth.accounts.wallet.decrypt( [keystore], '' ); w = web3.eth.accounts.wallet.decrypt( [keystore], password );
} }
catch(e) catch(e)
{ {
...@@ -172,15 +175,26 @@ function getnonce( account ) ...@@ -172,15 +175,26 @@ function getnonce( account )
function prepareCall() function prepareCall()
{ {
var abi = [ { var abi = [
"name" : "proveControl", {
"type" : "function", "name" : "hash",
"inputs" : [ { "name": "key", "type": "string" } ], "type" : "function",
"outputs" : [ { "name": "", "type": "bool" } ], "inputs" : [ { "name": "key", "type": "string" } ],
"constant" : false, "outputs" : [ { "name": "", "type": "bytes32" } ],
"payable" : false, "constant" : true,
"stateMutability" : "nonpayable" "payable" : false,
} ]; "stateMutability" : "pure"
},
{
"name" : "proveControl",
"type" : "function",
"inputs" : [ { "name": "key", "type": "string" } ],
"outputs" : [ { "name": "", "type": "bool" } ],
"constant" : false,
"payable" : false,
"stateMutability" : "nonpayable"
}
];
return new Promise( return new Promise(
function(resolve, reject) function(resolve, reject)
{ {
...@@ -197,6 +211,7 @@ function prepareCall() ...@@ -197,6 +211,7 @@ function prepareCall()
var contractInstance = new web3.eth.Contract(abi, contractaddr ); var contractInstance = new web3.eth.Contract(abi, contractaddr );
//Estimá el gas que vas a gastar //Estimá el gas que vas a gastar
let method = contractInstance.methods.proveControl( proof ); let method = contractInstance.methods.proveControl( proof );
// contractInstance.methods.hash(proof).call().then( console.log );
rawdata = method.encodeABI(); rawdata = method.encodeABI();
gasestimate( method ). gasestimate( method ).
then( resolve ); then( resolve );
...@@ -232,7 +247,7 @@ function signrawtx() ...@@ -232,7 +247,7 @@ function signrawtx()
return promise; return promise;
} }
function printRecepts( r ) function printReceipt( r )
{ {
console.log( "blockNumber: " + r.blockNumber ); console.log( "blockNumber: " + r.blockNumber );
console.log( "transactionHash: " + r.transactionHash ); console.log( "transactionHash: " + r.transactionHash );
...@@ -248,12 +263,14 @@ findaccountfile( myaccount ) ...@@ -248,12 +263,14 @@ findaccountfile( myaccount )
// Manda la transaccion a la blockchain // Manda la transaccion a la blockchain
.then( tx => { .then( tx => {
console.log( "Sending this transaction: " + tx.rawTransaction ); console.log( "Sending this transaction: " + tx.rawTransaction );
// web3.eth.sendSignedTransaction( tx.rawTransaction ) console.log( "TX hash: " + tx.transactionHash );
// //Obtené el recibo. //process.exit( 0 );
// .once( 'receipt', printReceipt ); web3.eth.sendSignedTransaction( tx.rawTransaction )
//Obtené el recibo.
.once( 'receipt', printReceipt )
.catch( (e) => { console.error( "It would seem that the transaction has failed:\n" + e)} );
}) })
.catch( e => { .catch( e => {
console.error( "Oh no. Something most definitely seems to have gone wrong. What I was told is:" ); console.error( "Oh no. Something most definitely seems to have gone wrong. What I was told is:" );
console.error( e ); console.error( e );
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment