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

Renaming create.contract

parent 4ed50c99
Branches sealers
No related tags found
No related merge requests found
......@@ -47,14 +47,14 @@ request: **geth**
Connects you to your running local geth.
## create.contract
## compile.and.deploy.contract
requires: **geth**, **solc**, **jq**
Compiles and deploys a contract to the blockchain. A local "node1" must already be running and synchronized.
Argument 1 is the filename of the contract to compile.
Example: `create.contract src/TimestampAuthority.sol`
Example: `compile.and.deploy.contract src/TimestampAuthority.sol`
## tsa-insert.sh
requires: **geth**
......
#!/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
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