Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion client/src/lib/paymentsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ import {
onchainSend as onchainSendNitro,
movements as movementsNitro,
finishLightningReceive as finishLightningReceiveNitro,
claimAllOpenInvoices as claimAllOpenInvoicesNitro,
lightningReceiveStatus as lightningReceiveStatusNitro,
NewAddressResult,
BarkMovement,
LightningReceive,
} from "react-native-nitro-ark";
import { captureException } from "@sentry/react-native";
import { Result, ResultAsync } from "neverthrow";

export type { ArkoorPaymentResult, OnchainPaymentResult, Bolt11PaymentResult, LnurlPaymentResult };
export type {
ArkoorPaymentResult,
OnchainPaymentResult,
Bolt11PaymentResult,
LnurlPaymentResult,
LightningReceive,
};

export type PaymentResult =
| ArkoorPaymentResult
Expand Down Expand Up @@ -180,3 +189,25 @@ export const finishLightningReceive = async (bolt11: string): Promise<Result<voi
return e;
});
};

export const claimAllOpenInvoices = async (): Promise<Result<void, Error>> => {
return ResultAsync.fromPromise(claimAllOpenInvoicesNitro(), (error) => {
const e = new Error(
`Failed to claim all open invoices: ${error instanceof Error ? error.message : String(error)}`,
);
captureException(e);
return e;
});
};

export const lightningReceiveStatus = async (
paymentHash: string,
): Promise<Result<LightningReceive | undefined, Error>> => {
return ResultAsync.fromPromise(lightningReceiveStatusNitro(paymentHash), (error) => {
const e = new Error(
`Failed to get lightning receive status: ${error instanceof Error ? error.message : String(error)}`,
);
captureException(e);
return e;
});
};
68 changes: 62 additions & 6 deletions scripts/ark-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,6 @@ start_lnd() {
echo " RPC Port: 10009"
echo " P2P Port: 9735"
echo ""
echo "Note: Update the placeholder flags in the script:"
echo " - <BITCOIND_RPC_PORT>"
echo " - <BITCOIND_RPC_USER>"
echo " - <BITCOIND_RPC_PASS>"
echo " - <ZMQ_RAWBLOCK_PORT>"
echo " - <ZMQ_RAWTX_PORT>"
}

# Stops and removes the LND container
Expand All @@ -312,6 +306,64 @@ stop_lnd() {
fi
}

# Sets up Lightning Network channels between LND and CLN
setup_lightning_channels() {
echo "⚡ Setting up Lightning Network channels..."

if ! command -v jq &> /dev/null; then
echo "Error: 'jq' is not installed. Please install it to continue." >&2
exit 1
fi

echo ""
echo "⏳ Waiting for LND to fully start..."
sleep 10

echo ""
echo "🔍 Getting LND node pubkey..."
local lnd_pubkey
lnd_pubkey=$(docker exec "$LND_CONTAINER" lncli --network=regtest getinfo | jq -r '.identity_pubkey')
echo " LND pubkey: $lnd_pubkey"

echo ""
echo "🔍 Getting CLN node pubkey..."
local cln_pubkey
cln_pubkey=$(dcr exec "$CLN_SERVICE" lightning-cli --regtest getinfo | jq -r '.id')
echo " CLN pubkey: $cln_pubkey"

echo ""
echo "💰 Generating new address on LND node..."
local lnd_address
lnd_address=$(docker exec "$LND_CONTAINER" lncli --network=regtest newaddress p2tr | jq -r '.address')
echo " Address: $lnd_address"

echo ""
echo "💸 Sending 0.1 BTC to LND address..."
send_to_address "$lnd_address" "0.1"

echo ""
echo "⛏️ Generating 10 blocks..."
generate_blocks 10

echo ""
echo "⏳ Waiting for LND to sync to chain..."
sleep 10

echo ""
echo "🔗 Connecting LND to CLN..."
dcr exec "$CLN_SERVICE" lightning-cli --regtest connect "[email protected]:9735" || echo " (Already connected or connection failed, continuing...)"

echo ""
echo "⚡ Opening channel from LND to CLN (1,000,000 sats with 900,000 push amount)..."
docker exec "$LND_CONTAINER" lncli --network=regtest openchannel "$cln_pubkey" 1000000 900000

echo ""
echo "⛏️ Generating 10 more blocks to confirm channel..."
generate_blocks 10

echo "✅ Lightning Network channels setup complete!"
}

# Runs the complete setup sequence
setup_everything() {
echo "🚀 Running complete setup sequence..."
Expand Down Expand Up @@ -344,6 +396,9 @@ setup_everything() {
echo ""
start_lnd

echo ""
setup_lightning_channels

echo ""
echo "🎉 Complete setup finished successfully!"
echo "Your Ark dev environment is ready to use."
Expand All @@ -354,6 +409,7 @@ setup_everything() {
echo " - Noah Server: http://localhost:3000"
echo " - Noah Server Health: http://localhost:3099/health"
echo " - LND (Lightning): RPC at localhost:10009, P2P at localhost:9735"
echo " - CLN (Lightning): Connected to LND with open channel"
}

# --- Main Logic ---
Expand Down