redgold-schema 0.1.0

A relative proof conflict resolution & irreversibility service with trust modeling custodial pooling and executor contracts
Documentation
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
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
syntax = "proto3";

package structs;

// TODO: Schema version hash

enum SignatureType {
  ECDSA = 0;
  EcdsaBitcoinSignMessageHardware = 1;
}

message Signature {
  BytesData bytes = 1;
  SignatureType signature_type = 2;
}

enum PublicKeyType {
  secp256k1 = 0;
}

message PublicKey {
  BytesData bytes = 1;
  PublicKeyType key_type = 2;
}

// TODO: BytesData for signature?
// Multiple public key types
// TODO: Move the 'repeated' into this so that we encompass multi-sig proofs inside a single class
message Proof {
  Signature signature = 1;
  PublicKey public_key = 2;
}

// TODO: refactor
message PoWProof {
  uint32 proof_type = 1;
  bytes proof = 2;
}

message ProductId {
  Hash network = 1;
  Hash product = 2;
}

// TODO: We need to handle case where UtxoId is missing, a floating dependency or input based on code execution.

// TODO: Should we unify transaction hash / output_index into UtxoId?
// TODO: Support other output extraction operations, a function that processes a transaction and results ?

message FixedUtxoId {
  Hash transaction_hash = 1;
  int64 output_index = 2;
}

message FloatingUtxoId {

}

message OutputIndex {
  int64 output_index = 1;
}

message Input {
  // The hash associated with a parent / ancestor transaction which has already been accepted as valid.
  Hash transaction_hash = 1;
  // The index of the output in the parent transaction which is being spent.
  int64 output_index = 2;
  // The signed proof that this input is a valid reference to the previous output.
  repeated Proof proof = 3;
  // The identifier associated with the currency or product being used, for multi-currency support.
  ProductId product_id = 4;
  // Hydration purposes only! Not used for hashes
  Output output = 5;
}

message TrustData {
  // A score from -1 to 1 normalized to 1e3 (1000) scale for Equality avoidance of floats
  // Otherwise equivalent to a rounded float
  int64 label = 2;
  // Confidence level associated with the label, how certain is this value?
  optional int64 confidence = 3;
  // Variance associated with the confidence estimate, sigma / stddev
  optional int64 hardness = 5;
  // Additional unstructured or otherwise custom label data
  optional StandardData data = 6;
}

message TrustLabel {
  // TODO: Should this be bytesData?
  bytes peer_id = 1;
  repeated TrustData trust_data = 2;
}

message PartitionInfo {
  // Times 1000
  // TODO: Change to UtxoDistance
  // so we can preserve PartialEq and convert explicitly
  optional int64 utxo_distance = 1;
}

// This also needs a proof maybe?
message NodeMetadata {
  string external_address = 1;
  bytes multi_hash = 2;
  // May not be to store public key if we merkle the multi_hashes too.
  PublicKey public_key = 3;
  MerkleProof proof = 4;
  optional NodeType node_type = 5;
  optional VersionInfo version_info = 6;
  optional PartitionInfo partition_info = 7;
  optional int64 port_offset = 8;
  optional string alias = 9;
  optional string name = 10;
  PeerId peer_id = 11;
  optional bool nat_restricted = 12;
  NetworkEnvironment network_environment = 13;
}
/**
Used to store the version of the executable and the commit hash of the source code used to build it.
Security verifications associated with the node software should be done with this message.
 */
message VersionInfo {
  // The value associated with the Sha2-256 hash of the executable calculated with shasum locally
  // Should match github release page.
  string executable_checksum = 1;
  // This is only really useful in the security scenario where the node is building from source
  // Otherwise, even if filled with a value from git, it's not really verified
  optional string commit_hash = 2;
  // Same as prior hash except the intended upgrade hash of a node, not yet used.
  optional string next_executable_checksum = 3;
  // Intended time for performing a software update, for coordination of upgrades (not yet used.)
  optional int64 next_upgrade_time = 4;
}

message PeerId {
  BytesData peer_id = 1;
  repeated Proof known_proof = 3;
}

