Skip to content

Commit 4424f36

Browse files
committed
Add bitcoin cli commands
1 parent 606a3a5 commit 4424f36

File tree

1 file changed

+82
-13
lines changed

1 file changed

+82
-13
lines changed

submission/test.sh

Lines changed: 82 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,68 @@ echo "----------------------------------------"
2222
echo "Create a wallet named 'btrustwallet' to track your Bitcoin exploration"
2323
# STUDENT TASK: Use bitcoin-cli to create a wallet named "btrustwallet"
2424
# WRITE YOUR SOLUTION BELOW:
25+
bitcoin-cli -regtest createwallet "btrustwallet"
26+
2527

2628

2729
# Create a second wallet that will hold the treasure
2830
echo "Now, create another wallet called 'treasurewallet' to fund your adventure"
2931
# STUDENT TASK: Create another wallet called "treasurewallet"
3032
# WRITE YOUR SOLUTION BELOW:
33+
bitcoin-cli -regtest createwallet "treasurewallet"
3134

3235

3336
# Generate an address for mining in the treasure wallet
3437
# STUDENT TASK: Generate a new address in the treasurewallet
3538
# WRITE YOUR SOLUTION BELOW:
36-
TREASURE_ADDR=
37-
check_cmd "Address generation"
39+
TREASURE_ADDR=$(bitcoin-cli -regtest -rpcwallet="treasurewallet" getnewaddress)
40+
#check_cmd "Address generation"
41+
check_cmd() {
42+
if [ $? -ne 0 ]; then
43+
echo "Error: $1 failed."
44+
exit 1
45+
else
46+
echo "$1 succeeded."
47+
fi
48+
}
49+
3850
echo "Mining to address: $TREASURE_ADDR"
3951

4052
# Mine some blocks to get initial coins
53+
mine_blocks() {
54+
local num_blocks=$1
55+
local address=$2
56+
57+
for ((i=0; i<num_blocks; i++)); do
58+
# Generate a block by mining to the specified address
59+
bitcoin-cli -regtest -rpcwallet="treasurewallet" generatetoaddress 1 "$address"
60+
done
61+
}
62+
63+
# Now you can call the function to mine 101 blocks
4164
mine_blocks 101 $TREASURE_ADDR
4265

66+
4367
# CHALLENGE PART 2: Check your starting balance
4468
echo ""
4569
echo "CHALLENGE 2: Check your starting resources"
4670
echo "-----------------------------------------"
4771
echo "Check your wallet balance to see what resources you have to start"
4872
# STUDENT TASK: Get the balance of btrustwallet
4973
# WRITE YOUR SOLUTION BELOW:
50-
BALANCE=
51-
check_cmd "Balance check"
52-
echo "Your starting balance: $BALANCE BTC"
74+
#BALANCE=
75+
#check_cmd "Balance check"
76+
#echo "Your starting balance: $BALANCE BTC"
77+
# Get the balance of btrustwallet
78+
BALANCE=$(bitcoin-cli -regtest -rpcwallet="btrustwallet" getbalance)
79+
# Check if the balance check was successful
80+
if [ $? -ne 0 ]; then
81+
echo "Error: Balance check failed."
82+
exit 1
83+
else
84+
echo "Your starting balance: $BALANCE BTC"
85+
fi
86+
5387

5488
# CHALLENGE PART 3: Generate different address types to collect treasures
5589
echo ""
@@ -59,18 +93,53 @@ echo "The treasure hunt requires 4 different types of addresses to collect funds
5993
echo "Generate one of each address type (legacy, p2sh-segwit, bech32, bech32m)"
6094
# STUDENT TASK: Generate addresses of each type
6195
# WRITE YOUR SOLUTION BELOW:
62-
LEGACY_ADDR=
63-
check_cmd "Legacy address generation"
96+
#LEGACY_ADDR=
97+
#check_cmd "Legacy address generation"
98+
99+
#P2SH_ADDR=
100+
#check_cmd "P2SH address generation"
64101

65-
P2SH_ADDR=
66-
check_cmd "P2SH address generation"
102+
#SEGWIT_ADDR=
103+
#check_cmd "SegWit address generation"
67104

68-
SEGWIT_ADDR=
69-
check_cmd "SegWit address generation"
105+
#TAPROOT_ADDR=
106+
#check_cmd "Taproot address generation"
70107

71-
TAPROOT_ADDR=
72-
check_cmd "Taproot address generation"
108+
#echo "Your exploration addresses:"
109+
#echo "- Legacy treasure map: $LEGACY_ADDR"
110+
#echo "- P2SH ancient vault: $P2SH_ADDR"
111+
#echo "- SegWit digital safe: $SEGWIT_ADDR"
112+
#echo "- Taproot quantum vault: $TAPROOT_ADDR"
113+
114+
# Generate a Legacy Address
115+
LEGACY_ADDR=$(bitcoin-cli -regtest -rpcwallet="btrustwallet" getnewaddress "" "legacy")
116+
if [ $? -ne 0 ]; then
117+
echo "Error: Legacy address generation failed."
118+
exit 1
119+
fi
120+
121+
# Generate a P2SH Address
122+
P2SH_ADDR=$(bitcoin-cli -regtest -rpcwallet="btrustwallet" getnewaddress "" "p2sh-segwit")
123+
if [ $? -ne 0 ]; then
124+
echo "Error: P2SH address generation failed."
125+
exit 1
126+
fi
127+
128+
# Generate a SegWit Address (Bech32)
129+
SEGWIT_ADDR=$(bitcoin-cli -regtest -rpcwallet="btrustwallet" getnewaddress "" "bech32")
130+
if [ $? -ne 0 ]; then
131+
echo "Error: SegWit address generation failed."
132+
exit 1
133+
fi
134+
135+
# Generate a Taproot Address (Bech32m)
136+
TAPROOT_ADDR=$(bitcoin-cli -regtest -rpcwallet="btrustwallet" getnewaddress "" "bech32m")
137+
if [ $? -ne 0 ]; then
138+
echo "Error: Taproot address generation failed."
139+
exit 1
140+
fi
73141

142+
# Output the generated addresses
74143
echo "Your exploration addresses:"
75144
echo "- Legacy treasure map: $LEGACY_ADDR"
76145
echo "- P2SH ancient vault: $P2SH_ADDR"

0 commit comments

Comments
 (0)