From 150854ef9d35ac65dd99fc88667cc6bed729d9d7 Mon Sep 17 00:00:00 2001 From: Shun Usami Date: Sun, 22 Sep 2019 01:27:11 +0900 Subject: [PATCH] :recycle: Refactor Address/BitcoinAddress related interfaces - input from external to be Address - output to external to be BitcoinAddress --- Sources/BitcoinKit/Core/BlockChain.swift | 2 +- Sources/BitcoinKit/Core/Keys/PublicKey+Address.swift | 5 ----- Sources/BitcoinKit/Core/PaymentURI.swift | 2 +- Sources/BitcoinKit/Wallet/HDWallet.swift | 8 ++++---- Sources/BitcoinKit/Wallet/TransactionBuilder.swift | 2 +- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Sources/BitcoinKit/Core/BlockChain.swift b/Sources/BitcoinKit/Core/BlockChain.swift index d74c14c9..9254c7ce 100644 --- a/Sources/BitcoinKit/Core/BlockChain.swift +++ b/Sources/BitcoinKit/Core/BlockChain.swift @@ -46,7 +46,7 @@ public class BlockChain { try blockStore.addTransaction(transaction, hash: hash) } - public func calculateBalance(address: BitcoinAddress) throws -> Int64 { + public func calculateBalance(address: Address) throws -> Int64 { return try blockStore.calculateBalance(address: address) } diff --git a/Sources/BitcoinKit/Core/Keys/PublicKey+Address.swift b/Sources/BitcoinKit/Core/Keys/PublicKey+Address.swift index 43fb678c..2641246e 100644 --- a/Sources/BitcoinKit/Core/Keys/PublicKey+Address.swift +++ b/Sources/BitcoinKit/Core/Keys/PublicKey+Address.swift @@ -35,11 +35,6 @@ extension PublicKey { return toBitcoinAddress() } - @available(*, deprecated, message: "toAddress() will be removed. Use toBitcoinAddress instead.") - public func toAddress() -> Address { - return toBitcoinAddress() - } - public func toBitcoinAddress() -> BitcoinAddress { return try! BitcoinAddress(data: pubkeyHash, hashType: .pubkeyHash, network: network) } diff --git a/Sources/BitcoinKit/Core/PaymentURI.swift b/Sources/BitcoinKit/Core/PaymentURI.swift index 7fd4866e..f1a81b4f 100644 --- a/Sources/BitcoinKit/Core/PaymentURI.swift +++ b/Sources/BitcoinKit/Core/PaymentURI.swift @@ -26,7 +26,7 @@ import Foundation public struct PaymentURI { - public let address: Address + public let address: BitcoinAddress public let label: String? public let message: String? public let amount: Decimal? diff --git a/Sources/BitcoinKit/Wallet/HDWallet.swift b/Sources/BitcoinKit/Wallet/HDWallet.swift index 1e46ddf0..378b30f2 100644 --- a/Sources/BitcoinKit/Wallet/HDWallet.swift +++ b/Sources/BitcoinKit/Wallet/HDWallet.swift @@ -58,9 +58,9 @@ open class HDWallet { public private(set) var internalIndex: UInt32 /// [Cached] Latest Address for receiving payment. - public var address: Address { return externalAddresses.last! } + public var address: BitcoinAddress { return externalAddresses.last! } /// [Cached] Latest Address for change output. - public var changeAddress: Address { return internalAddresses.last! } + public var changeAddress: BitcoinAddress { return internalAddresses.last! } // MARK: - Private Keys /// [Secret] [Cached] Private keys for external addresses (receive). @@ -84,7 +84,7 @@ open class HDWallet { /// [Cached] Internal addresses for change output. public private(set) var internalAddresses: [BitcoinAddress]! /// [Cached] Addresses combined both external and internal. - public var addresses: [Address] { return externalAddresses + internalAddresses } + public var addresses: [BitcoinAddress] { return externalAddresses + internalAddresses } private init(mnemonic: [String]?, seed: Data, @@ -168,7 +168,7 @@ open class HDWallet { } /// [Non-Cache] Get address for index - public func address(index: UInt32, chain: Chain) -> Address { + public func address(index: UInt32, chain: Chain) -> BitcoinAddress { return pubKey(index: index, chain: chain).toBitcoinAddress() } diff --git a/Sources/BitcoinKit/Wallet/TransactionBuilder.swift b/Sources/BitcoinKit/Wallet/TransactionBuilder.swift index 69423d6f..1c199775 100644 --- a/Sources/BitcoinKit/Wallet/TransactionBuilder.swift +++ b/Sources/BitcoinKit/Wallet/TransactionBuilder.swift @@ -37,7 +37,7 @@ public struct TransactionBuilder { /// - toAddress: Address to send the amount /// - changeAddress: Address to receive the change /// - Returns: The transaction whose inputs are not signed. - public static func build(from plan: TransactionPlan, toAddress: BitcoinAddress, changeAddress: BitcoinAddress) -> Transaction { + public static func build(from plan: TransactionPlan, toAddress: Address, changeAddress: Address) -> Transaction { let toLockScript: Data = Script(address: toAddress)!.data var outputs: [TransactionOutput] = [ TransactionOutput(value: plan.amount, lockingScript: toLockScript)