Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
metalurgical committed Jan 26, 2024
1 parent fc27d01 commit 9cc43af
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Sources/BitcoinCore/Classes/ApiSync/BlockHashFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class BlockHashFetcher: IBlockHashFetcher {
}

if afterCheckpoint.count > 0 {
await try blockHashes.merge(blockchairFetcher.fetch(heights: afterCheckpoint), uniquingKeysWith: { a, _ in a })
try await blockHashes.merge(blockchairFetcher.fetch(heights: afterCheckpoint), uniquingKeysWith: { a, _ in a })
}

return blockHashes
Expand Down
14 changes: 9 additions & 5 deletions Sources/BitcoinCore/Classes/Core/BitcoinCoreBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,20 @@ public class BitcoinCoreBuilder {
var transactionCreator: TransactionCreator?

if let hdWallet {
let ecdsaInputSigner = EcdsaInputSigner(hdWallet: hdWallet, network: network)
let schnorrInputSigner = SchnorrInputSigner(hdWallet: hdWallet)
let transactionSizeCalculatorInstance = TransactionSizeCalculator()
if (self.signer == nil) {
let ecdsaInputSigner = EcdsaInputSigner(hdWallet: hdWallet, network: network)
let schnorrInputSigner = SchnorrInputSigner(hdWallet: hdWallet)
let transactionSigner = TransactionSigner(ecdsaInputSigner: ecdsaInputSigner, schnorrInputSigner: schnorrInputSigner)
self.signer = transactionSigner
}

let dustCalculatorInstance = DustCalculator(dustRelayTxFee: network.dustRelayTxFee, sizeCalculator: transactionSizeCalculatorInstance)
let recipientSetter = RecipientSetter(addressConverter: addressConverter, pluginManager: pluginManager)
let outputSetter = OutputSetter(outputSorterFactory: transactionDataSorterFactory, factory: factory)
let inputSetter = InputSetter(unspentOutputSelector: unspentOutputSelector, transactionSizeCalculator: transactionSizeCalculatorInstance, addressConverter: addressConverter, publicKeyManager: publicKeyManager, factory: factory, pluginManager: pluginManager, dustCalculator: dustCalculatorInstance, changeScriptType: purpose.scriptType, inputSorterFactory: transactionDataSorterFactory)
let lockTimeSetter = LockTimeSetter(storage: storage)
//let transactionSigner = TransactionSigner(ecdsaInputSigner: ecdsaInputSigner, schnorrInputSigner: schnorrInputSigner)
let transactionBuilder = TransactionBuilder(recipientSetter: recipientSetter, inputSetter: inputSetter, lockTimeSetter: lockTimeSetter, outputSetter: outputSetter, signer: self.signer ?? TransactionSigner(ecdsaInputSigner: ecdsaInputSigner, schnorrInputSigner: schnorrInputSigner))
let transactionBuilder = TransactionBuilder(recipientSetter: recipientSetter, inputSetter: inputSetter, lockTimeSetter: lockTimeSetter, outputSetter: outputSetter, signer: self.signer!)
transactionFeeCalculator = TransactionFeeCalculator(recipientSetter: recipientSetter, inputSetter: inputSetter, addressConverter: addressConverter, publicKeyManager: publicKeyManager, changeScriptType: purpose.scriptType)
let transactionSendTimer = TransactionSendTimer(interval: 60)
let transactionSenderInstance = TransactionSender(transactionSyncer: pendingTransactionSyncer, initialBlockDownload: initialDownload, peerManager: peerManager, storage: storage, timer: transactionSendTimer, logger: logger)
Expand All @@ -323,7 +327,7 @@ public class BitcoinCoreBuilder {

transactionSendTimer.delegate = transactionSender

transactionCreator = TransactionCreator(transactionBuilder: transactionBuilder, transactionProcessor: pendingTransactionProcessor, transactionSender: transactionSenderInstance, bloomFilterManager: bloomFilterManager, signer: self.signer ?? TransactionSigner(ecdsaInputSigner: ecdsaInputSigner, schnorrInputSigner: schnorrInputSigner))
transactionCreator = TransactionCreator(transactionBuilder: transactionBuilder, transactionProcessor: pendingTransactionProcessor, transactionSender: transactionSenderInstance, bloomFilterManager: bloomFilterManager, signer: self.signer!)
}
let mempoolTransactions = MempoolTransactions(transactionSyncer: pendingTransactionSyncer, transactionSender: transactionSender)

Expand Down
2 changes: 1 addition & 1 deletion Sources/BitcoinCore/Classes/Core/Protocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public protocol IBlockchainDataListener: AnyObject {
func onInsert(block: Block)
}

protocol IInputSigner {
public protocol IInputSigner {
func sigScriptData(transaction: Transaction, inputsToSign: [InputToSign], outputs: [Output], index: Int) throws -> [Data]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ class TransactionBuilder {
private let inputSetter: IInputSetter
private let lockTimeSetter: ILockTimeSetter
private let outputSetter: IOutputSetter
// private let signer: ITransactionSigner

init(recipientSetter: IRecipientSetter, inputSetter: IInputSetter, lockTimeSetter: ILockTimeSetter, outputSetter: IOutputSetter, signer: ITransactionSigner) {
self.recipientSetter = recipientSetter
self.inputSetter = inputSetter
self.lockTimeSetter = lockTimeSetter
self.outputSetter = outputSetter
// self.signer = signer
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

class TransactionSigner {
public class TransactionSigner {
enum SignError: Error {
case notSupportedScriptType
case noRedeemScript
Expand Down Expand Up @@ -79,7 +79,7 @@ class TransactionSigner {
}

extension TransactionSigner: ITransactionSigner {
func sign(mutableTransaction: MutableTransaction) throws {
public func sign(mutableTransaction: MutableTransaction) throws {
for (index, inputToSign) in mutableTransaction.inputsToSign.enumerated() {
if inputToSign.previousOutput.scriptType == .p2tr {
try schnorrSign(index: index, mutableTransaction: mutableTransaction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
super.tearDown()
}

/*
func testTransactionSize() {
XCTAssertEqual(calculator.transactionSize(previousOutputs: [], outputScriptTypes: []), 10) // empty legacy tx
XCTAssertEqual(calculator.transactionSize(previousOutputs: outputs(withScriptTypes: [.p2pkh]), outputScriptTypes: [.p2pkh]), 192) // 1-in 1-out standard tx
Expand All @@ -28,7 +29,8 @@
XCTAssertEqual(calculator.transactionSize(previousOutputs: outputs(withScriptTypes: [.p2wpkhSh]), outputScriptTypes: [.p2pkh]), 136) // 1-in 1-out (sh) witness tx
XCTAssertEqual(calculator.transactionSize(previousOutputs: outputs(withScriptTypes: [.p2wpkh, .p2pkh, .p2pkh, .p2pkh]), outputScriptTypes: [.p2pkh]), 558) // 4-in 1-out witness tx
}

*/

func testTransactionSizeShInputsStandard() {
let redeemScript = Data(repeating: 0, count: 45)
let shOutput = Output(withValue: 0, index: 0, lockingScript: Data(), type: .p2sh, redeemScript: redeemScript)
Expand Down

0 comments on commit 9cc43af

Please sign in to comment.