message PeerData {
  optional PeerId peer_id = 1;
  optional MerkleProof merkle_proof = 2;
  // This proof should be removed in favor of the one
  // on the transaction itself
  optional Proof proof = 3;
  repeated NodeMetadata node_metadata = 4;
  // Rename as RatingLabel
  // Also we need to store model outputs on NMD dynamic?
  repeated TrustLabel labels = 5;
  optional VersionInfo version_info = 6;
}

//// should i use kv pairs here to capture other features?
//// or a typedValue or something?
//message StoredPeerData {
//  PeerData peer_data = 1;
//  uint64 time = 2;
//  optional TrustLabel secret_label = 3;
//  optional double deterministic_trust = 4;
//  optional double trust_score = 5;
//  optional StandardData data = 6;
//}

enum BytesDecoder {
  STANDARD = 0;
}

message BytesData {
  bytes value = 1;
  BytesDecoder decoder = 2;
  int64 version = 3;
}

enum HashFormatType {
  Sha3_256 = 0;
}

message Hash {
  BytesData bytes = 1;
  HashFormatType hash_format_type = 2;
  HashType hash_type = 3;
}

message DynamicNodeMetadata {
  optional int64 udp_port = 1;
  Proof proof = 2;
  PeerId peer_id = 3;
}

// Where to store parquet schema, avro schema, etc. etc.

// Generic data structure designed to hold arbitrary data in a common format.
// This should be considered supplementary to using a regular schema, not a
// complete substitute.
message StandardData {
  // Standard currency style field
  optional int64 amount = 1;

  // Move to separate class instance still stored here?
  // Direct data storage for small values
  optional TypedValue typed_value = 2;
  repeated TypedValue typed_value_list = 3;
  optional KeyedTypedValue keyed_typed_value = 4;
  repeated KeyedTypedValue keyed_typed_value_list = 5;
  optional MatrixTypedValue matrix_typed_value = 6;
  repeated MatrixTypedValue matrix_typed_value_list = 7;
  // TODO: ResolvableDataReference fields for larger amounts of data
  // matrix typed value
  // Peer metadata field
  optional PeerData peer_data = 8;
  optional NodeMetadata node_metadata = 9;
  optional DynamicNodeMetadata dynamic_node_metadata = 10;
  optional int64 height = 11;
  Hash data_hash = 12;
  Hash hash = 13;
  Observation observation = 14;
}

message KeyedTypedValue {
  TypedValue key = 1;
  TypedValue value = 2;
}

message MatrixTypedValue {
  TypedValue key_i = 1;
  TypedValue key_j = 2;
  TypedValue value = 3;
}

message TypedValue {
  // amount
  optional BytesData bytes_value = 2;
  optional string string_value = 3;
  optional uint64 uint64_value = 1;
  optional int64 int64_value = 5;
  // Used to avoid Eq comparison problem in rust for strings encoded from floats.
  optional string float_value = 7;
  optional string double_value = 4;
  optional bool bool_value = 6;
  // TODO: consider adding the rest of the proto types?
}

enum StandardContractType {
  CURRENCY = 0;
  DEPOSIT = 1;
  SWAP = 2;
}

message KeyValueOption {
  string key = 1;
  string value = 2;
}

message CodeExecutionContract {
  optional BytesData hash_contract_reference = 1;
  optional BytesData raw_dynamic_contract = 2;
}

message OutputContract {
  // hash references, same issue as other thing
  optional StandardContractType standard_contract_type = 1;
  optional CodeExecutionContract code_execution_contract = 2;
  optional int64 threshold = 3;
  repeated int64 weights = 4;
}

message Output {
  Address address = 1;
  ProductId product_id = 5;
  repeated Proof counter_party_proofs = 6;
  // change to outputData?
  StandardData data = 7;
  OutputContract contract = 8;
}

// monthly / daily / window size + window center
message TimeLockWindow {
  uint64 delay = 1;
  uint64 offset = 2;
  uint64 window_size = 3;
}

message TransactionAmount {
  int64 amount = 1;
}

