Skip to content

Commit bb257dc

Browse files
committed
build: leverage WASM codegen changes to auto-generate Python SWIG code
- Auto generate _wrap* calls for Python. - Assert that fixed length returns are the expected size where possible. - Ignore non _alloc init functions automatically. - Prefer SWIG %ignore directive to header defines. - Remove support for Python 2.x. - Fix base58 conversion length; use length override calls first. Following this change, no manual SWIG changes are needed to add typical new calls to Python wrappers.
1 parent 5c8f38b commit bb257dc

12 files changed

Lines changed: 629 additions & 421 deletions

File tree

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
wrappers default this to zero for backwards compatibility.
66
- bip39_mnemonic_to_seed is no longer available for SWIG-wrapped languages.
77
Callers should use bip39_mnemonic_to_seed512 instead.
8+
- Python: Some calls (e.g. bip39_mnemonic_to_seed512, aes, and aes_cbc) used
9+
to take output buffers to fill and return the number of bytes written. These
10+
calls now automatically create and fill thier buffer, returning it as the
11+
only return value. The number of bytes written can be determined by using
12+
len() on the returned output buffer.
813

914
## Version 0.8.6
1015
- Support for PSET v0 (Elements) has been removed.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Wally can currently be built for:
2424
And can be used from:
2525
- C and compatible languages which can call C interfaces
2626
- C++ (see include/wally.hpp for C++ container support)
27-
- Python 2.7+ or 3.x
27+
- Python 3.x
2828
- Java
2929
- Javascript via node.js or Cordova or WebAssembly/Emscripten compatible
3030

@@ -122,7 +122,7 @@ It is suggested you only install this way into a virtualenv while the library
122122
is under heavy development.
123123

124124
If you wish to explicitly choose the python version to use, set the
125-
`PYTHON_VERSION` environment variable (to e.g. `2.7`, `3`, `3.7` etc) before
125+
`PYTHON_VERSION` environment variable (to e.g. `3`, `3.7` etc) before
126126
running `pip` or (when compiling manually) `./configure`.
127127

