Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Binary file removed .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import HSCryptoKit
import OpenSslKit
import BitcoinCore
import AtomicSwapCore

Expand All @@ -22,7 +22,7 @@ public class BitcoinSwapBlockchain: ISwapBlockchain {
}

public var synced: Bool {
return (kit?.syncState ?? .notSynced) == .synced
(kit?.syncState ?? .notSynced(error: BitcoinCore.StateError.notStarted)) == .synced
}

public func changePublicKey() throws -> AtomicSwapCore.PublicKey {
Expand All @@ -46,16 +46,16 @@ public class BitcoinSwapBlockchain: ISwapBlockchain {

public func watchBailTransaction(withRedeemKeyHash redeemKeyHash: Data, refundKeyHash: Data, secretHash: Data, timestamp: Int) {
let redeemScript = scriptBuilder.redeemScript(redeemKeyHash: redeemKeyHash, refundKeyHash: refundKeyHash, secretHash: secretHash, timestamp: timestamp)
let scriptHash = CryptoKit.sha256ripemd160(redeemScript)
let scriptHash = Kit.sha256ripemd160(redeemScript)

kit?.watch(transaction: BitcoinCore.TransactionFilter.p2shOutput(scriptHash: scriptHash), delegate: self)
}

public func sendBailTransaction(withRedeemKeyHash redeemKeyHash: Data, refundKeyHash: Data, secretHash: Data, timestamp: Int, amount: Double) throws -> IBailTransaction {
let redeemScript = scriptBuilder.redeemScript(redeemKeyHash: redeemKeyHash, refundKeyHash: refundKeyHash, secretHash: secretHash, timestamp: timestamp)
let scriptHash = CryptoKit.sha256ripemd160(redeemScript)
let scriptHash = Kit.sha256ripemd160(redeemScript)

guard let transaction = try kit?.send(to: scriptHash, scriptType: .p2sh, value: Int(amount * BitcoinSwapBlockchain.satoshiPerBitcoin), feeRate: 42) else {
guard let transaction = try kit?.send(to: scriptHash, scriptType: .p2sh, value: Int(amount * BitcoinSwapBlockchain.satoshiPerBitcoin), feeRate: 42, sortType: .shuffle) else {
throw BitcoinKitSwapBlockchainError.transactionNotSent
}

Expand All @@ -82,7 +82,7 @@ public class BitcoinSwapBlockchain: ISwapBlockchain {
}

let redeemScript = scriptBuilder.redeemScript(redeemKeyHash: redeemKeyHash, refundKeyHash: refundKeyHash, secretHash: secretHash, timestamp: timestamp)
let scriptHash = CryptoKit.sha256ripemd160(redeemScript)
let scriptHash = Kit.sha256ripemd160(redeemScript)

guard let kit = self.kit else {
return
Expand All @@ -93,11 +93,15 @@ public class BitcoinSwapBlockchain: ISwapBlockchain {
withValue: transaction.amount, index: transaction.outputIndex, lockingScript: transaction.lockingScript,
transactionHash: transaction.transactionHash, type: .p2sh, redeemScript: redeemScript, keyHash: scriptHash, publicKey: publicKey
)
let unspentOutput = UnspentOutput(output: output, publicKey: publicKey, transaction: Transaction(version: 0, lockTime: 0, timestamp: nil))
output.signatureScriptFunction = { data in
let signature = data[0]
let publicKey = data[1]

_ = try kit.redeem(from: unspentOutput, to: kit.receiveAddress(for: .p2pkh), feeRate: 43) { signature, publicKey in
return OpCode.push(signature) + OpCode.push(publicKey) + OpCode.push(secret) + OpCode.push(1) + OpCode.push(redeemScript)
}

let unspentOutput = UnspentOutput(output: output, publicKey: publicKey, transaction: Transaction(version: 0, lockTime: 0, timestamp: nil))
_ = try kit.redeem(from: unspentOutput, to: kit.receiveAddress(), feeRate: 43, sortType: .shuffle)
}

public func bailTransaction(from data: Data) throws -> IBailTransaction {
Expand Down
4 changes: 2 additions & 2 deletions AtomicSwapCore/AtomicSwapCore/Core/SwapFactory.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import HSCryptoKit
import OpenSslKit

class SwapFactory {
enum FactoryError: Error {
Expand Down Expand Up @@ -46,7 +46,7 @@ extension SwapFactory : ISwapFactory {
id: id.reduce("") { $0 + String(format: "%02x", $1) }, state: Swap.State.requested,
initiator: true, initiatorCoinCode: initiatorCoinCode, responderCoinCode: responderCoinCode,
rate: rate, amount: amount,
secretHash: CryptoKit.sha256(secret), secret: secret,
secretHash: Kit.sha256(secret), secret: secret,
initiatorTimestamp: nil, responderTimestamp: nil,
refundPKId: refundPublicKey.id, redeemPKId: redeemPublicKey.id,
initiatorRefundPKH: refundPublicKey.keyHash, initiatorRedeemPKH: redeemPublicKey.keyHash,
Expand Down
12 changes: 8 additions & 4 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
2FA5D6F0A098AC3AF7D5481B /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA5DF188B4AD5B5A04ECFA5 /* Extensions.swift */; };
D053FF4222DC9FCC002982C6 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D053FF4122DC9FCC002982C6 /* ViewController.swift */; };
D053FF4722DC9FCC002982C6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D053FF4622DC9FCC002982C6 /* Assets.xcassets */; };
D053FF5322DCA04C002982C6 /* AtomicSwapBitcoinProvider.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D053FF5222DCA04C002982C6 /* AtomicSwapBitcoinProvider.framework */; };
Expand All @@ -20,7 +21,6 @@
D053FF7E22DCA2C8002982C6 /* Signal.swift in Sources */ = {isa = PBXBuildFile; fileRef = D053FF6122DCA2C7002982C6 /* Signal.swift */; };
D053FF7F22DCA2C8002982C6 /* PlainSwapCodec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D053FF6222DCA2C7002982C6 /* PlainSwapCodec.swift */; };
D053FF8022DCA2C8002982C6 /* TransactionRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = D053FF6322DCA2C7002982C6 /* TransactionRecord.swift */; };
D053FF8122DCA2C8002982C6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D053FF6422DCA2C7002982C6 /* AppDelegate.swift */; };
D053FF8222DCA2C8002982C6 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = D053FF6522DCA2C7002982C6 /* LaunchScreen.xib */; };
D053FF8322DCA2C8002982C6 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D053FF6622DCA2C8002982C6 /* Configuration.swift */; };
D053FF8422DCA2C8002982C6 /* BitcoinCashAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = D053FF6822DCA2C8002982C6 /* BitcoinCashAdapter.swift */; };
Expand All @@ -41,6 +41,7 @@
D053FF9422DCA2C8002982C6 /* SwapController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D053FF7A22DCA2C8002982C6 /* SwapController.xib */; };
D053FF9522DCA2C8002982C6 /* SendController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D053FF7B22DCA2C8002982C6 /* SendController.swift */; };
D053FF9622DCA2C8002982C6 /* ReceiveController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D053FF7C22DCA2C8002982C6 /* ReceiveController.xib */; };
D06A506B247D2AE300230602 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D06A506A247D2AE300230602 /* AppDelegate.swift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -60,6 +61,7 @@

/* Begin PBXFileReference section */
03A01452094FD962A5A18D22 /* Pods-Demo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Demo.debug.xcconfig"; path = "Target Support Files/Pods-Demo/Pods-Demo.debug.xcconfig"; sourceTree = "<group>"; };
2FA5DF188B4AD5B5A04ECFA5 /* Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
9A9B80CAD01312EED9D799DA /* Pods-Demo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Demo.release.xcconfig"; path = "Target Support Files/Pods-Demo/Pods-Demo.release.xcconfig"; sourceTree = "<group>"; };
D053FF3C22DC9FCC002982C6 /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; };
D053FF4122DC9FCC002982C6 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand All @@ -74,7 +76,6 @@
D053FF6122DCA2C7002982C6 /* Signal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Signal.swift; sourceTree = "<group>"; };
D053FF6222DCA2C7002982C6 /* PlainSwapCodec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlainSwapCodec.swift; sourceTree = "<group>"; };
D053FF6322DCA2C7002982C6 /* TransactionRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionRecord.swift; sourceTree = "<group>"; };
D053FF6422DCA2C7002982C6 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = "../../../bitcoin-kit-ios/Demo/Demo/AppDelegate.swift"; sourceTree = "<group>"; };
D053FF6522DCA2C7002982C6 /* LaunchScreen.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = LaunchScreen.xib; sourceTree = "<group>"; };
D053FF6622DCA2C8002982C6 /* Configuration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = "<group>"; };
D053FF6822DCA2C8002982C6 /* BitcoinCashAdapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BitcoinCashAdapter.swift; sourceTree = "<group>"; };
Expand All @@ -95,6 +96,7 @@
D053FF7A22DCA2C8002982C6 /* SwapController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SwapController.xib; sourceTree = "<group>"; };
D053FF7B22DCA2C8002982C6 /* SendController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SendController.swift; sourceTree = "<group>"; };
D053FF7C22DCA2C8002982C6 /* ReceiveController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ReceiveController.xib; sourceTree = "<group>"; };
D06A506A247D2AE300230602 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -136,10 +138,10 @@
D053FF3E22DC9FCC002982C6 /* Demo */ = {
isa = PBXGroup;
children = (
D06A506A247D2AE300230602 /* AppDelegate.swift */,
D053FF6722DCA2C8002982C6 /* Adapters */,
D053FF6C22DCA2C8002982C6 /* Controllers */,
D053FF5F22DCA2C7002982C6 /* Core */,
D053FF6422DCA2C7002982C6 /* AppDelegate.swift */,
D053FF6622DCA2C8002982C6 /* Configuration.swift */,
D053FF6522DCA2C7002982C6 /* LaunchScreen.xib */,
D053FF4122DC9FCC002982C6 /* ViewController.swift */,
Expand All @@ -166,6 +168,7 @@
D053FF6122DCA2C7002982C6 /* Signal.swift */,
D053FF6222DCA2C7002982C6 /* PlainSwapCodec.swift */,
D053FF6322DCA2C7002982C6 /* TransactionRecord.swift */,
2FA5DF188B4AD5B5A04ECFA5 /* Extensions.swift */,
);
path = Core;
sourceTree = "<group>";
Expand Down Expand Up @@ -349,17 +352,18 @@
D053FF7E22DCA2C8002982C6 /* Signal.swift in Sources */,
D053FF7F22DCA2C8002982C6 /* PlainSwapCodec.swift in Sources */,
D053FF9122DCA2C8002982C6 /* MainController.swift in Sources */,
D06A506B247D2AE300230602 /* AppDelegate.swift in Sources */,
D053FF8722DCA2C8002982C6 /* BaseAdapter.swift in Sources */,
D053FF7D22DCA2C8002982C6 /* Manager.swift in Sources */,
D053FF8C22DCA2C8002982C6 /* BalanceCell.swift in Sources */,
D053FF8122DCA2C8002982C6 /* AppDelegate.swift in Sources */,
D053FF9022DCA2C8002982C6 /* SwapController.swift in Sources */,
D053FF8E22DCA2C8002982C6 /* ReceiveController.swift in Sources */,
D053FF8322DCA2C8002982C6 /* Configuration.swift in Sources */,
D053FF8622DCA2C8002982C6 /* BitcoinAdapter.swift in Sources */,
D053FF9322DCA2C8002982C6 /* TransactionsController.swift in Sources */,
D053FF8922DCA2C8002982C6 /* BalanceController.swift in Sources */,
D053FF8022DCA2C8002982C6 /* TransactionRecord.swift in Sources */,
2FA5D6F0A098AC3AF7D5481B /* Extensions.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Loading