-
Notifications
You must be signed in to change notification settings - Fork 0
/
17_4_examinepsbt.c
66 lines (42 loc) · 1.53 KB
/
17_4_examinepsbt.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include "wally_core.h"
#include "wally_psbt.h"
int main(int argc, char *argv[]) {
/* 1. Request a PSBT */
if (argc != 2) {
printf("ERROR: Only %i arguments! Correct usage is '%s [psbt]'\n",argc-1,argv[0]);
exit(-1);
}
char *psbt_64 = argv[1];
/* 2. Convert the PSBT */
int lw_response;
struct wally_psbt *psbt;
lw_response = wally_psbt_from_base64(psbt_64,&psbt);
if (lw_response) {
printf("Error: Wally_psbt_from_base64 failed: %d\n",lw_response);
exit(-1);
}
/* 3. Read the Inputs */
int inputs = psbt->num_inputs;
printf("TOTAL INPUTS: %i\n",inputs);
/* This will crash if the inputs are not filled in, or if there are non_witness_utxos */
for (int i = 0 ; i < inputs ; i++) {
printf("\nINPUT #%i: %i satoshis\n",i, psbt->inputs[i].witness_utxo->satoshi);
char *script_hex;
wally_hex_from_bytes(psbt->inputs[i].witness_utxo->script,psbt->inputs[i].witness_utxo->script_len,&script_hex);
printf("scriptPubKey: %s\n",script_hex);
wally_free_string(script_hex);
}
/* 4. Read the Outputs */
int outputs = psbt->num_outputs;
printf("\nTOTAL OUTPUTS: %i\n",outputs);
/* This will crash if the outputs are not filled in */
for (int i = 0 ; i < outputs ; i++) {
char *pubkey_hex;
wally_hex_from_bytes(psbt->tx->outputs[i].script,psbt->tx->outputs[i].script_len,&pubkey_hex);
printf("\nINPUT #%i\n",i);
printf("scriptPubKey: %s\n",pubkey_hex);
wally_free_string(pubkey_hex);
}
wally_cleanup(0);
}