@@ -3,100 +3,95 @@ set -Eeuo pipefail
3
3
4
4
# Move bitcoin.conf to /bitcoind
5
5
if [ -f " /data/bitcoin.conf" ]; then
6
- mv /data/bitcoin.conf /bitcoind/bitcoin.conf
7
- ln -s /bitcoind /root/.
8
- # If not is assumed that the bitcoin.conf is already in /bitcoind
6
+ mv /data/bitcoin.conf /bitcoind/bitcoin.conf
7
+ ln -s /bitcoind /root/.
8
+ # If not is assumed that the bitcoin.conf is already in /bitcoind
9
9
fi
10
10
11
11
# Check if there is already the 'signetchallenge' option in 'bitcoin.conf' different from the default
12
12
# 'signetchallenge=00000000' added to not download any chain.
13
13
echo " ===================================="
14
14
echo " Signetchallenge creation process"
15
- while read -r line
16
- do
17
- # Check line by line
18
- if [[ " $line " == * " signetchallenge=00000000" * ]]; then
19
- SIGNETCHALLENGE=false
20
- elif [[ " $line " == * " signetchallenge=" * ]]; then
21
- echo " 'signetchallenge' param already present in bitcoin.conf"
22
- echo " $line "
23
- SIGNETCHALLENGE=true
24
- fi
25
- done < " /bitcoind/bitcoin.conf"
15
+ while read -r line; do
16
+ # Check line by line
17
+ if [[ " $line " == * " signetchallenge=00000000" * ]]; then
18
+ SIGNETCHALLENGE=false
19
+ elif [[ " $line " == * " signetchallenge=" * ]]; then
20
+ echo " 'signetchallenge' param already present in bitcoin.conf"
21
+ echo " $line "
22
+ SIGNETCHALLENGE=true
23
+ fi
24
+ done < " /bitcoind/bitcoin.conf"
26
25
27
26
if [ $SIGNETCHALLENGE = false ]; then
28
- # Create a new signetchallenge
29
- # Start bitcoind
30
- echo " Starting bitcoind..."
31
- bitcoind -datadir=/bitcoind -daemon 2>&1 > /dev/null
32
-
33
- # Wait for bitcoind startup
34
- until bitcoin-cli -datadir=/bitcoind -rpcwait getblockchaininfo > /dev/null 2>&1
35
- do
36
- echo -n " ."
37
- sleep 1
38
- done
39
- echo " bitcoind started."
40
- echo " ===================================="
41
-
42
- # Create a new wallet
43
- # Uncomment the following line if a custom wallet name is require and comment the `WALLET="wallet"` line.
44
- # read -p "Enter the name of the wallet: " WALLET
45
- WALLET=" wallet"
46
- bitcoin-cli -datadir=/bitcoind -named createwallet wallet_name=" $WALLET " descriptors=true 2>&1 > /dev/null
47
-
48
- # Get the signet script from the 86 descriptor
49
- ADDR=$( bitcoin-cli -datadir=/bitcoind getnewaddress)
50
- SCRIPT=$( bitcoin-cli -datadir=/bitcoind getaddressinfo $ADDR | jq -r " .scriptPubKey" )
51
- sed -i " s/signetchallenge=00000000/signetchallenge=$SCRIPT /" /bitcoind/bitcoin.conf
52
-
53
-
54
- # Dumping descriptor wallet privatekey
55
- WALLETFILE=" ${WALLET} _privkey.txt"
56
- bitcoin-cli -datadir=/bitcoind listdescriptors true | jq -r " .descriptors | .[].desc" >> " /bitcoind/${WALLETFILE} "
57
-
58
- # Wait for bitcoind shutdown
59
- echo " Waiting for bitcoind to stop."
60
- bitcoin-cli -datadir=/bitcoind stop &
61
- wait
62
- echo " bitcoind stopped."
63
- # Removing any downloaded timechain
64
- rm -rf /bitcoind/signet/ &
65
- wait
27
+ # Create a new signetchallenge
28
+ # Start bitcoind
29
+ echo " Starting bitcoind..."
30
+ bitcoind -datadir=/bitcoind -daemon 2>&1 > /dev/null
31
+
32
+ # Wait for bitcoind startup
33
+ until bitcoin-cli -datadir=/bitcoind -rpcwait getblockchaininfo > /dev/null 2>&1 ; do
34
+ echo -n " ."
35
+ sleep 1
36
+ done
37
+ echo " bitcoind started."
38
+ echo " ===================================="
39
+
40
+ # Create a new wallet
41
+ # Uncomment the following line if a custom wallet name is require and comment the `WALLET="wallet"` line.
42
+ # read -p "Enter the name of the wallet: " WALLET
43
+ WALLET=" wallet"
44
+ bitcoin-cli -datadir=/bitcoind -named createwallet wallet_name=" $WALLET " descriptors=true 2>&1 > /dev/null
45
+
46
+ # Get the signet script from the 86 descriptor
47
+ ADDR=$( bitcoin-cli -datadir=/bitcoind getnewaddress)
48
+ SCRIPT=$( bitcoin-cli -datadir=/bitcoind getaddressinfo $ADDR | jq -r " .scriptPubKey" )
49
+ sed -i " s/signetchallenge=00000000/signetchallenge=$SCRIPT /" /bitcoind/bitcoin.conf
50
+
51
+ # Dumping descriptor wallet privatekey
52
+ WALLETFILE=" ${WALLET} _privkey.txt"
53
+ bitcoin-cli -datadir=/bitcoind listdescriptors true | jq -r " .descriptors | .[].desc" >> " /bitcoind/${WALLETFILE} "
54
+
55
+ # Wait for bitcoind shutdown
56
+ echo " Waiting for bitcoind to stop."
57
+ bitcoin-cli -datadir=/bitcoind stop &
58
+ wait
59
+ echo " bitcoind stopped."
60
+ # Removing any downloaded timechain
61
+ rm -rf /bitcoind/signet/ &
62
+ wait
66
63
fi
67
64
68
65
# Start bitcoind
69
66
echo " Restarting bitcoind..."
70
67
bitcoind -datadir=/bitcoind -daemon
71
68
72
69
# Wait for bitcoind startup
73
- until bitcoin-cli -datadir=/bitcoind -rpcwait getblockchaininfo > /dev/null 2>&1
74
- do
75
- echo -n " ."
76
- sleep 1
70
+ until bitcoin-cli -datadir=/bitcoind -rpcwait getblockchaininfo > /dev/null 2>&1 ; do
71
+ echo -n " ."
72
+ sleep 1
77
73
done
78
74
echo
79
75
echo " bitcoind started"
80
76
81
77
if [ $SIGNETCHALLENGE = false ]; then
82
- # If there is any wallet, create a descriptor wallet
83
- bitcoin-cli -datadir=/bitcoind -named createwallet wallet_name=" $WALLET " blank=true descriptors=true 2>&1 > /dev/null
84
- echo " ================================================"
85
- echo " Importing descriptors for the private key:"
86
- line_count=0
87
- while read line; do
88
- # Increment the line counter
89
- line_count=$(( line_count+ 1 ))
90
-
91
- # Check if the line count is even or odd
92
- if [ $(( line_count % 2 )) -eq 0 ]; then
93
- is_even=" true"
94
- else
95
- is_even=" false"
96
- fi
97
-
98
-
99
- DESCRIPTORS="
78
+ # If there is any wallet, create a descriptor wallet
79
+ bitcoin-cli -datadir=/bitcoind -named createwallet wallet_name=" $WALLET " blank=true descriptors=true 2>&1 > /dev/null
80
+ echo " ================================================"
81
+ echo " Importing descriptors for the private key:"
82
+ line_count=0
83
+ while read line; do
84
+ # Increment the line counter
85
+ line_count=$(( line_count + 1 ))
86
+
87
+ # Check if the line count is even or odd
88
+ if [ $(( line_count % 2 )) -eq 0 ]; then
89
+ is_even=" true"
90
+ else
91
+ is_even=" false"
92
+ fi
93
+
94
+ DESCRIPTORS="
100
95
{
101
96
\" desc\" : \" ${line} \" ,
102
97
\" timestamp\" : 0,
@@ -107,37 +102,35 @@ if [ $SIGNETCHALLENGE = false ]; then
107
102
999
108
103
]
109
104
}"
110
-
111
- DESCRIPTORS=" [${DESCRIPTORS// [$'\t\r\n ']} ]"
112
-
113
- bitcoin-cli -datadir=/bitcoind importdescriptors " $DESCRIPTORS " 2>&1 > /dev/null
114
-
115
- done < " /bitcoind/${WALLETFILE} "
116
- echo " $( bitcoin-cli -datadir=/bitcoind listdescriptors) "
117
- echo " ================================================"
105
+
106
+ DESCRIPTORS=" [${DESCRIPTORS// [$'\t\r\n ']/ } ]"
107
+
108
+ bitcoin-cli -datadir=/bitcoind importdescriptors " $DESCRIPTORS " 2>&1 > /dev/null
109
+
110
+ done < " /bitcoind/${WALLETFILE} "
111
+ echo " $( bitcoin-cli -datadir=/bitcoind listdescriptors) "
112
+ echo " ================================================"
118
113
else
119
- # If restarting, load the wallet that already exists, so don't fail if it does,
120
- # just load the existing wallet:
121
- echo " ================================================"
122
- echo " Loading the main wallet:"
123
- WALLET=$( ls /bitcoind/signet/wallets -1 | head -1 | tail -1)
124
- bitcoin-cli -datadir=/bitcoind loadwallet " $WALLET " 2>&1 > /dev/null
125
- echo " Bitcoin core wallet \" $WALLET \" loaded."
126
- echo " ================================================"
114
+ # If restarting, load the wallet that already exists, so don't fail if it does,
115
+ # just load the existing wallet:
116
+ echo " ================================================"
117
+ echo " Loading the main wallet:"
118
+ WALLET=$( ls /bitcoind/signet/wallets -1 | head -1 | tail -1)
119
+ bitcoin-cli -datadir=/bitcoind loadwallet " $WALLET " 2>&1 > /dev/null
120
+ echo " Bitcoin core wallet \" $WALLET \" loaded."
121
+ echo " ================================================"
127
122
fi
128
123
129
124
# Get the signet magic string from bitcoind debug logs
130
125
131
-
132
126
if [ -f " /bitcoind/sig_magic.txt" ]; then
133
- # If the file exists, check if the magic string is the same
134
- echo " Signet magic: $( cat /bitcoind/sig_magic.txt) "
127
+ # If the file exists, check if the magic string is the same
128
+ echo " Signet magic: $( cat /bitcoind/sig_magic.txt) "
135
129
else
136
- # If the file doesn't exist, create it
137
- SIG_MAGIC=` cat /bitcoind/signet/debug.log | grep -oP ' Signet derived magic \(message start\): \K[a-f0-9]+' `
138
- echo $SIG_MAGIC > /bitcoind/sig_magic.txt
130
+ # If the file doesn't exist, create it
131
+ SIG_MAGIC=$( cat /bitcoind/signet/debug.log | grep -oP ' Signet derived magic \(message start\): \K[a-f0-9]+' )
132
+ echo $SIG_MAGIC > /bitcoind/sig_magic.txt
139
133
fi
140
134
141
135
# Executing CMD
142
136
exec " $@ "
143
-
0 commit comments