Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
104 changes: 104 additions & 0 deletions Bitkit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
objects = {

/* Begin PBXBuildFile section */
9637E6D32C32CE79004A92FC /* Env.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9637E6D22C32CE79004A92FC /* Env.swift */; };
9637E6D52C32D811004A92FC /* OnChainService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9637E6D42C32D811004A92FC /* OnChainService.swift */; };
9637E6D82C32D8A7004A92FC /* BitcoinDevKit in Frameworks */ = {isa = PBXBuildFile; productRef = 9637E6D72C32D8A7004A92FC /* BitcoinDevKit */; };
9637E6DA2C32E573004A92FC /* OnChainViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9637E6D92C32E573004A92FC /* OnChainViewModel.swift */; };
9637E6DD2C32EAA8004A92FC /* WalletNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9637E6DC2C32EAA8004A92FC /* WalletNetwork.swift */; };
9637E6DF2C32ED7B004A92FC /* LnPeer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9637E6DE2C32ED7B004A92FC /* LnPeer.swift */; };
96B129FD2C2EC05D00DD07B0 /* LDKNode in Frameworks */ = {isa = PBXBuildFile; productRef = 96B129FC2C2EC05D00DD07B0 /* LDKNode */; };
96B12A002C2EC37B00DD07B0 /* LightningViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96B129FF2C2EC37B00DD07B0 /* LightningViewModel.swift */; };
96B12A032C2EC65000DD07B0 /* LightningService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96B12A022C2EC65000DD07B0 /* LightningService.swift */; };
96FE1F652C2DE6AA006D0C8B /* BitkitApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96FE1F642C2DE6AA006D0C8B /* BitkitApp.swift */; };
96FE1F672C2DE6AA006D0C8B /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96FE1F662C2DE6AA006D0C8B /* ContentView.swift */; };
96FE1F692C2DE6AC006D0C8B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96FE1F682C2DE6AC006D0C8B /* Assets.xcassets */; };
Expand Down Expand Up @@ -34,6 +43,13 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
9637E6D22C32CE79004A92FC /* Env.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Env.swift; sourceTree = "<group>"; };
9637E6D42C32D811004A92FC /* OnChainService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnChainService.swift; sourceTree = "<group>"; };
9637E6D92C32E573004A92FC /* OnChainViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnChainViewModel.swift; sourceTree = "<group>"; };
9637E6DC2C32EAA8004A92FC /* WalletNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletNetwork.swift; sourceTree = "<group>"; };
9637E6DE2C32ED7B004A92FC /* LnPeer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LnPeer.swift; sourceTree = "<group>"; };
96B129FF2C2EC37B00DD07B0 /* LightningViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LightningViewModel.swift; sourceTree = "<group>"; };
96B12A022C2EC65000DD07B0 /* LightningService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LightningService.swift; sourceTree = "<group>"; };
96FE1F612C2DE6AA006D0C8B /* Bitkit.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Bitkit.app; sourceTree = BUILT_PRODUCTS_DIR; };
96FE1F642C2DE6AA006D0C8B /* BitkitApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BitkitApp.swift; sourceTree = "<group>"; };
96FE1F662C2DE6AA006D0C8B /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand All @@ -52,6 +68,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9637E6D82C32D8A7004A92FC /* BitcoinDevKit in Frameworks */,
96B129FD2C2EC05D00DD07B0 /* LDKNode in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -72,6 +90,41 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
9637E6D12C32CE65004A92FC /* Constants */ = {
isa = PBXGroup;
children = (
9637E6D22C32CE79004A92FC /* Env.swift */,
);
path = Constants;
sourceTree = "<group>";
};
9637E6DB2C32EA84004A92FC /* Models */ = {
isa = PBXGroup;
children = (
9637E6DC2C32EAA8004A92FC /* WalletNetwork.swift */,
9637E6DE2C32ED7B004A92FC /* LnPeer.swift */,
);
path = Models;
sourceTree = "<group>";
};
96B129FE2C2EC0ED00DD07B0 /* ViewModels */ = {
isa = PBXGroup;
children = (
96B129FF2C2EC37B00DD07B0 /* LightningViewModel.swift */,
9637E6D92C32E573004A92FC /* OnChainViewModel.swift */,
);
path = ViewModels;
sourceTree = "<group>";
};
96B12A012C2EC61500DD07B0 /* Services */ = {
isa = PBXGroup;
children = (
96B12A022C2EC65000DD07B0 /* LightningService.swift */,
9637E6D42C32D811004A92FC /* OnChainService.swift */,
);
path = Services;
sourceTree = "<group>";
};
96FE1F582C2DE6AA006D0C8B = {
isa = PBXGroup;
children = (
Expand All @@ -97,6 +150,10 @@
children = (
96FE1F642C2DE6AA006D0C8B /* BitkitApp.swift */,
96FE1F662C2DE6AA006D0C8B /* ContentView.swift */,
96B129FE2C2EC0ED00DD07B0 /* ViewModels */,
96B12A012C2EC61500DD07B0 /* Services */,
9637E6DB2C32EA84004A92FC /* Models */,
9637E6D12C32CE65004A92FC /* Constants */,
96FE1F682C2DE6AC006D0C8B /* Assets.xcassets */,
96FE1F6A2C2DE6AC006D0C8B /* Bitkit.entitlements */,
96FE1F6B2C2DE6AC006D0C8B /* Preview Content */,
Expand Down Expand Up @@ -145,6 +202,10 @@
dependencies = (
);
name = Bitkit;
packageProductDependencies = (
96B129FC2C2EC05D00DD07B0 /* LDKNode */,
9637E6D72C32D8A7004A92FC /* BitcoinDevKit */,
);
productName = Bitkit;
productReference = 96FE1F612C2DE6AA006D0C8B /* Bitkit.app */;
productType = "com.apple.product-type.application";
Expand Down Expand Up @@ -217,6 +278,10 @@
Base,
);
mainGroup = 96FE1F582C2DE6AA006D0C8B;
packageReferences = (
96B129FB2C2EC05D00DD07B0 /* XCRemoteSwiftPackageReference "ldk-node" */,
9637E6D62C32D8A7004A92FC /* XCRemoteSwiftPackageReference "bdk-swift" */,
);
productRefGroup = 96FE1F622C2DE6AA006D0C8B /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down Expand Up @@ -259,7 +324,14 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9637E6D32C32CE79004A92FC /* Env.swift in Sources */,
96B12A002C2EC37B00DD07B0 /* LightningViewModel.swift in Sources */,
9637E6DD2C32EAA8004A92FC /* WalletNetwork.swift in Sources */,
9637E6DA2C32E573004A92FC /* OnChainViewModel.swift in Sources */,
9637E6DF2C32ED7B004A92FC /* LnPeer.swift in Sources */,
96FE1F672C2DE6AA006D0C8B /* ContentView.swift in Sources */,
96B12A032C2EC65000DD07B0 /* LightningService.swift in Sources */,
9637E6D52C32D811004A92FC /* OnChainService.swift in Sources */,
96FE1F652C2DE6AA006D0C8B /* BitkitApp.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -621,6 +693,38 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
9637E6D62C32D8A7004A92FC /* XCRemoteSwiftPackageReference "bdk-swift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/bitcoindevkit/bdk-swift";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.31.1;
};
};
96B129FB2C2EC05D00DD07B0 /* XCRemoteSwiftPackageReference "ldk-node" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/lightningdevkit/ldk-node";
requirement = {
branch = main;
kind = branch;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
9637E6D72C32D8A7004A92FC /* BitcoinDevKit */ = {
isa = XCSwiftPackageProductDependency;
package = 9637E6D62C32D8A7004A92FC /* XCRemoteSwiftPackageReference "bdk-swift" */;
productName = BitcoinDevKit;
};
96B129FC2C2EC05D00DD07B0 /* LDKNode */ = {
isa = XCSwiftPackageProductDependency;
package = 96B129FB2C2EC05D00DD07B0 /* XCRemoteSwiftPackageReference "ldk-node" */;
productName = LDKNode;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 96FE1F592C2DE6AA006D0C8B /* Project object */;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
93 changes: 93 additions & 0 deletions Bitkit/Constants/Env.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//
// Env.swift
// Bitkit
//
// Created by Jason van den Berg on 2024/07/01.
//

import Foundation

struct Env {
static let isPreview = ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"
static let isTestFlight = Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"
static let isUnitTest = ProcessInfo.processInfo.environment["XCTestConfigurationFilePath"] != nil

#if targetEnvironment(simulator)
static let isSim = true
#else
static let isSim = false
#endif

#if DEBUG
static let isDebug = true
#else
static let isDebug = false
#endif

//MARK: wallet services
static let network: WalletNetwork = .regtest
static var esploraServerUrl: String {
switch network {
case .regtest:
//cargo run --release --bin electrs -- -vvv --jsonrpc-import --daemon-rpc-addr 127.0.0.1:18443 --cookie polaruser:polarpass
// return "https://jaybird-logical-sadly.ngrok-free.app"
return "http://localhost:3000"
case .bitcoin:
fatalError("Bitcoin network not implemented")
case .testnet:
fatalError("Testnet network not implemented")
case .signet:
fatalError("Signet network not implemented")
}
}

static var appStorageUrl: URL {
//TODO move to app group so files can be shared with extensions
guard let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else {
fatalError("Could not find documents directory")
}

return documentsDirectory
}

static var ldkStorage: URL {
let storageDirPath = appStorageUrl.appendingPathComponent("ldk")

switch network {
case .regtest:
return storageDirPath.appendingPathComponent("regtest")
case .bitcoin:
fatalError("Bitcoin network not implemented")
case .testnet:
fatalError("Testnet network not implemented")
case .signet:
fatalError("Signet network not implemented")
}
}

static var ldkRgsServerUrl: String? {
switch network {
case .regtest:
return nil
case .bitcoin:
return "https://rapidsync.lightningdevkit.org/snapshot/"
case .testnet:
return nil
case .signet:
return nil
}
}

static var trustedLnPeers: [LnPeer] {
switch network {
case .regtest:
return [.init(nodeId: "021de6ad59a78caf8f376cbd022e8c6ede2a1ef0a4fa035174e8b9c25ad5866584", address: "127.0.0.1:9736")]
case .bitcoin:
return []
case .testnet:
return []
case .signet:
return []
}
}
}
64 changes: 59 additions & 5 deletions Bitkit/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,68 @@
import SwiftUI

struct ContentView: View {
@StateObject var lnViewModel = LightningViewModel()
@StateObject var onChainViewModel = OnChainViewModel()

var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, Bitcoin!")
Group {
Text("LDK-Node running: \(lnViewModel.status?.isRunning == true ? "✅" : "❌")")


if let nodeId = lnViewModel.nodeId {
Text("LN Node ID: \(nodeId)")
.onTapGesture {
UIPasteboard.general.string = nodeId
}
}

if let peers = lnViewModel.peers {
ForEach(peers, id: \.nodeId) { peer in
Text("Peer: \(peer.nodeId) \(peer.address) \(peer.isConnected ? "✅" : "❌")")
}
}

if let lnBalance = lnViewModel.balance {
Text("Lightning \(lnBalance.totalLightningBalanceSats)")
}

if let onchainBalance = onChainViewModel.balance {
Text("On Chain \(onchainBalance.total)")
}

if let receiveAddress = onChainViewModel.address {
Text("Receive Address: \(receiveAddress)")
.onTapGesture {
UIPasteboard.general.string = receiveAddress
}
}

Button("New Receive Address") {
try! onChainViewModel.newReceiveAddress()
}

Button("Sync") {
Task {
await lnViewModel.sync()
await onChainViewModel.sync()
}
}
}
.multilineTextAlignment(.center)
.padding()
}
.padding(4)
.onAppear {
Task {
do {
try await lnViewModel.start()
try await onChainViewModel.start()
} catch {
print("Error: \(error)")
}
}
}
.padding()
}
}

Expand Down
30 changes: 30 additions & 0 deletions Bitkit/Models/LnPeer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// LnPeer.swift
// Bitkit
//
// Created by Jason van den Berg on 2024/07/01.
//

import Foundation

struct LnPeer {
let nodeId: String
let address: String

init(nodeId: String, address: String) {
self.nodeId = nodeId
self.address = address
}

init(connection: String) throws {
let parts = connection.split(separator: "@")
guard parts.count == 2 else {
// throw LnPeerError.invalidConnection
//TODO throw custom error
fatalError("Invalid connection")
}

nodeId = String(parts[0])
address = String(parts[1])
}
}
Loading