Skip to content

Commit 7095f6a

Browse files
committed
first commit
0 parents  commit 7095f6a

12 files changed

Lines changed: 194 additions & 0 deletions

File tree

.github/setup.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ln -s $PWD/bitcoin-28.0/bin/* /usr/local/bin/
2+
mkdir -p ~/.bitcoin
3+
4+
cat <<EOF > ~/.bitcoin/bitcoin.conf
5+
[regtest]
6+
regtest=1
7+
rpcuser=user
8+
rpcpassword=password
9+
rpcport=18332
10+
EOF
11+
12+
echo $(bitcoin-cli --version)

.github/workflows/main.yml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Run Setup Script
2+
3+
on:
4+
push:
5+
branches:
6+
- main # Trigger on pushes to the main branch
7+
8+
jobs:
9+
bitcoin-setup:
10+
runs-on: ubuntu-latest # Use the latest Ubuntu environment
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4 # Check out the repository code
15+
16+
- name: Cache Bitcoin Core
17+
id: cache-bitcoin
18+
uses: actions/cache@v3
19+
with:
20+
path: |
21+
bitcoin-28.0
22+
bitcoin-28.0-x86_64-linux-gnu.tar.gz
23+
key: bitcoin-core-28.0
24+
25+
- name: Setup Bitcoin Core
26+
run: |
27+
if [ "${{ steps.cache-bitcoin.outputs.cache-hit }}" != 'true' ]; then
28+
wget https://bitcoincore.org/bin/bitcoin-core-28.0/bitcoin-28.0-x86_64-linux-gnu.tar.gz
29+
tar -xzvf bitcoin-28.0-x86_64-linux-gnu.tar.gz
30+
fi
31+
sudo bash .github/setup.sh
32+
33+
- name: Start bitcoind in regtest mode
34+
run: |
35+
bitcoind -regtest -daemon
36+
echo "Waiting for bitcoind to be ready..."
37+
38+
# Wait for bitcoind to start (max 30s)
39+
for i in {1..30}; do
40+
if bitcoin-cli -regtest getblockchaininfo > /dev/null 2>&1; then
41+
echo "✅ bitcoind is ready!"
42+
break
43+
fi
44+
echo "Still waiting for bitcoind..."
45+
sleep 1
46+
done
47+
48+
- name: Verify Wallet Creation
49+
run: |
50+
chmod +x submission/01.sh
51+
WALLET=$(submission/01.sh)
52+
if [[ "$WALLET" == *"btrustwallet"* ]]; then
53+
echo "✅ Success: Wallet creation passed!"
54+
else
55+
echo "❌ Error: Wallet creation failed!"
56+
exit 1
57+
fi
58+
59+
- name: Verify Change Address Generation
60+
run: |
61+
chmod +x submission/02.sh
62+
CHANGE_ADDRESS=$(submission/02.sh)
63+
echo "CHANGE_ADDRESS=$CHANGE_ADDRESS"
64+
if [[ "$CHANGE_ADDRESS" =~ ^bcrt1[ac-hj-np-z02-9]{8,87}$ ]]; then
65+
echo "✅ Success: Change address generation passed!"
66+
else
67+
echo "❌ Error: Change address generation failed!"
68+
exit 1
69+
fi
70+
71+
- name: Verify Adding Funds to SegWit Address
72+
run: |
73+
chmod +x submission/03.sh
74+
ADD=$(submission/03.sh)
75+
echo "ADD=$ADD"
76+
BALANCE=$(bitcoin-cli -regtest getreceivedbyaddress "$ADD" 0)
77+
if (( $(echo "$BALANCE > 0" | bc -l) )); then
78+
echo "✅ Success: Adding funds to SegWit address passed!"
79+
else
80+
echo "❌ Error: Adding funds to SegWit address failed!"
81+
exit 1
82+
fi
83+
84+
- name: Verify Listing the current UTXOs in your wallet.
85+
run: |
86+
chmod +x submission/04.sh
87+
UTXOs=$(submission/04.sh)
88+
if [[ "$UTXOs" != "[]" && "$UTXOs" =~ "txid" ]]; then
89+
echo "✅ Success: Listing the current UTXOs in your wallet passed!"
90+
else
91+
echo "❌ Error: Listing the current UTXOs in your wallet failed!"
92+
exit 1
93+
fi
94+
95+
- name: Verify Transaction ID
96+
run: |
97+
chmod +x submission/05.sh
98+
TRANSACTION_ID=$(submission/05.sh)
99+
EXPECTED_OUTPUT=23c19f37d4e92e9a115aab86e4edc1b92a51add4e0ed0034bb166314dde50e16
100+
if [[ "$TRANSACTION_ID" == "$EXPECTED_OUTPUT" ]]; then
101+
echo "✅ Success: Transaction ID Check passed!"
102+
else
103+
echo "❌ Error: Transaction ID Check failed!"
104+
exit 1
105+
fi
106+
107+
- name: Verify Total Transaction Output
108+
run: |
109+
chmod +x submission/06.sh
110+
ACTUAL_OUTPUT=$(submission/06.sh)
111+
EXPECTED_OUTPUT=23679108
112+
if [[ "$ACTUAL_OUTPUT" == "$EXPECTED_OUTPUT" ]]; then
113+
echo "✅ Success: Total Transaction Output Check passed!"
114+
else
115+
echo "❌ Error: Total Transaction Output Check failed!"
116+
exit 1
117+
fi
118+
119+
- name: Verify Raw Transaction Hex
120+
run: |
121+
chmod +x submission/07.sh
122+
ACTUAL_OUTPUT=$(submission/07.sh)
123+
EXPECTED_OUTPUT=0200000002160ee5dd146316bb3400ede0d4ad512ab9c1ede486ab5a119a2ee9d4379fc1230000000000fdffffff160ee5dd146316bb3400ede0d4ad512ab9c1ede486ab5a119a2ee9d4379fc1230100000000fdffffff01002d31010000000017a91421ed90762e16eaaea188aae19142e5b25bf75d238700000000
124+
if [[ "$ACTUAL_OUTPUT" == "$EXPECTED_OUTPUT" ]]; then
125+
echo "✅ Success: Total Transaction Output Check passed!"
126+
else
127+
echo "❌ Error: Total Transaction Output Check failed!"
128+
exit 1
129+
fi
130+
131+
- name: Verify Raw Transaction Hex
132+
run: |
133+
chmod +x submission/08.sh
134+
ACTUAL_OUTPUT=$(submission/08.sh)
135+
EXPECTED_OUTPUT=0200000002160ee5dd146316bb3400ede0d4ad512ab9c1ede486ab5a119a2ee9d4379fc123000000000001000000160ee5dd146316bb3400ede0d4ad512ab9c1ede486ab5a119a2ee9d4379fc12301000000000100000001002d31010000000017a91421ed90762e16eaaea188aae19142e5b25bf75d238700000000
136+
if [[ "$ACTUAL_OUTPUT" == "$EXPECTED_OUTPUT" ]]; then
137+
echo "✅ Success: Total Transaction Output Check passed!"
138+
else
139+
echo "❌ Error: Total Transaction Output Check failed!"
140+
exit 1
141+
fi
142+

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Btrust Builders: LBCLI Week Two Exercises
2+
3+
## Instructions
4+
5+
Exercise should be done using Regtest network.
6+
7+
1. Fork this repository.
8+
2. Clone the fork to your local computer.
9+
3. Add your bitcoin cli commands to the script files in the submission folder. Example:
10+
```sh
11+
$ bitcoin-cli -regtest getblockcount
12+
```
13+
4. Commit and push your changes to your remote fork.
14+
5. Confirm your forked repository has a green check mark.
15+
16+
<img src="https://github.com/btrust-builders/lbcli-week-2-exercises/blob/main/success.png" width="200" />
17+
18+
6. Submit your solution to this form: [Google form](https://forms.gle/eDRGAJXpLqRxEExR6).
19+
20+
PS: You can commit and push as often as you like and GitHub Actions will re-evaluate your code every time.
21+
You will need to look through the auto-grader logs (in the "actions" tab) to see what exactly you got right or wrong.
22+

submission/01.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Create a wallet with the name "btrustwallet".

submission/02.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Create a new Bitcoin address, for receiving change.

submission/03.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Created a SegWit address.
2+
# Add funds to the address.
3+
# Return only the Address

submission/04.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# List the current UTXOs in your wallet.

submission/05.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# What is the txid of this transaction
2+
# raw_tx="01000000000101c8b0928edebbec5e698d5f86d0474595d9f6a5b2e4e3772cd9d1005f23bdef772500000000ffffffff0276b4fa0000000000160014f848fe5267491a8a5d32423de4b0a24d1065c6030e9c6e000000000016001434d14a23d2ba08d3e3edee9172f0c97f046266fb0247304402205fee57960883f6d69acf283192785f1147a3e11b97cf01a210cf7e9916500c040220483de1c51af5027440565caead6c1064bac92cb477b536e060f004c733c45128012102d12b6b907c5a1ef025d0924a29e354f6d7b1b11b5a7ddff94710d6f0042f3da800000000"

submission/06.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Calculate total output value of this transaction in satoshis
2+
# raw_tx="01000000000101c8b0928edebbec5e698d5f86d0474595d9f6a5b2e4e3772cd9d1005f23bdef772500000000ffffffff0276b4fa0000000000160014f848fe5267491a8a5d32423de4b0a24d1065c6030e9c6e000000000016001434d14a23d2ba08d3e3edee9172f0c97f046266fb0247304402205fee57960883f6d69acf283192785f1147a3e11b97cf01a210cf7e9916500c040220483de1c51af5027440565caead6c1064bac92cb477b536e060f004c733c45128012102d12b6b907c5a1ef025d0924a29e354f6d7b1b11b5a7ddff94710d6f0042f3da800000000"

submission/07.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Create a raw transaction with an amount of 20,000,000 satoshis to this address: 2MvLcssW49n9atmksjwg2ZCMsEMsoj3pzUP
2+
# Use the UTXOs from the transaction below
3+
# transaction="01000000000101c8b0928edebbec5e698d5f86d0474595d9f6a5b2e4e3772cd9d1005f23bdef772500000000ffffffff0276b4fa0000000000160014f848fe5267491a8a5d32423de4b0a24d1065c6030e9c6e000000000016001434d14a23d2ba08d3e3edee9172f0c97f046266fb0247304402205fee57960883f6d69acf283192785f1147a3e11b97cf01a210cf7e9916500c040220483de1c51af5027440565caead6c1064bac92cb477b536e060f004c733c45128012102d12b6b907c5a1ef025d0924a29e354f6d7b1b11b5a7ddff94710d6f0042f3da800000000"

0 commit comments

Comments
 (0)