Skip to content
Snippets Groups Projects
Commit 3d885f83 authored by Francisco Ruiz's avatar Francisco Ruiz
Browse files

v0.2

parent 8e447002
No related branches found
No related tags found
No related merge requests found
FROM ubuntu:xenial FROM ubuntu:xenial
MAINTAINER Francisco Ruiz BFA LABEL authors="Francisco Ruiz BFA,Matias Ruggieri UNSAM"
ENV DEBIAN_FRONTEND noninteractive ENV DEBIAN_FRONTEND noninteractive
ENV BFAHOME=/home/bfa ENV BFAHOME=/home/bfa
ENV PATH=${PATH}:${BFAHOME}/bin ENV PATH=${PATH}:${BFAHOME}/bin
WORKDIR /home/bfa WORKDIR /home/bfa
VOLUME ["/home/bfa"]
COPY src/deploy.sh /root/
RUN apt-get update && \ RUN apt-get update && \
apt-get -y -qq upgrade && \ apt-get -y -qq upgrade && \
apt-get install -y -qq git software-properties-common jq ncurses-bin curl apt-get install -y -qq git software-properties-common jq ncurses-bin curl && \
chmod +x /root/deploy.sh
COPY src/install.sh /root/ CMD bash -C '/root/deploy.sh';'bash'
CMD bash -C '/root/install.sh';'bash' EXPOSE 8545
EXPOSE 30303
#!/usr/bin/node
const Libbfa = require( process.env.BFAHOME + '/bin/libbfa.js');
const rl = require('readline').createInterface(
{ input: process.stdin, output: process.stdout }
);
var web3;
var Distillery;
var bfa;
var notation = [ 6 ];
function init()
{
notation.push( 10**notation[0] );
switch ( notation[0] ) {
case 6:
notation.push( "Mwei" );
break;
case 9:
notation.push( "Gwei" );
break;
default:
notation = [ 6, 10**6, "Mwei" ];
}
bfa = new Libbfa();
web3 = bfa.newweb3();
Distillery = bfa.contract( web3, 'Distillery' );
web3.eth.getBalance( Distillery.contractaddress ).then(
function receivedOwnBalance(val) {
Distillery.contractbalance = val;
getlist();
},
function err(x){ bfa.fatal("Can't do that: "+x);process.exit(1); }
);
}
function palletSort(a,b)
{
if ( b == undefined )
{
if ( a == undefined )
return 0;
else
return -1;
}
if ( a == undefined )
return 1;
var strA = a[0].toLowerCase();
var strB = b[0].toLowerCase();
if ( strA < strB )
return -1;
if ( strA > strB )
return 1;
return 0;
}
function requestBalances( count )
{
var pallet = new Array;
var proms = new Array;
var i;
// Fetch addresses from the list in the contract.
for ( i=0; i<count; i++ )
{
proms.push(
Distillery.methods.atPosition(i).call( {} )
.then(
function(res) { pallet.push(res); },
function(err) { bfa.fatal("Fetching position data failed: "+err) }
)
);
}
Promise.all( proms ).then(
function(x) {
// The Well has now been filled out
// so we will ask for the balances of the found accounts
var p2 = new Array();
for ( i=0; i<count; i++ )
{
var cb = setBal.bind(null,pallet,i);
p2.push( web3.eth.getBalance( pallet[i][0] ).then(cb) );
}
Promise.all( p2 ).then(
function allbalances(a) { displayBalances(pallet) },
function(err) { bfa.fatal("Getting balances failed: "+err) }
);
},
function(err) { bfa.fatal("Getting account list failed: "+err) }
);
}
function setBal( arr, idx, val )
{
arr[idx][2]=val;
}
function editAccount( entry, pallet )
{
if ( entry == undefined )
return;
var acct;
var value;
// it is an existing account address?
if ( bfa.isAddr(entry) )
{
var i = 0;
var n = pallet.length;
while ( i < n )
{
if (String(pallet[i][0]).toLowerCase() == String(entry).toLowerCase() )
entry = i;
i++;
}
}
// it is a new account address?
if ( bfa.isAddr(entry) )
{
acct = entry;
value = 0;
}
else
if ( bfa.isNumeric(entry) && entry < pallet.length )
{
acct = pallet[entry][0];
value = pallet[entry][1];
}
else
if ( entry == "x" )
{
// trigger distribution
Distillery.methods.distribute().send( {"from": bfa.account, "gas": 1000000 } )
.then(
function distOK(x) {
console.log(
"Distribute returned succesfully in block# "
+ x.blockNumber
+ " using "
+ x.gasUsed
+ " gas."
);
getlist();
},
function distFail(x) {
bfa.fatal(
"Distribute returned errors in block# "
+ x.blockNumber
+ " using "
+ x.gasUsed
+ " gas."
);
console.log(x);
process.exit( 1 );
}
);
return;
}
else
bfa.fatal("I don't know what to do with \""+entry+"\"." );
rl.question(
"Adjust the "
+ notation[2]
+ " fill value of "
+ acct
+ " (setting to 0 is the same as deleting)\n"
+ "Amount?: ",
(answer) => {
if ( bfa.isNumeric(answer) )
{
answer *= notation[1];
console.log("Sending update to the SC...");
Distillery.methods.setEtherAllowance(acct,answer)
.send( {"from": bfa.account } )
.then(
function(a){
console.log("Update accepted.")
getlist();
},
function(b){
bfa.fatal(
"\nMaybe you are not authorized:\n"
+b
+"\n\n\nI think you should leave now.\n"
);
}
)
}
else
bfa.fatal( "I have no idea what to do with \""+answer+"\"." );
rl.close;
}
);
}
function displayBalances( pallet )
{
var n = pallet.length;
var i;
pallet.sort(palletSort);
console.log(
"The contract's account ("
+ Distillery.contractaddress
+ ") has "
+ Math.floor(Distillery.contractbalance/notation[1]).toFixed(0)
+ " "
+ notation[2]
+ ".\n"
);
var longest = 1;
for ( i=0; i<n; i++ )
{
var len = (pallet[i][1]/notation[1]).toFixed(notation[0]).length;
if ( len > longest )
longest = len;
}
for ( i=0; i<n; i++ )
{
var entry = pallet[i];
if ( entry == undefined )
console.log( i+": <undef>" );
else
{
var numstr = (pallet[i][1]/notation[1]).toFixed(notation[0]);
while ( numstr.length < longest )
numstr = " "+numstr;
console.log(
i
+ ": "
+ pallet[i][0]
+ " fills to "
+ numstr
+ " "
+ notation[2]
+ " (has "
+ Number(pallet[i][2]/notation[1]).toFixed(notation[0])
+ ")."
);
}
}
console.log("\n[ Q=quit x=distribute ]");
rl.question("Which account to edit (enter index number of full account number)?: ",
(answer) => {
if ( answer != undefined )
{
if ( String(answer).toUpperCase() == 'Q' )
process.exit( 0 );
else
editAccount(answer, pallet);
}
rl.close;
}
)
}
function getlist()
{
Distillery.methods.numberOfBeneficiaries()
.call()
.then(
requestBalances,
function beneficiaryFail(x){bfa.fatal(x)}
);
}
init();
#!/bin/bash
# 20180626 Robert Martin-Legene <robert@nic.ar>
if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi
source ${BFAHOME}/bin/libbfa.sh || exit 1
geth_attach "$@"
#!/bin/bash
# Robert Martin-Legene <robert@nic.ar>
if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi
source ${BFAHOME}/bin/libbfa.sh || exit 1
bfaconfig node
exec tail -n 100 -F ${BFANODEDIR}/log
#!/bin/bash
if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi
source ${BFAHOME}/bin/libbfa.sh || exit 1
geth_exec "eth.getTransactionReceipt(\"$1\");" < /dev/null
#!/bin/bash
# 20180618 Robert Martin-Legene <robert@nic.ar>
if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi
source ${BFAHOME}/bin/libbfa.sh || exit 1
function create
{
workdir=$( mktemp -p . -d )
cleanup "$workdir"
json=$( solc --optimize --combined-json abi,bin $filename ); test $? = 0
prefix=$( echo "$json" | jq -M '.contracts | keys | .[0]' );
abi=$( echo "$json" | jq -rM ".contracts.${prefix}.abi" ); test $? = 0
bin=$( echo "$json" | jq -rM ".contracts.${prefix}.bin" ); test $? = 0
# Save abi for future use
echo $abi > ${workdir}/abi
# We could save the bin, but we don't actually use it later, plus
# it gets stored in the blockchain
#echo $bin > ${workdir}/bin
js=$( mktemp )
cleanup "$js"
cat > $js <<EOT
var mycontract = eth.contract($abi)
var transaction = mycontract.new( { from: eth.accounts[0], data: "0x${bin}", gas: 1000000 } )
var rcpt
while ( !rcpt )
{
admin.sleepBlocks( 1 )
rcpt = eth.getTransactionReceipt( transaction.transactionHash )
}
var address = rcpt.contractAddress
var pubcontract = mycontract.at(address)
console.log( pubcontract.address )
EOT
echo '*** Creating contract. This will take at least 16 seconds.'
outfile=$( mktemp )
cleanup "$outfile"
geth_exec_file $js > $outfile
if [ ` wc -l < $outfile ` = 2 -a `tail -1 < $outfile` = "true" ]
then
addr=` head -1 < $outfile `
mkdir -p ${BFANETWORKDIR}/contracts
mv ${workdir} ${BFANETWORKDIR}/contracts/${addr}
echo Your new contract can be found in ${BFANETWORKDIR}/contracts/${addr}
ln -snf ${addr} ${BFANETWORKDIR}/contracts/${contractname}
else
echo
echo ' *** INPUT ***'
echo
cat $js
echo
echo ' *** OUTPUT ***'
echo
cat $outfile
fi
}
filename="$1"
if [ -z "$filename" -o ! -r "$filename" ]
then
echo "Specify a filename of a contract you wish to compile."
false
fi
contractname=${filename%%.sol}
contractname=${contractname##*/}
contractname=${contractname##contract.}
contractname=${contractname%.*}
bfaconfig max
prereq jq solc geth
create
#!/bin/bash
trap 'exit 1' ERR
# Go $HOME
cd
# Log in home directory
exec < /dev/null > bfa-cron-output.log 2>&1
# Go to script bin, 'cause we expect to find $BFAHOME/bin/env there
cd `dirname $0`
source ./env
(
./start.sh &
# Yes, we wait 60 seconds after starting the server.
# If you don't want to wait, kill the sleep.. the || true
# will capture the ERR trap.
while sleep 60 || true
do
./monitor.sh
done &
)
export BFAHOME=${HOME}/bfa
export BFANETWORKDIR="${BFAHOME}/network5445"
export BFANETWORKID=5445
PATH=${PATH}:${BFAHOME}/bin
#!/bin/bash
# 20180619 Robert Martin-Legene <robert@nic.ar>
if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi
source ${BFAHOME}/bin/libbfa.sh || exit 1
bfaconfig max
prereq tput curl
cd "${BFANETWORKDIR}"
width=$( tput cols )
height=$( tput lines )
function showblock
{
local hexblock
if [ "$1" = "latest" ]
then
hexblock="latest"
else
hexblock=$( printf '0x%x' $(( $1 )) )
fi
local json=$( geth_rpc eth_getBlockByNumber \"${hexblock}\" true )
if [ "${_onscreen}" != "$( echo $json | jq .hash )" ]
then
hexblock=$( echo $json | jq -r .number )
printf '\e[H\e[JBlock %d (0x%x)\n' $(( $hexblock )) $(( $hexblock ))
echo $json |
jq -C . |
fold --width=$width |
head -$(( $height - 2 ))
_onscreen=$( echo $json | jq .hash )
printf '\e[mj=up k=down l=latest q=quit '
fi
}
function latest
{
local json=$( geth_rpc eth_blockNumber )
local num=$( echo "$json" | jq -r . )
# This arithmetic expansion in bash converts a hex number prefixed with 0x to a decimal number
echo $(( $num ))
}
function tm
{
if [ "$block" = "latest" ]
then
timeout="-t 1"
else
timeout=
fi
}
block=$1
maxblock=$( latest )
test -z "$block" &&
block=latest
showblock $block
lastblock=
tm
while :
do
read -r -s -n 1 ${timeout} || true
maxblock=$( latest )
case "${REPLY^^}" in
Q)
echo
exit 0
;;
K)
if [ "$block" = "latest" -a $maxblock -gt 0 ]
then
block=$(( $maxblock - 1 ))
else
if [ $block -gt 0 ]
then
block=$(( $block - 1 ))
fi
fi
;;
J)
if [ "$block" != "latest" ]
then
block=$(( $block + 1 ))
fi
;;
L)
block="latest"
;;
# *)
# continue
# ;;
esac
lastblock=$block
showblock $block
tm
done
#!/bin/bash
if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi
source ${BFAHOME}/bin/libbfa.sh || exit 1
function usage
{
fatal "Usage: $0 <addr> [...<addr>]"
}
prereq curl
test $# -ge 1 || usage
(
while [ -n "$1" ]
do
echo "'$1'+' '+web3.fromWei(eth.getBalance('$1'), 'Ether');"
shift
done
) | geth_attach
// 20180724 Robert Martin-Legene <robert@nic.ar>
module.exports = class Libbfa
{
constructor() {
this.fs = require('fs');
this.Web3 = require('web3');
this._account();
}
fatal( txt )
{
console.log( txt );
process.exit( 1 );
}
_home()
{
if ( this.home != undefined )
return;
if ( process.env.BFAHOME == undefined )
fatal( "$BFAHOME not set. Did you source bfa/bin/env ?" );
this.home = process.env.BFAHOME;
}
_getnetworkid()
{
if ( this.networkid != undefined )
return;
this._home();
if ( process.env.BFANETWORKID == undefined )
{
var netw = new Array();
this.fs.readdirSync( this.home ).forEach( function(file){
if ( file.startWith('network') )
netw.push( 0 + file.substring(7) );
});
if ( netw.length == 0 )
fatal( "Can't determine your network ID." );
netw.sort();
process.env.BFANETWORKID=
this.networkid = netw[0];
}
else
this.networkid = process.env.BFANETWORKID;
}
_networkdir()
{
if ( this.networkdir != undefined )
return;
this._getnetworkid();
if ( process.env.BFANETWORKDIR == undefined )
process.env.BFANETWORKDIR =
this.networkdir = process.env.BFAHOME + '/network' + process.env.BFANETWORKID;
else
this.networkdir = process.env.BFANETWORKDIR;
}
_nodedir()
{
if ( this.nodedir != undefined )
return;
this._networkdir();
if ( this.networkdir == undefined )
return;
if ( process.env.BFANODEDIR == undefined )
{
var dirs = new Array();
//var fs = this.fs;
var nwdir = this.networkdir;
this.fs.readdirSync( this.networkdir ).forEach(
function findnodedirs(f1) {
var name1 = [nwdir,f1].join('/');
var fs = require('fs');
if ( fs.statSync( name1 ).isDirectory() )
{
fs.readdirSync( name1 ).forEach(
function lookforkeystores(f2) {
var name2 = [nwdir,f1,f2].join('/');
if (f2 == "keystore" && fs.statSync( name2 ).isDirectory() )
{
dirs.push( name1 );
}
}
)
}
}
);
if ( dirs.length == 0 )
return;
dirs.sort();
process.env.BFANODEDIR =
this.nodedir = dirs[0];
}
else
this.nodedir = process.env.BFANODEDIR;
this.netport = Number.parseInt( this.fs.readFileSync( this.nodedir + '/netport' ) );
this.rpcport = Number.parseInt( this.fs.readFileSync( this.nodedir + '/rpcport' ) );
}
_account()
{
this._nodedir();
if ( this.acct != undefined )
return;
if ( process.env.BFANODEDIR == undefined )
return;
var files = new Array();
this.fs.readdirSync( process.env.BFANODEDIR + '/keystore' ).forEach( function(filename) {
if ( filename.includes('--') )
files.push( filename );
});
// found none?
if ( files.length == 0 )
return;
files.sort();
this.account = '0x' + files[0].replace( /^.*--/, '' );
}
contract(w3, name)
{
this._networkdir();
var contractdir = [ this.networkdir, 'contracts', name ].join('/');
var contractaddress = this.fs.realpathSync( contractdir ).replace(/^.*\//, '');
if ( contractaddress == undefined )
return;
var abi = JSON.parse(
this.fs.readFileSync( contractdir + '/abi' ).toString()
);
if ( abi == undefined )
return;
var c = new w3.eth.Contract( abi, contractaddress );
c.abi = abi;
c.contractaddress = contractaddress;
return c;
}
newweb3()
{
this._nodedir();
var provider = 'http://127.0.0.1:' + this.rpcport;
var w3 = new this.Web3( provider );
w3.eth.extend({
//property: 'bfaclique',
methods: [{
name: 'getSigners',
call: 'clique_getSigners',
params: 0
}]
});
return w3;
}
isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
isAddr(n) {
return n.length == 42 && n.substring(0,2) == "0x";
}
}
# This should only be sourced, not executed directly.
# 20180626 Robert Martin-Legene <robert@nic.ar>
trap "echo Argh! ; exit 1" ERR
set -e -o errtrace
function fatal()
{
echo "$@" >&2
exit 1
}
trap "fatal Argh!" ERR
test -n "$BASH_VERSION" ||
fatal "This file must be source(d) from bash."
test "$( caller 2>/dev/null | awk '{print $1}' )" != "0" ||
fatal "This file must be source(d), not executed."
function stderr
{
echo "$@" >&2
}
function cleanup
{
if [ $# -gt 0 ]
then
trap cleanup EXIT
cleanup_files="${cleanup_files} $@"
return
fi
rm -rf $cleanup_files
}
function geth_attach
{
bfaconfig node
# local cat=cat
# if echo $- | grep -q x
# then
# cat="tee /dev/tty |"
# fi
# $cat |
geth --cache 0 "$@" attach ipc:${BFANODEDIR}/geth.ipc
}
function geth_exec_file
{
test -r "$1"
if echo $- | grep -q x && [ -t 1 ]
then
sed "s/^/input: /" "$1"
fi
geth_attach --exec "loadScript(\"$1\")" </dev/null
}
function geth_exec
{
test -n "$1"
geth_attach --exec "$1" </dev/null
}
function geth_rpc
{
bfaconfig node
local cmd=$1
test -n "$cmd"
local params=
shift
if [ $# -gt 0 ]
then
params=',"params":['
while [ $# -gt 0 ]
do
params="${params}${1},"
shift
done
# Eat the last command and add a ]
params=${params/%,/]}
fi
local json=$(
curl \
-H 'Content-type: application/json' \
-X POST \
--data "{\"jsonrpc\":\"2.0\",\"method\":\"${cmd}\"${params},\"id\":1}" \
http://127.0.0.1:$rpcport \
2>/dev/null
)
test -n "$json"
if [ "$( echo "$json" | jq .error )" != "null" ]
then
echo "$json" | jq -r .error.message >&2
false
fi
echo "$json" | jq .result
}
function getnetworkid
{
test -n "${BFANETWORKID}" &&
return
local dir="${BFANETWORKDIR}"
for dir in $( ls -1d "${BFAHOME}"/* | sort --version-sort )
do
if [ -d "${dir}" ]
then
local base=$( basename "${dir}" )
base=$( echo "${base}" | grep -E '^network[0-9]+$' ) || true
if [ -n "${base:7}" ]
then
BFANETWORKID=${base:7}
return
fi
fi
done
}
function networkdir
{
test -n "${BFAHOME}" -a -d "${BFAHOME}" ||
fatal "\$BFAHOME in your environment must point to a directory."
# If no BFANETWORKDIR variable has been set, we will try to guess
# the network directory based on the directory we are in.
if [ -z "${BFANETWORKDIR}" ]
then
BFANETWORKDIR=$(
ls -1d "${BFAHOME}"/* |
grep -qE '/network[0-9]+$' |
sort --version-sort |
head -1
)
fi
test -n "${BFANETWORKDIR}" -a ! -d "${BFANETWORKDIR}" &&
fatal "\$BFANETWORKDIR (\"${BFANETWORKDIR}\") not found."
if [ -z "${BFANETWORKDIR}" -o ! -d "${BFANETWORKDIR}" ]
then
local num=0
while [ $num -lt 9876 ]
do
num=$(( $RANDOM * $RANDOM ))
done
stderr "I can not find your BFANETWORKDIR."
stderr "Consider running: mkdir ${BFAHOME}/network${num} or set BFANETWORKDIR in ${BFAHOME}/bin/env"
exit 1
fi
getnetworkid
gen_genesis
}
function nodedir
{
networkdir
# set defaults
if [ -z "$BFANODEDIR" ]
then
# If there is no nodedir found, use the first node we
# find in the networkdir
BFANODEDIR=$(
ls -1d "${BFANETWORKDIR}"/*/keystore 2>/dev/null |
sort --version-sort |
head -1
)
if [ -z "${BFANODEDIR}" ]
then
BFANODEDIR="${BFANETWORKDIR}/node1"
echo "No node directories found. Initialising a new node."
geth --datadir ${BFANODEDIR} init ${BFAHOME}/src/genesis.json
else
# Get rid of the "keystore" label
BFANODEDIR=$( dirname $BFANODEDIR )
fi
fi
test -n "${BFANODEDIR}" ||
fatal "Unable to guess \$BFANODEDIR . Consider setting it explicitly in ${BFAHOME}/bin/env"
test -d "${BFANODEDIR}" ||
fatal "$BFANODEDIR is not a directory."
test -d "${BFANODEDIR}/geth/chaindata" ||
fatal "Node is not initialised. Consider running: geth --datadir $BFANODEDIR init ${BFAHOME}/src/genesis.json"
# Support migrating from "former" setups
if [ -r "${BFANODEDIR}/port" -a ! -r "${BFANODEDIR}/netport" ]
then
mv "${BFANODEDIR}/port" "${BFANODEDIR}/netport"
fi
#
test -r "${BFANODEDIR}/netport" ||
echo $(( $RANDOM / 2 + 12345 )) > ${BFANODEDIR}/netport
netport=$( cat ${BFANODEDIR}/netport )
test $? = 0
test -r "${BFANODEDIR}/rpcport" ||
echo $(( $RANDOM / 2 + 12345 )) > ${BFANODEDIR}/rpcport
rpcport=$( cat ${BFANODEDIR}/rpcport )
}
function extradata
{
account
# something uniqueish
## find default interface
local def_if=$( ( ip -4 route show ; ip -6 route show ) | expand | sed -ne '/^default /{s/ */ /g;s/^.* dev //;s/ .*//;p;q}' )
local mymac=$( ip link show ${def_if} | sed -ne '/link\|ether/{s/^.*link.ether //;s/ .*//;s/://g;p;q}' )
#
echo -n "${account:0:19}.${mymac:0:12}"
}
function account
{
nodedir
if [ -z "$account" ]
then
test -d "${BFANODEDIR}/keystore"
account=$(
ls -1dl "${BFANODEDIR}"/keystore/*--* 2>/dev/null |
head -1 |
sed 's/.*--//'
)
fi
if [ -z "$account" ]
then
echo "No accounts found. Creating a new one (they are free)."
geth --datadir ${BFANODEDIR} --password /dev/null account new
if [ -n "$loop_protection" ]
then
fatal "Loop detected."
fi
loop_protection=1
account
fi
unset loop_protection
}
function bfaconfig
{
case "$1" in
network)
networkdir
;;
node)
nodedir
;;
account|max)
account
;;
*)
fatal "Unknown bfaconfig request"
;;
esac
}
function prereq
{
err=0
while [ -n "$1" ]
do
if ! which $1 > /dev/null
then
echo "Need $1"
err=1
fi
shift
done
test $err -eq 0
}
function gen_genesis
{
local genesis="${BFAHOME}/src/genesis.json"
test -e "${genesis}" &&
return
bfaconfig account
local zero4="0000"
local zero8="${zero4}${zero4}"
local zero16="${zero8}${zero8}"
local zero20="${zero16}${zero4}"
local zero32="${zero16}${zero16}"
local zero40="${zero20}${zero20}"
local zero60="${zero40}${zero20}"
local zero64="${zero32}${zero32}"
local zero128="${zero64}${zero64}"
local zero130="${zero128}00"
local nodes=$account
local timestamp=$( printf '0x%08x' $( date +%s ) )
local vanity_Blockchain="426c6f636b636861696e"
local vanity_Federal="4665646572616c"
local vanity_Argentina="417267656e74696e61"
local vanity_NIC="4e4943"
local vanity="${vanity_Blockchain}20${vanity_Federal}20${vanity_Argentina}20${vanity_NIC}"
## Make sure vanity is exactly 64 characters
vanity="${vanity}${zero64}"
vanity="${vanity:0:64}"
echo -n "$vanity" | grep -Evq '[^0-9a-fA-F]'
cat <<-EOCONF > ${genesis}
{
"config": {
"chainId": ${BFANETWORKID},
"homesteadBlock": 0, "eip150Block": 0, "eip155Block": 0, "eip158Block": 0, "byzantiumBlock": 4,
"eip150Hash": "0x${zero64}",
"clique": { "period": 15, "epoch": 30000 }
},
"nonce": "0x0000000000000000",
"timestamp": "${timestamp}",
"extraData": "0x${vanity}${account}${zero130}",
"gasUsed": "0x0", "gasLimit": "0xffeeddcc", "difficulty": "0x1",
"number": "0x0",
"mixHash": "0x${zero64}",
"coinbase": "0x${zero40}",
"parentHash": "0x${zero64}",
"alloc": { "${account}": { "balance": "0x200${zero60}" } }
}
EOCONF
}
function contract
{
bfaconfig network
local contract="${BFANETWORKDIR}/contracts/${1}"
local realdir=$( realpath "${contract}" )
test -r "${realdir}"
local address=$( basename "${realdir}" )
test -n "${address}"
abi=$( cat ${contract}/abi )
test -n "${abi}"
echo "eth.contract(${abi}).at(\"${address}\")"
}
function contractSendTx
{
local name=$1
local func=$2
shift 2
echo "var contract = $( contract "${name}" );"
local args=
for x in $*
do
args="${args}, ${x}"
done
args="${args:1},"
if [ "$args" = "," ]
then
args=
fi
echo "contract.${func}.sendTransaction(${args} {from: eth.accounts[0], gas: 1000000} )"
}
#!/bin/bash
trap "echo Argh; exit 1" ERR
true ${MAXSIZE:=$((10*1024*1024))}
log=$1
test -n "$log" ||
log=log
exec >> "$log"
while read
do
echo "$REPLY"
size=$( stat -c '%s' "${log}" )
if [ $size -ge $MAXSIZE ]
then
for gen in 8 7 6 5 4 3 2 1
do
test -e "${log}.${gen}" &&
mv -f "${log}.${gen}" "${log}.$(( ${gen} + 1 ))"
done
mv -f "${log}" "${log}.1"
exec >> "$log"
fi
done
#!/bin/bash
# Robert Martin-Legene <robert@nic.ar>
if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi
source ${BFAHOME}/bin/libbfa.sh || exit 1
bfaconfig node
res=$( geth_exec_file "${BFAHOME}/src/maymine.js" )
if [ "$res" = "true" ]
then
touch ${BFANODEDIR}/miner
else
rm -f ${BFANODEDIR}/miner
fi
#!/bin/bash
if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi
source ${BFAHOME}/bin/libbfa.sh || exit 1
function json_query
{
cmd=$1
params=$2
if [ -n "$params" ]
then
params=",\"parameters\":[$2]"
fi
json=$(
curl -s -H 'Content-type: application/json' -X POST --data "{\"jsonrpc\":\"2.0\",\"method\":\"${cmd}\"${params},\"id\":1}" http://127.0.0.1:$rpcport
)
}
function json_err
{
echo "$json" | jq -r '.result'
}
function json_arraylength
{
jq -r length
}
function json_result
{
echo "$json" | jq -r '.result'
}
bfaconfig node
json_query admin_peers
numpeers=$( json_result | json_arraylength )
statusfile=$( mktemp )
cleanup "${statusfile}"
chmod 644 "${statusfile}"
echo -n "time: " > ${statusfile}
date >> ${statusfile}
echo "total-peer-count: ${numpeers}" >> ${statusfile}
peercount=0
for idx in $( seq 0 $(( $numpeers - 1 )) )
do
eth=$( echo "$json" | jq -r .result[$idx].protocols.eth )
if [ "$eth" = "handshake" ]
then
continue
fi
#echo -n "$idx: "; echo "$eth" | jq -c
remoteid=$(
echo "$json" |
jq -r .result[$idx].id
)
remoteaddress=$(
echo "$json" |
jq -r .result[$idx].network.remoteAddress
)
remoteip=$(
echo "$remoteaddress" |
sed 's/:[0-9][0-9]*$//'
)
# IPv6 has the address surrounded by [ and ] - we strip that away
if [ "${remoteip:0:1}" = "[" -a "${remoteip:$((${#remoteip}-1))}" = "]" ]
then
remoteip="${remoteip:1:$((${#remoteip}-2))}"
fi
remoteport=$(
echo "$remoteaddress" |
sed 's/^.*://'
)
echo "peer: enode://${remoteid}@[${remoteip}]:${remoteport}" >> $statusfile
mkdir -p "${BFANETWORKDIR}/lastseen/${remoteid}"
if [ -r "${BFANETWORKDIR}/lastseen/${remoteid}/${remoteip}" ]
then
storedport=$( cat "${BFANETWORKDIR}/lastseen/${remoteid}/${remoteip}" )
test "${remoteport}" = "${storedport}" &&
unset remoteport
fi
if [ -n "${remoteport}" ]
then
echo "${remoteport}" > "${BFANETWORKDIR}/lastseen/${remoteid}/${remoteip}"
else
touch "${BFANETWORKDIR}/lastseen/${remoteid}/${remoteip}"
fi
peercount=$(( $peercount + 1 ))
done
echo "valid-peer-count: ${peercount}" >> $statusfile
mv -f $statusfile ${BFANETWORKDIR}/status
#!/bin/bash
if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi
source ${BFAHOME}/bin/libbfa.sh || exit 1
echo txpool.status.pending | geth_attach | grep -Ev '^> $' | tail -1
exit
function json_query
{
cmd=$1
params=$2
if [ -n "$params" ]
then
params=",\"parameters\":[$2]"
fi
json=$(
curl -s -H 'Content-type: application/json' -X POST --data "{\"jsonrpc\":\"2.0\",\"method\":\"${cmd}\"${params},\"id\":1}" http://127.0.0.1:$rpcport
)
}
bfaconfig node
json_query web3j_txpool
echo $json | jq
exit
#!/bin/bash
if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi
source ${BFAHOME}/bin/libbfa.sh || exit 1
geth_exec_file ${BFAHOME}/src/rewind.js
#!/bin/bash
# Robert Martin-Legene <robert@nic.ar>
# Proposes to promote a new sealer or to demote an existing sealer.
# Also sends this vote to the new Sealers contract, so we have a place
# a contract can look up which addresses are sealers.
if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi
source ${BFAHOME}/bin/libbfa.sh || exit 1
operation="false"
if [ $( basename $0 ) == "sealeradd.sh" ]
then
operation="true"
fi
victim="$1"
(
echo "clique.propose(\"0x${victim#0x}\", ${operation});"
contractSendTx Sealers admin_promote \"0x${victim#0x}\" ${operation}
) | geth_attach
sealeradd.sh
\ No newline at end of file
#!/bin/bash
if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi
source ${BFAHOME}/bin/libbfa.sh || exit 1
function usage
{
fatal "Usage: $0 <dest-addr> <amount-of-ether>"
}
test $# -eq 2 || usage
rcpt=$1
eth=$2
cat<<EOJS | geth_attach
eth.sendTransaction({from:eth.accounts[0], to: "${rcpt}", value: web3.toWei(${eth}, "ether")})
EOJS
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