-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaliases.sh
124 lines (90 loc) · 2.65 KB
/
aliases.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
123
124
#!/bin/bash
build() {
if [ "$(id -u)" != "1000" ]; then
echo "!! you may have permission problems - uncomment the bitcoin: build:"
echo " section in docker-compose.yml!"
echo
fi
mkdir -p bitcoin-datadir
docker-compose build --build-arg UID=$(id -u) --build-arg GID=$(id -g) $@
}
start-bitcoin() {
if [ "$1" = "fg" ]; then
docker-compose up bitcoin
else
docker-compose up -d bitcoin
docker-compose ps
fi
}
demo() {
docker-compose run --rm demo $@
}
bitcoin-cli() {
docker-compose exec bitcoin bitcoin-cli -regtest $@
}
check-bitcoin-up() {
docker-compose ps | grep Up | grep bitcoin_ >/dev/null
}
mine() {
NUM_BLOCKS=${1}
TO_ADDRESS=${2}
check-bitcoin-up || start-bitcoin
if [ -z "${TO_ADDRESS}" ]; then
bitcoin-cli -generate $@
else
bitcoin-cli generatetoaddress $@
fi
}
VAULT_GUIDE=$(cat << EOF
OP_VAULT shortcuts
------------------
build build docker containers
start-bitcoin run regtest bitcoind in the background
demo [cmd ...] run some command in the demo container
e.g. \`demo ./main.py watchtower\`
bitcoin-cli [...] run some bitcoin-cli command
mine [num=1] [addr] mine some blocks, maybe to an address
vault-help show this help
Getting started
---------------
Source this file:
source ./aliases.sh
Build the containers and start bitcoind:
build
start-bitcoin
Generate a config and start the watchtower. This will run in one window,
all other commands will happen in another:
demo ./createconfig.py
demo ./main.py
(then, in another window)
Fund the fee wallet:
source ./aliases.sh -q
bitcoin-cli createwallet fees
mine 200 [fee address printed above]
Deposit to the vault:
bitcoin-cli loadwallet fees # if necessary
mine 200 # mine another 200 blocks to the loaded wallet
bitcoin-cli sendtoaddress [addr] [amt-btc]
mine # mine a block to actually process the deposit
Start a withdrawal:
demo ./main.py withdraw bcrt1p33wm0auhr9kkahzd6l0kqj85af4cswn276hsxg6zpz85xe2r0y8s7hfsm7 120000
(you can use \`demo ./main.py withdraw --help\` too)
mine # call this until the trigger confirms and then "matures"
mine # mine once more to see the withdrawal confirm
Simulate a theft:
demo ./main.py steal bcrt1p33wm0auhr9kkahzd6l0kqj85af4cswn276hsxg6zpz85xe2r0y8s7hfsm7 12000
[ see watchtower freak out ]
demo ./main.py recover
EOF
)
vault-help() {
echo $VAULT_GUIDE
}
clean() {
docker-compose down
rm -rf bitcoin-datadir config.json secrets.json \
.local .bash_history .mypy_cache __pycache__
}
if [ "$1" != "-q" ]; then
vault-help
fi