Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift5 #222

Merged
merged 7 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode10
osx_image: xcode10.3
cache:
directories:
- Libraries
Expand Down
4 changes: 2 additions & 2 deletions BitcoinKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'BitcoinKit'
spec.version = '1.0.2'
spec.version = '1.1.0-beta5'
spec.summary = 'Bitcoin(BCH/BTC) protocol toolkit for Swift'
spec.description = <<-DESC
The BitcoinKit library is a Swift implementation of the Bitcoin(BCH/BTC) protocol. This library was originally made by Katsumi Kishikawa, and now is maintained by Yenom Inc. It allows maintaining a wallet and sending/receiving transactions without needing a full blockchain node. It comes with a simple wallet app showing how to use it.
Expand All @@ -17,7 +17,7 @@ Pod::Spec.new do |spec|
spec.exclude_files = 'Sources/**/LinuxSupport.swift'
spec.module_map = 'BitcoinKit/BitcoinKit.modulemap'
spec.ios.deployment_target = '8.0'
spec.swift_version = '4.1'
spec.swift_version = '5.0'

spec.pod_target_xcconfig = { 'SWIFT_WHOLE_MODULE_OPTIMIZATION' => 'YES',
'APPLICATION_EXTENSION_API_ONLY' => 'YES',
Expand Down
8 changes: 4 additions & 4 deletions BitcoinKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
6E20AED72112D417008A9810 /* MurmurHashTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E20AED62112D417008A9810 /* MurmurHashTests.swift */; };
6E797C452116C8A5003BEDFD /* OpCodeFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E797C442116C8A5003BEDFD /* OpCodeFactoryTests.swift */; };
6EE789DB2112C1E500EAB620 /* CryptoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EE789DA2112C1E500EAB620 /* CryptoTests.swift */; };
A201ABB6222ACF7100DEFE13 /* BitcoinKitPrivateSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = A201ABB5222ACF7100DEFE13 /* BitcoinKitPrivateSwift.swift */; };
A20B537F211C72F9009D147A /* UInt256Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A20B537E211C72F9009D147A /* UInt256Tests.swift */; };
A246ED102118621B0000418D /* MerkleTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = A246ED0F2118621B0000418D /* MerkleTree.swift */; };
A246ED12211864500000418D /* UInt256.swift in Sources */ = {isa = PBXBuildFile; fileRef = A246ED11211864500000418D /* UInt256.swift */; };
Expand All @@ -220,7 +221,6 @@
A2DE5110212AFCF200F54EA0 /* UInt256+BitcoinTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2DE510F212AFCF200F54EA0 /* UInt256+BitcoinTests.swift */; };
A2E11231212C400A00A0A40A /* ProofOfWorkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2E11230212C400A00A0A40A /* ProofOfWorkTests.swift */; };
A2F06FBA2126785200DFF652 /* UInt32+Utility.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2F06FB92126785200DFF652 /* UInt32+Utility.swift */; };
A201ABB6222ACF7100DEFE13 /* BitcoinKitPrivateSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = A201ABB5222ACF7100DEFE13 /* BitcoinKitPrivateSwift.swift */; };
CF432AF220F0CF9100AD4020 /* Base58Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF432AF120F0CF9100AD4020 /* Base58Tests.swift */; };
CF432AF420F0DFAC00AD4020 /* Bech32Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF432AF320F0DFAC00AD4020 /* Bech32Tests.swift */; };
CF432AF620F0ED4500AD4020 /* AddressTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF432AF520F0ED4500AD4020 /* AddressTests.swift */; };
Expand Down Expand Up @@ -455,6 +455,7 @@
6E20AED62112D417008A9810 /* MurmurHashTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MurmurHashTests.swift; sourceTree = "<group>"; };
6E797C442116C8A5003BEDFD /* OpCodeFactoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpCodeFactoryTests.swift; sourceTree = "<group>"; };
6EE789DA2112C1E500EAB620 /* CryptoTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CryptoTests.swift; sourceTree = "<group>"; };
A201ABB5222ACF7100DEFE13 /* BitcoinKitPrivateSwift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = BitcoinKitPrivateSwift.swift; path = Core/BitcoinKitPrivateSwift.swift; sourceTree = "<group>"; };
A20B537E211C72F9009D147A /* UInt256Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UInt256Tests.swift; sourceTree = "<group>"; };
A246ED0F2118621B0000418D /* MerkleTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MerkleTree.swift; sourceTree = "<group>"; };
A246ED11211864500000418D /* UInt256.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UInt256.swift; sourceTree = "<group>"; };
Expand All @@ -466,7 +467,6 @@
A2DE510F212AFCF200F54EA0 /* UInt256+BitcoinTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UInt256+BitcoinTests.swift"; sourceTree = "<group>"; };
A2E11230212C400A00A0A40A /* ProofOfWorkTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProofOfWorkTests.swift; sourceTree = "<group>"; };
A2F06FB92126785200DFF652 /* UInt32+Utility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UInt32+Utility.swift"; sourceTree = "<group>"; };
A201ABB5222ACF7100DEFE13 /* BitcoinKitPrivateSwift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = BitcoinKitPrivateSwift.swift; path = Core/BitcoinKitPrivateSwift.swift; sourceTree = "<group>"; };
CF432AF120F0CF9100AD4020 /* Base58Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base58Tests.swift; sourceTree = "<group>"; };
CF432AF320F0DFAC00AD4020 /* Bech32Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bech32Tests.swift; sourceTree = "<group>"; };
CF432AF520F0ED4500AD4020 /* AddressTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1488,7 +1488,7 @@
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "$(SRCROOT)/Libraries";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand Down Expand Up @@ -1526,7 +1526,7 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "$(SRCROOT)/Libraries";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:4.0
// swift-tools-version:5.0
import PackageDescription

let package = Package(
Expand All @@ -25,5 +25,5 @@ let package = Package(
dependencies: ["BitcoinKit"]
)
],
swiftLanguageVersions: [4]
swiftLanguageVersions: [.v5]
)
31 changes: 22 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
![BitcoinKit: Let’s Play with Bitcoin in Swift!](https://user-images.githubusercontent.com/23519083/44261174-cc64aa00-a251-11e8-85b6-145e0bcae102.jpg)

[![CI Status](http://img.shields.io/travis/yenom/BitcoinKit.svg)](https://travis-ci.org/yenom/BitcoinKit)
[![codecov](https://codecov.io/gh/yenom/BitcoinKit/branch/master/graph/badge.svg)](https://codecov.io/gh/yenom/BitcoinKit)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Version](https://img.shields.io/cocoapods/v/BitcoinKit.svg)](http://cocoadocs.org/docsets/BitcoinKit)
[![Platform](https://img.shields.io/cocoapods/p/BitcoinKit.svg)](http://cocoadocs.org/docsets/BitcoinKit)
[![Backers on Open Collective](https://opencollective.com/BitcoinKit/backers/badge.svg)](#backers)
[![Sponsors on Open Collective](https://opencollective.com/BitcoinKit/sponsors/badge.svg)](#sponsors)
<p align="center">
<img src="https://user-images.githubusercontent.com/23519083/44261174-cc64aa00-a251-11e8-85b6-145e0bcae102.jpg" alt="BitcoinKit: Let’s Play with Bitcoin in Swift!">
<a href="https://travis-ci.org/yenom/BitcoinKit">
<img src="http://img.shields.io/travis/yenom/BitcoinKit.svg" alt="TravisCI">
</a>
<a href="https://codecov.io/gh/yenom/BitcoinKit">
<img src="https://codecov.io/gh/yenom/BitcoinKit/branch/master/graph/badge.svg" />
</a>
<a href="https://swift.org">
<img src="http://img.shields.io/badge/swift-5.0+-brightgreen.svg" alt="Swift 5.0+">
</a>
<a href="https://github.com/Carthage/Carthage">
<img src="https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat" alt="Carthage">
</a>
<a href="https://swift.org/package-manager">
<img src="https://img.shields.io/badge/spm-compatible-brightgreen.svg?style=flat" alt="Swift Package Manager" />
</a>
<a href="http://cocoadocs.org/docsets/BitcoinKit">
<img src="https://img.shields.io/cocoapods/v/BitcoinKit.svg" alt="CococaPods" />
</a>
</p>


### Welcome to BitcoinKit

Expand Down
12 changes: 6 additions & 6 deletions Sources/BitcoinKit/Core/BitcoinKitPrivateSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class _SwiftKey {
if outputlen != 33 {
return Data()
}
return Data(bytes: serializedPubkey)
return Data(serializedPubkey)
} else {
var serializedPubkey = [UInt8](repeating: 0, count: 65)
var outputlen = 65
Expand All @@ -60,7 +60,7 @@ class _SwiftKey {
if outputlen != 65 {
return Data()
}
return Data(bytes: serializedPubkey)
return Data(serializedPubkey)
}
}
}
Expand Down Expand Up @@ -110,7 +110,7 @@ class _HDKey {
if secp256k1_ec_privkey_tweak_add(ctx, &privateKeyBytes, &derivedPrivateKeyBytes) == 0 {
return nil
}
result = Data(bytes: privateKeyBytes)
result = Data(privateKeyBytes)
} else {
guard let ctx = secp256k1_context_create(UInt32(SECP256K1_CONTEXT_VERIFY)) else {
return nil
Expand All @@ -129,10 +129,10 @@ class _HDKey {
if secp256k1_ec_pubkey_serialize(ctx, &compressedPublicKeyBytes, &compressedPublicKeyBytesLen, &secpPubkey, UInt32(SECP256K1_EC_COMPRESSED)) == 0 {
return nil
}
result = Data(bytes: compressedPublicKeyBytes)
result = Data(compressedPublicKeyBytes)
}
let fingerPrint: UInt32 = _Hash.sha256ripemd160(publicKey).withUnsafeBytes { $0.pointee }
return _HDKey(privateKey: result, publicKey: result, chainCode: Data(bytes: derivedChainCode), depth: self.depth + 1, fingerprint: fingerPrint, childIndex: childIndex)
let fingerPrint: UInt32 = _Hash.sha256ripemd160(publicKey).to(type: UInt32.self)
return _HDKey(privateKey: result, publicKey: result, chainCode: Data(derivedChainCode), depth: self.depth + 1, fingerprint: fingerPrint, childIndex: childIndex)
}
}
#endif
32 changes: 16 additions & 16 deletions Sources/BitcoinKit/Core/BlockStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ public class SQLiteBlockStore: BlockStore {
public func addBlock(_ block: BlockMessage, hash: Data) throws {
let stmt = statements["addBlock"]

try execute { hash.withUnsafeBytes { sqlite3_bind_blob(stmt, 1, $0, Int32(hash.count), SQLITE_TRANSIENT) } }
try execute { hash.withUnsafeBytes { sqlite3_bind_blob(stmt, 1, $0.baseAddress.unsafelyUnwrapped, Int32(hash.count), SQLITE_TRANSIENT) } }
try execute { sqlite3_bind_int64(stmt, 2, sqlite3_int64(bitPattern: UInt64(truncatingIfNeeded: block.version))) }
try execute { block.prevBlock.withUnsafeBytes { sqlite3_bind_blob(stmt, 3, $0, Int32(block.prevBlock.count), SQLITE_TRANSIENT) } }
try execute { block.merkleRoot.withUnsafeBytes { sqlite3_bind_blob(stmt, 4, $0, Int32(block.merkleRoot.count), SQLITE_TRANSIENT) } }
try execute { block.prevBlock.withUnsafeBytes { sqlite3_bind_blob(stmt, 3, $0.baseAddress.unsafelyUnwrapped, Int32(block.prevBlock.count), SQLITE_TRANSIENT) } }
try execute { block.merkleRoot.withUnsafeBytes { sqlite3_bind_blob(stmt, 4, $0.baseAddress.unsafelyUnwrapped, Int32(block.merkleRoot.count), SQLITE_TRANSIENT) } }
try execute { sqlite3_bind_int64(stmt, 5, sqlite3_int64(bitPattern: UInt64(truncatingIfNeeded: block.timestamp))) }
try execute { sqlite3_bind_int64(stmt, 6, sqlite3_int64(bitPattern: UInt64(truncatingIfNeeded: block.bits))) }
try execute { sqlite3_bind_int64(stmt, 7, sqlite3_int64(bitPattern: UInt64(truncatingIfNeeded: block.nonce))) }
Expand All @@ -307,20 +307,20 @@ public class SQLiteBlockStore: BlockStore {
public func addMerkleBlock(_ merkleBlock: MerkleBlockMessage, hash: Data) throws {
let stmt = statements["addMerkleBlock"]

try execute { hash.withUnsafeBytes { sqlite3_bind_blob(stmt, 1, $0, Int32(hash.count), SQLITE_TRANSIENT) } }
try execute { hash.withUnsafeBytes { sqlite3_bind_blob(stmt, 1, $0.baseAddress.unsafelyUnwrapped, Int32(hash.count), SQLITE_TRANSIENT) } }
try execute { sqlite3_bind_int64(stmt, 2, sqlite3_int64(bitPattern: UInt64(truncatingIfNeeded: merkleBlock.version))) }
try execute { merkleBlock.prevBlock.withUnsafeBytes { sqlite3_bind_blob(stmt, 3, $0, Int32(merkleBlock.prevBlock.count), SQLITE_TRANSIENT) } }
try execute { merkleBlock.merkleRoot.withUnsafeBytes { sqlite3_bind_blob(stmt, 4, $0, Int32(merkleBlock.merkleRoot.count), SQLITE_TRANSIENT) } }
try execute { merkleBlock.prevBlock.withUnsafeBytes { sqlite3_bind_blob(stmt, 3, $0.baseAddress.unsafelyUnwrapped, Int32(merkleBlock.prevBlock.count), SQLITE_TRANSIENT) } }
try execute { merkleBlock.merkleRoot.withUnsafeBytes { sqlite3_bind_blob(stmt, 4, $0.baseAddress.unsafelyUnwrapped, Int32(merkleBlock.merkleRoot.count), SQLITE_TRANSIENT) } }
try execute { sqlite3_bind_int64(stmt, 5, sqlite3_int64(bitPattern: UInt64(truncatingIfNeeded: merkleBlock.timestamp))) }
try execute { sqlite3_bind_int64(stmt, 6, sqlite3_int64(bitPattern: UInt64(truncatingIfNeeded: merkleBlock.bits))) }
try execute { sqlite3_bind_int64(stmt, 7, sqlite3_int64(bitPattern: UInt64(truncatingIfNeeded: merkleBlock.nonce))) }
try execute { sqlite3_bind_int64(stmt, 8, sqlite3_int64(bitPattern: UInt64(truncatingIfNeeded: merkleBlock.totalTransactions))) }
try execute { sqlite3_bind_int64(stmt, 9, sqlite3_int64(bitPattern: merkleBlock.numberOfHashes.underlyingValue)) }
let hashes = Data(merkleBlock.hashes.flatMap { $0 })
try execute { hashes.withUnsafeBytes { sqlite3_bind_blob(stmt, 10, $0, Int32(hashes.count), SQLITE_TRANSIENT) } }
try execute { hashes.withUnsafeBytes { sqlite3_bind_blob(stmt, 10, $0.baseAddress.unsafelyUnwrapped, Int32(hashes.count), SQLITE_TRANSIENT) } }
try execute { sqlite3_bind_int64(stmt, 11, sqlite3_int64(bitPattern: merkleBlock.numberOfFlags.underlyingValue)) }
let flags = Data(merkleBlock.flags)
try execute { flags.withUnsafeBytes { sqlite3_bind_blob(stmt, 12, $0, Int32(flags.count), SQLITE_TRANSIENT) } }
try execute { flags.withUnsafeBytes { sqlite3_bind_blob(stmt, 12, $0.baseAddress.unsafelyUnwrapped, Int32(flags.count), SQLITE_TRANSIENT) } }

try executeUpdate { sqlite3_step(stmt) }
try execute { sqlite3_reset(stmt) }
Expand All @@ -329,7 +329,7 @@ public class SQLiteBlockStore: BlockStore {
public func addTransaction(_ transaction: Transaction, hash: Data) throws {
let stmt = statements["addTransaction"]

try execute { hash.withUnsafeBytes { sqlite3_bind_blob(stmt, 1, $0, Int32(hash.count), SQLITE_TRANSIENT) } }
try execute { hash.withUnsafeBytes { sqlite3_bind_blob(stmt, 1, $0.baseAddress.unsafelyUnwrapped, Int32(hash.count), SQLITE_TRANSIENT) } }
try execute { sqlite3_bind_int64(stmt, 2, sqlite3_int64(bitPattern: UInt64(truncatingIfNeeded: transaction.version))) }
try execute { sqlite3_bind_int(stmt, 3, 0) } // Not supported 'flag' currently
try execute { sqlite3_bind_int64(stmt, 4, sqlite3_int64(bitPattern: transaction.txInCount.underlyingValue)) }
Expand All @@ -353,10 +353,10 @@ public class SQLiteBlockStore: BlockStore {
let stmt = statements["addTransactionInput"]

try execute { sqlite3_bind_int64(stmt, 1, sqlite3_int64(bitPattern: input.scriptLength.underlyingValue)) }
try execute { input.signatureScript.withUnsafeBytes { sqlite3_bind_blob(stmt, 2, $0, Int32(input.signatureScript.count), SQLITE_TRANSIENT) } }
try execute { input.signatureScript.withUnsafeBytes { sqlite3_bind_blob(stmt, 2, $0.baseAddress.unsafelyUnwrapped, Int32(input.signatureScript.count), SQLITE_TRANSIENT) } }
try execute { sqlite3_bind_int64(stmt, 3, sqlite3_int64(bitPattern: UInt64(truncatingIfNeeded: input.sequence))) }
try execute { txId.withUnsafeBytes { sqlite3_bind_blob(stmt, 4, $0, Int32(txId.count), SQLITE_TRANSIENT) } }
try execute { input.previousOutput.hash.withUnsafeBytes { sqlite3_bind_blob(stmt, 5, $0, Int32(input.previousOutput.hash.count), SQLITE_TRANSIENT) } }
try execute { txId.withUnsafeBytes { sqlite3_bind_blob(stmt, 4, $0.baseAddress.unsafelyUnwrapped, Int32(txId.count), SQLITE_TRANSIENT) } }
try execute { input.previousOutput.hash.withUnsafeBytes { sqlite3_bind_blob(stmt, 5, $0.baseAddress.unsafelyUnwrapped, Int32(input.previousOutput.hash.count), SQLITE_TRANSIENT) } }

try executeUpdate { sqlite3_step(stmt) }
try execute { sqlite3_reset(stmt) }
Expand All @@ -368,8 +368,8 @@ public class SQLiteBlockStore: BlockStore {
try execute { sqlite3_bind_int64(stmt, 1, sqlite3_int64(bitPattern: UInt64(truncatingIfNeeded: index))) }
try execute { sqlite3_bind_int64(stmt, 2, sqlite3_int64(bitPattern: UInt64(truncatingIfNeeded: output.value))) }
try execute { sqlite3_bind_int64(stmt, 3, sqlite3_int64(bitPattern: output.scriptLength.underlyingValue)) }
try execute { output.lockingScript.withUnsafeBytes { sqlite3_bind_blob(stmt, 4, $0, Int32(output.lockingScript.count), SQLITE_TRANSIENT) } }
try execute { txId.withUnsafeBytes { sqlite3_bind_blob(stmt, 5, $0, Int32(txId.count), SQLITE_TRANSIENT) } }
try execute { output.lockingScript.withUnsafeBytes { sqlite3_bind_blob(stmt, 4, $0.baseAddress.unsafelyUnwrapped, Int32(output.lockingScript.count), SQLITE_TRANSIENT) } }
try execute { txId.withUnsafeBytes { sqlite3_bind_blob(stmt, 5, $0.baseAddress.unsafelyUnwrapped, Int32(txId.count), SQLITE_TRANSIENT) } }
if Script.isPublicKeyHashOut(output.lockingScript) {
let pubKeyHash = Script.getPublicKeyHash(from: output.lockingScript)
let address = publicKeyHashToAddress(Data([network.pubkeyhash]) + pubKeyHash)
Expand All @@ -382,14 +382,14 @@ public class SQLiteBlockStore: BlockStore {

private func deleteTransactionInput(txId: Data) throws {
let stmt = statements["deleteTransactionInput"]
try execute { txId.withUnsafeBytes { sqlite3_bind_blob(stmt, 1, $0, Int32(txId.count), SQLITE_TRANSIENT) } }
try execute { txId.withUnsafeBytes { sqlite3_bind_blob(stmt, 1, $0.baseAddress.unsafelyUnwrapped, Int32(txId.count), SQLITE_TRANSIENT) } }
try executeUpdate { sqlite3_step(stmt) }
try execute { sqlite3_reset(stmt) }
}

private func deleteTransactionOutput(txId: Data) throws {
let stmt = statements["deleteTransactionOutput"]
try execute { txId.withUnsafeBytes { sqlite3_bind_blob(stmt, 1, $0, Int32(txId.count), SQLITE_TRANSIENT) } }
try execute { txId.withUnsafeBytes { sqlite3_bind_blob(stmt, 1, $0.baseAddress.unsafelyUnwrapped, Int32(txId.count), SQLITE_TRANSIENT) } }
try executeUpdate { sqlite3_step(stmt) }
try execute { sqlite3_reset(stmt) }
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/BitcoinKit/Core/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func pton(_ address: String) -> Data {
inet_pton(AF_INET6, address, UnsafeMutablePointer($0))
}
var buffer = Data(count: 16)
_ = buffer.withUnsafeMutableBytes { memcpy($0, &addr, 16) }
_ = buffer.withUnsafeMutableBytes { memcpy($0.baseAddress.unsafelyUnwrapped, &addr, 16) }
return buffer
}

Expand Down
Loading