yenom / BitcoinKit

Bitcoin protocol toolkit for Swift
MIT License
842 stars 262 forks source link

Bug in BTC #195

Closed j-ibarra closed 5 years ago

j-ibarra commented 5 years ago

The blockStore no calculateBalance from Address

Expected behavior

Steps to reproduce

class ViewController: UIViewController, PeerGroupDelegate {

    var peerGroup: PeerGroup?

    public static func `default`() throws -> SQLiteBlockStore {
        let cachesDir = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]
        return try SQLiteBlockStore(file: cachesDir.appendingPathComponent("btc-testnet-blockchain.sqlite"), network: .testnetBTC)
    }

    let blockStore = try! ViewController.default()

    @IBAction func test1ButtonPressed(_ sender: UIButton) {
        print("##test1ButtonPressed")

        if let peerGroup = peerGroup {
            print("stop sync")
            peerGroup.stop()
            sender.setTitle("Sync", for: .normal)
        } else {
            print("start sync")

            let blockChain = BlockChain(network: .testnetBTC, blockStore: blockStore)

            peerGroup = PeerGroup(blockChain: blockChain)
            peerGroup?.delegate = self

            peerGroup?.start()
            sender.setTitle("Stop", for: .normal)
        }
    }

    @IBAction func test2ButtonPressed(_ sender: UIButton) {
        print("##test2ButtonPressed")

        do {
            let wallet = try Wallet(wif: "#####################################")
            let address = try AddressFactory.create(wallet.publicKey.toCashaddr().base58)

            let balance: Int64 = try! blockStore.calculateBalance(address: address)

            let decimal = Decimal(balance)
            print(address)
            print("\(decimal / Decimal(100000000)) BTC")

        } catch {
        }
    }
image

but in the logs

image
Sajjon commented 5 years ago

You did not explain what the bug was...

j-ibarra commented 5 years ago

Sorry, my problem is trying to rebuild a wallet in generate in Java with the bitcoinJ library with WIF, this is perfectly my public address.

but when asking for the balance of this portfolio from the blockStore.calculateBalance throws me 0!

j-ibarra commented 5 years ago

well, I modified some files to btcnetwork