Skip to content

Commit

Permalink
chore: update quickstart yml and bump quickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhart1o1 committed Jan 18, 2024
1 parent cb5499a commit 5fe6eea
Show file tree
Hide file tree
Showing 84 changed files with 1,649 additions and 22 deletions.
6 changes: 3 additions & 3 deletions vendir.lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ apiVersion: vendir.k14s.io/v1alpha1
directories:
- contents:
- git:
commitTitle: 'chore(release): [ci skip] bump quickstart image to sha256@5c314b628585c528c141615e175ef83470d84b61c8bd2c2edc5012abfa24c3a4'
sha: d69a4d33ad510f90f638a14d91b84108a6ec6c7b
commitTitle: 'refactor(core): cleanup old notification code (#3866)...'
sha: 87302ead3d5f75ce4f9dadda122bf119bd1f0b30
tags:
- 0.19.35-1-gd69a4d33a
- 0.20.9
path: galoy-quickstart
path: vendor
kind: LockConfig
28 changes: 15 additions & 13 deletions vendir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ apiVersion: vendir.k14s.io/v1alpha1
kind: Config

directories:
- path: vendor
contents:
- path: galoy-quickstart
git:
url: https://github.com/GaloyMoney/galoy.git
ref: main
includePaths:
- quickstart/.env.galoy
- quickstart/docker-compose.yml
- quickstart/dev/**/*
- quickstart/graphql/**/*
newRootPath: quickstart

- path: vendor
contents:
- path: galoy-quickstart
git:
url: https://github.com/GaloyMoney/galoy.git
ref: 'main'
includePaths:
- quickstart/.env.galoy
- quickstart/docker-compose.yml
- quickstart/dev/**/*
- quickstart/graphql/**/*
- quickstart/galoy/test/**/*
- quickstart/bin/*
- quickstart/.gitignore
newRootPath: quickstart
2 changes: 2 additions & 0 deletions vendor/galoy-quickstart/.env.galoy
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ UNSECURE_IP_FROM_REQUEST_OBJECT=true

HYDRA_PUBLIC_API="http://hydra:4444"
HYDRA_ADMIN_API="http://hydra:4445"

NOTIFICATIONS_HOST="dummy"
1 change: 1 addition & 0 deletions vendor/galoy-quickstart/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tmp*
11 changes: 11 additions & 0 deletions vendor/galoy-quickstart/bin/bump-galoy-git-ref.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

DIR="$(dirname "$(readlink -f "$BASH_SOURCE")")"

TMPDIR=""
TMPDIR=$(mktemp -d -t repipe.XXXXXX)
trap "rm -rf ${TMPDIR}" INT TERM QUIT EXIT

sed "s/^galoy_git_ref:.*/galoy_git_ref: ${1}/" ${DIR}/../vendir/values.yml > ${TMPDIR}/new_values.yml

mv ${TMPDIR}/new_values.yml ${DIR}/../vendir/values.yml
11 changes: 11 additions & 0 deletions vendor/galoy-quickstart/bin/bump-galoy-image-digest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

DIR="$(dirname "$(readlink -f "$BASH_SOURCE")")"

TMPDIR=""
TMPDIR=$(mktemp -d -t repipe.XXXXXX)
trap "rm -rf ${TMPDIR}" INT TERM QUIT EXIT

sed "s/^#@ galoy_${1}_image_digest = \".*\"/#@ galoy_${1}_image_digest = \"${2}\"/" ${DIR}/../docker-compose.tmpl.yml > ${TMPDIR}/docker-compose.tmpl.yml

mv ${TMPDIR}/docker-compose.tmpl.yml ${DIR}/../docker-compose.tmpl.yml
11 changes: 11 additions & 0 deletions vendor/galoy-quickstart/bin/bump-mongodb-migrate-image-digest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

DIR="$(dirname "$(readlink -f "$BASH_SOURCE")")"

TMPDIR=""
TMPDIR=$(mktemp -d -t repipe.XXXXXX)
trap "rm -rf ${TMPDIR}" INT TERM QUIT EXIT

sed "s/^#@ mongodb_migrate_image_digest = \".*\"/#@ mongodb_migrate_image_digest = \"${1}\"/" ${DIR}/../docker-compose.tmpl.yml > ${TMPDIR}/docker-compose.tmpl.yml

mv ${TMPDIR}/docker-compose.tmpl.yml ${DIR}/../docker-compose.tmpl.yml
239 changes: 239 additions & 0 deletions vendor/galoy-quickstart/bin/helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
#!/bin/bash

set -e

