int serialize_version(struct buff *buf, const btc_msg_version *v) { int res; res = serialize_uint32(buf, v->version); res |= serialize_uint64(buf, v->services); res |= serialize_uint64(buf, v->time); res |= serialize_addr(buf, &v->addrTo); res |= serialize_addr(buf, &v->addrFrom); res |= serialize_uint64(buf, v->nonce); res |= serialize_str(buf, v->strVersion); res |= serialize_uint32(buf, v->startingHeight); return res; }
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; }
int serialize_addr(struct buff *buf, const btc_msg_address *addr) { int res; res = serialize_uint64(buf, addr->services); res |= serialize_bytes(buf, addr->ip, ARRAYSIZE(addr->ip)); res |= serialize_uint16(buf, addr->port); return res; }
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; }
/** * @brief Serialize a size_t into a managed string. * @note This function will reallocate the output managed string if necessary, and append the serialized data, updating the length field to reflect the changes. * @param data a pointer to the address of a managed string to receive the output, which will be allocated for the caller if NULL is passed. * @param number the value of the size_t to be serialized. * @return true if the specified value was serialized and stored successfully, or false on failure. */ bool_t serialize_sz(stringer_t **data, size_t number) { return serialize_uint64(data, number); }