message TransactionData {
  optional string message = 1;
  optional uint64 time = 2;
  optional StandardData standard_data = 3;
}

message TransactionContract {
  // input gets signed with a proof;
  // output gets signed with a counter-party proof;
  // transaction then
  // should this confirmation thing be on the output or the transaction??? Transaction
  optional bool confirmation_= 1;
  repeated Proof confirmation_proofs = 2;
  // How long the network / each node must wait between PENDING and finalization
  optional uint64 finalize_window = 3;
  // How long the network must wait after FINALIZED to use.
  optional uint64 lock_period = 4;
  // Used to allow network criteria to vote on reversing in event of hacking.
  optional bool network_reversible = 5;

  optional TimeLockWindow time_lock_window = 6;
  repeated KeyValueOption options = 7;

  // Used only for anti-spam limiting at low limits.
  optional PoWProof pow_proof = 8;
}

enum NetworkEnvironment {
  // Production release, using real data and currency
 MAIN = 0;
 // Pre-production release, used for integration testing with release version before updating main net
 TEST = 1;
 // Latest dev branch code, continuously updated from latest build, unstable and non-release version
 DEV = 2;
 // Latest staging branch code, continuously updated but considered stable, upon verification is rolled to test net
 STAGING = 3;
 // Performance testing network, used for debugging performance issues and not tied to a particular version or stage
  // Can be manually set as for debugging, generally paired with staging code.
 PERF = 4;
 // Manually deployed network over arbitrary machines
  INTEGRATION = 5;
 // Designation for an entire network running as local processes not connecting to external services
 LOCAL = 6;
 // Designation for an entire network running within a single process. Either with mock-ups or other testing
  // harnesses -- generally used for debugging within an IDE,
 DEBUG = 7;
 // Operations which can potentially span all networks, like a host manager or infrastructure configuration.
 ALL = 8;
  // Testing branch before dev, force push commits here for manual debugging, one user at a time.
  PREDEV = 9;
}

message Salt {
  int64 value = 1;
}

// For use in providing a secondary, recent, submission time for offline signing process with delayed broadcast.
message OfflineTimeSponsor {
  int64 time = 1;
  Proof proof = 2;
}

message TransactionOptions {
  optional int64 salt = 1;
  optional NetworkEnvironment network_type = 2;
  repeated KeyValueOption key_value_options = 3;
  TransactionData data = 4;
  TransactionContract contract = 5;
  OfflineTimeSponsor offline_time_sponsor = 6;
}

message Transaction {
  repeated Input inputs = 1;
  repeated Output outputs = 2;
  StructMetadata struct_metadata = 3;
  TransactionOptions options = 4;

}

message BlockMetadata {
}

// Information about the data type itself, such as time produced and hash representations of it
message StructMetadata {
  // If present, represents some time related information that should be signed, typically transaction origination time
  optional int64 time = 1;
  // The version of the object, used for backwards / forward compatability and to determine which fields are present
  int32 version = 2;
  // The hash of the present object data, including all relevant fields, but excluding any enriched / hydrated data fields
  // This can be any one of the below hash values, and reflects the current state of the object.
  Hash hash = 3;
  // The hash of the object data, excluding any witness information, object should be cleared of other fields
  // or hydration related fields before signing.
  // This is equivalent to the SegWit hash.
  Hash signable_hash = 5;
  // The hash of the object after being signed once, this is the hash that includes the witness data / signature data.
  // This is equivalent to the hash of a transaction containing witness data ala standard ETH transaction.
  Hash signed_hash = 6;
  // The hash of the object after being signed twice, includes witness data from a counter-signature from an
  // accepting party. Used for transaction contracts that require counter party acceptance
  Hash counter_party_hash = 7;
  // The hash of the object after being signed three times, includes witness data from original signer,
  // counter-signer accepting party, and a final signature from the original of the counter party hashed object.
  Hash confirmation_hash = 8;
}

message AddressBlock {
  bytes address = 1;
  int64 balance = 2;
  int64 height = 3;
  bytes hash = 4;
}