COMPOSE_PROJECT_NAME="${COMPOSE_PROJECT_NAME:-quickstart}"
# default is oathkeeper endpoint
GALOY_ENDPOINT=${GALOY_ENDPOINT:-localhost:4455}

if [ -n "$HOST_PROJECT_PATH" ]; then
GALOY_DIR="./vendor/galoy-quickstart"
else
GALOY_DIR="."
fi
export GALOY_DIR

CACHE_DIR=$GALOY_DIR/tmp/quickstart-cache
mkdir -p $CACHE_DIR

cache_value() {
echo $2 >${CACHE_DIR}/$1
}

read_value() {
cat ${CACHE_DIR}/$1
}

bitcoin_cli() {
docker exec "${COMPOSE_PROJECT_NAME}-bitcoind-1" bitcoin-cli $@
}

lnd_cli() {
docker exec "${COMPOSE_PROJECT_NAME}-lnd1-1" \
lncli \
--macaroonpath /root/.lnd/data/chain/bitcoin/regtest/admin.macaroon \
--tlscertpath /root/.lnd/tls.cert \
$@
}

lnd_outside_cli() {
docker exec "${COMPOSE_PROJECT_NAME}-lnd-outside-1-1" \
lncli \
--macaroonpath /root/.lnd/data/chain/bitcoin/regtest/admin.macaroon \
--tlscertpath /root/.lnd/tls.cert \
$@
}

init_lnd_channel() {
lnd_cli closeallchannels || true

local amount="1"
local address="$(lnd_outside_cli newaddress p2wkh | jq -r '.address')"
local local_amount="10000000"
bitcoin_cli sendtoaddress "$address" "$amount"
bitcoin_cli -generate 3

# Open balanced channel from lnd1 to lndoutside1
lnd_local_pubkey="$(lnd_cli getinfo | jq -r '.identity_pubkey')"
lnd_outside_cli connect "${lnd_local_pubkey}@${COMPOSE_PROJECT_NAME}-lnd1-1:9735" || true
for i in {1..10}; do
lnd_outside_cli openchannel \
--node_key "$lnd_local_pubkey" \
--local_amt "$local_amount" && break
done

for i in {1..10}; do
local txid="$(bitcoin_cli getrawmempool | jq -r '.[0]')"
[[ "$txid" != "null" ]] && break
sleep 1
done

bitcoin_cli -generate 3

}

bria_cli() {
docker exec "${COMPOSE_PROJECT_NAME}-bria-1" bria $@
}

bitcoin_signer_cli() {
docker exec "${COMPOSE_PROJECT_NAME}-bitcoind-signer-1" bitcoin-cli $@
}

gql_file() {
echo "$GALOY_DIR/galoy/test/bats/gql/$1.gql"
}

gql_query() {
cat "$(gql_file $1)" | tr '\n' ' ' | sed 's/"/\\"/g'
}

graphql_output() {
echo $output | jq -r "$@"
}

exec_graphql() {
local token_name=$1
local query_name=$2
local variables=${3:-"{}"}

if [[ ${token_name} == "anon" ]]; then
AUTH_HEADER=""
else
AUTH_HEADER="Authorization: Bearer $(read_value ${token_name})"
fi

gql_route="graphql"

output=$(curl -s \
-X POST \
${AUTH_HEADER:+ -H "$AUTH_HEADER"} \
-H "Content-Type: application/json" \
-d "{\"query\": \"$(gql_query $query_name)\", \"variables\": $variables}" \
"${GALOY_ENDPOINT}/${gql_route}")
}

login_user() {
local token_name=$1
local phone=$2
local code=$3

local variables=$(
jq -n \
--arg phone "$phone" \
--arg code "$code" \
'{input: {phone: $phone, code: $code}}'
)
exec_graphql 'anon' 'user-login' "$variables"
auth_token="$(graphql_output '.data.userLogin.authToken')"
[[ -n "${auth_token}" && "${auth_token}" != "null" ]]
cache_value "$token_name" "$auth_token"

exec_graphql "$token_name" 'wallets-for-account'

account_id="$(graphql_output '.data.me.defaultAccount.id')"
[[ "${account_id}" != "null" ]]
cache_value "$token_name.account_id" "$account_id"

btc_wallet_id="$(graphql_output '.data.me.defaultAccount.wallets[] | select(.walletCurrency == "BTC") .id')"
[[ "${btc_wallet_id}" != "null" ]]
cache_value "$token_name.btc_wallet_id" "$btc_wallet_id"

usd_wallet_id="$(graphql_output '.data.me.defaultAccount.wallets[] | select(.walletCurrency == "USD") .id')"
[[ "${usd_wallet_id}" != "null" ]]
cache_value "$token_name.usd_wallet_id" "$usd_wallet_id"
}

