Skip to content

Commit 508bfcc

Browse files
committed
New post. Doc update. Swift 6
1 parent 2bee169 commit 508bfcc

File tree

4,284 files changed

+7396
-4384
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,284 files changed

+7396
-4384
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Install Swift
3434
uses: sersoft-gmbh/swifty-linux-action@v3
3535
with:
36-
release-version: 5.9
36+
release-version: 6.0
3737
- name: Build with SwiftySites
3838
run: swift run -c release generate --clean
3939
- name: Upload artifact

.swiftpm/configuration/Package.resolved

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1540"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES"
8+
buildArchitectures = "Automatic">
9+
<BuildActionEntries>
10+
<BuildActionEntry
11+
buildForTesting = "YES"
12+
buildForRunning = "YES"
13+
buildForProfiling = "YES"
14+
buildForArchiving = "YES"
15+
buildForAnalyzing = "YES">
16+
<BuildableReference
17+
BuildableIdentifier = "primary"
18+
BlueprintIdentifier = "generate"
19+
BuildableName = "generate"
20+
BlueprintName = "generate"
21+
ReferencedContainer = "container:">
22+
</BuildableReference>
23+
</BuildActionEntry>
24+
</BuildActionEntries>
25+
</BuildAction>
26+
<TestAction
27+
buildConfiguration = "Debug"
28+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
29+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
30+
shouldUseLaunchSchemeArgsEnv = "YES"
31+
shouldAutocreateTestPlan = "YES">
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "YES"
39+
customWorkingDirectory = "/Users/d/Developer/CraigWrong/swift-bitcoin.github.io"
40+
ignoresPersistentStateOnLaunch = "NO"
41+
debugDocumentVersioning = "YES"
42+
debugServiceExtension = "internal"
43+
allowLocationSimulation = "YES">
44+
<BuildableProductRunnable
45+
runnableDebuggingMode = "0">
46+
<BuildableReference
47+
BuildableIdentifier = "primary"
48+
BlueprintIdentifier = "generate"
49+
BuildableName = "generate"
50+
BlueprintName = "generate"
51+
ReferencedContainer = "container:">
52+
</BuildableReference>
53+
</BuildableProductRunnable>
54+
</LaunchAction>
55+
<ProfileAction
56+
buildConfiguration = "Release"
57+
shouldUseLaunchSchemeArgsEnv = "YES"
58+
savedToolIdentifier = ""
59+
useCustomWorkingDirectory = "NO"
60+
debugDocumentVersioning = "YES">
61+
<BuildableProductRunnable
62+
runnableDebuggingMode = "0">
63+
<BuildableReference
64+
BuildableIdentifier = "primary"
65+
BlueprintIdentifier = "generate"
66+
BuildableName = "generate"
67+
BlueprintName = "generate"
68+
ReferencedContainer = "container:">
69+
</BuildableReference>
70+
</BuildableProductRunnable>
71+
</ProfileAction>
72+
<AnalyzeAction
73+
buildConfiguration = "Debug">
74+
</AnalyzeAction>
75+
<ArchiveAction
76+
buildConfiguration = "Release"
77+
revealArchiveInOrganizer = "YES">
78+
</ArchiveAction>
79+
</Scheme>

Package.resolved

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:6.0
22
import PackageDescription
33