message Block {
  Hash merkle_root = 1;
  // These are dropped for the hash calculation as the merkle root is present.
  repeated Transaction transactions = 2;
  StructMetadata struct_metadata = 3;
  Hash previous_block_hash = 4;
  optional BlockMetadata metadata = 5;
  // This is dropped for hash calculation as it represents the calculation after the fact,
  // Only stored for ease of preventing excess recalculations.
  Hash hash = 6;
  // Not really needed for hash calc, but harmless to include
  int64 height = 7;
}

enum State {
  PENDING = 0;
  // TODO: Change to accepted
  FINALIZED = 1;
  // Does this belong here?
  REJECTED = 2;
}

enum HashType {
  TRANSACTION = 0;
  OBSERVATION_METADATA = 1;
  OBSERVATION_MERKLE_ROOT = 2;
  TOMBSTONE = 3;
  ADDRESS = 4;
  UNKNOWN = 5;
}

message Tombstone {
  bytes hash = 1;
  // TODO: Other fields for the reason 'why'
}

message ObservationData {
  Transaction transaction = 1;
  Observation observation = 2;
}

enum ValidationType {
  // Perfect validation with all resolved dependencies
  FULL = 0;
  PARTIAL = 1;
}


// Metadata associated with some node observing and validating data associated with some hash
message ObservationMetadata {
  // The data under consideration which has had some validation performed for it.
  Hash observed_hash = 1;
  // Whether or not we have fully resolved all prior dependencies associated with the data internally
  ValidationType observation_type = 2;
  // How much we have accepted this data, whether or not sufficient time has passed to consider it confirmed
  optional State state = 3;
  // The degree of certainty associated with our validation, based on trustworthiness of information received from
  // other peers
  TrustData validation_confidence = 4;
  // Information about this object itself, such as time produced and hash representations of it
  StructMetadata struct_metadata = 5;
}



// TODO: Salt? Peer identifier? Etc
message Observation {
  // Merkle root of observations
  Hash merkle_root = 1;
  // Individual metadata of observations
  repeated ObservationMetadata observations = 2;
  // Signature associated with node key
  Proof proof = 3;
  StructMetadata struct_metadata = 4;
  // TODO: These can be removed after unifying to transaction ?
  int64 salt = 6;
  int64 height = 7;
  // Hash of the preceding observation reference
  Hash parent_hash = 8;
}

// Derived data structure, not a primary chain data structure
message ObservationEdge {
    ObservationProof observation_proof = 1;
    int64 time = 2;
}

// TODO: Update types here
// Derived data structure, not a primary chain data structure
message UtxoEntry {
  bytes transaction_hash = 1;
  int64 output_index = 2;
  // This is duplicated, but used for indexing.
  bytes address = 3;
  Output output = 4;
  int64 time = 5;
  // Consider adding additional fields to index here? amount? etc. for now just de-ser
}

//}
// should we add longer confirmation windows to transactions for fee?
// let's just assume the deposit addresses are well known?
// assume addresses are well known enough -- but network still needs to confirm that address is usable. ?? or does it
// or should we issue a unique deposit address per input?

// should we even have a deposit request??
// Should we just move this out of the schema entirely and use it as rest api call ? or leave it?
// Should a deposit just be a regular transaction?
// This type doesn't have a double spending issue, only requires single finalization.
// DepositRequest does not need to be observed. It only needs to be signed.
// how the hell do we collect the fee?
// just collect a fee from a redgold input to deposit.
//message DepositMulti {
//  repeated DepositInput inputs = 1;
//  repeated DepositOutput outputs = 2;
//  optional uint32 version = 6;
//  optional PoWProof anti_spam_proof = 7;
//  optional uint64 request_ttl_seconds = 8; // default 1 day
//}

// Let's assume deposit has already happened and this is the 'claim' of it.
// Deposit address is currently just requested from active nodes.
// They must agree on the main deposit address, and maintain old ones periodically.
// Deposit should be rejected if not confirmed -- but it can later be re-attempted.
// Once a deposit has been claimed it's 'used' in same way UTXO's are.
// How do we map from a deposit to an amount??

