[wip] swift
This commit is contained in:
parent
c11e17b5e2
commit
6f46e2deb6
@ -1,4 +1,4 @@
|
|||||||
Setup build environment
|
Setup Android build environment
|
||||||
|
|
||||||
1. Add Android rust targets
|
1. Add Android rust targets
|
||||||
|
|
||||||
@ -12,6 +12,10 @@ rustup target add x86_64-apple-darwin x86_64-unknown-linux-gnu x86_64-linux-andr
|
|||||||
export ANDROID_NDK_HOME=/home/<user>/Android/Sdk/ndk/<NDK version, ie. 21.4.7075529>
|
export ANDROID_NDK_HOME=/home/<user>/Android/Sdk/ndk/<NDK version, ie. 21.4.7075529>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Setup Swift build environment
|
||||||
|
|
||||||
|
1. Install Swift, see ["Download Swift"](https://swift.org/download/) page
|
||||||
|
|
||||||
Adding new structs and functions
|
Adding new structs and functions
|
||||||
|
|
||||||
1. Create C safe Rust structs and related functions using safer-ffi
|
1. Create C safe Rust structs and related functions using safer-ffi
|
||||||
|
7
bdk-swift/.gitignore
vendored
Normal file
7
bdk-swift/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
.DS_Store
|
||||||
|
/.build
|
||||||
|
/Packages
|
||||||
|
/*.xcodeproj
|
||||||
|
xcuserdata/
|
||||||
|
DerivedData/
|
||||||
|
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
7
bdk-swift/bdk.swift/.gitignore
vendored
Normal file
7
bdk-swift/bdk.swift/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
.DS_Store
|
||||||
|
/.build
|
||||||
|
/Packages
|
||||||
|
/*.xcodeproj
|
||||||
|
xcuserdata/
|
||||||
|
DerivedData/
|
||||||
|
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
16
bdk-swift/bdk.swift/Package.resolved
Normal file
16
bdk-swift/bdk.swift/Package.resolved
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"object": {
|
||||||
|
"pins": [
|
||||||
|
{
|
||||||
|
"package": "Clibbdkffi",
|
||||||
|
"repositoryURL": "/home/steve/git/notmandatory/Clibbdkffi",
|
||||||
|
"state": {
|
||||||
|
"branch": null,
|
||||||
|
"revision": "9c96e359a3b1e1d5c0db61125147f6ef929bf567",
|
||||||
|
"version": "0.1.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"version": 1
|
||||||
|
}
|
28
bdk-swift/bdk.swift/Package.swift
Normal file
28
bdk-swift/bdk.swift/Package.swift
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// swift-tools-version:5.5
|
||||||
|
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||||
|
|
||||||
|
import PackageDescription
|
||||||
|
|
||||||
|
let package = Package(
|
||||||
|
name: "bdk.swift",
|
||||||
|
products: [
|
||||||
|
// Products define the executables and libraries a package produces, and make them visible to other packages.
|
||||||
|
.library(
|
||||||
|
name: "bdk.swift",
|
||||||
|
targets: ["bdk.swift"]),
|
||||||
|
],
|
||||||
|
dependencies: [
|
||||||
|
// Dependencies declare other packages that this package depends on.
|
||||||
|
.package(url: "../../../Clibbdkffi", from: "0.1.0"),
|
||||||
|
],
|
||||||
|
targets: [
|
||||||
|
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||||
|
// Targets can depend on other targets in this package, and on products in packages this package depends on.
|
||||||
|
.target(
|
||||||
|
name: "bdk.swift",
|
||||||
|
dependencies: ["Clibbdkffi"]),
|
||||||
|
.testTarget(
|
||||||
|
name: "bdk.swiftTests",
|
||||||
|
dependencies: ["bdk.swift"]),
|
||||||
|
]
|
||||||
|
)
|
11
bdk-swift/bdk.swift/README.md
Normal file
11
bdk-swift/bdk.swift/README.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# bdk.swift
|
||||||
|
|
||||||
|
To build:
|
||||||
|
```
|
||||||
|
swift build -Xlinker -L../../target/debug
|
||||||
|
```
|
||||||
|
|
||||||
|
To test:
|
||||||
|
```
|
||||||
|
swift test -Xlinker -L../../target/debug
|
||||||
|
```
|
8
bdk-swift/bdk.swift/Sources/bdk.swift/bdk_swift.swift
Normal file
8
bdk-swift/bdk.swift/Sources/bdk.swift/bdk_swift.swift
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import Clibbdkffi
|
||||||
|
|
||||||
|
public struct bdk_swift {
|
||||||
|
public private(set) var text = "Hello, World!"
|
||||||
|
|
||||||
|
public init() {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
import XCTest
|
||||||
|
import Clibbdkffi
|
||||||
|
|
||||||
|
@testable import bdk_swift
|
||||||
|
|
||||||
|
final class bdk_swiftTests: XCTestCase {
|
||||||
|
func testExample() throws {
|
||||||
|
// This is an example of a functional test case.
|
||||||
|
// Use XCTAssert and related functions to verify your tests produce the correct
|
||||||
|
// results.
|
||||||
|
XCTAssertEqual(bdk_swift().text, "Hello, World!")
|
||||||
|
let desc = "wpkh([bf988dd3/84'/1'/0']tpubDD7bHVspyCSvvU8qEycydF664NAX6EAPjJ77j9E614GU2zVdXgnZZo6JJjKbDT6fUn8owMN6TCP9rZMznsNEhJbpkEwp6fAyyoSqy3DH2Qj/0/*)";
|
||||||
|
let change = "wpkh([bf988dd3/84'/1'/0']tpubDD7bHVspyCSvvU8qEycydF664NAX6EAPjJ77j9E614GU2zVdXgnZZo6JJjKbDT6fUn8owMN6TCP9rZMznsNEhJbpkEwp6fAyyoSqy3DH2Qj/1/*)";
|
||||||
|
let net = "testnet";
|
||||||
|
let blocks = "ssl://electrum.blockstream.info:60002";
|
||||||
|
|
||||||
|
let bc_config = new_electrum_config(blocks, nil, 5, 30, 100)
|
||||||
|
let db_config = new_memory_config()
|
||||||
|
|
||||||
|
let wallet_result = new_wallet_result(desc,change,net,bc_config,db_config)
|
||||||
|
|
||||||
|
free_blockchain_config(bc_config)
|
||||||
|
free_database_config(db_config)
|
||||||
|
|
||||||
|
let wallet = wallet_result.ok
|
||||||
|
let sync_result = sync_wallet(wallet)
|
||||||
|
assert(sync_result.err == FFI_ERROR_NONE)
|
||||||
|
free_void_result(sync_result)
|
||||||
|
|
||||||
|
let address1_result = new_address(wallet).ok
|
||||||
|
let address1 = String(cString: address1_result!, encoding: .utf8)
|
||||||
|
//print("address1 = \(address1!)")
|
||||||
|
assert(address1! == "tb1qh4ajvhz9nd76tqddnl99l89hx4dat33hrjauzw")
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user