summaryrefslogtreecommitdiff
path: root/nlnet/task5/long-poll/start.sh
blob: 46a0af22628af57bde25b0fd230922b8b78bdb9b (plain)
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
125
126
127
128
129
130
131
132
133
134
#!/bin/bash

set -eu

service postgresql start
sudo -u postgres createuser -s root
createdb libeufincheck

wire_transfer () {
  RESERVE_PUB=$(gnunet-ecc -g1 /tmp/www &> /dev/null && gnunet-ecc -p /tmp/www)
  DB_CONN="postgresql:///libeufincheck"
  libeufin-sandbox \
    make-transaction \
      --credit-account=sandbox-user \
      --debit-account=admin MANA:2 \
      $RESERVE_PUB
}

WITH_TASKS=1
echo RUNNING SANDBOX-NEXUS EBICS PAIR
jq --version &> /dev/null || (echo "'jq' command not found"; exit 77)
curl --version &> /dev/null || (echo "'curl' command not found"; exit 77)

DB_CONN="postgresql:///libeufincheck"
export LIBEUFIN_SANDBOX_DB_CONNECTION=$DB_CONN
export LIBEUFIN_NEXUS_DB_CONNECTION=$DB_CONN

echo -n Delete previous data...
libeufin-sandbox reset-tables
libeufin-nexus reset-tables
echo DONE
echo -n Configure the default demobank with MANA...
libeufin-sandbox config --with-signup-bonus --currency MANA default
echo DONE
echo -n Setting the default exchange at Sandbox...
libeufin-sandbox \
  default-exchange \
  "https://exchange.example.com/" \
  "payto://iban/NOTUSED"
echo DONE
echo -n Start the bank...
export LIBEUFIN_SANDBOX_ADMIN_PASSWORD=foo
libeufin-sandbox serve > sandbox.log 2>&1 &
SANDBOX_PID=$!
echo DONE
echo -n Wait for the bank...
curl --max-time 4 --retry-all-errors --retry-connrefused --retry-delay 1 --retry 10 http://localhost:5000/ &> /dev/null
echo DONE
echo -n Make one superuser at Nexus...
libeufin-nexus superuser test-user --password x
echo DONE
echo -n Launching Nexus...
libeufin-nexus serve &> nexus.log &
NEXUS_PID=$!
echo DONE
echo -n Waiting for Nexus...
curl --max-time 4 --retry-all-errors --retry-connrefused --retry-delay 1 --retry 10 http://localhost:5001/ &> /dev/null
echo DONE

echo -n "Register the Sandbox account..."
export LIBEUFIN_SANDBOX_USERNAME=sandbox-user
export LIBEUFIN_SANDBOX_PASSWORD=foo
libeufin-cli \
  sandbox --sandbox-url http://localhost:5000/ \
  demobank \
  register
echo DONE
echo -n Creating the x-libeufin-bank connection at Nexus...
export LIBEUFIN_NEXUS_USERNAME=test-user
export LIBEUFIN_NEXUS_PASSWORD=x
export LIBEUFIN_NEXUS_URL=http://localhost:5001
# echoing the password to STDIN, as that is a "prompt" option.
libeufin-cli connections new-xlibeufinbank-connection \
  --bank-url "http://localhost:5000/demobanks/default/access-api" \
  --username sandbox-user \
  --password foo \
  wwwconn
echo DONE
echo -n Connecting the x-libeufin-bank connection...
libeufin-cli connections connect wwwconn
echo DONE
# Importing the bank account under a local name at Nexus.
echo -n Importing the x-libeufin-bank account locally..
libeufin-cli connections import-bank-account \
  --offered-account-id sandbox-user \
  --nexus-bank-account-id foo-at-nexus wwwconn
echo DONE
echo -n Create the Taler facade at Nexus...
libeufin-cli facades \
  new-taler-wire-gateway-facade \
  --currency TESTKUDOS --facade-name test-facade \
  wwwconn foo-at-nexus
echo DONE
if test 1 = $WITH_TASKS; then
  echo -n Creating submit transactions task..
  libeufin-cli accounts task-schedule \
    --task-type submit \
    --task-name www-payments \
    --task-cronspec "* * *" \
    foo-at-nexus || true
  # Tries every second.  Ask C52
  echo DONE
  echo -n Creating fetch transactions task..
  # Not idempotent, FIXME #7739
  libeufin-cli accounts task-schedule \
    --task-type fetch \
    --task-name www-history \
    --task-cronspec "* * *" \
    --task-param-level statement \
    --task-param-range-type since-last \
    foo-at-nexus || true
  echo DONE
else
  echo NOT creating background tasks!
fi

echo
echo Services are online!  The following shell offers a 'wire_transfer'
echo command that wires money to Nexus 'test-user'.  Give it after having
echo connected an HTTP client that long-polls to Nexus.  As an example, a
echo 100 seconds long-poller to Nexus is the following command:
echo curl -v -u test-user:x "'http://localhost:5001/facades/test-facade/taler-wire-gateway/history/incoming?delta=5&long_poll_ms=100000'"
echo
echo Hint: after having issued the previous command and having observed
echo that it actually long-polls, press CTRL-Z to send it in the background,
echo "then wire the funds to the long-poller with 'wire_transfer',"
echo "and finally give 'fg 1' to bring the long-poller in the foreground."
echo If the client now shows a response, then the long-polling mechanism
echo worked.
echo

cd /
export -f wire_transfer
bash