From 78219c0e045f5f1b9954d51997d7d96e561b747d Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Tue, 19 Mar 2024 21:11:52 -0500 Subject: [PATCH] Ask nitor --- .../data/config/nitro-rpc-client/start.sh | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/stack_orchestrator/data/config/nitro-rpc-client/start.sh b/stack_orchestrator/data/config/nitro-rpc-client/start.sh index e1240129..c61eb04e 100755 --- a/stack_orchestrator/data/config/nitro-rpc-client/start.sh +++ b/stack_orchestrator/data/config/nitro-rpc-client/start.sh @@ -21,7 +21,6 @@ while true; do sleep $retry_interval done - if [[ "$CERC_NITRO_RPC_FUND_AMOUNT" -gt 0 ]]; then nitro-rpc-client -h $CERC_NITRO_RPC_HOST_ALICE \ -p $CERC_NITRO_RPC_PORT_ALICE \ @@ -29,32 +28,25 @@ if [[ "$CERC_NITRO_RPC_FUND_AMOUNT" -gt 0 ]]; then get-all-ledger-channels | \ jq "[.[] | select(.Status == \"Open\") | select(.Balance.Them == \"$CERC_NITRO_ADDRESS_BOB\")] | first" > \ /app/deployment/nitro-ledger-channel-alice-to-bob.json - if [[ ! -f "/app/deployment/nitro-ledger-channel-alice-to-bob.json" ]]; then + + ledger_channel=$(jq -r '.ID' /app/deployment/nitro-ledger-channel-alice-to-bob.json 2>/dev/null | sed 's/^null$//') + + if [[ -z "${ledger_channel}" ]]; then echo "Creating new ledger channel ..." nitro-rpc-client -h $CERC_NITRO_RPC_HOST_ALICE \ -p $CERC_NITRO_RPC_PORT_ALICE \ -s=$CERC_NITRO_USE_TLS \ -n \ direct-fund --amount $CERC_NITRO_RPC_FUND_AMOUNT $CERC_NITRO_ADDRESS_BOB - fi - - nitro-rpc-client -h $CERC_NITRO_RPC_HOST_ALICE \ - -p $CERC_NITRO_RPC_PORT_ALICE \ - -s=$CERC_NITRO_USE_TLS \ - get-all-ledger-channels | \ - jq "[.[] | select(.Status == \"Open\") | select(.Balance.Them == \"$CERC_NITRO_ADDRESS_BOB\")] | first" > \ - /app/deployment/nitro-ledger-channel-alice-to-bob.json - - ledger_channel=$(jq -r '.ID' /app/deployment/nitro-ledger-channel-alice-to-bob.json) - - if [[ ! -f "/app/deployment/nitro-payment-channels-alice-to-bob.json" ]]; then - echo "Creating new payment channel ..." nitro-rpc-client -h $CERC_NITRO_RPC_HOST_ALICE \ -p $CERC_NITRO_RPC_PORT_ALICE \ -s=$CERC_NITRO_USE_TLS \ - -n \ - virtual-fund --amount $((CERC_NITRO_RPC_FUND_AMOUNT/2)) $CERC_NITRO_ADDRESS_BOB + get-all-ledger-channels | \ + jq "[.[] | select(.Status == \"Open\") | select(.Balance.Them == \"$CERC_NITRO_ADDRESS_BOB\")] | first" > \ + /app/deployment/nitro-ledger-channel-alice-to-bob.json + + ledger_channel=$(jq -r '.ID' /app/deployment/nitro-ledger-channel-alice-to-bob.json) fi nitro-rpc-client -h $CERC_NITRO_RPC_HOST_ALICE \ @@ -63,6 +55,25 @@ if [[ "$CERC_NITRO_RPC_FUND_AMOUNT" -gt 0 ]]; then get-payment-channels-by-ledger $ledger_channel > \ /app/deployment/nitro-payment-channels-alice-to-bob.json + first_open_channel=$(jq '[.[] | select(.Status == "Open")] | first' /app/deployment/nitro-payment-channels-alice-to-bob.json | sed 's/^null$//') + + if [[ -z "$first_open_channel" ]]; then + echo "Creating new payment channel ..." + nitro-rpc-client -h $CERC_NITRO_RPC_HOST_ALICE \ + -p $CERC_NITRO_RPC_PORT_ALICE \ + -s=$CERC_NITRO_USE_TLS \ + -n \ + virtual-fund --amount $((CERC_NITRO_RPC_FUND_AMOUNT/2)) $CERC_NITRO_ADDRESS_BOB + + nitro-rpc-client -h $CERC_NITRO_RPC_HOST_ALICE \ + -p $CERC_NITRO_RPC_PORT_ALICE \ + -s=$CERC_NITRO_USE_TLS \ + get-payment-channels-by-ledger $ledger_channel > \ + /app/deployment/nitro-payment-channels-alice-to-bob.json + + first_open_channel=$(jq '[.[] | select(.Status == "Open")] | first' /app/deployment/nitro-payment-channels-alice-to-bob.json | sed 's/^null$//') + fi + echo "" echo "################################################################" echo ""