44
let package = Package(
55
name: "SwiftBitcoin",
66
platforms: [.macOS(.v14)],
77
dependencies: [
8-
.package(url: "https://github.com/swiftysites/swiftysites", branch: "release")],
8+
.package(url: "https://github.com/swiftysites/swiftysites", from: "2.0.0")],
99
targets: [
1010
.executableTarget(
1111
name: "generate",

src/content/post/posts2024.swift

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
let post04 = Post("/post/2024-10-06-update", "October Update", "2024-10-06T12:00:00Z", .announcements) { """
2+
3+
So far this year the focus has shifted a bit from getting the client fluent in the peer-to-peer language protocol to making important refinements to many of the public APIs offered by the package.
4+
5+
# New package organization
6+
7+
Swift Bitcoin is now organized in several discreet modules:
8+
9+
- _Crypto_ – Contains all the elliptic curve cryptography needed as well as indispensable hash functions and encodings.
10+
- _Base_ – Focuses on transaction building and verifying, including a full SCRIPT interpreter.
11+
- _Wallet_ – Adds a layer which includes addresses, key derivation, mnemonics and signing.
12+
- _Blockchain_ – Exposes services for blocks, mempool and chain state management, complete with a basic mining algorithm.
13+
- _Transport_ – Introduces the notion of network peers and how they communicate using the P2P protocol.
14+
- _RPC_ – Provides codecs for important remote node commands.
15+
16+
In additions to these libraries, the package delivers two command-line tools:
17+
18+
- _Node_ – Launches an instance of a full node which listens to RPC commands and can speak the wire protocol.
19+
- _Utility_ – Can be used to control running service instances as well as perform a series of offline operations.
20+
21+
# Improved API examples
22+
23+
As an example of the simplicity of the new APIs here's some code snippets taken from the revamped [documentation](https://swift-bitcoin.github.io/docc/documentation/bitcoin/):
24+
25+
## Running a simple script
26+
27+
Here's how to add two numbers:
28+
29+
```swift
30+
let stack = try BitcoinScript([.constant(1), .constant(1), .add]).run()
31+
#expect(stack.count == 1)
32+
let number = try ScriptNumber(stack[0])
33+
#expect(number.value == 2)
34+
```
35+
36+
## Spending a transaction
37+
38+
This is how Bob would send satoshis to Alice:
39+
40+
```swift
41+
// Bob gets paid.
42+
let bobsSecretKey = SecretKey()
43+
let bobsAddress = BitcoinAddress(bobsSecretKey)
44+
45+
// The funding transaction, sending money to Bob.
46+
let fundingTransaction = BitcoinTransaction(inputs: [.init(outpoint: .coinbase)], outputs: [
47+
bobsAddress.output(100) // 100 satoshis
48+
])
49+
50+
// Alice generates an address to give Bob.
51+
52+
let alicesSecretKey = SecretKey()
53+
let alicesAddress = BitcoinAddress(alicesSecretKey)
54+
55+
// Bob constructs, sings and broadcasts a transaction which pays Alice at her address.
56+
57+
// The spending transaction by which Bob sends money to Alice
58+
let spendingTransaction = BitcoinTransaction(inputs: [
59+
.init(outpoint: fundingTransaction.outpoint(0)),
60+
], outputs: [
61+
alicesAddress.output(50) // 50 satoshis
62+
])
63+
64+
// Sign the spending transaction.
65+
let prevouts = [fundingTransaction.outputs[0]]
66+
let signer = TransactionSigner(
67+
transaction: spendingTransaction, prevouts: prevouts, sighashType: .all
68+
)
69+
let signedTransaction = signer.sign(input: 0, with: bobsSecretKey)
70+
71+
// Verify transaction signatures.
72+
let result = signedTransaction.verifyScript(prevouts: prevouts)
73+
#expect(result)
74+
```
75+
76+
## Connecting two nodes
77+
78+
Here's how Hal would connect to Satoshi:
79+
80+
```swift
81+
let satoshiChain = BitcoinService()
82+
let publicKey = try #require(PublicKey(compressed: [0x03, …]))
83+
await satoshiChain.generateTo(publicKey)
84+
85+
let satoshi = NodeService(bitcoinService: satoshiChain, feeFilterRate: 2)
86+
let halPeer = await satoshi.addPeer()
87+
var satoshiOut = await satoshi.getChannel(for: halPeer).makeAsyncIterator()
88+
89+
let halChain = BitcoinService()
90+
let hal = NodeService(bitcoinService: halChain, feeFilterRate: 3)
91+
let satoshiPeer = await hal.addPeer(incoming: false)
92+
var halOut = await hal.getChannel(for: satoshiPeer).makeAsyncIterator()
93+
94+
// Perform the wire protocol handshake (simplified)
95+
96+
await hal.connect(satoshiPeer)
97+
98+
// `messageHS0` means "0th Message from Hal to Satoshi".
99+
100+
// Hal --(version)->> …
101+
let messageHS0_version = try #require(await hal.popMessage(satoshiPeer))
102+
103+
// … --(version)->> Satoshi
104+
try await satoshi.processMessage(messageHS0_version, from: halPeer)
105+
106+
// Satoshi --(version)->> …
107+
let messageSH0_version = try #require(await satoshi.popMessage(halPeer))
108+
109+
// Satoshi --(verack)->> …
110+
let messageSH3_verack = try #require(await satoshi.popMessage(halPeer))
111+
112+
// … --(version)->> Hal
113+
try await hal.processMessage(messageSH0_version, from: satoshiPeer)
114+
115+
// … --(verack)->> Hal
116+
try await hal.processMessage(messageSH3_verack, from: satoshiPeer)
117+
118+
// Hal --(verack)->> …
119+
let messageHS3_verack = try #require(await hal.popMessage(satoshiPeer))
120+
121+
// … --(verack)->> Satoshi
122+
try await satoshi.processMessage(messageHS3_verack, from: halPeer)
123+
```
124+
125+
# Next steps
126+
127+
Going forward the priority should be to get the transport layer to perform an initial block download against a running Core regtest instance.
128+
129+
The blockchain component needs to be developed further including all block related BIPs.
130+
131+
Finally even more tests need to be migrated over to increase the reliability of the implementation.
132+
""" }

src/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import SwiftySites
22

33
let posts = [
4-
post01, post02, post03
4+
post01, post02, post03, post04
55
]
66

77
let site = Site(

src/partials/footerPartial.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import SwiftySites
22

3-
let footerPartial = { (page: Page?) -> String in """
3+
func footerPartial(_ page: Page?) -> String { """
44
<footer>
55
<a href="https://github.com/swift-bitcoin/swift-bitcoin">Cypherpunks write code 👾</a>
66
</footer>

src/partials/navigationPartial.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import SwiftySites
22

3-
let navigationPartial = { (page: Page?) -> String in """
3+
func navigationPartial(_ page: Page?) -> String { """
44
<nav>
55
<ul>
66
\([pageHome, pageInfo].reduce("") {

src/partials/summaryPartial.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import SwiftySites
22

3-
let summaryPartial = { (post: Post) -> String in """
3+
func summaryPartial(_ post: Post) -> String { """
44
<article class="summary">
55
<header>
66
<p class="date"><a href="\(post.path)">\(post.dateFormatted)</a> • <a href="/category/\(post.category)">\(post.category.name)</a></p>

0 commit comments

Comments
 (0)