diff --git a/bin/registro-verificar b/bin/registro-verificar index 2ce53f3e4f2a683bcb4d80af6c3a2815f4305c7d..23b90b1a11ffbddc8bd6560cbf8db6421ea5cc9a 100755 --- a/bin/registro-verificar +++ b/bin/registro-verificar @@ -8,15 +8,18 @@ var web3 = new Web3( 'http://localhost:8545/' ); var myArgs = process.argv.slice(2); var myaccount = myArgs[0]; var proof = myArgs[1]; +var password = myArgs[2] || ''; var contractaddr; var networkid; var chainid; var rawdata; 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 ); } @@ -98,7 +101,7 @@ function loadaccount( path ) } let w; try { - w = web3.eth.accounts.wallet.decrypt( [keystore], '' ); + w = web3.eth.accounts.wallet.decrypt( [keystore], password ); } catch(e) { @@ -172,15 +175,26 @@ function getnonce( account ) function prepareCall() { - var abi = [ { - "name" : "proveControl", - "type" : "function", - "inputs" : [ { "name": "key", "type": "string" } ], - "outputs" : [ { "name": "", "type": "bool" } ], - "constant" : false, - "payable" : false, - "stateMutability" : "nonpayable" - } ]; + var abi = [ + { + "name" : "hash", + "type" : "function", + "inputs" : [ { "name": "key", "type": "string" } ], + "outputs" : [ { "name": "", "type": "bytes32" } ], + "constant" : true, + "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( function(resolve, reject) { @@ -197,6 +211,7 @@ function prepareCall() var contractInstance = new web3.eth.Contract(abi, contractaddr ); //Estimá el gas que vas a gastar let method = contractInstance.methods.proveControl( proof ); +// contractInstance.methods.hash(proof).call().then( console.log ); rawdata = method.encodeABI(); gasestimate( method ). then( resolve ); @@ -232,7 +247,7 @@ function signrawtx() return promise; } -function printRecepts( r ) +function printReceipt( r ) { console.log( "blockNumber: " + r.blockNumber ); console.log( "transactionHash: " + r.transactionHash ); @@ -248,12 +263,14 @@ findaccountfile( myaccount ) // Manda la transaccion a la blockchain .then( tx => { console.log( "Sending this transaction: " + tx.rawTransaction ); -// web3.eth.sendSignedTransaction( tx.rawTransaction ) -// //Obtené el recibo. -// .once( 'receipt', printReceipt ); +console.log( "TX hash: " + tx.transactionHash ); +//process.exit( 0 ); + 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 => { console.error( "Oh no. Something most definitely seems to have gone wrong. What I was told is:" ); console.error( e ); }); -