-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-lin.sh
122 lines (96 loc) · 3.81 KB
/
setup-lin.sh
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
# Print a message to the user
echo "Starting setup for TradeLayer environment..."
# Install npm dependencies (for the NPM package)
echo "Installing NPM dependencies..."
npm install
# Fetch litecoind binaries from official Litecoin GitHub
echo "Fetching litecoind binaries..."
LITECOIN_VERSION=0.21.3
wget https://download.litecoin.org/litecoin-${LITECOIN_VERSION}/linux/litecoin-${LITECOIN_VERSION}-x86_64-linux-gnu.tar.gz
# Extract the downloaded binaries
echo "Extracting litecoind binaries..."
tar -xzf litecoin-${LITECOIN_VERSION}-x86_64-linux-gnu.tar.gz
mv litecoin-${LITECOIN_VERSION} ~/litecoin
# Check if litecoin.conf exists, if not create it
chmod 755 $HOME/.litecoin
LITECOIN_CONF_DIR="$HOME/.litecoin" # Replace ~ with $HOME to ensure the correct home directory is used
LITECOIN_CONF_FILE=$LITECOIN_CONF_DIR/litecoin.conf
echo "Checking for litecoin.conf at: $LITECOIN_CONF_FILE"
if [ ! -f "$LITECOIN_CONF_FILE" ]; then
echo "Creating litecoin.conf file..."
mkdir -p "$LITECOIN_CONF_DIR" # Ensure the directory is created
echo "rpcuser=user" > "$LITECOIN_CONF_FILE"
echo "rpcpassword=pass" >> "$LITECOIN_CONF_FILE"
echo "rpcallowip=127.0.0.1" >> "$LITECOIN_CONF_FILE"
echo "testnet=1" >> "$LITECOIN_CONF_FILE"
echo "txindex=1" >> "$LITECOIN_CONF_FILE"
echo "[test]"
echo "rpcport=18322" >> "$LITECOIN_CONF_FILE"
echo "[main]"
echo "rpcport=8322" >> "$LITECOIN_CONF_FILE"
echo "litecoin.conf created successfully."
else
echo "litecoin.conf already exists."
fi
# Clone the TradeLayer.js repository if it doesn't exist
echo "Checking for TradeLayer.js directory..."
if [ ! -d "tradelayer.js" ]; then
echo "Cloning TradeLayer.js repository..."
git clone https://github.com/patrickdugan/tradelayer.js.git
else
echo "TradeLayer.js directory already exists."
fi
# Navigate to the TradeLayer directory
cd tradelayer.js
# Check out the txIndexRefactor branch
echo "Checking out the txIndexRefactor branch..."
git checkout txIndexRefactor
# Run npm install in the TradeLayer.js directory
echo "Installing NPM dependencies for TradeLayer.js..."
npm install
# Run npm dedupe for the TradeLayer.js directory
echo "Removing redundant lib for TradeLayer.js..."
npm uninstall bitcore-lib-ltc
# Start litecoind from the bin folder
echo "Starting litecoind..."
~/litecoin/bin/litecoind -daemon -server -testnet -rpcuser=user -rpcpassword=pass -rpcport=18332
# Function to check if litecoind is ready
check_litecoind() {
while true; do
sleep 10 # Wait before checking again
response=$(~/litecoin/bin/litecoin-cli -testnet -rpcport=18332 getblockchaininfo 2>/dev/null)
if [[ $? -eq 0 ]]; then
echo "litecoind is ready."
break
else
echo "Waiting for litecoind to initialize..."
fi
done
}
# Wait for litecoind to be ready
check_litecoind
# Check if the wallet exists, if not create a new wallet
WALLET_NAME="mywallet" # You can customize the wallet name here
WALLET_FILE="$HOME/.litecoin/$WALLET_NAME"
echo "Checking for existing wallet at: $WALLET_FILE"
if [ ! -f "$WALLET_FILE" ]; then
echo "Creating new wallet..."
~/litecoin/bin/litecoin-cli -rpcport=18332 createwallet "$WALLET_NAME"
else
echo "Wallet already exists, loading wallet..."
~/litecoin/bin/litecoin-cli -rpcport=18332 loadwallet "$WALLET_NAME"
fi
# Create a wallet address
echo "Creating wallet address..."
address=$(~/litecoin/bin/litecoin-cli -testnet -rpcport=18332 -rpcwallet="$WALLET_NAME" getnewaddress)
echo "Wallet address created: $address"
# Command to dump the entire wallet to a file
echo "Exporting wallet..."
~/litecoin/bin/litecoin-cli -testnet dumpwallet ./dumpfile.txt
# Build TradeLayer API
echo "Building TradeLayer API..."
cd src
npm install # Ensure dependencies are installed
cd ..
echo "Setup complete!"