-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·44 lines (30 loc) · 941 Bytes
/
run.sh
File metadata and controls
executable file
·44 lines (30 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
# clean folder and define genesis block
rm block_*.txt
HEIGHT=0
DIFFICULTY=0
while true; do
# start building blocks
# output to terminal current block height
echo "Current block height: $HEIGHT"
echo "Current difficulty: $DIFFICULTY"
# define block filename
FILENAME="block_"$HEIGHT".txt"
VARIABLENAME="test$HEIGHT"
# search for POW and measure time
# hashcash --help for list of options
START_TIME=$SECONDS
OUTPUT=$(hashcash -P -b $DIFFICULTY -m -r $VARIABLENAME)
ELAPSED_TIME=$(($SECONDS - $START_TIME))
# announce new block
echo "BLOCK FOUND!!!"
echo "Elapsed time:" $ELAPSED_TIME "SECONDS"
# write block to file
HEADER1=$(echo $OUTPUT)
HEADER2=$(echo $OUTPUT | shasum)
echo $HEADER1 >> $FILENAME
echo $HEADER2 >> $FILENAME
# define next block height
let HEIGHT=HEIGHT+1
let DIFFICULTY=DIFFICULTY+1
done