예제 #1
0
BtcUnspentOutputs BtcHelper::ListNewOutputs(BtcUnspentOutputs knownOutputs, const btc::stringList &addresses)
{
    if(addresses.empty())
        return BtcUnspentOutputs();

    // extract txids from unspent outputs
    btc::stringList knownOutputTxIds = btc::stringList();
    for(BtcUnspentOutputs::iterator output = knownOutputs.begin(); output != knownOutputs.end(); output++)
    {
        knownOutputTxIds.push_back((*output)->txId);
    }

    // get list of all unspent outputs
    BtcUnspentOutputs outputs = this->modules->btcJson->ListUnspent(MinConfirms, MaxConfirms, addresses);

    // iterate through them
    BtcUnspentOutputs newOutputs = BtcUnspentOutputs();
    for(BtcUnspentOutputs::iterator output = outputs.begin(); output != outputs.end(); output++)
    {
        // check if we already know about them
        btc::stringList::iterator it;
        it = std::find (knownOutputTxIds.begin(), knownOutputTxIds.end(), (*output)->txId);
        if(it == knownOutputTxIds.end())
            newOutputs.push_back((*output));   // add them if we don't
        else
            knownOutputTxIds.erase(it, it);
    }

    return newOutputs;
}
예제 #2
0
BtcUnspentOutputs BtcHelper::FindUnspentOutputs(const btc::stringList &txIdsToCheck)
{
    BtcUnspentOutputs unspentOutputs = BtcUnspentOutputs();
    std::string lastTxId = std::string();   // prevent double inserts

    for(btc::stringList::const_iterator txId = txIdsToCheck.begin(); txId != txIdsToCheck.end(); txId++)
    {
        if((*txId) == lastTxId)
            continue;
        lastTxId = (*txId);

        BtcRawTransactionPtr rawTx = GetDecodedRawTransaction((*txId));
        if(rawTx == NULL)
            continue;

        // iterate through raw transaction VOUT array
        for(std::vector<BtcRawTransaction::VOUT>::const_iterator vout = rawTx->outputs.begin(); vout != rawTx->outputs.end(); vout++)
        {
            BtcUnspentOutputPtr output = this->modules->btcJson->GetTxOut(rawTx->txId, vout->n);
            if(output == NULL)
                continue;

            if(!output->address.empty())
                unspentOutputs.push_back(output);
        }
    }

    return unspentOutputs;
}
예제 #3
0
BtcUnspentOutputs BtcHelper::FindSignableOutputs(const btc::stringList &txIds)
{
    BtcUnspentOutputs outputsToCheck = BtcUnspentOutputs();
    std::string lastTxId = std::string();   // prevent double inserts

    // iterate through txids
    for(btc::stringList::const_iterator txId = txIds.begin(); txId != txIds.end(); txId++)
    {
        if((*txId) == lastTxId)
            continue;
        lastTxId = (*txId);

        // get transaction details
        BtcRawTransactionPtr txRaw = GetDecodedRawTransaction((*txId));
        // iterate through raw transaction VOUT array
        for(std::vector<BtcRawTransaction::VOUT>::const_iterator vout = txRaw->outputs.begin(); vout != txRaw->outputs.end(); vout++)
        {
            BtcUnspentOutputPtr output = BtcUnspentOutputPtr(new BtcUnspentOutput(Json::Value()));
            output->txId = (*txId);
            if(vout->addresses.size() == 1)
                output->address = vout->addresses.front();
            output->scriptPubKey = vout->scriptPubKeyHex;
            output->amount = vout->value;
            output->vout = vout->n;
            outputsToCheck.push_back(output);
        }
    }

    return FindSignableOutputs(outputsToCheck);
}
예제 #4
0
BtcUnspentOutputs BtcHelper::FindUnspentSignableOutputs(const btc::stringList &txIds)
{
    BtcUnspentOutputs signableOutputs = FindSignableOutputs(txIds);
    if(signableOutputs.empty())
        return BtcUnspentOutputs();

    BtcUnspentOutputs unspentSignableOutputs = FindUnspentOutputs(signableOutputs);
    return unspentSignableOutputs;
}
예제 #5
0
BtcUnspentOutputs BtcHelper::FindSignableOutputs(const BtcUnspentOutputs &outputs)
{
    BtcUnspentOutputs signableOutputs = BtcUnspentOutputs();

    for(BtcUnspentOutputs::const_iterator output = outputs.begin(); output != outputs.end(); output++)
    {
        if(IsMine((*output)->address))
            signableOutputs.push_back((*output));
    }

    return signableOutputs;
}
예제 #6
0
BtcUnspentOutputs BtcHelper::FindUnspentOutputs(BtcUnspentOutputs possiblySpentOutputs)
{
    BtcUnspentOutputs unspentOutputs = BtcUnspentOutputs();
    for(BtcUnspentOutputs::iterator outputToCheck = possiblySpentOutputs.begin(); outputToCheck != possiblySpentOutputs.end(); outputToCheck++)
    {
        BtcUnspentOutputPtr output = this->modules->btcJson->GetTxOut((*outputToCheck)->txId, (*outputToCheck)->vout);
        if(output != NULL)
        {
            std::printf ("found unspent output %s : %ld, %f BTC\n", output->txId.c_str(), output->vout, SatoshisToCoins(output->amount));
            unspentOutputs.push_back(output);
        }
    }

    return unspentOutputs;
}