Example #1
0
static void script_tx_sighash(struct wallet *wallet, uint256 *hash,
                              const struct buff *scriptPubKey,
                              const struct btc_msg_tx *tx, uint32 idx,
                              enum script_hash_type hashType) {
  struct btc_msg_tx *tx2;
  struct buff *buf;
  int i;

  ASSERT(idx < tx->in_count);

  memset(hash, 0, sizeof *hash);
  tx2 = btc_msg_tx_dup(tx);

  Log(LGPFX " Computing sighash for txi-%u/%llu\n", idx, tx2->in_count);

  /*
   * Zero-out all the inputs' signatures.
   */
  for (i = 0; i < tx2->in_count; i++) {
    tx2->tx_in[i].scriptLength = 0;
  }

  size_t len = buff_maxlen(scriptPubKey);
  ASSERT(len > 0);

  ASSERT(tx2->tx_in[idx].scriptSig == NULL);
  ASSERT(tx2->tx_in[idx].scriptLength == 0);

  tx2->tx_in[idx].scriptLength = len;
  tx2->tx_in[idx].scriptSig = safe_malloc(len);

  memcpy(tx2->tx_in[idx].scriptSig, buff_base(scriptPubKey), len);

  ASSERT((hashType & 0x1f) == SIGHASH_ALL);

  /*
   * Final step:
   *
   * Serialize tx + hashType (as a uint32) and compute hash.
   */

  buf = buff_alloc();
  serialize_tx(buf, tx2);
  serialize_uint32(buf, hashType);
  hash256_calc(buff_base(buf), buff_curlen(buf), hash);
  buff_free(buf);

  btc_msg_tx_free(tx2);
  free(tx2);
}
Example #2
0
File: txdb.c Project: haraldh/bitc
static void
txdb_free_tx_entry(struct tx_entry *txe)
{
    btc_msg_tx_free(&txe->tx);
    free(txe);
}