-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: quickstart in swift is now runnable
- Loading branch information
1 parent
308fce9
commit 34876cc
Showing
6 changed files
with
101 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/configuration/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"originHash" : "80a7f511dc9201d59f1672d17a6a92dca3d40856c08e16f03e8087f59734809a", | ||
"pins" : [ | ||
{ | ||
"identity" : "bdk-swift", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/bitcoindevkit/bdk-swift", | ||
"state" : { | ||
"revision" : "875877e5c5eb753df2673958ee2f54a5360581f7", | ||
"version" : "1.0.0-beta.5" | ||
} | ||
} | ||
], | ||
"version" : 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// swift-tools-version: 5.10 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "QuickstartExample", | ||
platforms: [ | ||
.macOS(.v12) | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/bitcoindevkit/bdk-swift", from: "1.0.0-beta.5") | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "QuickstartExample", | ||
dependencies: [ | ||
.product(name: "BitcoinDevKit", package: "bdk-swift") | ||
], | ||
path: "Sources" | ||
) | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// --8<-- [start:file] | ||
import BitcoinDevKit | ||
|
||
// --8<-- [start:descriptors] | ||
let descriptor = try Descriptor(descriptor: "tr([12071a7c/86'/1'/0']tpubDCaLkqfh67Qr7ZuRrUNrCYQ54sMjHfsJ4yQSGb3aBr1yqt3yXpamRBUwnGSnyNnxQYu7rqeBiPfw3mjBcFNX4ky2vhjj9bDrGstkfUbLB9T/0/*)#z3x5097m", network: Network.signet) | ||
let changeDescriptor = try Descriptor(descriptor: "tr([12071a7c/86'/1'/0']tpubDCaLkqfh67Qr7ZuRrUNrCYQ54sMjHfsJ4yQSGb3aBr1yqt3yXpamRBUwnGSnyNnxQYu7rqeBiPfw3mjBcFNX4ky2vhjj9bDrGstkfUbLB9T/1/*)#n9r4jswr", network: Network.signet) | ||
// --8<-- [end:descriptors] | ||
|
||
let wallet = try Wallet( | ||
descriptor: descriptor, | ||
changeDescriptor: changeDescriptor, | ||
network: Network.signet, | ||
connection: Connection.newInMemory() | ||
) | ||
|
||
let addressInfo = wallet.revealNextAddress(keychain: .external) | ||
print("Generated address \(addressInfo.address) at index \(addressInfo.index)") | ||
|
||
// --8<-- [start:client] | ||
let esploraClient = EsploraClient(url: "https://mutinynet.com/api") | ||
// --8<-- [end:client] | ||
|
||
// --8<-- [start:scan] | ||
let syncRequest = try wallet.startSyncWithRevealedSpks().build() | ||
let update = try esploraClient.sync( | ||
syncRequest: syncRequest, | ||
parallelRequests: UInt64(5) | ||
) | ||
try wallet.applyUpdate(update: update) | ||
let balance = wallet.balance() | ||
print("Wallet balance: \(balance.total.toSat()) sat") | ||
// --8<-- [end:scan] | ||
|
||
// --8<-- [end:file] |
This file was deleted.
Oops, something went wrong.