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

Distribution works too now.

parent 87f9ad23
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@
var port = 14349; // cloud
port = 16437; // bc
const contractaddr= '0x283bc55557c08dbc4f902b2b8479a2201a47e1c1';
const networkdir = 'network5445';
const readline = require('readline');
const rl = readline.createInterface( { input: process.stdin, output: process.stdout } );
const Web3 = require('web3');
......@@ -11,19 +11,28 @@ const Personal = require('web3-eth-personal');
var web3;
var GasWell;
var from;
var contractbalance;
var contractaddr;
function fatal( txt )
{
console.log( txt );
process.exit( 1 );
}
function init()
{
if ( process.env.BFAHOME == undefined )
{
console.log( "$BFAHOME not set. Did you source bfa/bin/env ?" );
process.exit( 1 );
}
fatal( "$BFAHOME not set. Did you source bfa/bin/env ?" );
web3 = new Web3( "http://127.0.0.1:"+port );
//accounts = new Accounts( web3 );
var abi = "";
var abifile = fs.createReadStream(
process.env.BFAHOME+"/network5445/contracts/"+contractaddr+"/abi" )
contractaddr = fs.realpathSync([ process.env.BFAHOME, networkdir, 'contracts', 'GasWell' ].join('/'));
if ( contractaddr == undefined )
fatal( "I can't seem to find the contract directory containing the Gas Well's ABI" );
contractaddr = contractaddr.replace(/^.*\//, '');
var abipath = [ process.env.BFAHOME, networkdir, 'contracts', contractaddr, 'abi' ].join('/');
var abifile = fs.createReadStream( abipath )
.on('readable', () => {
var data;
while (data = abifile.read())
......@@ -31,6 +40,7 @@ function init()
})
.on('end', () => {
GasWell = new web3.eth.Contract( JSON.parse(abi), contractaddr );
web3.eth.getBalance( contractaddr ).then( function(v){contractbalance=v} );
getlist();
})
;
......@@ -52,12 +62,11 @@ function getAccount()
personal.getAccounts().then(
function gotPersonalAccounts(obj) {
console.log("Setting default account to "+ obj[0]);
from = obj[0];
from = obj[0];
web3.eth.defaultAccount = obj[0];
},
function failedGettingPersonalAccounts(err){
console.log("Did you remember to allow 'personal' via the RPC port? " + err)
process.exit( 1 );
fatal ("Did you remember to allow 'personal' via the RPC port? " + err)
}
);
}
......@@ -190,10 +199,7 @@ function editAccount( entry, well )
return;
}
else
{
console.log("I don't know what to do with \""+entry+"\"." );
process.exit( 1 );
}
fatal("I don't know what to do with \""+entry+"\"." );
rl.question("Adjust the Mwei fill value of "+acct+" (setting to 0 is the same as deleting)\nAmount?: ", (answer) => {
if ( isNumeric(answer) )
{
......@@ -206,17 +212,13 @@ function editAccount( entry, well )
getlist();
},
function(b){
console.log("\nMaybe you are not authorized:\n"+b+"\n\n\nI think you should leave now.\n");
process.exit( 1 );
fatal("\nMaybe you are not authorized:\n"+b+"\n\n\nI think you should leave now.\n");
}
)
;
}
else
{
console.log( "I have no idea what to do with \""+answer+"\"." );
process.exit( 1 );
}
fatal( "I have no idea what to do with \""+answer+"\"." );
rl.close;
});
}
......@@ -226,12 +228,9 @@ function displayBalances( well )
var n = well.length;
var i;
if ( well == undefined )
{
console.log( "Bank is not defined." );
process.exit( 1 );
}
fatal( "Bank is not defined." );
well.sort(wellSort);
console.log("");
console.log("The contract's account ("+contractaddr+") has "+Math.floor(contractbalance/1000000)+" Mwei.\n");
var longestbefore = 1;
var longestafter = 9;
for ( i=0; i<n; i++ )
......@@ -266,7 +265,7 @@ function displayBalances( well )
console.log( i+": "+well[i][0]+" fills to "+numstr+" Mwei (has "+has+")." );
}
}
console.log("");
console.log("\n[ Q=quit x=distribute ]");
rl.question("Which account to edit (enter index number of full account number)?: ",
(answer) => {
if ( answer != undefined )
......
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