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

Merge branch 'master' of github.com:rlegene/bfa

parents d55fe06a c4b0e9fd
No related branches found
No related tags found
No related merge requests found
......@@ -33,7 +33,7 @@ var pubcontract = mycontract.at(address)
console.log( pubcontract.address )
EOT
echo '*** Creating contract. This will take at least 16 seconds.'
outfile=$( bfamktemp )
outfile=$( mktemp )
cleanup "$outfile"
geth_exec_js $js > $outfile
if [ ` wc -l < $outfile ` = 2 -a `tail -1 < $outfile` = "true" ]
......
......@@ -4,7 +4,7 @@
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
res=$( geth_execjs "${BFAHOME}/bin/maymine.js" )
res=$( geth_exec_js "${BFAHOME}/src/js.maymine" )
if [ "$res" = "true" ]
then
......
#!/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_js ${BFAHOME}/src/js.rewind
......@@ -35,7 +35,7 @@ function getminer
{
if [ -e "${BFANODEDIR}/miner" ]
then
echo -- "--miner"
echo "--mine"
fi
}
......@@ -79,6 +79,7 @@ function getsyncmode
--txpool.accountqueue 512 \
--txpool.globalqueue 8192 \
--extradata "${BFAEXTRADATA}" \
--gcmode archive \
--cache 512 \
--verbosity 3 &
set +x
......
#!/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
contract="TimeStampAuthority"
contract=${BFANETWORKDIR}/contracts/${contract}
contract=$( realpath "${contract}" )
test -r "${contract}"
basecontract=$( basename "${contract}" )
test -n "${basecontract}"
abi=$( cat ${BFANETWORKDIR}/contracts/${basecontract}/abi )
test -n "${abi}"
hashes=
while read -p :
do
sum=$( echo -n "$REPLY" | sha256sum | cut -c -64 )
echo $sum
hashes="$hashes,web3.toDecimal(\"0x$sum\")"
done
hashes="${hashes:1}"
echo $hashes
js=$( mktemp )
cleanup "$js"
cat > $js <<EOT
var mycontract = eth.contract(${abi})
var thecontract = mycontract.at("${basecontract}")
console.log( thecontract.put.sendTransaction( [${hashes}], {from: eth.accounts[0], gas: 1000000} ) )
EOT
out=$( mktemp )
cleanup "$out"
geth_exec_js "${js}" > ${out}
if [ ` wc -l < ${out} ` = 2 -a ` tail -1 < ${out} ` = "true" ]
then
trans=` head -1 < ${out} `
echo "Sent checksum(s) in transaction ${trans}."
else
(
cat ${js}
echo
echo ' ***'
echo
cat ${out}
) >&2
exit 1
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
contract="TimeStampAuthority"
contract=${BFANETWORKDIR}/contracts/${contract}
contract=$( realpath "${contract}" )
test -r "${contract}"
basecontract=$( basename "${contract}" )
test -n "${basecontract}"
abi=$( cat ${BFANETWORKDIR}/contracts/${basecontract}/abi )
test -n "${abi}"
hashes=
sum=$( echo -n "$1" | sha256sum | cut -c -64 )
echo $sum
hashes="web3.toDecimal(\"0x$sum\")"
echo $hashes
js=$( mktemp )
cleanup "$js"
cat > $js <<EOT
var mycontract = eth.contract(${abi})
var thecontract = mycontract.at("${basecontract}")
console.log( thecontract.get.call( [${hashes}], {from: eth.accounts[0], gas: 1000000} ) )
EOT
out=$( mktemp )
cleanup "$out"
geth_exec_js "${js}" > ${out}
if [ ` wc -l < ${out} ` = 2 -a ` tail -1 < ${out} ` = "true" ]
then
block=` head -1 < $out `
if [ "${block}" -gt "0" ]
then
echo "Checksum first seen in block ${block}"
else
echo "The checksum has not been stored in the smart contract yet."
exit 1
fi
else
(
cat ${js}
echo
echo ' ***'
echo
cat ${out}
) >&2
fi
0x0fa811ac6643a29ad9c17acbed34918a4875f63c
\ No newline at end of file
0x3935260bb04ee7e820fc03b7b271f1085f4365e3
\ No newline at end of file
......@@ -5,17 +5,22 @@ pragma solidity ^0.4.24;
contract TimeStampAuthority {
// This mapping is almost an "associative array"
mapping (bytes32 => uint) private hashes;
mapping (uint256 => uint) private hashstore;
// Stores the hash of the document in the mapping
function put( bytes32 hash ) public {
require( hashes[hash] == 0, "That checksum has already been stored." );
hashes[hash] = block.number;
// Stores hashes (256 bit uint) of a document in the mapping
function put( uint256[] hasharray ) public {
uint256 i = hasharray.length;
while (i>0) {
i--;
uint256 h = hasharray[i];
if (hashstore[h] == 0) {
hashstore[h] = block.number;
}
}
}
// Returns the block number in which the hash was first seen
function get( bytes32 hash ) public view returns (uint) {
require( hashes[hash] != 0, "That checksum has never been stored." );
return hashes[hash];
function get( uint256 hash ) public view returns (uint) {
return hashstore[hash];
}
}
// 20180612 Robert Martin-Legene <robert@nic.ar>
// It can be difficult to feed large binary "documents" into this
// routine, so it should be changed to accept just the checksum,
// so we'll call this v0.1
pragma solidity ^0.4.24;
contract TimestampDocument {
// This mapping is almost an "associative array"
mapping (bytes32 => uint) private hashes;
// Public functions
//
// Calculate and store the hash for a document
//
function storeDocument( string document ) public {
bytes32 hash = sha256(abi.encodePacked(document));
storeHash( hash );
}
//
// Returns the block number a hash was first seen in.
// zero (0) means not found.
//
function checkDocument( string document ) public view returns (uint) {
return getBlock( sha256(abi.encodePacked(document)) );
}
// Private functions
//
// Stores the hash of the document in the mapping
// if we have not seen the hash before.
//
function storeHash( bytes32 hash ) private {
if ( hashes[hash] == 0 ) {
hashes[hash] = block.number;
}
}
//
// Returns the block number in which the hash was first seen,
// or zero (0) if never seen.
//
function getBlock( bytes32 hash ) private view returns (uint) {
return hashes[hash];
}
}
// vim:syntax:filetype=javascript:ai:sm
// vim:expandtab:backspace=indent,eol,start:softtabstop=4
var signer
signer = (clique.getSigners().indexOf(eth.accounts[0]) > -1)
if (signer) miner.start() else miner.stop()
console.log( signer )
if (signer)
miner.start()
else
miner.stop()
signer
// vim:syntax:filetype=javascript:ai:sm
// vim:expandtab:backspace=indent,eol,start:softtabstop=4
// How many blocks to step back.
var backstep = 6
// If we are syncing, there's no need to rewind (I think?)
if (!eth.syncing && eth.blockNumber > 10)
{
var max = 0
// Get the maximum difficulty of all valid connected peers
for (x in admin.peers)
{
var xd = admin.peers[x].protocols.eth.difficulty
if (admin.peers[x].protocols.eth!="handshake" && xd>max)
max=xd
}
if (eth.blockNumber.totalDifficulty+200<max) {
console.log(
"Max total difficulty is "
+ max
+ ", but mine is just "
+ eth.blockNumber.totalDifficulty
+ " (in block "
+ eth.blockNumber
+ "). Rolling "
+ backstep+" blocks back, to block "
+ web3.toHex(eth.blockNumber-backstep)
)
// Rollback a bit and see if we weren't stuck just because we were stuck in a side fork.
debug.setHead(web3.toHex(eth.blockNumber-backstep))
}
}
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