Esempio n. 1
0
void
blockstore_get_highest(struct blockstore *bs,
                       const uint256 *hash0,
                       const uint256 *hash1,
                       uint256 *hash)
{
   int height0;
   int height1;

   if (uint256_iszero(hash0)) {
      memcpy(hash, hash1, sizeof *hash1);
      return;
   }
   if (uint256_iszero(hash1)) {
      memcpy(hash, hash0, sizeof *hash0);
      return;
   }

   height0 = blockstore_get_block_height(bs, hash0);
   height1 = blockstore_get_block_height(bs, hash1);
   ASSERT(height0 > 0);
   ASSERT(height1 > 0);

   if (height0 < height1) {
      memcpy(hash, hash1, sizeof *hash1);
   } else {
      memcpy(hash, hash0, sizeof *hash0);
   }
}
Esempio n. 2
0
File: txdb.c Progetto: haraldh/bitc
static void
txdb_export_tx_cb(const void *key,
                  size_t keyLen,
                  void *cbData,
                  void *keyData)
{
    struct bitcui_tx **txiPtr = (struct bitcui_tx **)cbData;
    struct tx_entry *txe = (struct tx_entry *)keyData;
    struct bitcui_tx *txi = *txiPtr;
    char hashStr[80];

    if (txe->relevant == 0) {
        return;
    }

    /*
     * We need to weed out transactions that made it in an orphan block but were
     * not integrated later on in the main chain.
     */

    txi->src  = NULL;
    txi->dst  = NULL;
    txi->desc = NULL;

    ASSERT(keyLen == sizeof(uint256));
    memcpy(&txi->txHash, key, keyLen);
    txi->value  = txdb_get_tx_credit(&txe->tx);
    txi->value -= txdb_get_tx_debit(&txe->tx);

    txi->blockHeight = -1;
    if (!uint256_iszero(&txe->blkHash)) {
        txi->blockHeight = blockstore_get_block_height(btc->blockStore,
                           &txe->blkHash);
    }

    uint256_snprintf_reverse(hashStr, sizeof hashStr, (uint256*)key);
    txi->desc = config_getstring(btc->txLabelsCfg, NULL, "tx.%s.label", hashStr) ;
    /*
     * This is a workaround for a bug caused by truncated hashStr.
     */
    if (txi->desc == NULL) {
        hashStr[63] = '\0';
        txi->desc = config_getstring(btc->txLabelsCfg, NULL, "tx.%s.label", hashStr) ;
    }

    txi->timestamp = txe->timestamp;
    *txiPtr += 1;
}