forked from rustyrussell/pettycoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash_tx.c
36 lines (31 loc) · 934 Bytes
/
hash_tx.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "hash_tx.h"
#include "marshal.h"
#include "merkle_recurse.h"
#include "protocol.h"
#include "shadouble.h"
#include "tx.h"
#include <assert.h>
void hash_refs(const struct protocol_input_ref *refs,
size_t num_refs,
struct protocol_double_sha *sha)
{
SHA256_CTX shactx;
/* Get double sha of references (may be 0 for non-normal trans) */
SHA256_Init(&shactx);
SHA256_Update(&shactx, refs, sizeof(refs[0]) * num_refs);
SHA256_Double_Final(&shactx, sha);
}
void hash_tx_and_refs(const union protocol_tx *tx,
const struct protocol_input_ref *refs,
struct protocol_txrefhash *txrefhash)
{
hash_tx(tx, &txrefhash->txhash);
hash_refs(refs, num_inputs(tx), &txrefhash->refhash);
}
void hash_tx(const union protocol_tx *tx, struct protocol_tx_id *txid)
{
SHA256_CTX shactx;
SHA256_Init(&shactx);
SHA256_Update(&shactx, tx, marshal_tx_len(tx));
SHA256_Double_Final(&shactx, &txid->sha);
}