forked from dcdpr/libtxref
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathc_usage_decoding_example.c
More file actions
36 lines (26 loc) · 952 Bytes
/
c_usage_decoding_example.c
File metadata and controls
36 lines (26 loc) · 952 Bytes
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
#include "txref.h"
#include <stdio.h>
// make sure we can check these examples even when building a release version
#undef NDEBUG
#include <assert.h>
int main() {
// create storage for decoded txref data
txref_DecodedResult *decodedResult = txref_create_DecodedResult();
if(!decodedResult) {
printf("txref_DecodedResult can not be created");
return E_TXREF_NO_MEMORY;
}
txref_error err = txref_decode(decodedResult, "tx1:yq3n-qqzq-qrqq-9z4d-2n");
if(err != E_TXREF_SUCCESS) {
printf("%s\n", txref_strerror(err));
txref_free_DecodedResult(decodedResult);
return (int)err;
}
// check for expected values (see c_usage_encoding_example.c)
assert(decodedResult->blockHeight == 10000);
assert(decodedResult->transactionIndex == 2);
assert(decodedResult->txoIndex == 3);
// free memory
txref_free_DecodedResult(decodedResult);
return E_TXREF_SUCCESS;
}