128128
You can also install the binary [wally releases](https://github.com/ElementsProject/libwally-core/releases)

include/wally_bip32.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ WALLY_CORE_API int bip32_key_free(
9292
const struct ext_key *hdkey);
9393
#endif /* SWIG_PYTHON */
9494

95-
#ifndef SWIG
9695
/**
9796
* Initialize a key.
9897
*/
@@ -111,7 +110,6 @@ WALLY_CORE_API int bip32_key_init(
111110
const unsigned char *parent160,
112111
size_t parent160_len,
113112
struct ext_key *output);
114-
#endif
115113

116114
/**
117115
* As per `bip32_key_init`, but allocates the key.
@@ -132,7 +130,6 @@ WALLY_CORE_API int bip32_key_init_alloc(
132130
size_t parent160_len,
133131
struct ext_key **output);
134132

135-
#ifndef SWIG
136133
/**
137134
* Create a new master extended key from entropy.
138135
*
@@ -170,7 +167,6 @@ WALLY_CORE_API int bip32_key_from_seed(
170167
uint32_t version,
171168
uint32_t flags,
172169
struct ext_key *output);
173-
#endif
174170

175171
/**
176172
* As per `bip32_key_from_seed_custom`, but allocates the key.
@@ -212,7 +208,6 @@ WALLY_CORE_API int bip32_key_serialize(
212208
size_t len);
213209

214210

215-
#ifndef SWIG
216211
/**
217212
* Un-serialize an extended key from memory.
218213
*
@@ -224,7 +219,6 @@ WALLY_CORE_API int bip32_key_unserialize(
224219
const unsigned char *bytes,
225220
size_t bytes_len,
226221
struct ext_key *output);
227-
#endif
228222

229223
/**
230224
* As per `bip32_key_unserialize`, but allocates the key.
@@ -236,7 +230,6 @@ WALLY_CORE_API int bip32_key_unserialize_alloc(
236230
size_t bytes_len,
237231
struct ext_key **output);
238232

239-
#ifndef SWIG
240233
/**
241234
* Create a new child extended key from a parent extended key.
242235
*
@@ -255,7 +248,6 @@ WALLY_CORE_API int bip32_key_from_parent(
255248
uint32_t child_num,
256249
uint32_t flags,
257250
struct ext_key *output);
258-
#endif
259251

260252
/**
261253
* As per `bip32_key_from_parent`, but allocates the key.
@@ -267,7 +259,6 @@ WALLY_CORE_API int bip32_key_from_parent_alloc(
267259
uint32_t flags,
268260
struct ext_key **output);
269261

270-
#ifndef SWIG
271262
/**
272263
* Create a new child extended key from a parent extended key and a path.
273264
*
@@ -286,7 +277,6 @@ WALLY_CORE_API int bip32_key_from_parent_path(
286277
size_t child_path_len,
287278
uint32_t flags,
288279
struct ext_key *output);
289-
#endif
290280

291281
/**
292282
* As per `bip32_key_from_parent_path`, but allocates the key.
@@ -299,7 +289,6 @@ WALLY_CORE_API int bip32_key_from_parent_path_alloc(
299289
uint32_t flags,
300290
struct ext_key **output);
301291

302-
#ifndef SWIG
303292
/**
304293
* Create a new child extended key from a parent extended key and a path string.
305294
*
@@ -331,7 +320,6 @@ WALLY_CORE_API int bip32_key_from_parent_path_str_n(
331320
uint32_t child_num,
332321
uint32_t flags,
333322
struct ext_key *output);
334-
#endif
335323

336324
/**
337325
* As per `bip32_key_from_parent_path_str`, but allocates the key.
@@ -357,7 +345,6 @@ WALLY_CORE_API int bip32_key_from_parent_path_str_n_alloc(
357345
struct ext_key **output);
358346

359347
#ifdef BUILD_ELEMENTS
360-
#ifndef SWIG
361348
/**
362349
* Derive the pub tweak from a parent extended key and a path.
363350
*
@@ -373,7 +360,6 @@ WALLY_CORE_API int bip32_key_with_tweak_from_parent_path(
373360
size_t child_path_len,
374361
uint32_t flags,
375362
struct ext_key *output);
376-
#endif
377363

378364
/**
379365
* As per `bip32_key_with_tweak_from_parent_path`, but allocates the key.
@@ -401,7 +387,6 @@ WALLY_CORE_API int bip32_key_to_base58(
401387
uint32_t flags,
402388
char **output);
403389

404-
#ifndef SWIG
405390
/**
406391
* Convert a base58 encoded extended key to an extended key.
407392
*
@@ -421,7 +406,6 @@ WALLY_CORE_API int bip32_key_from_base58_n(
421406
const char *base58,
422407
size_t base58_len,
423408
struct ext_key *output);
424-
#endif
425409

426410
/**
427411
* As per `bip32_key_from_base58`, but allocates the key.

include/wally_bip39.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ WALLY_CORE_API int bip39_mnemonic_validate(
103103
const struct words *w,
104104
const char *mnemonic);
105105

106-
#ifndef SWIG
107106
/**
108107
* Convert a mnemonic into a binary seed.
109108
*
@@ -119,7 +118,6 @@ WALLY_CORE_API int bip39_mnemonic_to_seed(
119118
unsigned char *bytes_out,
120119
size_t len,
121120
size_t *written);
122-
#endif /* SWIG */
123121

124122
/**
125123
* Convert a mnemonic into a binary seed of 512 bits.

include/wally_map.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ struct wally_map {
3434
};
3535
#endif /* SWIG */
3636

37-
#ifndef SWIG
3837
/**
3938
* Initialize a new map.
4039
*
@@ -45,7 +44,6 @@ WALLY_CORE_API int wally_map_init(
4544
size_t allocation_len,
4645
wally_map_verify_fn_t verify_fn,
4746
struct wally_map *output);
48-
#endif /* SWIG_PYTHON */
4947

5048
/**
5149
* Allocate and initialize a new map.
@@ -378,7 +376,6 @@ WALLY_CORE_API int wally_map_keypath_get_bip32_key_from_alloc(
378376
const struct ext_key *hdkey,
379377
struct ext_key **output);
380378

381-
#ifndef SWIG
382379
/**
383380
* Verify a PSBT keypath keyed by a serialized bip32 extended public key.
384381
*
@@ -420,7 +417,6 @@ WALLY_CORE_API int wally_keypath_xonly_public_key_verify(
420417
size_t key_len,
421418
const unsigned char *val,
422419
size_t val_len);
423-
#endif /* SWIG */
424420

425421
/**
426422
* Allocate and initialize a new BIP32 keypath map.

include/wally_psbt.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ struct wally_psbt {
133133
};
134134
#endif /* SWIG */
135135

136-
#ifndef SWIG
137136
/**
138137
* Set the previous txid in an input.
139138
*
@@ -1806,7 +1805,6 @@ WALLY_CORE_API int wally_psbt_output_get_blinding_status(
18061805
uint32_t flags,
18071806
size_t *written);
18081807
#endif /* BUILD_ELEMENTS */
1809-
#endif /* SWIG */
18101808

18111809
/**
18121810
* Allocate and initialize a new PSBT.
@@ -2142,7 +2140,6 @@ WALLY_CORE_API int wally_psbt_clone_alloc(
21422140
uint32_t flags,
21432141
struct wally_psbt **output);
21442142

2145-
#ifndef SWIG
21462143
/**
21472144
* Blind a PSBT.
21482145
*
@@ -2171,7 +2168,6 @@ WALLY_CORE_API int wally_psbt_blind(
21712168
uint32_t output_index,
21722169
uint32_t flags,
21732170
struct wally_map *output);
2174-
#endif
21752171

21762172
/**
21772173
* Blind a PSBT.

include/wally_transaction.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,13 @@ WALLY_CORE_API int wally_tx_witness_stack_set_dummy(
205205
size_t index,
206206
uint32_t flags);
207207

208-
#ifndef SWIG_PYTHON
209208
/**
210209
* Free a transaction witness stack allocated by `wally_tx_witness_stack_init_alloc`.
211210
*
212211
* :param stack: The transaction witness stack to free.
213212
*/
214213
WALLY_CORE_API int wally_tx_witness_stack_free(
215214
struct wally_tx_witness_stack *stack);
216-
#endif /* SWIG_PYTHON */
217215

218216
/**
219217
* Allocate and initialize a new transaction input.
@@ -238,16 +236,13 @@ WALLY_CORE_API int wally_tx_input_init_alloc(
238236
const struct wally_tx_witness_stack *witness,
239237
struct wally_tx_input **output);
240238

241-
#ifndef SWIG_PYTHON
242239
/**
243240
* Free a transaction input allocated by `wally_tx_input_init_alloc`.
244241
*
245242
* :param input: The transaction input to free.
246243
*/
247244
WALLY_CORE_API int wally_tx_input_free(struct wally_tx_input *input);
248-
#endif /* SWIG_PYTHON */
249245

250-
#ifndef SWIG
251246
/**
252247
* Initialize a new transaction output.
253248
*
@@ -260,7 +255,6 @@ WALLY_CORE_API int wally_tx_output_init(uint64_t satoshi,
260255
const unsigned char *script,
261256
size_t script_len,
262257
struct wally_tx_output *output);
263-
#endif /* SWIG */
264258

265259
/**
266260
* Allocate and initialize a new transaction output.
@@ -286,7 +280,6 @@ WALLY_CORE_API int wally_tx_output_clone_alloc(
286280
const struct wally_tx_output *tx_output_in,
287281
struct wally_tx_output **output);
288282

289-
#ifndef SWIG
290283
/**
291284
* Create a new copy of a transaction output in place.
292285
*
@@ -298,16 +291,13 @@ WALLY_CORE_API int wally_tx_output_clone_alloc(
298291
WALLY_CORE_API int wally_tx_output_clone(
299292
const struct wally_tx_output *tx_output_in,
300293
struct wally_tx_output *output);
301-
#endif /* SWIG */
302294

303-
#ifndef SWIG_PYTHON
304295
/**
305296
* Free a transaction output allocated by `wally_tx_output_init_alloc`.
306297
*
307298
* :param output: The transaction output to free.
308299
*/
309300
WALLY_CORE_API int wally_tx_output_free(struct wally_tx_output *output);
310-
#endif /* SWIG_PYTHON */
311301

312302
/**
313303
* Allocate and initialize a new transaction.
@@ -524,14 +514,12 @@ WALLY_CORE_API int wally_tx_get_witness_count(
524514
const struct wally_tx *tx,
525515
size_t *written);
526516

527-
#ifndef SWIG_PYTHON
528517
/**
529518
* Free a transaction allocated by `wally_tx_init_alloc`.
530519
*
531520
* :param tx: The transaction to free.
532521
*/
533522
WALLY_CORE_API int wally_tx_free(struct wally_tx *tx);
534-
#endif /* SWIG_PYTHON */
535523

536524
/**
537525
* Return the txid of a transaction.
@@ -761,15 +749,13 @@ WALLY_CORE_API int wally_tx_elements_input_issuance_set(
761749
const unsigned char *inflation_keys_rangeproof,
762750
size_t inflation_keys_rangeproof_len);
763751

764-
#ifndef SWIG_PYTHON
765752
/**
766753
* Free issuance data on an input.
767754
*
768755
* :param input: The input issuance data to free.
769756
*/
770757
WALLY_CORE_API int wally_tx_elements_input_issuance_free(
771758
struct wally_tx_input *input);
772-
#endif /* SWIG_PYTHON */
773759

774760
/**
775761
* Allocate and initialize a new elements transaction input.
@@ -858,17 +844,14 @@ WALLY_CORE_API int wally_tx_elements_output_commitment_set(
858844
const unsigned char *rangeproof,
859845
size_t rangeproof_len);
860846

861-
#ifndef SWIG_PYTHON
862847
/**
863848
* Free commitment data on an output.
864849
*
865850
* :param output: The output with the commitment data to free.
866851
*/
867852
WALLY_CORE_API int wally_tx_elements_output_commitment_free(
868853
struct wally_tx_output *output);
869-
#endif /* SWIG_PYTHON */
870854

871-
#ifndef SWIG
872855
/**
873856
* Initialize a new elements transaction output in place.
874857
*
@@ -902,7 +885,6 @@ WALLY_CORE_API int wally_tx_elements_output_init(
902885
const unsigned char *rangeproof,
903886
size_t rangeproof_len,
904887
struct wally_tx_output *output);
905-
#endif /* SWIG */
906888

907889
/**
908890
* Allocate and initialize a new elements transaction output.

0 commit comments

Comments
 (0)