-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeMethods.cs
More file actions
912 lines (741 loc) · 36.8 KB
/
NativeMethods.cs
File metadata and controls
912 lines (741 loc) · 36.8 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
using System;
using System.Runtime.InteropServices;
using BitcoinKernel.Interop.Structs;
using BitcoinKernel.Interop.Helpers;
using BitcoinKernel.Interop.Enums;
using BitcoinKernel.Interop.Delegates;
namespace BitcoinKernel.Interop;
/// <summary>
/// Low-level P/Invoke declarations for the Bitcoin Kernel C API.
/// Maps directly to the bitcoinkernel.h C header.
/// </summary>
internal static class NativeMethods
{
#region Library Configuration
private const string LibName = "bitcoinkernel";
// For loading platform-specific libraries
static NativeMethods()
{
NativeLibraryLoader.EnsureLoaded();
}
#endregion
#region Context Management
/// <summary>
/// Creates a new kernel context.
/// </summary>
/// <returns>Pointer to kernel context, or IntPtr.Zero on failure</returns>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_context_create")]
public static extern IntPtr ContextCreate(IntPtr options);
/// <summary>
/// Destroys a kernel context and frees associated resources.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_context_destroy")]
public static extern void ContextDestroy(IntPtr context);
/// <summary>
/// Interrupts long-running operations associated with this context.
/// Returns 0 on success.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_context_interrupt")]
public static extern int ContextInterrupt(IntPtr context);
#endregion
#region Context Options
/// <summary>
/// Creates context options with default values.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_context_options_create")]
public static extern IntPtr ContextOptionsCreate();
/// <summary>
/// Destroys context options.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_context_options_destroy")]
public static extern void ContextOptionsDestroy(IntPtr options);
/// <summary>
/// Sets the chain parameters for the context.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_context_options_set_chainparams")]
public static extern void ContextOptionsSetChainParams(IntPtr options, IntPtr chain_params);
/// <summary>
/// Sets the notification callbacks for the context.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_context_options_set_notifications")]
public static extern void ContextOptionsSetNotifications(IntPtr options, NotificationInterfaceCallbacks callbacks);
/// <summary>
/// Sets the validation interface for the context.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_context_options_set_validation_interface")]
public static extern void ContextOptionsSetValidationInterface(IntPtr options, ValidationInterfaceCallbacks callbacks);
#endregion
#region Chain Parameters
/// <summary>
/// Creates chain parameters for the specified chain type.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chain_parameters_create")]
public static extern IntPtr ChainParametersCreate(ChainType chain_type);
/// <summary>
/// Destroys chain parameters.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chain_parameters_destroy")]
public static extern void ChainParametersDestroy(IntPtr chain_params);
#endregion
#region Chainstate Manager
/// <summary>
/// Creates a chainstate manager.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chainstate_manager_create")]
public static extern IntPtr ChainstateManagerCreate(IntPtr options);
/// <summary>
/// Destroys a chainstate manager.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chainstate_manager_destroy")]
public static extern void ChainstateManagerDestroy(IntPtr manager);
/// <summary>
/// Processes a block through validation.
/// Returns 0 on success.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chainstate_manager_process_block")]
public static extern int ChainstateManagerProcessBlock(
IntPtr manager,
IntPtr block,
ref int new_block);
/// <summary>
/// Gets a block tree entry by its block hash.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chainstate_manager_get_block_tree_entry_by_hash")]
public static extern IntPtr ChainstateManagerGetBlockTreeEntryByHash(
IntPtr manager,
IntPtr block_hash);
/// <summary>
/// Gets the active chain from the chainstate manager.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chainstate_manager_get_active_chain")]
public static extern IntPtr ChainstateManagerGetActiveChain(IntPtr manager);
/// <summary>
/// Gets the block tree entry with the most cumulative proof of work.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chainstate_manager_get_best_entry")]
public static extern IntPtr ChainstateManagerGetBestEntry(IntPtr manager);
/// <summary>
/// Processes and validates a block header.
/// Returns 0 on success.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chainstate_manager_process_block_header")]
public static extern int ChainstateManagerProcessBlockHeader(
IntPtr manager,
IntPtr header,
IntPtr block_validation_state);
/// <summary>
/// Imports blocks from an array of file paths.
/// Returns 0 on success.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chainstate_manager_import_blocks")]
public static extern int ChainstateManagerImportBlocks(
IntPtr manager,
[MarshalAs(UnmanagedType.LPArray)] string[] block_file_paths_data,
nuint[] block_file_paths_lens,
nuint block_file_paths_data_len);
#endregion
#region Chainstate Manager Options
/// <summary>
/// Creates chainstate manager options.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chainstate_manager_options_create")]
public static extern IntPtr ChainstateManagerOptionsCreate(
IntPtr context,
[MarshalAs(UnmanagedType.LPUTF8Str)] string data_directory,
nuint data_directory_len,
[MarshalAs(UnmanagedType.LPUTF8Str)] string blocks_directory,
nuint blocks_directory_len);
/// <summary>
/// Destroys chainstate manager options.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chainstate_manager_options_destroy")]
public static extern void ChainstateManagerOptionsDestroy(IntPtr options);
/// <summary>
/// Sets the number of worker threads for script verification.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chainstate_manager_options_set_worker_threads_num")]
public static extern void ChainstateManagerOptionsSetWorkerThreads(
IntPtr options,
int worker_threads);
/// <summary>
/// Sets whether to wipe the databases on load.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chainstate_manager_options_set_wipe_dbs")]
public static extern int ChainstateManagerOptionsSetWipeDbs(
IntPtr options,
int wipe_block_tree_db,
int wipe_chainstate_db);
/// <summary>
/// Sets block tree db in memory.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chainstate_manager_options_update_block_tree_db_in_memory")]
public static extern void ChainstateManagerOptionsUpdateBlockTreeDbInMemory(
IntPtr options,
int block_tree_db_in_memory);
/// <summary>
/// Sets chainstate db in memory.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chainstate_manager_options_update_chainstate_db_in_memory")]
public static extern void ChainstateManagerOptionsUpdateChainstateDbInMemory(
IntPtr options,
int chainstate_db_in_memory);
#endregion
#region Block Operations
/// <summary>
/// Creates a block from raw data.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_create")]
public static extern IntPtr BlockCreate(
byte[] raw_block,
UIntPtr raw_block_len);
/// <summary>
/// Destroys a block.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_destroy")]
public static extern void BlockDestroy(IntPtr block);
/// <summary>
/// Reads a block from disk by its block tree entry.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_read")]
public static extern IntPtr BlockRead(
IntPtr chainstate_manager,
IntPtr block_tree_entry);
/// <summary>
/// Gets the number of transactions in a block.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_count_transactions")]
public static extern nuint BlockCountTransactions(IntPtr block);
/// <summary>
/// Gets the block hash.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_get_hash")]
public static extern IntPtr BlockGetHash(IntPtr block);
/// <summary>
/// Gets the block header from a block.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_get_header")]
public static extern IntPtr BlockGetHeader(IntPtr block);
/// <summary>
/// Serializes the block to bytes.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_to_bytes")]
public static extern int BlockToBytes(
IntPtr block,
WriteBytes writer,
IntPtr user_data);
/// <summary>
/// Delegate for writing bytes during serialization.
/// </summary>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int WriteBytes(IntPtr bytes, nuint size, IntPtr userdata);
/// <summary>
/// Gets the block hash from a block tree entry.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_tree_entry_get_block_hash")]
public static extern IntPtr BlockTreeEntryGetBlockHash(IntPtr block_tree_entry);
/// <summary>
/// Gets the block height from a block tree entry.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_tree_entry_get_height")]
public static extern int BlockTreeEntryGetHeight(IntPtr block_tree_entry);
/// <summary>
/// Gets the previous block tree entry from a block tree entry.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_tree_entry_get_previous")]
public static extern IntPtr BlockTreeEntryGetPrevious(IntPtr block_tree_entry);
/// <summary>
/// Gets the block header from a block tree entry.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_tree_entry_get_block_header")]
public static extern IntPtr BlockTreeEntryGetBlockHeader(IntPtr block_tree_entry);
/// <summary>
/// Checks if two block tree entries are equal. Two block tree entries are equal when they
/// point to the same block.
/// Returns 1 if equal, 0 otherwise.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_tree_entry_equals")]
public static extern int BlockTreeEntryEquals(IntPtr entry1, IntPtr entry2);
/// <summary>
/// Copies a block (reference counted).
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_copy")]
public static extern IntPtr BlockCopy(IntPtr block);
/// <summary>
/// Gets a transaction at the specified index in a block.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_get_transaction_at")]
public static extern IntPtr BlockGetTransactionAt(IntPtr block, nuint index);
#endregion
#region BlockHash Operations
/// <summary>
/// Creates a block hash from 32 bytes.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_hash_create")]
public static extern IntPtr BlockHashCreate(IntPtr hash);
/// <summary>
/// Creates a block hash from 32 bytes (unsafe version).
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_hash_create")]
public static extern unsafe IntPtr BlockHashCreate(byte* hash);
/// <summary>
/// Serializes the block hash to bytes (32 bytes).
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_hash_to_bytes")]
public static extern void BlockHashToBytes(IntPtr block_hash, [MarshalAs(UnmanagedType.LPArray, SizeConst = 32)] byte[] output);
/// <summary>
/// Destroys a block hash.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_hash_destroy")]
public static extern void BlockHashDestroy(IntPtr block_hash);
#endregion
#region Block Header Operations
/// <summary>
/// Creates a block header from raw serialized data (80 bytes).
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_header_create")]
public static extern IntPtr BlockHeaderCreate(
byte[] raw_block_header,
UIntPtr raw_block_header_len);
/// <summary>
/// Copies a block header.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_header_copy")]
public static extern IntPtr BlockHeaderCopy(IntPtr header);
/// <summary>
/// Gets the block hash from a block header.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_header_get_hash")]
public static extern IntPtr BlockHeaderGetHash(IntPtr header);
/// <summary>
/// Gets the previous block hash from a block header.
/// The returned hash is unowned and only valid for the lifetime of the block header.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_header_get_prev_hash")]
public static extern IntPtr BlockHeaderGetPrevHash(IntPtr header);
/// <summary>
/// Gets the timestamp from a block header (Unix epoch seconds).
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_header_get_timestamp")]
public static extern uint BlockHeaderGetTimestamp(IntPtr header);
/// <summary>
/// Gets the nBits difficulty target from a block header (compact format).
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_header_get_bits")]
public static extern uint BlockHeaderGetBits(IntPtr header);
/// <summary>
/// Gets the version from a block header.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_header_get_version")]
public static extern int BlockHeaderGetVersion(IntPtr header);
/// <summary>
/// Gets the nonce from a block header.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_header_get_nonce")]
public static extern uint BlockHeaderGetNonce(IntPtr header);
/// <summary>
/// Destroys a block header.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_header_destroy")]
public static extern void BlockHeaderDestroy(IntPtr header);
#endregion
#region Chain Operations
/// <summary>
/// Gets the height of the chain.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chain_get_height")]
public static extern int ChainGetHeight(IntPtr chain);
/// <summary>
/// Gets a block tree entry by height.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chain_get_by_height")]
public static extern IntPtr ChainGetByHeight(IntPtr chain, int height);
/// <summary>
/// Checks if a block tree entry is in the chain.
/// Returns 1 if in chain, 0 otherwise.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chain_contains")]
public static extern int ChainContains(IntPtr chain, IntPtr block_tree_entry);
#endregion
#region Transaction Operations
/// <summary>
/// Creates a transaction from serialized data.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_create")]
public static extern IntPtr TransactionCreate(IntPtr raw_transaction, nuint raw_transaction_len);
/// <summary>
/// Copies a transaction (reference counted).
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_copy")]
public static extern IntPtr TransactionCopy(IntPtr transaction);
/// <summary>
/// Serializes a transaction to bytes.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_to_bytes")]
public static extern int TransactionToBytes(
IntPtr transaction,
WriteBytes writer,
IntPtr user_data);
/// <summary>
/// Gets the transaction ID (txid).
/// Returns a pointer to btck_Txid (not owned, lifetime depends on transaction).
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_get_txid")]
public static extern IntPtr TransactionGetTxid(IntPtr transaction);
/// <summary>
/// Gets the number of outputs in a transaction.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_count_outputs")]
public static extern nuint TransactionCountOutputs(IntPtr transaction);
/// <summary>
/// Gets the number of inputs in a transaction.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_count_inputs")]
public static extern nuint TransactionCountInputs(IntPtr transaction);
/// <summary>
/// Gets a transaction output at the specified index.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_get_output_at")]
public static extern IntPtr TransactionGetOutputAt(IntPtr transaction, nuint index);
/// <summary>
/// Gets a transaction input at the specified index.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_get_input_at")]
public static extern IntPtr TransactionGetInputAt(IntPtr transaction, nuint index);
/// <summary>
/// Gets the nLockTime value of a transaction.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_get_locktime")]
public static extern uint TransactionGetLocktime(IntPtr transaction);
/// <summary>
/// Destroys a transaction.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_destroy")]
public static extern void TransactionDestroy(IntPtr transaction);
/// <summary>
/// Gets the script pubkey from a transaction output.
/// Returns a pointer to btck_ScriptPubkey.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_output_get_script_pubkey")]
public static extern IntPtr TransactionOutputGetScriptPubkey(IntPtr output);
/// <summary>
/// Gets the value (amount) from a transaction output.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_output_get_amount")]
public static extern long TransactionOutputGetAmount(IntPtr output);
/// <summary>
/// Copy a transaction output.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_output_copy")]
public static extern IntPtr TransactionOutputCopy(IntPtr output);
/// <summary>
/// Destroys a transaction output.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_output_destroy")]
public static extern void TransactionOutputDestroy(IntPtr output);
#endregion
#region PrecomputedTransactionData Operations
/// <summary>
/// Creates precomputed transaction data for script verification.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_precomputed_transaction_data_create")]
public static extern IntPtr PrecomputedTransactionDataCreate(
IntPtr tx_to,
IntPtr[] spent_outputs,
nuint spent_outputs_len);
/// <summary>
/// Copies precomputed transaction data.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_precomputed_transaction_data_copy")]
public static extern IntPtr PrecomputedTransactionDataCopy(IntPtr precomputed_txdata);
/// <summary>
/// Destroys precomputed transaction data.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_precomputed_transaction_data_destroy")]
public static extern void PrecomputedTransactionDataDestroy(IntPtr precomputed_txdata);
#endregion
#region ScriptPubkey Operations
/// <summary>
/// Creates a script pubkey from serialized data.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_script_pubkey_create")]
public static extern IntPtr ScriptPubkeyCreate(IntPtr script_pubkey_data, nuint script_pubkey_len);
/// <summary>
/// Copies a script pubkey.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_script_pubkey_copy")]
public static extern IntPtr ScriptPubkeyCopy(IntPtr script_pubkey);
/// <summary>
/// Verifies a script pubkey.
/// Returns 1 if valid, 0 otherwise.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_script_pubkey_verify")]
public static extern int ScriptPubkeyVerify(
IntPtr script_pubkey,
long amount,
IntPtr tx_to,
IntPtr precomputed_txdata,
uint input_index,
uint flags,
IntPtr status);
/// <summary>
/// Serializes a script pubkey to bytes.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_script_pubkey_to_bytes")]
public static extern int ScriptPubkeyToBytes(
IntPtr script_pubkey,
WriteBytes writer,
IntPtr user_data);
/// <summary>
/// Destroys a script pubkey.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_script_pubkey_destroy")]
public static extern void ScriptPubkeyDestroy(IntPtr script_pubkey);
#endregion
#region TransactionOutput Operations (Additional)
/// <summary>
/// Creates a transaction output from a script pubkey and amount.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_output_create")]
public static extern IntPtr TransactionOutputCreate(IntPtr script_pubkey, long amount);
#endregion
#region Logging
/// <summary>
/// Creates a logging connection with a callback.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_logging_connection_create")]
public static extern IntPtr LoggingConnectionCreate(
LoggingCallback callback,
IntPtr user_data,
DestroyCallback? user_data_destroy_callback);
/// <summary>
/// Destroys a logging connection.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_logging_connection_destroy")]
public static extern void LoggingConnectionDestroy(IntPtr connection);
/// <summary>
/// Disables logging permanently.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_logging_disable")]
public static extern void LoggingDisable();
/// <summary>
/// Sets the log level for a category.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_logging_set_level_category")]
public static extern void LoggingSetLevelCategory(LogCategory category, LogLevel level);
/// <summary>
/// Sets logging options.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_logging_set_options")]
public static extern void LoggingSetOptions(LoggingOptions options);
/// <summary>
/// Enables a log category.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_logging_enable_category")]
public static extern void LoggingEnableCategory(LogCategory category);
/// <summary>
/// Disables a log category.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_logging_disable_category")]
public static extern void LoggingDisableCategory(LogCategory category);
#endregion
#region Block Validation State
/// <summary>
/// Creates a new block validation state.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_validation_state_create")]
public static extern IntPtr BlockValidationStateCreate();
/// <summary>
/// Gets the validation mode from a block validation state.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_validation_state_get_validation_mode")]
public static extern ValidationMode BlockValidationStateGetValidationMode(IntPtr validation_state);
/// <summary>
/// Gets the block validation result from a block validation state.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_validation_state_get_block_validation_result")]
public static extern BlockValidationResult BlockValidationStateGetBlockValidationResult(IntPtr validation_state);
/// <summary>
/// Copies a block validation state.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_validation_state_copy")]
public static extern IntPtr BlockValidationStateCopy(IntPtr validation_state);
/// <summary>
/// Destroys a block validation state.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_validation_state_destroy")]
public static extern void BlockValidationStateDestroy(IntPtr validation_state);
#endregion
#region Txid Operations
/// <summary>
/// Copies a txid.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_txid_copy")]
public static extern IntPtr TxidCopy(IntPtr txid);
/// <summary>
/// Checks if two txids are equal.
/// Returns 1 if equal, 0 otherwise.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_txid_equals")]
public static extern int TxidEquals(IntPtr txid1, IntPtr txid2);
/// <summary>
/// Serializes a txid to bytes (32 bytes).
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_txid_to_bytes")]
public static extern void TxidToBytes(IntPtr txid, [MarshalAs(UnmanagedType.LPArray, SizeConst = 32)] byte[] output);
/// <summary>
/// Destroys a txid.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_txid_destroy")]
public static extern void TxidDestroy(IntPtr txid);
#endregion
#region Coin Operations
/// <summary>
/// Copies a coin.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_coin_copy")]
public static extern IntPtr CoinCopy(IntPtr coin);
/// <summary>
/// Returns the block height where the transaction that created this coin was included.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_coin_confirmation_height")]
public static extern uint CoinConfirmationHeight(IntPtr coin);
/// <summary>
/// Returns whether the containing transaction was a coinbase.
/// Returns 1 if coinbase, 0 otherwise.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_coin_is_coinbase")]
public static extern int CoinIsCoinbase(IntPtr coin);
/// <summary>
/// Gets the transaction output of a coin.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_coin_get_output")]
public static extern IntPtr CoinGetOutput(IntPtr coin);
/// <summary>
/// Destroys a coin.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_coin_destroy")]
public static extern void CoinDestroy(IntPtr coin);
#endregion
#region BlockSpentOutputs Operations
/// <summary>
/// Reads block spent outputs (undo data) from disk.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_spent_outputs_read")]
public static extern IntPtr BlockSpentOutputsRead(
IntPtr chainstate_manager,
IntPtr block_tree_entry);
/// <summary>
/// Copies block spent outputs.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_spent_outputs_copy")]
public static extern IntPtr BlockSpentOutputsCopy(IntPtr block_spent_outputs);
/// <summary>
/// Gets the count of transaction spent outputs in block spent outputs.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_spent_outputs_count")]
public static extern nuint BlockSpentOutputsCount(IntPtr block_spent_outputs);
/// <summary>
/// Gets transaction spent outputs at the specified index.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_spent_outputs_get_transaction_spent_outputs_at")]
public static extern IntPtr BlockSpentOutputsGetTransactionSpentOutputsAt(
IntPtr block_spent_outputs,
nuint index);
/// <summary>
/// Destroys block spent outputs.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_spent_outputs_destroy")]
public static extern void BlockSpentOutputsDestroy(IntPtr block_spent_outputs);
#endregion
#region TransactionSpentOutputs Operations
/// <summary>
/// Copies transaction spent outputs.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_spent_outputs_copy")]
public static extern IntPtr TransactionSpentOutputsCopy(IntPtr transaction_spent_outputs);
/// <summary>
/// Gets the count of coins in transaction spent outputs.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_spent_outputs_count")]
public static extern nuint TransactionSpentOutputsCount(IntPtr transaction_spent_outputs);
/// <summary>
/// Gets a coin at the specified index.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_spent_outputs_get_coin_at")]
public static extern IntPtr TransactionSpentOutputsGetCoinAt(
IntPtr transaction_spent_outputs,
nuint index);
/// <summary>
/// Destroys transaction spent outputs.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_spent_outputs_destroy")]
public static extern void TransactionSpentOutputsDestroy(IntPtr transaction_spent_outputs);
#endregion
#region Missing Functions
/// <summary>
/// Copy a context.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_context_copy")]
public static extern IntPtr ContextCopy(IntPtr context);
/// <summary>
/// Copy chain parameters.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_chain_parameters_copy")]
public static extern IntPtr ChainParametersCopy(IntPtr chain_params);
/// <summary>
/// Checks if two block hashes are equal.
/// Returns 1 if equal, 0 otherwise.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_hash_equals")]
public static extern int BlockHashEquals(IntPtr hash1, IntPtr hash2);
/// <summary>
/// Copy a block hash.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_block_hash_copy")]
public static extern IntPtr BlockHashCopy(IntPtr block_hash);
#endregion
#region TransactionInput Operations
/// <summary>
/// Copies a transaction input.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_input_copy")]
public static extern IntPtr TransactionInputCopy(IntPtr transaction_input);
/// <summary>
/// Gets the transaction out point from a transaction input.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_input_get_out_point")]
public static extern IntPtr TransactionInputGetOutPoint(IntPtr transaction_input);
/// <summary>
/// Gets the nSequence value from a transaction input.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_input_get_sequence")]
public static extern uint TransactionInputGetSequence(IntPtr transaction_input);
/// <summary>
/// Destroys a transaction input.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_input_destroy")]
public static extern void TransactionInputDestroy(IntPtr transaction_input);
#endregion
#region TransactionOutPoint Operations
/// <summary>
/// Copies a transaction out point.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_out_point_copy")]
public static extern IntPtr TransactionOutPointCopy(IntPtr transaction_out_point);
/// <summary>
/// Gets the output index from a transaction out point.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_out_point_get_index")]
public static extern uint TransactionOutPointGetIndex(IntPtr transaction_out_point);
/// <summary>
/// Gets the txid from a transaction out point.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_out_point_get_txid")]
public static extern IntPtr TransactionOutPointGetTxid(IntPtr transaction_out_point);
/// <summary>
/// Destroys a transaction out point.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "btck_transaction_out_point_destroy")]
public static extern void TransactionOutPointDestroy(IntPtr transaction_out_point);
#endregion
}