Skip to content

Commit

Permalink
Initial version of Bitcoin Widgets iOS application
Browse files Browse the repository at this point in the history
  • Loading branch information
yanascz committed Jun 15, 2022
0 parents commit 749fa1c
Show file tree
Hide file tree
Showing 74 changed files with 2,707 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xcuserdata/
15 changes: 15 additions & 0 deletions App/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"colors" : [
{
"color" : {
"platform" : "universal",
"reference" : "systemOrangeColor"
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 116 additions & 0 deletions App/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"images" : [
{
"filename" : "BitcoinWidgets_40px-2.png",
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"filename" : "BitcoinWidgets_60px.png",
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"filename" : "BitcoinWidgets_58px.png",
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"filename" : "BitcoinWidgets_87px.png",
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"filename" : "BitcoinWidgets_80px.png",
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"filename" : "BitcoinWidgets_120px-1.png",
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"filename" : "BitcoinWidgets_120px.png",
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"filename" : "BitcoinWidgets_180px.png",
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"filename" : "BitcoinWidgets_20px.png",
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"filename" : "BitcoinWidgets_40px-1.png",
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"filename" : "BitcoinWidgets_29px.png",
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"filename" : "BitcoinWidgets_58px-1.png",
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"filename" : "BitcoinWidgets_40px.png",
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"filename" : "BitcoinWidgets_80px-1.png",
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"filename" : "BitcoinWidgets_76px.png",
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"filename" : "BitcoinWidgets_152px.png",
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"filename" : "BitcoinWidgets_167px.png",
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"filename" : "BitcoinWidgets_1024px.png",
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
3 changes: 3 additions & 0 deletions App/Assets.xcassets/Bitcoin.imageset/Bitcoin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions App/Assets.xcassets/Bitcoin.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "Bitcoin.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions App/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
20 changes: 20 additions & 0 deletions App/Assets.xcassets/LaunchScreenBackground.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x00",
"green" : "0x00",
"red" : "0x00"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
26 changes: 26 additions & 0 deletions App/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UILaunchScreen</key>
<dict>
<key>UIColorName</key>
<string>LaunchScreenBackground</string>
<key>UIImageName</key>
<string>Bitcoin</string>
<key>UIImageRespectsSafeAreaInsets</key>
<true/>
</dict>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>NSUserActivityTypes</key>
<array>
<string>ConfigurationIntent</string>
</array>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
</dict>
</dict>
</plist>
11 changes: 11 additions & 0 deletions App/Sources/BitcoinWidgetsApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import SwiftUI

@main
struct BitcoinWidgetsApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.preferredColorScheme(.dark)
}
}
}
46 changes: 46 additions & 0 deletions App/Sources/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import SwiftUI

struct ContentView: View {

var body: some View {
VStack {
HStack {
Image(uiImage: UIImage(named: "AppIcon")!)
.resizable()
.frame(width: 29, height: 29)
Text("Bitcoin Widgets")
.font(.title)
}.padding()
List {
Section(header: Text("Add to Today View").font(.title2)) {
Label("From the Home Screen, swipe right to access the Today View.", systemImage: "1.circle.fill")
Label("Scroll down and tap the Edit button, then tap the Add button in the upper-left corner.", systemImage: "2.circle.fill")
Label("Look up Bitcoin Widgets, then choose desired widget and size.", systemImage: "3.circle.fill")
Label("Tap Add Widget, then tap Done.", systemImage: "4.circle.fill")
}
Section(header: Text("Add to Home Screen").font(.title2)) {
Label("From the Home Screen, touch and hold a widget or an empty area until the apps jiggle.", systemImage: "1.circle.fill")
Label("Tap the Add button in the upper-left corner.", systemImage: "2.circle.fill")
Label("Look up Bitcoin Widgets, then choose desired widget and size.", systemImage: "3.circle.fill")
Label("Tap Add Widget, then tap Done.", systemImage: "4.circle.fill")
}
Section(header: Text("Configure").font(.title2)) {
Label("Touch and hold a widget until menu appears, then tap Edit Widget.", systemImage: "1.circle.fill")
Label("Provide required properties, then tap anywhere when done.", systemImage: "2.circle.fill")
}
Section(header: Text("Find out more").font(.title2)) {
LabelLink("Source code", url: "https://github.com/yanascz/bitcoin-widgets-ios", systemImage: "chevron.left.forwardslash.chevron.right")
LabelLink("Issue tracking", url: "https://github.com/yanascz/bitcoin-widgets-ios/issues",
systemImage: "ladybug.fill")
}
}.listStyle(.plain)
}
}

}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
28 changes: 28 additions & 0 deletions App/Sources/LabelLink.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import SwiftUI

struct LabelLink: View {

let title: String
let destination: URL
let systemImage: String

init (_ title: String, url: String, systemImage: String) {
self.title = title
self.destination = URL(string: url)!
self.systemImage = systemImage
}

var body: some View {
Label {
HStack {
Link(title, destination: destination)
Spacer()
Image(systemName: "chevron.right")
.foregroundColor(.secondary)
}
} icon: {
Image(systemName: systemImage)
}
}

}
60 changes: 60 additions & 0 deletions BitcoinClient/Sources/BitcoinClient.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import Foundation
import Network

class BitcoinClient {

private let urlSession = URLSession.init(configuration: .ephemeral)

private let host: String
private let port: Int

init(host: String, port: Int) {
self.host = host
self.port = port
}

func getVersionMessage() async throws -> VersionMessage {
let streamTask = urlSession.streamTask(withHostName: host, port: port)
streamTask.resume()

try await streamTask.write(clientVersionMessage)

guard let headerData = try await streamTask.readData(length: MessageHeader.size) else {
throw BitcoinClientError.communicationFailure
}

let header = MessageHeader(from: headerData)

guard header.magicNumber == MagicNumber.main.rawValue else {
throw BitcoinClientError.invalidMagicNumber
}
guard header.command == VersionMessage.command else {
throw BitcoinClientError.protocolViolation
}

guard let messageData = try await streamTask.readData(length: Int(header.payloadSize)) else {
throw BitcoinClientError.communicationFailure
}
guard messageData.checksum == header.payloadChecksum else {
throw BitcoinClientError.protocolViolation
}

return VersionMessage(from: messageData)
}

private var clientVersionMessage: VersionMessage {
return VersionMessage(
protocolVersion: 70001,
userAgent: "/BitcoinClient:1.0.0/",
timestamp: Date.now,
nonce: UInt64.random(in: UInt64.min...UInt64.max)
)
}

}

enum BitcoinClientError: Error {
case communicationFailure
case invalidMagicNumber
case protocolViolation
}
Loading

0 comments on commit 749fa1c

Please sign in to comment.