Beispiel #1
0
int serialize_tx(struct buff *buf, const btc_msg_tx *tx) {
  uint64 i;
  int res;

  res = serialize_uint32(buf, tx->version);
  res |= serialize_varint(buf, tx->in_count);

  for (i = 0; i < tx->in_count; i++) {
    res |= serialize_uint256(buf, &tx->tx_in[i].prevTxHash);
    res |= serialize_uint32(buf, tx->tx_in[i].prevTxOutIdx);
    res |= serialize_varint(buf, tx->tx_in[i].scriptLength);
    res |=
        serialize_bytes(buf, tx->tx_in[i].scriptSig, tx->tx_in[i].scriptLength);
    res |= serialize_uint32(buf, tx->tx_in[i].sequence);
  }

  res |= serialize_varint(buf, tx->out_count);

  for (i = 0; i < tx->out_count; i++) {
    res |= serialize_uint64(buf, tx->tx_out[i].value);
    res |= serialize_varint(buf, tx->tx_out[i].scriptLength);
    res |= serialize_bytes(buf, tx->tx_out[i].scriptPubKey,
                           tx->tx_out[i].scriptLength);
  }

  res |= serialize_uint32(buf, tx->lock_time);

  return res;
}
Beispiel #2
0
int serialize_str(struct buff *buf, const char *str) {
  uint64 len;
  int res;

  len = str ? strlen(str) : 0;
  res = serialize_varint(buf, len);
  if (res) {
    return res;
  }
  return serialize_bytes(buf, str, len);
}
Beispiel #3
0
int serialize_blocklocator(struct buff *buf, const btc_block_locator *bl) {
  int res;
  int i;

  res = serialize_uint32(buf, bl->protversion);
  res |= serialize_varint(buf, bl->numHashes);
  for (i = 0; i < bl->numHashes; i++) {
    res |= serialize_uint256(buf, &bl->hashArray[i]);
  }
  res |= serialize_uint256(buf, &bl->hashStop);

  return res;
}
Beispiel #4
0
static struct buff *
txdb_serialize_tx_data(const struct tx_ser_data *tx)
{
    struct buff *buf;

    ASSERT(tx);

    buf = buff_alloc();

    serialize_uint256(buf, &tx->blkHash);
    serialize_uint64(buf,   tx->timestamp);
    serialize_varint(buf,   tx->len);
    serialize_bytes(buf,    tx->buf, tx->len);

    return buf;
}