// screw it just use transaction?
//
//message Deposit {
//  bytes source_address = 1;
//  uint32 network = 2;
//  bytes destination_address = 3;
//  repeated Proof source_proof = 4;
//  OperationMetadata metadata =  5;
//}

// when the deposit is finalized, how do we determine the actual amount?
//
//message Deposit {
//  bytes deposit_request_hash = 1;
//  Proof control_proof = 2;
//  optional uint32 version = 3;
//}

// maybe a deposit should just be to a wrapped coin?
// that adds tons of complication..

// actually, wrapped bitcoin is fine, that's easily composible actually? maybe

// TODO: unify types here
message EagerFullGossipPush {
  repeated Transaction transactions = 1;
  repeated Observation observations = 2;
  repeated ObservationEdge observation_edges = 3;
  repeated PeerData peer_data = 7;
}



// These should both be broadcasts at some point
// Consider using a response here if needed.
message GossipTransactionRequest {
  Transaction transaction = 1;
}

message GossipObservationRequest {
  Observation observation = 1;
}

message ResolveHashRequest {
  Hash hash = 1;
  optional int64 output_index = 2;
}

// Add request id's here??

message ResolveHashResponse {
  TransactionInfo transaction_info = 1;
  AddressInfo address_info = 2;
  Observation observation = 3;
  PeerData peer_data = 4;
}


enum DownloadDataType {
  UTXO_ENTRY = 0;
  TRANSACTION_ENTRY = 1;
  OBSERVATION_ENTRY = 2;
  OBSERVATION_EDGE_ENTRY = 3;

  // Currently unsupported
  BLOCK_ENTRY = 4;
  SNAPSHOT_ENTRY = 5;
}

message DownloadRequest {
    uint64 start_time = 1;
    uint64 end_time = 2;
    DownloadDataType data_type = 3;
    optional uint64 offset = 4;
}

// Only used temporarily for download, not reliable 'time' value
message TransactionEntry {
  uint64 time = 1;
  Transaction transaction = 2;
}

message ObservationEntry {
  uint64 time = 1;
  Observation observation = 2;
}

message DownloadResponse {
  repeated UtxoEntry utxo_entries = 1;
  repeated TransactionEntry transactions = 2;
  repeated ObservationEntry observations = 3;
  repeated ObservationEdge observation_edges = 4;
  bool complete_response = 5;
}
//
//message DownloadMetadataRequest {
//  optional bool debug = 1;
//}
//
//message DownloadMetadataResponse {
//
//}

message GetPeersInfoRequest {

}

message PeerNodeInfo {
  Transaction latest_peer_transaction = 1;
  Transaction latest_node_transaction = 2;
  DynamicNodeMetadata dynamic_node_metadata = 3;
}

message PeerIdInfo {
  Transaction latest_peer_transaction = 1;
  repeated PeerNodeInfo peer_node_info = 2;
}

message GetPeersInfoResponse {
  repeated PeerNodeInfo peer_info = 2;
}


message MultipartyBroadcast {
  string room_id = 1;
  string message = 2;
}

message MultipartyIssueUniqueIndex {
  string room_id = 1;
}

message MultipartyIssueUniqueIndexResponse {
  int64 unique_index = 1;
}

message MultipartySubscribe {
  string room_id = 1;
  optional int64 last_event_id = 2;
  bool shutdown = 3;
}

message MultipartySubscribeEvent {
  string room_id = 1;
  string id = 2;
  string message = 3;
}

message MultipartyThresholdRequest {
  MultipartyBroadcast multiparty_broadcast = 1;
  MultipartyIssueUniqueIndex multiparty_issue_unique_index = 2;
  MultipartySubscribe multiparty_subscribe = 3;
  repeated MultipartySubscribeEvent multiparty_subscribe_events = 4;
  // TODO ^ all of these are only used by the internal adaptation which hit an error, only below are actually used
  InitiateMultipartyKeygenRequest initiate_keygen = 5;
  InitiateMultipartySigningRequest initiate_signing = 6;
}

