public function discoverWalletFunds($increment = 200) {
        $totalBalance = 0;
        $totalUTXOs = 0;
        $totalAddressesGenerated = 0;

        $addressUTXOs = array();    //addresses and their utxos, paths and redeem scripts

        //for each blocktrail pub key, do fund discovery on batches of addresses
        foreach ($this->blocktrailPublicKeys as $keyIndex => $blocktrailPubKey) {
            $i = 0;
            do {
                if ($this->debug) {
                    echo "\ngenerating $increment addresses using blocktrail key index $keyIndex\n";
                }
                $addresses = $this->createBatchAddresses($i, $increment, $keyIndex);
                $totalAddressesGenerated += count($addresses);
                if ($this->debug) {
                    echo "\nstarting fund discovery for $increment addresses";
                }

                //get the unspent outputs for this batch of addresses
                $utxos = $this->utxoFinder->getUTXOs(array_keys($addresses));
                //save the address utxos, along with relevant path and redeem script
                foreach ($utxos as $utxo) {
                    if (!isset($utxo['address'], $utxo['value'])) {
                        throw new BlocktrailSDKException("Missing data");
                    }

                    $address = $utxo['address'];

                    if (!isset($addressUTXOs[$address])) {
                        $addressUTXOs[$address] = [
                            'path' =>  $addresses[$address]['path'],
                            'redeem' =>  $addresses[$address]['redeem'],
                            'witness' =>  $addresses[$address]['witness'],
                            'utxos' =>  [],
                        ];
                    }

                    $addressUTXOs[$address]['utxos'][] = $utxo;
                    $totalUTXOs ++;

                    //add up the total utxo value for all addresses
                    $totalBalance += $utxo['value'];
                }

                if ($this->debug) {
                    echo "\nfound ".count($utxos)." unspent outputs";
                }

                //increment for next batch
                $i += $increment;
            } while (count($utxos) > 0);
        }

        if ($this->debug) {
            echo "\nfinished fund discovery: $totalBalance Satoshi (in $totalUTXOs outputs) found when searching $totalAddressesGenerated addresses";
        }

        $this->sweepData = ['utxos' => $addressUTXOs, 'count' => $totalUTXOs, 'balance' => $totalBalance, 'addressesSearched' => $totalAddressesGenerated];
        return $this->sweepData;
    }
public function discoverWalletFunds($increment = 200) {
        $totalBalance = 0;
        $totalUTXOs = 0;
        $totalAddressesGenerated = 0;

        $addressUTXOs = array();    //addresses and their utxos, paths and redeem scripts

        //for each blocktrail pub key, do fund discovery on batches of addresses
        foreach ($this->blocktrailPublicKeys as $keyIndex => $blocktrailPubKey) {
            $i = 0;
            do {
                if ($this->debug) {
                    echo "\ngenerating $increment addresses using blocktrail key index $keyIndex\n";
                }
                $addresses = $this->createBatchAddresses($i, $increment, $keyIndex);
                $totalAddressesGenerated += count($addresses);
                if ($this->debug) {
                    echo "\nstarting fund discovery for $increment addresses";
                }

                //get the unspent outputs for this batch of addresses
                $utxos = $this->utxoFinder->getUTXOs(array_keys($addresses));
                //save the address utxos, along with relevant path and redeem script
                foreach ($utxos as $utxo) {
                    if (!isset($utxo['address'], $utxo['value'])) {
                        throw new BlocktrailSDKException("Missing data");
                    }

                    $address = $utxo['address'];

                    if (!isset($addressUTXOs[$address])) {
                        $addressUTXOs[$address] = [
                            'path' =>  $addresses[$address]['path'],
                            'redeem' =>  $addresses[$address]['redeem'],
                            'witness' =>  $addresses[$address]['witness'],
                            'utxos' =>  [],
                        ];
                    }

                    $addressUTXOs[$address]['utxos'][] = $utxo;
                    $totalUTXOs ++;

                    //add up the total utxo value for all addresses
                    $totalBalance += $utxo['value'];
                }

                if ($this->debug) {
                    echo "\nfound ".count($utxos)." unspent outputs";
                }

                //increment for next batch
                $i += $increment;
            } while (count($utxos) > 0);
        }

        if ($this->debug) {
            echo "\nfinished fund discovery: $totalBalance Satoshi (in $totalUTXOs outputs) found when searching $totalAddressesGenerated addresses";
        }

        $this->sweepData = ['utxos' => $addressUTXOs, 'count' => $totalUTXOs, 'balance' => $totalBalance, 'addressesSearched' => $totalAddressesGenerated];
        return $this->sweepData;
    }
public function discoverWalletFunds ( $ increment = 200 ) { $ totalBalance = 0 ; $ totalUTXOs = 0 ; $ totalAddressesGenerated = 0 ; $ addressUTXOs = array ( ) ; //addresses and their utxos, paths and redeem scripts //for each blocktrail pub key, do fund discovery on batches of addresses foreach ( $ this -> blocktrailPublicKeys as $ keyIndex => $ blocktrailPubKey ) { $ i = 0 ; do { if ( $ this -> debug ) { echo "\ngenerating $increment addresses using blocktrail key index $keyIndex\n" ; } $ addresses = $ this -> createBatchAddresses ( $ i , $ increment , $ keyIndex ) ; $ totalAddressesGenerated += count ( $ addresses ) ; if ( $ this -> debug ) { echo "\nstarting fund discovery for $increment addresses" ; } //get the unspent outputs for this batch of addresses $ utxos = $ this -> utxoFinder -> getUTXOs ( array_keys ( $ addresses ) ) ; //save the address utxos, along with relevant path and redeem script foreach ( $ utxos as $ utxo ) { if ( ! isset ( $ utxo [ 'address' ] , $ utxo [ 'value' ] ) ) { throw new BlocktrailSDKException ( "Missing data" ) ; } $ address = $ utxo [ 'address' ] ; if ( ! isset ( $ addressUTXOs [ $ address ] ) ) { $ addressUTXOs [ $ address ] = [ 'path' => $ addresses [ $ address ] [ 'path' ] , 'redeem' => $ addresses [ $ address ] [ 'redeem' ] , 'witness' => $ addresses [ $ address ] [ 'witness' ] , 'utxos' => [ ] , ] ; } $ addressUTXOs [ $ address ] [ 'utxos' ] [ ] = $ utxo ; $ totalUTXOs ++ ; //add up the total utxo value for all addresses $ totalBalance += $ utxo [ 'value' ] ; } if ( $ this -> debug ) { echo "\nfound " . count ( $ utxos ) . " unspent outputs" ; } //increment for next batch $ i += $ increment ; } while ( count ( $ utxos ) > 0 ) ; } if ( $ this -> debug ) { echo "\nfinished fund discovery: $totalBalance Satoshi (in $totalUTXOs outputs) found when searching $totalAddressesGenerated addresses" ; } $ this -> sweepData = [ 'utxos' => $ addressUTXOs , 'count' => $ totalUTXOs , 'balance' => $ totalBalance , 'addressesSearched' => $ totalAddressesGenerated ] ; return $ this -> sweepData ; }
discover funds in the wallet

@param int $increment how many addresses to scan at a time
@return array
@throws BlocktrailSDKException
discover funds in the wallet