receive_onchain() {
token_name="alice"
btc_wallet_name="$token_name.btc_wallet_id"
amount="0.01"

variables=$(
jq -n \
--arg wallet_id "$(read_value $btc_wallet_name)" \
'{input: {walletId: $wallet_id}}'
)

exec_graphql "$token_name" 'on-chain-address-create' "$variables"
address="$(graphql_output '.data.onChainAddressCreate.address')"

bitcoin_cli sendtoaddress "$address" "$amount"
bitcoin_cli -generate 4

variables=$(
jq -n \
--argjson first "1" \
'{"first": $first}'
)
for i in {1..60}; do
exec_graphql "$token_name" 'transactions' "$variables"

jq_query='.data.me.defaultAccount.transactions.edges[] | select(.node.initiationVia.address == $address) .node'
settled_status=$(echo $output \
| jq -r --arg address "$address" "$jq_query" \
| jq -r ".status")
[[ "${settled_status}" = "SUCCESS" ]] && break
sleep 1
done
}

receive_lightning() {
token_name="alice"
btc_wallet_name="$token_name.btc_wallet_id"
btc_amount=1000

variables=$(
jq -n \
--arg wallet_id "$(read_value $btc_wallet_name)" \
--arg amount "$btc_amount" \
'{input: {walletId: $wallet_id, amount: $amount}}'
)
exec_graphql "$token_name" 'ln-invoice-create' "$variables"
payment_request="$(echo $invoice | jq -r '.paymentRequest')"
lnd_outside_cli payinvoice -f \
--pay_req "$payment_request"

for i in {1..20}; do
jq_query='.data.me.defaultAccount.transactions.edges[] | select(.node.initiationVia.paymentHash == $payment_hash) .node'
echo $output \
| jq -r --arg payment_hash "$1" "$jq_query" \
| jq -r ".status"
[[ "${settled_status}" = "SUCCESS" ]] && break
sleep 1
done
}

fund_wallet_from_onchain() {
local token_name=$1
local wallet_id_name="$2"
local amount=$3

variables=$(
jq -n \
--arg wallet_id "$(read_value $wallet_id_name)" \
'{input: {walletId: $wallet_id}}'
)
exec_graphql "$token_name" 'on-chain-address-create' "$variables"
address="$(graphql_output '.data.onChainAddressCreate.address')"
[[ "${address}" != "null" ]]

bitcoin_cli sendtoaddress "$address" "$amount"
bitcoin_cli -generate 5
}

initialize_user_from_onchain() {
local token_name="$1"
local phone="$2"
local code="$3"

local btc_amount_in_btc="1"

login_user "$token_name" "$phone" "$code"

fund_wallet_from_onchain \
"$token_name" \
"$token_name.btc_wallet_id" \
"$btc_amount_in_btc"
}

15 changes: 15 additions & 0 deletions vendor/galoy-quickstart/bin/init-lightning.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -e

COMPOSE_PROJECT_NAME="${COMPOSE_PROJECT_NAME:-quickstart}"

DIR="$(dirname "$(readlink -f "$BASH_SOURCE")")"
source ${DIR}/helpers.sh

echo "Running getinfo on lnd..."
lnd_cli getinfo
echo "DONE"
echo "Opening lnd-outside -> lnd channel"
init_lnd_channel
echo "DONE"
26 changes: 26 additions & 0 deletions vendor/galoy-quickstart/bin/init-onchain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -e

COMPOSE_PROJECT_NAME="${COMPOSE_PROJECT_NAME:-quickstart}"

DIR="$(dirname "$(readlink -f "$BASH_SOURCE")")"
source ${DIR}/helpers.sh

echo "Seeding some regtest blocks..."

bitcoin_cli createwallet "outside" || true
bitcoin_cli -generate 200 > /dev/null 2>&1

bitcoin_signer_cli createwallet "dev" || true
bitcoin_signer_cli -rpcwallet=dev importdescriptors "$(cat $GALOY_DIR/galoy/test/bats/bitcoind_signer_descriptors.json)"

echo "Checking that bria is running..."

for i in {1..20}; do
bria_cli wallet-balance -w dev-wallet && break
sleep 1
done
bria_cli wallet-balance -w dev-wallet || exit 1

echo "DONE"
Loading

0 comments on commit 5fe6eea

Please sign in to comment.