message MultipartyThresholdResponse {
  MultipartyIssueUniqueIndexResponse multiparty_issue_unique_index_response = 1;
  InitiateMultipartyKeygenResponse initiate_keygen_response = 2;
  InitiateMultipartySigningResponse initiate_signing_response = 3;
}


message UtxoConflictResolveRequest {
  repeated FixedUtxoId utxo_ids = 1;
  Hash transaction_hash = 2;
}

message UtxoConflictResolveResponse {
  repeated TransactionInfo transactions = 1;
}

message QueryObservationProofRequest{
  Hash hash = 1;
}

message QueryObservationProofResponse {
  repeated ObservationProof observation_proof = 1;
}


message Request {
  optional GossipTransactionRequest gossip_transaction_request = 1;
  optional GossipObservationRequest gossip_observation_request = 2;
  optional ResolveHashRequest resolve_hash_request = 3;
  optional DownloadRequest download_request = 4;
  AboutNodeRequest about_node_request = 5;
  Proof proof = 7;
  NodeMetadata node_metadata = 8;
  GetPeersInfoRequest get_peers_info_request = 9;
  //  optional DownloadMetadataRequest download_metadata_request = 5;
  MultipartyThresholdRequest multiparty_threshold_request = 10;
  SubmitTransactionRequest submit_transaction_request = 11;
  UtxoConflictResolveRequest utxo_conflict_resolve_request = 12;
  QueryObservationProofRequest query_observation_proof_request = 13;
  HashSearchRequest hash_search_request = 14;
  optional string trace_id = 15;
  optional bool trace = 16;
}

message Response {
  ResponseMetadata response_metadata = 1;
  // Pull in other response classes if needed.
  optional ResolveHashResponse resolve_hash_response = 2;
  optional DownloadResponse download_response = 3;
  AboutNodeResponse about_node_response = 4;
  GetPeersInfoResponse get_peers_info_response = 5;
  NodeMetadata node_metadata = 6;
  Proof proof = 7;

  MultipartyThresholdResponse multiparty_threshold_response = 8;
  SubmitTransactionResponse submit_transaction_response = 9;
  UtxoConflictResolveResponse utxo_conflict_resolve_response = 10;
  QueryObservationProofResponse query_observation_proof_response = 11;
  HashSearchResponse hash_search_response = 12;
}

message QueryTransactionRequest {
  Hash transaction_id = 1;
}


message MerkleProof {
  Hash root = 1;
  Hash leaf = 2;
  repeated Hash nodes = 3;
}

message ObservationProof {
  Hash observation_hash = 1;
  MerkleProof merkle_proof = 2;
  ObservationMetadata metadata = 3;
  Proof proof = 4;
}

message QueryTransactionResponse {
  repeated ObservationProof observation_proofs = 1;
  Hash block_hash = 2;
}

message SubmitTransactionRequest {
  Transaction transaction = 1;
  bool sync_query_response = 2;
}

// TODO: This should just return the entire transaction with it's hash also calculated
// Also include the signing hash in the response, modify transaction schema for that
message SubmitTransactionResponse {
  Hash transaction_hash = 1;
  QueryTransactionResponse query_transaction_response = 2;
  Transaction transaction = 3;
}

message AboutNodeRequest {
  bool verbose = 1;
}

message AboutNodeResponse {
  Transaction latest_metadata = 2;
  Transaction latest_node_metadata = 3;
  int64 num_known_peers = 4;
  int64 num_active_peers = 5;
  repeated Transaction recent_transactions = 6;
  int64 pending_transactions = 7;
  int64 total_accepted_transactions = 8;
  int64 observation_height = 9;
  PeerNodeInfo peer_node_info = 10;
}

enum AddressType {
  Sha3_224_Checksum_Public = 0;
  MULTIHASH_KEYHASH = 1;
  BITCOIN_COMPAT_ADDRESS = 2;
  ETHEREUM_COMPAT_ADDRESS = 3;
  PUBLIC_KEY_DIRECT_ADDRESS = 4;
  UNKNOWN_ADDRESS_TYPE = 5;
}

