예제 #1
0
const BtcRawTransactionPtr BtcHelper::TransactionSuccessfull(const int64_t &amount, BtcUnspentOutputs outputs, const std::string &targetAddress, const int32_t &minConfirms)
{
    if(amount < 0 || outputs.empty() || targetAddress.empty() || minConfirms < 0)
        return BtcRawTransactionPtr();

    for(BtcUnspentOutputs::iterator output = outputs.begin(); output != outputs.end(); output++)
    {
        BtcRawTransactionPtr transaction =  WaitGetRawTransaction((*output)->txId);
        if(TransactionSuccessfull(amount, transaction, targetAddress, minConfirms))
            return transaction;
    }

    return BtcRawTransactionPtr();
}
예제 #2
0
BtcRawTransactionPtr BtcHelper::GetDecodedRawTransaction(const BtcTransactionPtr &tx) const
{
    if(tx == NULL)
        return BtcRawTransactionPtr();

    if(!tx->Hex.empty())
        return this->modules->btcJson->DecodeRawTransaction(tx->Hex);
    return this->modules->btcJson->GetDecodedRawTransaction(tx->TxId);
}
예제 #3
0
BtcRawTransactionPtr BtcHelper::WaitGetRawTransaction(const std::string &txId, const int32_t &timerMS, int32_t maxAttempts)
{
    if(txId.empty())
        return BtcRawTransactionPtr();

    BtcRawTransactionPtr rawTransaction = BtcRawTransactionPtr();

    while(maxAttempts)
    {
        rawTransaction = GetDecodedRawTransaction(txId);
        if(rawTransaction != NULL)
            return rawTransaction;

        maxAttempts--;
        btc::Sleep(timerMS);
    }

    return rawTransaction;
}
예제 #4
0
BtcRawTransactionPtr BtcHelper::GetDecodedRawTransaction(const std::string &txId) const
{
    if(txId.empty())
        return BtcRawTransactionPtr();

    // first check transaction database
    BtcTransactionPtr tx = this->modules->btcJson->GetTransaction(txId);
    if(tx != NULL)
        if(!tx->Hex.empty())
            return this->modules->btcJson->DecodeRawTransaction(tx->Hex);

    // otherwise check block database
    // use bitcoind -txindex to keep a complete list of all transactions, otherwise it might not find it if it's too old
    // or use 'importaddress' and bitcoind will index all relevant transactions and return them with 'gettransaction'
    return this->modules->btcJson->GetDecodedRawTransaction(txId);
}