yenom / BitcoinKit

Bitcoin protocol toolkit for Swift
MIT License
841 stars 261 forks source link

What usedAddress and usekeys functions does ? #199

Closed DiwakarThapa closed 5 years ago

DiwakarThapa commented 5 years ago

private func usedAddresses() -> [Address] { var addresses = [Address]() guard let wallet = AppController.shared.wallet else { return [] } for index in 0..<(AppController.shared.externalIndex + 20) { if let address = try? wallet.receiveAddress(index: index) { addresses.append(address) } } for index in 0..<(AppController.shared.internalIndex + 20) { if let address = try? wallet.changeAddress(index: index) { addresses.append(address) } } return addresses }

private func usedKeys() -> [PrivateKey] {
    var keys = [PrivateKey]()
    guard let wallet = AppController.shared.wallet else {
        return []
    }
    // Receive key
    for index in 0..<(AppController.shared.externalIndex + 20) {
        if let key = try? wallet.privateKey(index: index) {
            keys.append(key)
        }
    }
    // Change key
    for index in 0..<(AppController.shared.internalIndex + 20) {
        if let key = try? wallet.changePrivateKey(index: index) {
            keys.append(key)
        }
    }

    return keys
}
akifuji commented 5 years ago

usedAddress: Return addresses you used. usecase: Sometimes you need addresses, when you want UTXOs or txs with API,

usedKeys: Return private keys you used. usecase: You need private keys to create ScriptSig, when you create txs.

DiwakarThapa commented 5 years ago

@akifuji I am creating wallet using bitcoin kit ? I used testnetBtc network for testing. I guess there is some bug in this library. When I try to send amount it does not work. Why?

akifuji commented 5 years ago

@DiwakarThapa I replied here.