Skip to content

Commit

Permalink
♻️ Refactor Address/BitcoinAddress related interfaces
Browse files Browse the repository at this point in the history
- input from external to be Address
- output to external to be BitcoinAddress
  • Loading branch information
usatie committed Sep 21, 2019
1 parent e5a6cbc commit 150854e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Sources/BitcoinKit/Core/BlockChain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
5 changes: 0 additions & 5 deletions Sources/BitcoinKit/Core/Keys/PublicKey+Address.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/BitcoinKit/Core/PaymentURI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
8 changes: 4 additions & 4 deletions Sources/BitcoinKit/Wallet/HDWallet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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,
Expand Down Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/BitcoinKit/Wallet/TransactionBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 150854e

Please sign in to comment.