message Address {
  BytesData address = 1;
  AddressType address_type = 2;
}

message QueryAddressesRequest {
  repeated Address addresses = 1;
}

message QueryAddressesResponse {
  repeated UtxoEntry utxo_entries = 1;
}

message FaucetRequest {
  Address address = 1;
}
// Should this just be transactionInfo?
message FaucetResponse {
  SubmitTransactionResponse submit_transaction_response = 1;
}

message RecentTransactionsRequest {}
message RecentTransactionsResponse {
  repeated Transaction transactions = 1;
}

message HashSearchRequest {
  string search_string = 1;
  // TODO: Optional data types etc.
}

message UsedOutputs {
  FixedUtxoId utxo_id = 1;
  repeated ObservationProof proof = 2;
}

message TransactionInfo {
  Transaction transaction = 1;
  repeated ObservationProof observation_proofs = 2;
  // Which output indexes are still considered valid.
  repeated int32 valid_utxo_index = 3;
  // In order to calculate this quantity, we need another index to determine if something has been used.
  repeated UsedOutputs used_outputs = 4;
  bool accepted = 5;
  ErrorInfo rejection_reason = 6;
  // Move this outside to the class / request that requires it for resolving.
  optional bool queried_output_index_valid = 7;
  TransactionState state = 8;
}

message AddressInfo {
  Address address = 1;
  repeated UtxoEntry utxo_entries = 2;
  int64 balance = 3;
  repeated Transaction recent_transactions = 4;
}

message HashSearchResponse {
  TransactionInfo transaction_info = 1;
  AddressInfo address_info = 2;
  Observation observation = 3;
  PeerNodeInfo peer_node_info = 4;
  PeerIdInfo peer_id_info = 5;
}

message PublicRequest {
  optional SubmitTransactionRequest submit_transaction_request = 1;
  optional QueryTransactionRequest query_transaction_request = 2;
  optional AboutNodeRequest about_node_request = 3;
  optional QueryAddressesRequest query_addresses_request = 4;
  // Debug only
  FaucetRequest faucet_request = 5;
  RecentTransactionsRequest recent_transactions_request = 6;
  HashSearchRequest hash_search_request = 7;
}


message PublicResponse {
  optional ResponseMetadata response_metadata = 1;
  optional SubmitTransactionResponse submit_transaction_response = 2;
  optional QueryTransactionResponse query_transaction_response = 3;
  optional AboutNodeResponse about_node_response = 4;
  optional QueryAddressesResponse query_addresses_response = 5;
  FaucetResponse faucet_response = 6;
  RecentTransactionsResponse recent_transactions_response = 7;
  HashSearchResponse hash_search_response = 8;
}

message ErrorDetails {
  string detail_name = 1;
  string detail = 2;
}

message ErrorInfo {
  Error code = 1;
  string description = 2;
  string description_extended = 3;
  string message = 4;
  repeated ErrorDetails details = 5;
  bool retriable = 6;
  string stacktrace = 7;
  string lib_message = 8;
}

message TaskLocalDetails {
  string key = 1;
  string value = 2;
}

message ResponseMetadata {
  bool success = 1;
  ErrorInfo error_info = 2;
  repeated TaskLocalDetails task_local_details = 3;
  optional string request_id = 4;
  optional string trace_id = 5;
}
//
//message AddPeerFullRequest {
//  bytes id = 1;
//  double trust = 2;
//  bytes public_key = 3;
//  string address = 4;
//  bool connect_to_peer = 5;
//}

message MultipartyIdentifier {
  repeated PublicKey party_keys = 1;
  int64 threshold = 2;
  string uuid = 3;
  int64 num_parties = 4;
}

message InitiateMultipartyKeygenRequest {
  MultipartyIdentifier identifier = 1;
  optional PublicKey host_key = 2;
  optional string host_address = 3;
  optional uint32 port = 4;
  optional int64 index = 6;
  optional bool return_local_share = 7;
  optional bool store_local_share = 8;
  optional int64 timeout_seconds = 9;
}

message InitiateMultipartyKeygenResponse {
  optional string local_share = 1;
  optional InitiateMultipartyKeygenRequest initial_request = 2;
}
message InitiateMultipartySigningResponse{
  Proof proof = 1;
  optional InitiateMultipartySigningRequest initial_request = 2;
}

message InitiateMultipartySigningRequest {
  MultipartyIdentifier identifier = 1;
  optional PublicKey host_key = 2;
  optional string host_address = 3;
  optional uint32 port = 4;
  repeated int64 party_indexes = 5;
  BytesData data_to_sign = 6;
  optional bool store_proof = 8;
  optional int64 timeout_seconds = 9;
  InitiateMultipartyKeygenRequest keygen_room = 10;
}


message ControlRequest {
//  AddPeerFullRequest add_peer_full_request = 1;
  InitiateMultipartyKeygenRequest initiate_multiparty_keygen_request = 2;
  InitiateMultipartySigningRequest initiate_multiparty_signing_request = 3;
}

message UpdatePeerTrustRequest {}


message ControlResponse {
  ResponseMetadata response_metadata = 1;
  InitiateMultipartyKeygenResponse initiate_multiparty_keygen_response = 2;
  InitiateMultipartySigningResponse initiate_multiparty_signing_response = 3;
}

enum Error {
  /// Signature failed verification
  IncorrectSignature = 0;
  MissingInputs = 1;
  MissingOutputs = 2;
  InvalidAddressInputIndex = 3;
  InvalidHashLength = 4;
  TransactionAlreadyProcessing = 5;
  UnknownUTXO = 6;
  BalanceMismatch = 7;
  InsufficientBalance = 8;
  InsufficientFee = 9;
  MissingProof = 10;
  TransactionRejectedDoubleSpend = 11;
  InternalDatabaseError = 12;
  AddressPublicKeyProofMismatch = 13;
  UnknownError = 14;
  DatabaseFailure = 15;
  MissingField = 16;
  ProtoDecoderFailure = 17;
  InvalidNetworkEnvironment = 18;
  DataStoreInternalCorruption = 19;
  HexDecodeFailure = 20;
  AddressDecodeFailure = 21;
  UnsupportedCurrency = 22;
  AddressNotFound = 23;
  UnknownTransaction = 24;
  UnknownBlock = 25;
  InternalChannelSendError = 26;
  InternalChannelReceiveError = 27;
  ParseFailure = 28;
  DeserializationFailure = 29;
  SerializationFailure = 30;
}

enum NodeType {
  Ephemeral = 0;
  Static = 1;
}

enum NodeState {
  Ready = 0;
  Offline = 2;
  Initializing = 3;
  Downloading = 4;
  Synchronizing = 5;
  ShuttingDown = 6;
}

enum KeyType {
  Transport = 0;
  ObservationMerkle = 2;
  Deposit = 3;
  Reward = 4;
}


message UdpMessage {
  BytesData bytes = 1;
  int64 part = 2;
  int64 parts = 3;
  string uuid = 4;
  int64 timestamp = 5;
}
//
//message Server {
//  string host = 1;
//  optional string username = 2;
//  optional string key_path = 3;
//
//}
/*

#[derive(Clone, Debug)]
pub struct SeedNode {
    pub peer_id: Option<Vec<u8>>,
    pub trust: Vec<TrustData>,
    pub public_key: Option<PublicKey>,
    pub external_address: String,
    pub port_offset: Option<u16>,
    pub environments: Vec<NetworkEnvironment>,
}
 */

message Seed {
  string external_address = 1;
  repeated NetworkEnvironment environments = 2;
  optional uint32 port_offset = 3;
  repeated TrustData trust = 4;
  PeerId peer_id = 5;
  optional PublicKey public_key = 6;
}


message DebugVersionChange {
  optional string field1 = 1;
}

message DebugVersionChange2 {
  optional string field1 = 1;
  optional string field2 = 2;
}

enum TransactionState {
  Rejected = 0;
  Mempool = 1;
  Validated = 2;
  Pending = 3;
  Finalized = 4;
  Accepted = 5;
  Unknown = 6;
}