Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nucleo
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blockchain
nucleo
Commits
a69e5910
Commit
a69e5910
authored
7 years ago
by
Robert Martin-Legene
Browse files
Options
Downloads
Patches
Plain Diff
Trying to make us a nifty lib
parent
cb3dd8a8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
create.contract
+23
-20
23 additions, 20 deletions
create.contract
libbfa.sh
+126
-0
126 additions, 0 deletions
libbfa.sh
with
149 additions
and
20 deletions
create.contract
+
23
−
20
View file @
a69e5910
#!/bin/bash
#!/bin/bash
cd
$(
dirname
$0
)
.
./libbfa.sh
function
prereq
function
prereq
{
{
err
=
0
err
=
0
...
@@ -15,25 +18,26 @@ function prereq
...
@@ -15,25 +18,26 @@ function prereq
test
$err
-eq
0
||
exit
1
test
$err
-eq
0
||
exit
1
}
}
function
cleanup
{
rmfiles
=
"
$rmfiles
$@
"
trap
"rm -rf
${
rmfiles
}
"
EXIT
}
function
create
function
create
{
{
workdir
=
`
mktemp
-p
.
-d
`
workdir
=
$(
bfamktemp
-p
.
-d
)
cleanup
"
${
workdir
}
"
json
=
$(
solc
--optimize
--combined-json
abi,bin
$filename
)
json
=
$(
solc
--optimize
--combined-json
abi,bin
$filename
)
test
$?
eq 0
prefix
=
$(
echo
"
$json
"
| jq
'.contracts|keys[0]'
)
prefix
=
$(
echo
"
$json
"
| jq
'.contracts|keys[0]'
)
test
$?
eq 0
abi
=
$(
echo
"
$json
"
| jq
".contracts.
${
prefix
}
.abi"
)
abi
=
$(
echo
"
$json
"
| jq
".contracts.
${
prefix
}
.abi"
)
test
$?
eq 0
bin
=
$(
echo
"
$json
"
| jq
".contracts.
${
prefix
}
.bin"
)
bin
=
$(
echo
"
$json
"
| jq
".contracts.
${
prefix
}
.bin"
)
test
$?
eq 0
# Remove all quote marks "
bin
=
"
${
bin
//\
"}"
bin
=
"
${
bin
//\
"}"
# Save abi for future use
echo
$abi
>
${
workdir
}
/abi
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
#echo $bin > ${workdir}/bin
cleanup g1.js
js=$( bfamktemp )
cat >
g1.
js <<EOT
cat >
$
js <<EOT
var mycontract = eth.contract(JSON.parse($abi))
var mycontract = eth.contract(JSON.parse($abi))
var transaction = mycontract.new( { from: eth.accounts[0], data: "0x${bin}", gas: 1000000 } )
var transaction = mycontract.new( { from: eth.accounts[0], data: "0x${bin}", gas: 1000000 } )
var rcpt
var rcpt
...
@@ -47,21 +51,20 @@ var pubcontract = mycontract.at(address);
...
@@ -47,21 +51,20 @@ var pubcontract = mycontract.at(address);
console.log( pubcontract.address );
console.log( pubcontract.address );
EOT
EOT
echo '
*** Creating contract. Will take 16-30 seconds
'
echo '
*** Creating contract. Will take 16-30 seconds
'
cleanup out1
outfile=$( geth_exec_js $js )
geth --datadir network5445/node1 --exec 'loadScript("
g1.js
")' attach ipc:network5445/node1/geth.ipc > out1
if [ ` wc -l < $outfile ` = 2 -a `tail -1 < $outfile` = "true" ]
if [
`
wc
-l
< out1
`
= 2 -a
`
tail
-1
< out1
`
= "
true
" ]
then
then
addr=
`
head
-1
< out
1
`
addr=` head -1 <
$
out
file
`
mkdir network
5445
/contracts
mkdir
${
network
}
/contracts
mv
${
workdir
}
network
5445
/contracts/
${
addr
}
mv ${workdir}
${
network
}
/contracts/${addr}
echo Your new contract can be found in contracts/
${
addr
}
echo Your new contract can be found in
${network}/
contracts/${addr}
ln -sf
${
addr
}
network
5445
/contracts/
${
contractname
}
ln -sf ${addr}
${
network
}
/contracts/${contractname}
else
else
cat
g1.
js
cat
$
js
echo
echo
echo '
***
'
echo '
***
'
echo
echo
cat out
1
cat
$
out
file
fi
fi
}
}
...
...
This diff is collapsed.
Click to expand it.
libbfa.sh
0 → 100644
+
126
−
0
View file @
a69e5910
# Probably, this should only be sourced, not executed directly.
# 20180626 Robert Martin-Legene <robert@nic.ar>
fatal
()
{
echo
"
$@
"
>
&2
exit
1
}
trap
"echo Argh! ; exit 1"
ERR
test
"
$(
basename
$SHELL
2>/dev/null
)
"
=
"bash"
||
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
cleanup
{
if
[
$#
-gt
0
]
then
trap
cleanup EXIT
cleanup_files
=
"
${
cleanup_files
}
$@
"
return
fi
rm
-rf
$cleanup_files
}
# calls mktemp and then cleanup - makes other scripts more compact
function
bfamktemp
{
local
file
=
$(
mktemp
"
$@
"
)
cleanup
$file
echo
$file
}
function
geth_attach
{
geth
"
$@
"
attach ipc:node1/geth.ipc
}
function
geth_exec_js
{
test
-r
"
$1
"
local
out
=
$(
bfamktemp
)
geth_attach
--exec
"loadScript(
\"
$1
\"
)"
>
$out
echo
$out
}
function
config_environment
{
creating
=
0
if
[
-z
"
${
networkdir
}
"
]
then
local
basedir
=
$(
basename
$PWD
)
if
[
-n
"
${
networkdir
}
"
-a
!
-d
"
${
networkdir
}
"
]
then
# Networkdir is set and we can't find it. Let's see if
# we happen to already be in that directory.
if
[
"
${
basedir
}
"
-ne
"
${
networkdir
}
"
]
then
fatal
"Your
\$
networkdir environment variable conflicts with"
\
"the name of the directory you are currently in, and I can"
\
"not find the networkdir you specified (if any)."
fi
elif
$(
echo
"
${
basedir
}
"
|
grep
-qE
'^network[0-9]+$'
)
then
networkdir
=
"
$basedir
"
fi
local
n
for
n
in
$(
ls
-ld
network
*
2>/dev/null |
grep
-qE
'^network[0-9]+$'
)
do
if
[
-n
"
${
networkdir
}
"
]
then
fatal
"If you have more than one work listed in your"
\
"current directory, you must specify which one to"
\
"use, using the
\"
networkdir
\"
environment variable."
fi
networkdir
=
${
n
}
done
if
[
-z
"
${
networkdir
}
"
]
then
echo
"I can't find your networkdir."
REPLY
=
while
[
"
$REPLY
"
!=
"y"
-a
"
$REPLY
"
!=
"n"
]
do
read
-n
1
-p
"Would you like me to create a random one for you? [yN]: "
if
[
-z
"
$REPLY
"
]
then
REPLY
=
n
else
if
[
"
${
REPLY
,,
}
"
=
"y"
]
then
creating
=
1
fi
fi
done
if
[
$creating
=
1
]
then
local
num
=
0
while
[
$num
-lt
123456
]
do
num
=
$((
$RANDOM
*
$RANDOM
))
done
networkdir
=
"network
${
num
}
"
echo
"You had no network defined, so I am creating network
${
network
}
for you in
${
networkdir
}
/ ."
mkdir
"
${
networkdir
}
"
fi
fi
fi
# set defaults
true
${
nodedir
:
=node1
}
test
-n
"
${
nodedir
}
"
if
[
!
-d
"
${
nodedir
}
"
-a
$creating
=
1
]
then
mkdir
${
networkdir
}
/
${
nodedir
}
else
test
-d
"
${
nodedir
}
"
fi
if
[
-z
"
$account
"
]
then
test
-d
"
${
nodedir
}
/keystore"
account
=
$(
ls
-1dl
"
${
nodedir
}
"
/keystore/
*
|
head
-1
|
sed
's/.*--//'
)
fi
test
-n
"
$account
"
}
config_environment
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment