Skip to content

Commit ca57e06

Browse files
committed
♻️ Rename MockUnlockScriptBuilder
1 parent 078d8c0 commit ca57e06

File tree

5 files changed

+43
-25
lines changed

5 files changed

+43
-25
lines changed

BitcoinKit.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
2914BE5C211BD0DF00B349CB /* OP_CHECKSEQUENCEVERIFY.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2914BE5B211BD0DF00B349CB /* OP_CHECKSEQUENCEVERIFY.swift */; };
133133
2914BE5E211C062200B349CB /* OP_PUBKEYHASH.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2914BE5D211C062200B349CB /* OP_PUBKEYHASH.swift */; };
134134
2914BE60211C063300B349CB /* OP_PUBKEY.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2914BE5F211C063300B349CB /* OP_PUBKEY.swift */; };
135-
292185372154B50E00570618 /* UnlockScriptBuilderProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 292185362154B50E00570618 /* UnlockScriptBuilderProtocol.swift */; };
135+
292185372154B50E00570618 /* MockUnlockScriptBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 292185362154B50E00570618 /* MockUnlockScriptBuilder.swift */; };
136136
29248EEF2104B64E00CC9051 /* ScriptChunkHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29248EEE2104B64E00CC9051 /* ScriptChunkHelper.swift */; };
137137
29290B8D210AF59600D2BE78 /* OpCodeFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29290B8C210AF59600D2BE78 /* OpCodeFactory.swift */; };
138138
29290B91210AF79300D2BE78 /* OP_DUP.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29290B90210AF79300D2BE78 /* OP_DUP.swift */; };
@@ -358,7 +358,7 @@
358358
2914BE5B211BD0DF00B349CB /* OP_CHECKSEQUENCEVERIFY.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OP_CHECKSEQUENCEVERIFY.swift; sourceTree = "<group>"; };
359359
2914BE5D211C062200B349CB /* OP_PUBKEYHASH.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OP_PUBKEYHASH.swift; sourceTree = "<group>"; };
360360
2914BE5F211C063300B349CB /* OP_PUBKEY.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OP_PUBKEY.swift; sourceTree = "<group>"; };
361-
292185362154B50E00570618 /* UnlockScriptBuilderProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnlockScriptBuilderProtocol.swift; sourceTree = "<group>"; };
361+
292185362154B50E00570618 /* MockUnlockScriptBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockUnlockScriptBuilder.swift; sourceTree = "<group>"; };
362362
29248EEE2104B64E00CC9051 /* ScriptChunkHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScriptChunkHelper.swift; sourceTree = "<group>"; };
363363
29290B8C210AF59600D2BE78 /* OpCodeFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpCodeFactory.swift; sourceTree = "<group>"; };
364364
29290B90210AF79300D2BE78 /* OP_DUP.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OP_DUP.swift; sourceTree = "<group>"; };
@@ -585,6 +585,7 @@
585585
29089F112122D07500E0C305 /* Mock */ = {
586586
isa = PBXGroup;
587587
children = (
588+
292185362154B50E00570618 /* MockUnlockScriptBuilder.swift */,
588589
29089F0B2122B9CD00E0C305 /* MockHelper.swift */,
589590
29089F0F2122D06300E0C305 /* MockKey.swift */,
590591
);
@@ -648,7 +649,6 @@
648649
298E17C12150AD6000FF6C77 /* UtxoSelector.swift */,
649650
298E17C32150AD6900FF6C77 /* TransactionBuilder.swift */,
650651
298E17C52150AD7100FF6C77 /* TransactionSigner.swift */,
651-
292185362154B50E00570618 /* UnlockScriptBuilderProtocol.swift */,
652652
);
653653
path = Protocol;
654654
sourceTree = "<group>";
@@ -1193,7 +1193,7 @@
11931193
0C1DD40821181719004BA8A8 /* OP_ABS.swift in Sources */,
11941194
1482B5E8202721FF0098B612 /* HDPrivateKey.swift in Sources */,
11951195
298E17CD2150AEB300FF6C77 /* StandardTransactionBuilder.swift in Sources */,
1196-
292185372154B50E00570618 /* UnlockScriptBuilderProtocol.swift in Sources */,
1196+
292185372154B50E00570618 /* MockUnlockScriptBuilder.swift in Sources */,
11971197
0C09002621169B430077E9BC /* OP_MIN.swift in Sources */,
11981198
0C1DD421211820D4004BA8A8 /* OP_DIV.swift in Sources */,
11991199
0C1DE157211D79D900FE8E43 /* OP_FROMALTSTACK.swift in Sources */,

Sources/BitcoinKit/Mock/MockHelper.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public struct MockHelper {
7575
lockTime: tx.lockTime)
7676
}
7777

78-
public static func verifySingleKey(lockScript: Script, unlockScriptBuilder: UnlockScriptBuilderProtocol, key: MockKey, verbose: Bool = true) throws -> Bool {
78+
public static func verifySingleKey(lockScript: Script, unlockScriptBuilder: MockUnlockScriptBuilder, key: MockKey, verbose: Bool = true) throws -> Bool {
7979
// mocks
8080
let utxoMock: UnspentTransaction = MockHelper.createUtxo(lockScript: lockScript)
8181
let txMock: Transaction = MockHelper.createTransaction(utxo: utxoMock)
@@ -97,7 +97,7 @@ public struct MockHelper {
9797
return try ScriptMachine.verify(lockScript: lockScript, unlockScript: unlockScript, context: context)
9898
}
9999

100-
public static func verifyMultiKey(lockScript: Script, unlockScriptBuilder: UnlockScriptBuilderProtocol, keys: [MockKey], verbose: Bool = true) throws -> Bool {
100+
public static func verifyMultiKey(lockScript: Script, unlockScriptBuilder: MockUnlockScriptBuilder, keys: [MockKey], verbose: Bool = true) throws -> Bool {
101101
// mocks
102102
let utxoMock: UnspentTransaction = MockHelper.createUtxo(lockScript: lockScript)
103103
let txMock: Transaction = MockHelper.createTransaction(utxo: utxoMock)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// MockUnlockScriptBuilder.swift
3+
//
4+
// Copyright © 2018 BitcoinKit developers
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
// THE SOFTWARE.
23+
//
24+
25+
import Foundation
26+
27+
public typealias SigKeyPair = (signature: Data, key: PublicKey)
28+
29+
// This protocol is prepared for playing with Script.
30+
// If you are building production application, you should implement TransactionSigner instead of MockUnlockScriptBuilder.
31+
public protocol MockUnlockScriptBuilder {
32+
func build(pairs: [SigKeyPair]) -> Script
33+
}

Sources/BitcoinKit/Wallet/Protocol/UnlockScriptBuilderProtocol.swift

Lines changed: 0 additions & 15 deletions
This file was deleted.

Tests/BitcoinKitTests/MockHelperTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class MockHelperTests: XCTestCase {
3434
MockKey.keyC.pubkey],
3535
signaturesRequired: 1)!
3636

37-
struct UnlockScriptBuilder: UnlockScriptBuilderProtocol {
37+
struct UnlockScriptBuilder: MockUnlockScriptBuilder {
3838
func build(pairs: [SigKeyPair]) -> Script {
3939
guard let signature = pairs.first?.signature else {
4040
return Script()
@@ -91,7 +91,7 @@ class MockHelperTests: XCTestCase {
9191

9292
static let lockScript: Script = redeemScript.toP2SH()
9393

94-
struct UnlockScriptBuilder: UnlockScriptBuilderProtocol {
94+
struct UnlockScriptBuilder: MockUnlockScriptBuilder {
9595
func build(pairs: [SigKeyPair]) -> Script {
9696
guard let signature = pairs.first?.signature else {
9797
return Script()
@@ -165,7 +165,7 @@ class MockHelperTests: XCTestCase {
165165
// stack: sig pub
166166
.append(.OP_CHECKSIG)
167167

168-
struct UnlockScriptBuilder: UnlockScriptBuilderProtocol {
168+
struct UnlockScriptBuilder: MockUnlockScriptBuilder {
169169
func build(pairs: [SigKeyPair]) -> Script {
170170
guard let key = pairs.first?.key, let signature = pairs.first?.signature else {
171171
return Script()
@@ -244,7 +244,7 @@ class MockHelperTests: XCTestCase {
244244
MockKey.keyB.pubkey,
245245
MockKey.keyC.pubkey],
246246
signaturesRequired: 2)!
247-
struct UnlockScriptBuilder: UnlockScriptBuilderProtocol {
247+
struct UnlockScriptBuilder: MockUnlockScriptBuilder {
248248
func build(pairs: [SigKeyPair]) -> Script {
249249
let script = try! Script().append(.OP_0)
250250
pairs.forEach { try! script.appendData($0.signature) }

0 commit comments

Comments
 (0)