-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcfdgo_tests_elements_test.go
2453 lines (2136 loc) · 211 KB
/
cfdgo_tests_elements_test.go
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
package cfdgo
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCfdCreateRawTransaction(t *testing.T) {
txHex, err := CfdGoInitializeConfidentialTx(uint32(2), uint32(0))
assert.NoError(t, err)
assert.Equal(t, "0200000000000000000000", txHex)
sequence := (uint32)(KCfdSequenceLockTimeDisable)
if err == nil {
txHex, err = CfdGoAddConfidentialTxIn(
txHex,
"7461b02405414d79e79a5050684a333c922c1136f4bdff5fb94b551394edebbd", 0,
sequence)
assert.NoError(t, err)
assert.Equal(t, "020000000001bdebed9413554bb95fffbdf436112c923c334a6850509ae7794d410524b061740000000000ffffffff0000000000", txHex)
}
if err == nil {
txHex, err = CfdGoAddConfidentialTxIn(
txHex,
"1497e1f146bc5fe00b6268ea16a7069ecb90a2a41a183446d5df8965d2356dc1", 1,
sequence)
assert.NoError(t, err)
assert.Equal(t, "020000000002bdebed9413554bb95fffbdf436112c923c334a6850509ae7794d410524b061740000000000ffffffffc16d35d26589dfd54634181aa4a290cb9e06a716ea68620be05fbc46f1e197140100000000ffffffff0000000000", txHex)
}
if err == nil {
txHex, err = CfdGoAddConfidentialTxOut(
txHex,
"ef47c42d34de1b06a02212e8061323f50d5f02ceed202f1cb375932aa299f751",
int64(100000000), "",
"CTEw7oSCUWDfmfhCEdsB3gsG7D9b4xLCZEq71H8JxRFeBu7yQN3CbSF6qT6J4F7qji4bq1jVSdVcqvRJ",
"", "")
assert.NoError(t, err)
assert.Equal(t, "020000000002bdebed9413554bb95fffbdf436112c923c334a6850509ae7794d410524b061740000000000ffffffffc16d35d26589dfd54634181aa4a290cb9e06a716ea68620be05fbc46f1e197140100000000ffffffff010151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000005f5e10003a630456ab6d50b57981e085abced70e2816289ae2b49a44c2f471b205134c12b1976a914d08f5ba8874d36cf97d19379b370f1f23ba36d5888ac00000000", txHex)
}
if err == nil {
txHex, err = CfdGoAddConfidentialTxOut(
txHex,
"6f1a4b6bd5571b5f08ab79c314dc6483f9b952af2f5ef206cd6f8e68eb1186f3",
int64(1900500000), "",
"2dxZw5iVZ6Pmqoc5Vn8gkUWDGB5dXuMBCmM", "", "")
assert.NoError(t, err)
assert.Equal(t, "020000000002bdebed9413554bb95fffbdf436112c923c334a6850509ae7794d410524b061740000000000ffffffffc16d35d26589dfd54634181aa4a290cb9e06a716ea68620be05fbc46f1e197140100000000ffffffff020151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000005f5e10003a630456ab6d50b57981e085abced70e2816289ae2b49a44c2f471b205134c12b1976a914d08f5ba8874d36cf97d19379b370f1f23ba36d5888ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f010000000071475420001976a914fdd725970db682de970e7669646ed7afb8348ea188ac00000000", txHex)
}
if err == nil {
txHex, err = CfdGoAddConfidentialTxOut(
txHex,
"6f1a4b6bd5571b5f08ab79c314dc6483f9b952af2f5ef206cd6f8e68eb1186f3",
int64(500000), "", "", "", "")
assert.NoError(t, err)
assert.Equal(t, "020000000002bdebed9413554bb95fffbdf436112c923c334a6850509ae7794d410524b061740000000000ffffffffc16d35d26589dfd54634181aa4a290cb9e06a716ea68620be05fbc46f1e197140100000000ffffffff030151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000005f5e10003a630456ab6d50b57981e085abced70e2816289ae2b49a44c2f471b205134c12b1976a914d08f5ba8874d36cf97d19379b370f1f23ba36d5888ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f010000000071475420001976a914fdd725970db682de970e7669646ed7afb8348ea188ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f01000000000007a120000000000000", txHex)
}
if err == nil {
txHex, err = CfdGoAddDestroyConfidentialTxOut(
txHex,
"ef47c42d34de1b06a02212e8061323f50d5f02ceed202f1cb375932aa299f751",
int64(50000000))
assert.NoError(t, err)
assert.Equal(t, "020000000002bdebed9413554bb95fffbdf436112c923c334a6850509ae7794d410524b061740000000000ffffffffc16d35d26589dfd54634181aa4a290cb9e06a716ea68620be05fbc46f1e197140100000000ffffffff040151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000005f5e10003a630456ab6d50b57981e085abced70e2816289ae2b49a44c2f471b205134c12b1976a914d08f5ba8874d36cf97d19379b370f1f23ba36d5888ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f010000000071475420001976a914fdd725970db682de970e7669646ed7afb8348ea188ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f01000000000007a12000000151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000002faf08000016a00000000", txHex)
}
if err == nil {
txHex, err = CfdGoUpdateConfidentialTxOut(txHex, uint32(2), "6f1a4b6bd5571b5f08ab79c314dc6483f9b952af2f5ef206cd6f8e68eb1186f3", int64(1000000), "", "", "", "")
assert.NoError(t, err)
assert.Equal(t, "020000000002bdebed9413554bb95fffbdf436112c923c334a6850509ae7794d410524b061740000000000ffffffffc16d35d26589dfd54634181aa4a290cb9e06a716ea68620be05fbc46f1e197140100000000ffffffff040151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000005f5e10003a630456ab6d50b57981e085abced70e2816289ae2b49a44c2f471b205134c12b1976a914d08f5ba8874d36cf97d19379b370f1f23ba36d5888ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f010000000071475420001976a914fdd725970db682de970e7669646ed7afb8348ea188ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f0100000000000f424000000151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000002faf08000016a00000000", txHex)
}
if err != nil {
fmt.Print("[error message] " + err.Error() + "\n")
}
fmt.Printf("%s test done.\n", GetFuncName())
}
func TestCfdCreateRawTransaction2(t *testing.T) {
handle, err := CfdGoInitializeConfidentialTransaction(uint32(2), uint32(0))
assert.NoError(t, err)
defer CfdGoFreeTransactionHandle(handle)
sequence := uint32(0xffffffff)
if err == nil {
err = CfdGoAddTxInput(
handle,
"7461b02405414d79e79a5050684a333c922c1136f4bdff5fb94b551394edebbd", 0,
sequence)
assert.NoError(t, err)
}
if err == nil {
err = CfdGoAddTxInput(
handle,
"1497e1f146bc5fe00b6268ea16a7069ecb90a2a41a183446d5df8965d2356dc1", 1,
sequence)
assert.NoError(t, err)
}
if err == nil {
err = CfdGoAddConfidentialTxOutput(
handle,
"ef47c42d34de1b06a02212e8061323f50d5f02ceed202f1cb375932aa299f751",
int64(100000000),
"CTEw7oSCUWDfmfhCEdsB3gsG7D9b4xLCZEq71H8JxRFeBu7yQN3CbSF6qT6J4F7qji4bq1jVSdVcqvRJ")
assert.NoError(t, err)
}
if err == nil {
err = CfdGoAddConfidentialTxOutput(
handle,
"6f1a4b6bd5571b5f08ab79c314dc6483f9b952af2f5ef206cd6f8e68eb1186f3",
int64(1900500000),
"2dxZw5iVZ6Pmqoc5Vn8gkUWDGB5dXuMBCmM")
assert.NoError(t, err)
}
if err == nil {
err = CfdGoAddConfidentialTxOutputFee(
handle,
"6f1a4b6bd5571b5f08ab79c314dc6483f9b952af2f5ef206cd6f8e68eb1186f3",
int64(500000))
assert.NoError(t, err)
}
if err == nil {
err = CfdGoAddConfidentialTxOutputDestroyAmount(
handle,
"ef47c42d34de1b06a02212e8061323f50d5f02ceed202f1cb375932aa299f751",
int64(50000000))
assert.NoError(t, err)
}
if err == nil {
txHex, err := CfdGoFinalizeTransaction(handle)
assert.NoError(t, err)
assert.Equal(t, "020000000002bdebed9413554bb95fffbdf436112c923c334a6850509ae7794d410524b061740000000000ffffffffc16d35d26589dfd54634181aa4a290cb9e06a716ea68620be05fbc46f1e197140100000000ffffffff040151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000005f5e10003a630456ab6d50b57981e085abced70e2816289ae2b49a44c2f471b205134c12b1976a914d08f5ba8874d36cf97d19379b370f1f23ba36d5888ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f010000000071475420001976a914fdd725970db682de970e7669646ed7afb8348ea188ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f01000000000007a12000000151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000002faf08000016a00000000", txHex)
}
if err == nil {
handle2, err := CfdGoInitializeConfidentialTransactionByHex("020000000002bdebed9413554bb95fffbdf436112c923c334a6850509ae7794d410524b061740000000000ffffffffc16d35d26589dfd54634181aa4a290cb9e06a716ea68620be05fbc46f1e197140100000000ffffffff040151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000005f5e10003a630456ab6d50b57981e085abced70e2816289ae2b49a44c2f471b205134c12b1976a914d08f5ba8874d36cf97d19379b370f1f23ba36d5888ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f010000000071475420001976a914fdd725970db682de970e7669646ed7afb8348ea188ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f01000000000007a12000000151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000002faf08000016a00000000")
assert.NoError(t, err)
defer CfdGoFreeTransactionHandle(handle2)
if err == nil {
err = CfdGoAddConfidentialTxOutputByScript(
handle2,
"6f1a4b6bd5571b5f08ab79c314dc6483f9b952af2f5ef206cd6f8e68eb1186f3",
int64(10000),
"0014eb3c0d55b7098a4aef4a18ee1eebcb1ed924a82b")
assert.NoError(t, err)
}
if err == nil {
txHex, err := CfdGoFinalizeTransaction(handle2)
assert.NoError(t, err)
assert.Equal(t, "020000000002bdebed9413554bb95fffbdf436112c923c334a6850509ae7794d410524b061740000000000ffffffffc16d35d26589dfd54634181aa4a290cb9e06a716ea68620be05fbc46f1e197140100000000ffffffff050151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000005f5e10003a630456ab6d50b57981e085abced70e2816289ae2b49a44c2f471b205134c12b1976a914d08f5ba8874d36cf97d19379b370f1f23ba36d5888ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f010000000071475420001976a914fdd725970db682de970e7669646ed7afb8348ea188ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f01000000000007a12000000151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000002faf08000016a01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f01000000000000271000160014eb3c0d55b7098a4aef4a18ee1eebcb1ed924a82b00000000", txHex)
}
}
fmt.Printf("%s test done.\n", GetFuncName())
}
func TestCfdGetTransaction(t *testing.T) {
txHex := "0200000000020f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570000000000ffffffff0f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570100008000ffffffffd8bbe31bc590cbb6a47d2e53a956ec25d8890aefd60dcfc93efd34727554890b0683fe0819a4f9770c8a7cd5824e82975c825e017aff8ba0d6a5eb4959cf9c6f010000000023c346000004017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000003b947f6002200d8510dfcf8e2330c0795c771d1e6064daab2f274ac32a6e2708df9bfa893d17a914ef3e40882e17d6e477082fcafeb0f09dc32d377b87010bad521bafdac767421d45b71b29a349c7b2ca2a06b5d8e3b5898c91df2769ed010000000029b9270002cc645552109331726c0ffadccab21620dd7a5a33260c6ac7bd1c78b98cb1e35a1976a9146c22e209d36612e0d9d2a20b814d7d8648cc7a7788ac017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000000000c350000001cdb0ed311810e61036ac9255674101497850f5eee5e4320be07479c05473cbac010000000023c3460003ce4c4eac09fe317f365e45c00ffcf2e9639bc0fd792c10f72cdc173c4e5ed8791976a9149bdcb18911fa9faad6632ca43b81739082b0a19588ac00000000"
count, err := CfdGoGetConfidentialTxInCount(txHex)
assert.NoError(t, err)
assert.Equal(t, uint32(2), count)
count, err = CfdGoGetConfidentialTxOutCount(txHex)
assert.NoError(t, err)
assert.Equal(t, uint32(4), count)
if err == nil {
txData, err := CfdGoGetConfidentialTxData(txHex)
assert.NoError(t, err)
assert.Equal(t, "cf7783b2b1de646e35186df988a219a17f0317b5c3f3c47fa4ab2d7463ea3992", txData.Txid)
assert.Equal(t, "cf7783b2b1de646e35186df988a219a17f0317b5c3f3c47fa4ab2d7463ea3992", txData.Wtxid)
assert.Equal(t, "938e3a9b5bac410e812d08db74c4ef2bc58d1ed99d94b637cab0ac2e9eb59df8", txData.WitHash)
assert.Equal(t, uint32(512), txData.Size)
assert.Equal(t, uint32(512), txData.Vsize)
assert.Equal(t, uint32(2048), txData.Weight)
assert.Equal(t, uint32(2), txData.Version)
assert.Equal(t, uint32(0), txData.LockTime)
}
if err == nil {
txid, vout, sequence, scriptSig, err := CfdGoGetConfidentialTxIn(txHex, uint32(1))
assert.NoError(t, err)
assert.Equal(t, "57a15002d066ce52573d674df925c9bc0f1164849420705f2cfad8a68111230f", txid)
assert.Equal(t, uint32(1), vout)
assert.Equal(t, uint32(4294967295), sequence)
assert.Equal(t, "", scriptSig)
if err == nil {
txinIndex, err := CfdGoGetConfidentialTxInIndex(txHex, txid, vout)
assert.NoError(t, err)
assert.Equal(t, uint32(1), txinIndex)
}
}
if err == nil {
entropy, nonce, assetAmount, assetValue, tokenAmount, tokenValue, assetRangeproof, tokenRangeproof, err := CfdGoGetTxInIssuanceInfo(txHex, uint32(1))
assert.NoError(t, err)
assert.Equal(t, "6f9ccf5949eba5d6a08bff7a015e825c97824e82d57c8a0c77f9a41908fe8306", entropy)
assert.Equal(t, "0b8954757234fd3ec9cf0dd6ef0a89d825ec56a9532e7da4b6cb90c51be3bbd8", nonce)
assert.Equal(t, "010000000023c34600", assetValue)
assert.Equal(t, "", tokenValue)
assert.Equal(t, int64(600000000), assetAmount)
assert.Equal(t, int64(0), tokenAmount)
assert.Equal(t, "", assetRangeproof)
assert.Equal(t, "", tokenRangeproof)
}
if err == nil {
asset, satoshiValue, valueCommitment, nonce, lockingScript, surjectionProof, rangeproof, err := CfdGoGetConfidentialTxOut(txHex, uint32(3))
assert.NoError(t, err)
assert.Equal(t, "accb7354c07974e00b32e4e5eef55078490141675592ac3610e6101831edb0cd", asset)
assert.Equal(t, int64(600000000), satoshiValue)
assert.Equal(t, "010000000023c34600", valueCommitment)
assert.Equal(t, "03ce4c4eac09fe317f365e45c00ffcf2e9639bc0fd792c10f72cdc173c4e5ed879", nonce)
assert.Equal(t, "76a9149bdcb18911fa9faad6632ca43b81739082b0a19588ac", lockingScript)
assert.Equal(t, "", surjectionProof)
assert.Equal(t, "", rangeproof)
if err == nil {
txoutIndex, err := CfdGoGetConfidentialTxOutIndex(txHex, "2dodsWJgP3pTWWidK5hDxuYHqC1U4CEnT3n", "")
assert.NoError(t, err)
assert.Equal(t, uint32(3), txoutIndex)
}
if err == nil {
txoutIndex, err := CfdGoGetConfidentialTxOutIndex(txHex, "", lockingScript)
assert.NoError(t, err)
assert.Equal(t, uint32(3), txoutIndex)
}
}
if err != nil {
fmt.Print("[error message] " + err.Error() + "\n")
}
fmt.Printf("%s test done.\n", GetFuncName())
}
func TestCfdGetTransactionByHandle(t *testing.T) {
txHex := "0200000000020f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570000000000ffffffff0f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570100008000ffffffffd8bbe31bc590cbb6a47d2e53a956ec25d8890aefd60dcfc93efd34727554890b0683fe0819a4f9770c8a7cd5824e82975c825e017aff8ba0d6a5eb4959cf9c6f010000000023c346000004017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000003b947f6002200d8510dfcf8e2330c0795c771d1e6064daab2f274ac32a6e2708df9bfa893d17a914ef3e40882e17d6e477082fcafeb0f09dc32d377b87010bad521bafdac767421d45b71b29a349c7b2ca2a06b5d8e3b5898c91df2769ed010000000029b9270002cc645552109331726c0ffadccab21620dd7a5a33260c6ac7bd1c78b98cb1e35a1976a9146c22e209d36612e0d9d2a20b814d7d8648cc7a7788ac017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000000000c350000001cdb0ed311810e61036ac9255674101497850f5eee5e4320be07479c05473cbac010000000023c3460003ce4c4eac09fe317f365e45c00ffcf2e9639bc0fd792c10f72cdc173c4e5ed8791976a9149bdcb18911fa9faad6632ca43b81739082b0a19588ac00000000"
txData, txinList, txoutList, err := GetConfidentialTxData(txHex, true)
assert.NoError(t, err)
assert.Equal(t, 2, len(txinList))
assert.Equal(t, 4, len(txoutList))
if err == nil {
assert.Equal(t, "cf7783b2b1de646e35186df988a219a17f0317b5c3f3c47fa4ab2d7463ea3992", txData.Txid)
assert.Equal(t, "cf7783b2b1de646e35186df988a219a17f0317b5c3f3c47fa4ab2d7463ea3992", txData.Wtxid)
assert.Equal(t, "938e3a9b5bac410e812d08db74c4ef2bc58d1ed99d94b637cab0ac2e9eb59df8", txData.WitHash)
assert.Equal(t, uint32(512), txData.Size)
assert.Equal(t, uint32(512), txData.Vsize)
assert.Equal(t, uint32(2048), txData.Weight)
assert.Equal(t, uint32(2), txData.Version)
assert.Equal(t, uint32(0), txData.LockTime)
// txid, vout, sequence, scriptSig, err := CfdGoGetConfidentialTxIn(txHex, uint32(1))
assert.NoError(t, err)
assert.Equal(t, "57a15002d066ce52573d674df925c9bc0f1164849420705f2cfad8a68111230f", txinList[1].OutPoint.Txid)
assert.Equal(t, uint32(1), txinList[1].OutPoint.Vout)
assert.Equal(t, uint32(4294967295), txinList[1].Sequence)
assert.Equal(t, "", txinList[1].ScriptSig)
// entropy, nonce, assetAmount, assetValue, tokenAmount, tokenValue, assetRangeproof, tokenRangeproof, err := CfdGoGetTxInIssuanceInfo(txHex, uint32(1))
assert.Equal(t, "6f9ccf5949eba5d6a08bff7a015e825c97824e82d57c8a0c77f9a41908fe8306", txinList[1].Issuance.Entropy)
assert.Equal(t, "0b8954757234fd3ec9cf0dd6ef0a89d825ec56a9532e7da4b6cb90c51be3bbd8", txinList[1].Issuance.Nonce)
assert.Equal(t, "010000000023c34600", txinList[1].Issuance.AssetValue)
assert.Equal(t, "", txinList[1].Issuance.TokenValue)
assert.Equal(t, int64(600000000), txinList[1].Issuance.AssetAmount)
assert.Equal(t, int64(0), txinList[1].Issuance.TokenAmount)
assert.Equal(t, "", txinList[1].IssuanceAmountRangeproof)
assert.Equal(t, "", txinList[1].InflationKeysRangeproof)
// asset, satoshiValue, valueCommitment, nonce, lockingScript, surjectionProof, rangeproof, err := CfdGoGetConfidentialTxOut(txHex, uint32(3))
assert.Equal(t, "accb7354c07974e00b32e4e5eef55078490141675592ac3610e6101831edb0cd", txoutList[3].Asset)
assert.Equal(t, int64(600000000), txoutList[3].Amount)
assert.Equal(t, "010000000023c34600", txoutList[3].CommitmentValue)
assert.Equal(t, "03ce4c4eac09fe317f365e45c00ffcf2e9639bc0fd792c10f72cdc173c4e5ed879", txoutList[3].CommitmentNonce)
assert.Equal(t, "76a9149bdcb18911fa9faad6632ca43b81739082b0a19588ac", txoutList[3].LockingScript)
assert.Equal(t, "", txoutList[3].Surjectionproof)
assert.Equal(t, "", txoutList[3].Rangeproof)
}
txHandle, err := CfdGoInitializeTxDataHandle(int(KCfdNetworkLiquidv1), txHex)
assert.NoError(t, err)
if err == nil {
txinIndex, err := CfdGoGetTxInIndexByHandle(txHandle, txinList[1].OutPoint.Txid, txinList[1].OutPoint.Vout)
assert.NoError(t, err)
assert.Equal(t, uint32(1), txinIndex)
if err == nil {
txinIndex, err = CfdGoGetTxInIndexByHandle(txHandle, txinList[0].OutPoint.Txid, txinList[0].OutPoint.Vout)
assert.NoError(t, err)
assert.Equal(t, uint32(0), txinIndex)
}
if err == nil {
txoutIndex, err := CfdGoGetTxOutIndexByHandle(txHandle, "2dodsWJgP3pTWWidK5hDxuYHqC1U4CEnT3n", "")
assert.NoError(t, err)
assert.Equal(t, uint32(3), txoutIndex)
}
if err == nil {
txoutIndex, err := CfdGoGetTxOutIndexByHandle(txHandle, "", txoutList[3].LockingScript)
assert.NoError(t, err)
assert.Equal(t, uint32(3), txoutIndex)
}
if err == nil {
txoutIndex, err := CfdGoGetTxOutIndexByHandle(txHandle, "", txoutList[2].LockingScript)
assert.NoError(t, err)
assert.Equal(t, uint32(2), txoutIndex)
}
freeErr := CfdGoFreeTxDataHandle(txHandle)
assert.NoError(t, freeErr)
}
if err != nil {
fmt.Print("[error message] " + err.Error() + "\n")
}
fmt.Printf("%s test done.\n", GetFuncName())
}
func TestCfdSetRawReissueAsset(t *testing.T) {
txHex := "0200000000020f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570000000000ffffffff0f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570100000000ffffffff03017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000003b947f6002200d8510dfcf8e2330c0795c771d1e6064daab2f274ac32a6e2708df9bfa893d17a914ef3e40882e17d6e477082fcafeb0f09dc32d377b87010bad521bafdac767421d45b71b29a349c7b2ca2a06b5d8e3b5898c91df2769ed010000000029b9270002cc645552109331726c0ffadccab21620dd7a5a33260c6ac7bd1c78b98cb1e35a1976a9146c22e209d36612e0d9d2a20b814d7d8648cc7a7788ac017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000000000c350000000000000"
asset, outTxHex, err := CfdGoSetRawReissueAsset(
txHex, "57a15002d066ce52573d674df925c9bc0f1164849420705f2cfad8a68111230f",
uint32(1),
int64(600000000), "0b8954757234fd3ec9cf0dd6ef0a89d825ec56a9532e7da4b6cb90c51be3bbd8",
"6f9ccf5949eba5d6a08bff7a015e825c97824e82d57c8a0c77f9a41908fe8306",
"CTExCoUri8VzkxbbhqzgsruWJ5zYtmoFXxCWtjiSLAzcMbpEWhHmDrZ66bAb41VsmSKnvJWrq2cfjUw9",
"")
assert.NoError(t, err)
assert.Equal(t, "accb7354c07974e00b32e4e5eef55078490141675592ac3610e6101831edb0cd", asset)
assert.Equal(t, "0200000000020f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570000000000ffffffff0f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570100008000ffffffffd8bbe31bc590cbb6a47d2e53a956ec25d8890aefd60dcfc93efd34727554890b0683fe0819a4f9770c8a7cd5824e82975c825e017aff8ba0d6a5eb4959cf9c6f010000000023c346000004017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000003b947f6002200d8510dfcf8e2330c0795c771d1e6064daab2f274ac32a6e2708df9bfa893d17a914ef3e40882e17d6e477082fcafeb0f09dc32d377b87010bad521bafdac767421d45b71b29a349c7b2ca2a06b5d8e3b5898c91df2769ed010000000029b9270002cc645552109331726c0ffadccab21620dd7a5a33260c6ac7bd1c78b98cb1e35a1976a9146c22e209d36612e0d9d2a20b814d7d8648cc7a7788ac017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000000000c350000001cdb0ed311810e61036ac9255674101497850f5eee5e4320be07479c05473cbac010000000023c3460003ce4c4eac09fe317f365e45c00ffcf2e9639bc0fd792c10f72cdc173c4e5ed8791976a9149bdcb18911fa9faad6632ca43b81739082b0a19588ac00000000", outTxHex)
if err != nil {
fmt.Print("[error message] " + err.Error() + "\n")
}
fmt.Printf("%s test done.\n", GetFuncName())
}
func TestCfdGetIssuanceBlindingKey(t *testing.T) {
blindingKey, err := CfdGoGetIssuanceBlindingKey(
"ac2c1e4cce122139bb25abc50599e09738143cc4bc96e55f399a5e1e45d916a9",
"57a15002d066ce52573d674df925c9bc0f1164849420705f2cfad8a68111230f", uint32(1))
assert.NoError(t, err)
assert.Equal(t, "7d65c7970d836a878a1080399a3c11de39a8e82493e12b1ad154e383661fb77f", blindingKey)
if err != nil {
fmt.Print("[error message] " + err.Error() + "\n")
}
fmt.Printf("%s test done.\n", GetFuncName())
}
func TestCfdGetDefaultBlindingKey(t *testing.T) {
masterBlindingKey := "ac2c1e4cce122139bb25abc50599e09738143cc4bc96e55f399a5e1e45d916a9"
address := "ex1qav7q64dhpx9y4m62rrhpa67trmvjf2ptum84qh"
lockingScript := "0014eb3c0d55b7098a4aef4a18ee1eebcb1ed924a82b"
blindingKey, err := CfdGoGetDefaultBlindingKey(masterBlindingKey, lockingScript)
assert.NoError(t, err)
assert.Equal(t, "24ff3843a00c29fadee220b7d4943915cc5f65fddf1c20363495568bf406fc71", blindingKey)
blindingKey, err = CfdGoGetDefaultBlindingKeyByAddress(masterBlindingKey, address)
assert.NoError(t, err)
assert.Equal(t, "24ff3843a00c29fadee220b7d4943915cc5f65fddf1c20363495568bf406fc71", blindingKey)
fmt.Printf("%s test done.\n", GetFuncName())
}
func TestCfdBlindTransaction(t *testing.T) {
txHex := "0200000000020f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570000000000ffffffff0f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570100008000ffffffffd8bbe31bc590cbb6a47d2e53a956ec25d8890aefd60dcfc93efd34727554890b0683fe0819a4f9770c8a7cd5824e82975c825e017aff8ba0d6a5eb4959cf9c6f010000000023c346000004017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000003b947f6002200d8510dfcf8e2330c0795c771d1e6064daab2f274ac32a6e2708df9bfa893d17a914ef3e40882e17d6e477082fcafeb0f09dc32d377b87010bad521bafdac767421d45b71b29a349c7b2ca2a06b5d8e3b5898c91df2769ed010000000029b9270002cc645552109331726c0ffadccab21620dd7a5a33260c6ac7bd1c78b98cb1e35a1976a9146c22e209d36612e0d9d2a20b814d7d8648cc7a7788ac017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000000000c350000001cdb0ed311810e61036ac9255674101497850f5eee5e4320be07479c05473cbac010000000023c3460003ce4c4eac09fe317f365e45c00ffcf2e9639bc0fd792c10f72cdc173c4e5ed8791976a9149bdcb18911fa9faad6632ca43b81739082b0a19588ac00000000"
blindHandle, err := CfdGoInitializeBlindTx()
assert.NoError(t, err)
if err == nil {
option := NewCfdBlindTxOption()
option.MinimumBits = 36
err = CfdGoSetBlindTxOption(blindHandle, option)
assert.NoError(t, err)
}
if err == nil {
err = CfdGoAddBlindTxInData(
blindHandle,
"57a15002d066ce52573d674df925c9bc0f1164849420705f2cfad8a68111230f", uint32(0),
"186c7f955149a5274b39e24b6a50d1d6479f552f6522d91f3a97d771f1c18179",
"a10ecbe1be7a5f883d5d45d966e30dbc1beff5f21c55cec76cc21a2229116a9f",
"ae0f46d1940f297c2dc3bbd82bf8ef6931a2431fbb05b3d3bc5df41af86ae808",
int64(999637680), "", "")
assert.NoError(t, err)
}
if err == nil {
err = CfdGoAddBlindTxInData(
blindHandle,
"57a15002d066ce52573d674df925c9bc0f1164849420705f2cfad8a68111230f", uint32(1),
"ed6927df918c89b5e3d8b5062acab2c749a3291bb7451d4267c7daaf1b52ad0b",
"0b8954757234fd3ec9cf0dd6ef0a89d825ec56a9532e7da4b6cb90c51be3bbd8",
"62e36e1f0fa4916b031648a6b6903083069fa587572a88b729250cde528cfd3b",
int64(700000000),
"7d65c7970d836a878a1080399a3c11de39a8e82493e12b1ad154e383661fb77f",
"7d65c7970d836a878a1080399a3c11de39a8e82493e12b1ad154e383661fb77f")
assert.NoError(t, err)
}
if err == nil {
err = CfdGoAddBlindTxOutData(
blindHandle, uint32(0),
"02200d8510dfcf8e2330c0795c771d1e6064daab2f274ac32a6e2708df9bfa893d")
assert.NoError(t, err)
}
if err == nil {
err = CfdGoAddBlindTxOutData(
blindHandle, uint32(1),
"02cc645552109331726c0ffadccab21620dd7a5a33260c6ac7bd1c78b98cb1e35a")
assert.NoError(t, err)
}
if err == nil {
err = CfdGoAddBlindTxOutData(
blindHandle, uint32(3),
"03ce4c4eac09fe317f365e45c00ffcf2e9639bc0fd792c10f72cdc173c4e5ed879")
assert.NoError(t, err)
}
if err == nil {
txHex, err = CfdGoFinalizeBlindTx(blindHandle, txHex)
assert.NoError(t, err)
}
err2 := CfdGoFreeBlindHandle(blindHandle) // release
assert.NoError(t, err2)
if err == nil {
txData, err := CfdGoGetConfidentialTxData(txHex)
assert.NoError(t, err)
assert.Equal(t, 64, len(txData.Txid))
assert.Equal(t, 64, len(txData.Wtxid))
assert.Equal(t, 64, len(txData.WitHash))
assert.Equal(t, uint32(12589), txData.Size)
assert.Equal(t, uint32(3604), txData.Vsize)
assert.Equal(t, uint32(14413), txData.Weight)
assert.Equal(t, uint32(2), txData.Version)
assert.Equal(t, uint32(0), txData.LockTime)
}
// unblind test
if err == nil {
asset, assetValue, aabf, avbf, token, tokenValue, tabf, tvbf, err := CfdGoUnblindIssuance(
txHex, uint32(1),
"7d65c7970d836a878a1080399a3c11de39a8e82493e12b1ad154e383661fb77f",
"7d65c7970d836a878a1080399a3c11de39a8e82493e12b1ad154e383661fb77f")
assert.NoError(t, err)
assert.Equal(t, "accb7354c07974e00b32e4e5eef55078490141675592ac3610e6101831edb0cd", asset)
assert.Equal(t, int64(600000000), assetValue)
assert.Equal(t, "0000000000000000000000000000000000000000000000000000000000000000", aabf)
assert.NotEqual(t, "0000000000000000000000000000000000000000000000000000000000000000", avbf)
assert.Equal(t, "", token)
assert.Equal(t, int64(0), tokenValue)
assert.Equal(t, "", tabf)
assert.Equal(t, "", tvbf)
}
if err == nil {
asset, value, abf, vbf, err := CfdGoUnblindTxOut(
txHex, uint32(0),
"6a64f506be6e60b948987aa4d180d2ab05034a6a214146e06e28d4efe101d006")
assert.NoError(t, err)
assert.Equal(t, "186c7f955149a5274b39e24b6a50d1d6479f552f6522d91f3a97d771f1c18179", asset)
assert.Equal(t, int64(999587680), value)
assert.NotEqual(t, "0000000000000000000000000000000000000000000000000000000000000000", abf)
assert.NotEqual(t, "0000000000000000000000000000000000000000000000000000000000000000", vbf)
}
if err == nil {
asset, value, abf, vbf, err := CfdGoUnblindTxOut(
txHex, uint32(1),
"94c85164605f589c4c572874f36b8301989c7fabfd44131297e95824d473681f")
assert.NoError(t, err)
assert.Equal(t, "ed6927df918c89b5e3d8b5062acab2c749a3291bb7451d4267c7daaf1b52ad0b", asset)
assert.Equal(t, int64(700000000), value)
assert.NotEqual(t, "0000000000000000000000000000000000000000000000000000000000000000", abf)
assert.NotEqual(t, "0000000000000000000000000000000000000000000000000000000000000000", vbf)
}
if err == nil {
asset, value, abf, vbf, err := CfdGoUnblindTxOut(
txHex, uint32(3),
"0473d39aa6542e0c1bb6a2343b2319c3e92063dd019af4d47dbf50c460204f32")
assert.NoError(t, err)
assert.Equal(t, "accb7354c07974e00b32e4e5eef55078490141675592ac3610e6101831edb0cd", asset)
assert.Equal(t, int64(600000000), value)
assert.NotEqual(t, "0000000000000000000000000000000000000000000000000000000000000000", abf)
assert.NotEqual(t, "0000000000000000000000000000000000000000000000000000000000000000", vbf)
}
if err != nil {
fmt.Print("[error message] " + err.Error() + "\n")
}
fmt.Printf("%s test done.\n", GetFuncName())
}
func TestCfdBlindTransaction2(t *testing.T) {
baseTxHex := "0200000000020f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570000000000ffffffff0f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570100008000ffffffffd8bbe31bc590cbb6a47d2e53a956ec25d8890aefd60dcfc93efd34727554890b0683fe0819a4f9770c8a7cd5824e82975c825e017aff8ba0d6a5eb4959cf9c6f010000000023c346000004017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000003b947f6002200d8510dfcf8e2330c0795c771d1e6064daab2f274ac32a6e2708df9bfa893d17a914ef3e40882e17d6e477082fcafeb0f09dc32d377b87010bad521bafdac767421d45b71b29a349c7b2ca2a06b5d8e3b5898c91df2769ed010000000029b9270002cc645552109331726c0ffadccab21620dd7a5a33260c6ac7bd1c78b98cb1e35a1976a9146c22e209d36612e0d9d2a20b814d7d8648cc7a7788ac017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000000000c350000001cdb0ed311810e61036ac9255674101497850f5eee5e4320be07479c05473cbac010000000023c3460003ce4c4eac09fe317f365e45c00ffcf2e9639bc0fd792c10f72cdc173c4e5ed8791976a9149bdcb18911fa9faad6632ca43b81739082b0a19588ac00000000"
// option := NewCfdBlindTxOption()
// option.MinimumBits = 36
txinList := []CfdBlindInputData{
{
Txid: "57a15002d066ce52573d674df925c9bc0f1164849420705f2cfad8a68111230f",
Vout: uint32(0),
Asset: "186c7f955149a5274b39e24b6a50d1d6479f552f6522d91f3a97d771f1c18179",
AssetBlindFactor: "a10ecbe1be7a5f883d5d45d966e30dbc1beff5f21c55cec76cc21a2229116a9f",
Amount: int64(999637680),
ValueBlindFactor: "ae0f46d1940f297c2dc3bbd82bf8ef6931a2431fbb05b3d3bc5df41af86ae808",
AssetBlindingKey: "",
TokenBlindingKey: "",
},
{
Txid: "57a15002d066ce52573d674df925c9bc0f1164849420705f2cfad8a68111230f",
Vout: uint32(1),
Asset: "ed6927df918c89b5e3d8b5062acab2c749a3291bb7451d4267c7daaf1b52ad0b",
AssetBlindFactor: "0b8954757234fd3ec9cf0dd6ef0a89d825ec56a9532e7da4b6cb90c51be3bbd8",
Amount: int64(700000000),
ValueBlindFactor: "62e36e1f0fa4916b031648a6b6903083069fa587572a88b729250cde528cfd3b",
AssetBlindingKey: "7d65c7970d836a878a1080399a3c11de39a8e82493e12b1ad154e383661fb77f",
TokenBlindingKey: "7d65c7970d836a878a1080399a3c11de39a8e82493e12b1ad154e383661fb77f",
},
}
// already set confidentialNonce in baseTxHex
txoutList := []CfdBlindOutputData{}
txHex, blinderList, err := CfdGoBlindRawTransactionAndGetBlinder(baseTxHex, txinList, txoutList, nil)
// txHex, err := CfdGoBlindRawTransaction(baseTxHex, txinList, txoutList, &option)
assert.NoError(t, err)
if err == nil {
txData, err := CfdGoGetConfidentialTxData(txHex)
assert.NoError(t, err)
assert.Equal(t, 64, len(txData.Txid))
assert.Equal(t, 64, len(txData.Wtxid))
assert.Equal(t, 64, len(txData.WitHash))
assert.Equal(t, uint32(12589), txData.Size)
assert.Equal(t, uint32(3604), txData.Vsize)
assert.Equal(t, uint32(14413), txData.Weight)
assert.Equal(t, uint32(2), txData.Version)
assert.Equal(t, uint32(0), txData.LockTime)
assert.Equal(t, 4, len(blinderList))
}
// unblind test
if err == nil {
asset, assetValue, aabf, avbf, token, tokenValue, tabf, tvbf, err := CfdGoUnblindIssuance(
txHex, uint32(1),
"7d65c7970d836a878a1080399a3c11de39a8e82493e12b1ad154e383661fb77f",
"7d65c7970d836a878a1080399a3c11de39a8e82493e12b1ad154e383661fb77f")
assert.NoError(t, err)
assert.Equal(t, "accb7354c07974e00b32e4e5eef55078490141675592ac3610e6101831edb0cd", asset)
assert.Equal(t, int64(600000000), assetValue)
assert.Equal(t, "0000000000000000000000000000000000000000000000000000000000000000", aabf)
assert.NotEqual(t, "0000000000000000000000000000000000000000000000000000000000000000", avbf)
assert.Equal(t, "", token)
assert.Equal(t, int64(0), tokenValue)
assert.Equal(t, "", tabf)
assert.Equal(t, "", tvbf)
if len(blinderList) == 4 {
assert.Equal(t, avbf, blinderList[0].ValueBlindFactor)
}
}
if err == nil {
asset, value, abf, vbf, err := CfdGoUnblindTxOut(
txHex, uint32(0),
"6a64f506be6e60b948987aa4d180d2ab05034a6a214146e06e28d4efe101d006")
assert.NoError(t, err)
assert.Equal(t, "186c7f955149a5274b39e24b6a50d1d6479f552f6522d91f3a97d771f1c18179", asset)
assert.Equal(t, int64(999587680), value)
assert.NotEqual(t, "0000000000000000000000000000000000000000000000000000000000000000", abf)
assert.NotEqual(t, "0000000000000000000000000000000000000000000000000000000000000000", vbf)
if len(blinderList) == 4 {
assert.Equal(t, abf, blinderList[1].AssetBlindFactor)
assert.Equal(t, vbf, blinderList[1].ValueBlindFactor)
}
}
if err == nil {
asset, value, abf, vbf, err := CfdGoUnblindTxOut(
txHex, uint32(1),
"94c85164605f589c4c572874f36b8301989c7fabfd44131297e95824d473681f")
assert.NoError(t, err)
assert.Equal(t, "ed6927df918c89b5e3d8b5062acab2c749a3291bb7451d4267c7daaf1b52ad0b", asset)
assert.Equal(t, int64(700000000), value)
assert.NotEqual(t, "0000000000000000000000000000000000000000000000000000000000000000", abf)
assert.NotEqual(t, "0000000000000000000000000000000000000000000000000000000000000000", vbf)
if len(blinderList) == 4 {
assert.Equal(t, abf, blinderList[2].AssetBlindFactor)
assert.Equal(t, vbf, blinderList[2].ValueBlindFactor)
}
}
if err == nil {
asset, value, abf, vbf, err := CfdGoUnblindTxOut(
txHex, uint32(3),
"0473d39aa6542e0c1bb6a2343b2319c3e92063dd019af4d47dbf50c460204f32")
assert.NoError(t, err)
assert.Equal(t, "accb7354c07974e00b32e4e5eef55078490141675592ac3610e6101831edb0cd", asset)
assert.Equal(t, int64(600000000), value)
assert.NotEqual(t, "0000000000000000000000000000000000000000000000000000000000000000", abf)
assert.NotEqual(t, "0000000000000000000000000000000000000000000000000000000000000000", vbf)
if len(blinderList) == 4 {
assert.Equal(t, abf, blinderList[3].AssetBlindFactor)
assert.Equal(t, vbf, blinderList[3].ValueBlindFactor)
}
}
if err != nil {
fmt.Print("[error message] " + err.Error() + "\n")
}
fmt.Printf("%s test done.\n", GetFuncName())
}
func TestCfdBlindTransaction3(t *testing.T) {
baseTxHex := "02000000000125b251070e29ca19043cf33ccd7324e2ddab03ecc4ae0b5e77c4fc0e5cf6c95a0000000000ffffffff030125b251070e29ca19043cf33ccd7324e2ddab03ecc4ae0b5e77c4fc0e5cf6c95a010000000005f5e100036a2e218bb512a3e65c80b59fec57aee428b7512276bcfa366c154dd7262994c817a914363273e2f851bda01e24cda41ba748b8d1f54cfe870125b251070e29ca19043cf33ccd7324e2ddab03ecc4ae0b5e77c4fc0e5cf6c95a01000000000000000002b29c3d0985a680ed6918d62a918d2df5fed13f9f72d4eb09003fe802a3b5954f016a0125b251070e29ca19043cf33ccd7324e2ddab03ecc4ae0b5e77c4fc0e5cf6c95a0100000000000000c8000000000000"
baseTxHex2 := "02000000000125b251070e29ca19043cf33ccd7324e2ddab03ecc4ae0b5e77c4fc0e5cf6c95a0000000000ffffffff030125b251070e29ca19043cf33ccd7324e2ddab03ecc4ae0b5e77c4fc0e5cf6c95a010000000005f5e100036a2e218bb512a3e65c80b59fec57aee428b7512276bcfa366c154dd7262994c817a914363273e2f851bda01e24cda41ba748b8d1f54cfe870125b251070e29ca19043cf33ccd7324e2ddab03ecc4ae0b5e77c4fc0e5cf6c95a01000000000000000002b29c3d0985a680ed6918d62a918d2df5fed13f9f72d4eb09003fe802a3b5954f17a91436e5e2e8732fe013bbec71c9d4866f882071f7e7870125b251070e29ca19043cf33ccd7324e2ddab03ecc4ae0b5e77c4fc0e5cf6c95a0100000000000000c8000000000000"
// option := NewCfdBlindTxOption()
// option.MinimumRangeValue = int64(0)
txinList := []CfdBlindInputData{
{
Txid: "5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225",
Vout: uint32(0),
Asset: "5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225",
AssetBlindFactor: "ebfecaae1665f32a3843ce65c42fb6e3f51136fa9d37274b810887923ae89339",
Amount: int64(100000200),
ValueBlindFactor: "80af7bd339db43ad22c1fa9109eea6d617c8b87b91c4bde2b5fafcbb1902211a",
AssetBlindingKey: "",
TokenBlindingKey: "",
},
}
// already set confidentialNonce in baseTxHex
txoutList := []CfdBlindOutputData{}
_, err := CfdGoBlindRawTransaction(baseTxHex2, txinList, txoutList, nil)
assert.Error(t, err)
if err != nil {
assert.Equal(t, "CFD Error: message=[Amount is 0. Cannot specify 0 for amount if there is a valid confidential address.], code=[1]", err.Error())
}
txHex, err := CfdGoBlindRawTransaction(baseTxHex, txinList, txoutList, nil)
// txHex, err := CfdGoBlindRawTransaction(baseTxHex, txinList, txoutList, &option)
assert.NoError(t, err)
if err == nil {
txData, err := CfdGoGetConfidentialTxData(txHex)
assert.NoError(t, err)
assert.Equal(t, 64, len(txData.Txid))
assert.Equal(t, 64, len(txData.Wtxid))
assert.Equal(t, 64, len(txData.WitHash))
assert.Equal(t, uint32(6246), txData.Size)
assert.Equal(t, uint32(1802), txData.Vsize)
assert.Equal(t, uint32(7206), txData.Weight)
assert.Equal(t, uint32(2), txData.Version)
assert.Equal(t, uint32(0), txData.LockTime)
// assert.Equal(t, "", txHex)
}
baseTxHex3 := "02000000000125b251070e29ca19043cf33ccd7324e2ddab03ecc4ae0b5e77c4fc0e5cf6c95a0000000000ffffffff020125b251070e29ca19043cf33ccd7324e2ddab03ecc4ae0b5e77c4fc0e5cf6c95a010000000005f5e100036a2e218bb512a3e65c80b59fec57aee428b7512276bcfa366c154dd7262994c817a914363273e2f851bda01e24cda41ba748b8d1f54cfe870125b251070e29ca19043cf33ccd7324e2ddab03ecc4ae0b5e77c4fc0e5cf6c95a0100000000000000c8000000000000"
txHex, err = CfdGoBlindRawTransaction(baseTxHex3, txinList, txoutList, nil)
// txHex, err := CfdGoBlindRawTransaction(baseTxHex, txinList, txoutList, &option)
assert.NoError(t, err)
if err == nil {
txData, err := CfdGoGetConfidentialTxData(txHex)
assert.NoError(t, err)
assert.Equal(t, 64, len(txData.Txid))
assert.Equal(t, 64, len(txData.Wtxid))
assert.Equal(t, 64, len(txData.WitHash))
assert.Equal(t, uint32(3189), txData.Size)
assert.Equal(t, uint32(962), txData.Vsize)
assert.Equal(t, uint32(3846), txData.Weight)
assert.Equal(t, uint32(2), txData.Version)
assert.Equal(t, uint32(0), txData.LockTime)
// assert.Equal(t, "", txHex)
}
pubkey := "03f942716865bb9b62678d99aa34de4632249d066d99de2b5a2e542e54908450d6"
privkey := "cU4KjNUT7GjHm7CkjRjG46SzLrXHXoH3ekXmqa2jTCFPMkQ64sw1"
txid := "5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225"
vout := uint32(0)
sigHashType := (int)(KCfdSigHashAll)
hashType := (int)(KCfdP2wpkh)
txHex2, err := CfdGoAddConfidentialTxSignWithPrivkey(txHex, txid, vout, hashType, pubkey, privkey, int64(0), "085e6338f9da8a7f754b8e2726894e04bee997c8ada526f3215de8bc151aa063d3", sigHashType, false, true)
assert.NoError(t, err)
// assert.Equal(t, "", txHex2)
inputs := []CfdUtxo{
{
Txid: "5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225",
Vout: uint32(0),
Amount: int64(100000000),
Asset: "5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225",
Descriptor: "wpkh(030000000000000000000000000000000000000000000000000000000000000a01)",
IsIssuance: false,
IsBlindIssuance: false,
IsPegin: false,
PeginBtcTxSize: uint32(0),
},
}
feeOption := NewCfdEstimateFeeOption()
feeOption.EffectiveFeeRate = float64(0.1)
feeOption.UseElements = true
feeOption.FeeAsset = "5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225"
feeOption.RequireBlind = true
feeOption.MinimumBits = 36
totalFee, txFee, inputFee, err := CfdGoEstimateFeeUsingUtxo(baseTxHex3, inputs, feeOption)
assert.NoError(t, err)
assert.Equal(t, int64(99), totalFee)
assert.Equal(t, int64(92), txFee)
assert.Equal(t, int64(7), inputFee)
totalFee, txFee, inputFee, err = CfdGoEstimateFeeUsingUtxo(txHex2, inputs, feeOption)
assert.NoError(t, err)
assert.Equal(t, int64(99), totalFee)
assert.Equal(t, int64(92), txFee)
assert.Equal(t, int64(7), inputFee)
// feeOption.MinimumBits = 52
//assert.Equal(t, int64(129), totalFee)
//assert.Equal(t, int64(123), txFee)
//assert.Equal(t, int64(6), inputFee)
if err != nil {
fmt.Print("[error message] " + err.Error() + "\n")
}
fmt.Printf("%s test done.\n", GetFuncName())
}
func TestCfdAddSignConfidentialTx(t *testing.T) {
kTxData := "0200000000020f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570000000000ffffffff0f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570100008000ffffffffd8bbe31bc590cbb6a47d2e53a956ec25d8890aefd60dcfc93efd34727554890b0683fe0819a4f9770c8a7cd5824e82975c825e017aff8ba0d6a5eb4959cf9c6f010000000023c346000004017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000003b947f6002200d8510dfcf8e2330c0795c771d1e6064daab2f274ac32a6e2708df9bfa893d17a914ef3e40882e17d6e477082fcafeb0f09dc32d377b87010bad521bafdac767421d45b71b29a349c7b2ca2a06b5d8e3b5898c91df2769ed010000000029b9270002cc645552109331726c0ffadccab21620dd7a5a33260c6ac7bd1c78b98cb1e35a1976a9146c22e209d36612e0d9d2a20b814d7d8648cc7a7788ac017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000000000c350000001cdb0ed311810e61036ac9255674101497850f5eee5e4320be07479c05473cbac010000000023c3460003ce4c4eac09fe317f365e45c00ffcf2e9639bc0fd792c10f72cdc173c4e5ed8791976a9149bdcb18911fa9faad6632ca43b81739082b0a19588ac00000000"
pubkey := "03f942716865bb9b62678d99aa34de4632249d066d99de2b5a2e542e54908450d6"
privkey := "cU4KjNUT7GjHm7CkjRjG46SzLrXHXoH3ekXmqa2jTCFPMkQ64sw1"
privkeyWifNetworkType := (int)(KCfdNetworkRegtest)
txid := "57a15002d066ce52573d674df925c9bc0f1164849420705f2cfad8a68111230f"
vout := uint32(0)
txHex := ""
sigHashType := (int)(KCfdSigHashAll)
hashType := (int)(KCfdP2wpkh)
isWitness := true
if (hashType == (int)(KCfdP2pkh)) || (hashType == (int)(KCfdP2sh)) {
isWitness = false
}
sighash, err := CfdGoCreateConfidentialSighash(
kTxData, txid, vout, hashType,
pubkey, "", int64(13000000000000), "", sigHashType, false)
assert.NoError(t, err)
assert.Equal(t, "c90939ef311f105806b401bcfa494921b8df297195fc125ebbd91a018c4066b9", sighash)
signature, err := CfdGoCalculateEcSignature(
sighash, "", privkey, privkeyWifNetworkType, true)
assert.NoError(t, err)
assert.Equal(t, "0268633a57723c6612ef217c49bdf804c632a14be2967c76afec4fd5781ad4c2131f358b2381a039c8c502959c64fbfeccf287be7dae710b4446968553aefbea", signature)
isVerify, err := CfdGoVerifyEcSignature(sighash, pubkey, signature)
assert.NoError(t, err)
assert.True(t, isVerify)
// add signature
txHex, err = CfdGoAddConfidentialTxDerSign(
kTxData, txid, vout, isWitness, signature, sigHashType, false, true)
assert.NoError(t, err)
// add pubkey
txHex, err = CfdGoAddConfidentialTxSign(
txHex, txid, vout, isWitness, pubkey, false)
assert.NoError(t, err)
assert.Equal(t, "0200000001020f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570000000000ffffffff0f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570100008000ffffffffd8bbe31bc590cbb6a47d2e53a956ec25d8890aefd60dcfc93efd34727554890b0683fe0819a4f9770c8a7cd5824e82975c825e017aff8ba0d6a5eb4959cf9c6f010000000023c346000004017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000003b947f6002200d8510dfcf8e2330c0795c771d1e6064daab2f274ac32a6e2708df9bfa893d17a914ef3e40882e17d6e477082fcafeb0f09dc32d377b87010bad521bafdac767421d45b71b29a349c7b2ca2a06b5d8e3b5898c91df2769ed010000000029b9270002cc645552109331726c0ffadccab21620dd7a5a33260c6ac7bd1c78b98cb1e35a1976a9146c22e209d36612e0d9d2a20b814d7d8648cc7a7788ac017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000000000c350000001cdb0ed311810e61036ac9255674101497850f5eee5e4320be07479c05473cbac010000000023c3460003ce4c4eac09fe317f365e45c00ffcf2e9639bc0fd792c10f72cdc173c4e5ed8791976a9149bdcb18911fa9faad6632ca43b81739082b0a19588ac0000000000000247304402200268633a57723c6612ef217c49bdf804c632a14be2967c76afec4fd5781ad4c20220131f358b2381a039c8c502959c64fbfeccf287be7dae710b4446968553aefbea012103f942716865bb9b62678d99aa34de4632249d066d99de2b5a2e542e54908450d600000000000000000000000000", txHex)
count, err := CfdGoGetConfidentialTxInWitnessCount(txHex, 0)
assert.NoError(t, err)
assert.Equal(t, uint32(2), count)
stackData, err := CfdGoGetConfidentialTxInWitness(txHex, 0, 1)
assert.NoError(t, err)
assert.Equal(t, pubkey, stackData)
isVerify, err = CfdGoVerifySignature(int(KCfdNetworkLiquidv1), txHex, signature, hashType, pubkey, "", txid, vout, sigHashType, false, int64(13000000000000), "")
assert.NoError(t, err)
assert.True(t, isVerify)
isVerify, err = CfdGoVerifyTxSign(int(KCfdNetworkLiquidv1), txHex, txid, vout, "ert1qav7q64dhpx9y4m62rrhpa67trmvjf2ptxfddld", int(KCfdP2wpkhAddress), "", int64(13000000000000), "")
assert.NoError(t, err)
assert.True(t, isVerify)
isVerify, reason, err := CfdGoVerifyTxSignReason(int(KCfdNetworkLiquidv1), txHex, txid, vout, "ert1qs58jzsgjsteydejyhy32p2v2vm8llh9uns6d93", int(KCfdP2wpkhAddress), "", int64(13000000000000), "")
assert.NoError(t, err)
assert.False(t, isVerify)
assert.Equal(t, "Unmatch locking script.", reason)
if err != nil {
fmt.Print("[error message] " + err.Error() + "\n")
}
fmt.Printf("%s test done.\n", GetFuncName())
}
func TestCfdAddSignConfidentialTxPkh(t *testing.T) {
kTxData := "0200000000020f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570000000000ffffffff0f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570100008000ffffffffd8bbe31bc590cbb6a47d2e53a956ec25d8890aefd60dcfc93efd34727554890b0683fe0819a4f9770c8a7cd5824e82975c825e017aff8ba0d6a5eb4959cf9c6f010000000023c346000004017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000003b947f6002200d8510dfcf8e2330c0795c771d1e6064daab2f274ac32a6e2708df9bfa893d17a914ef3e40882e17d6e477082fcafeb0f09dc32d377b87010bad521bafdac767421d45b71b29a349c7b2ca2a06b5d8e3b5898c91df2769ed010000000029b9270002cc645552109331726c0ffadccab21620dd7a5a33260c6ac7bd1c78b98cb1e35a1976a9146c22e209d36612e0d9d2a20b814d7d8648cc7a7788ac017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000000000c350000001cdb0ed311810e61036ac9255674101497850f5eee5e4320be07479c05473cbac010000000023c3460003ce4c4eac09fe317f365e45c00ffcf2e9639bc0fd792c10f72cdc173c4e5ed8791976a9149bdcb18911fa9faad6632ca43b81739082b0a19588ac00000000"
pubkey := "03f942716865bb9b62678d99aa34de4632249d066d99de2b5a2e542e54908450d6"
privkey := "cU4KjNUT7GjHm7CkjRjG46SzLrXHXoH3ekXmqa2jTCFPMkQ64sw1"
privkeyWifNetworkType := (int)(KCfdNetworkRegtest)
txid := "57a15002d066ce52573d674df925c9bc0f1164849420705f2cfad8a68111230f"
vout := uint32(0)
txHex := ""
sigHashType := (int)(KCfdSigHashAll)
hashType := (int)(KCfdP2pkh)
isWitness := true
if (hashType == (int)(KCfdP2pkh)) || (hashType == (int)(KCfdP2sh)) {
isWitness = false
}
sighash, err := CfdGoCreateConfidentialSighash(
kTxData, txid, vout, hashType,
pubkey, "", int64(13000000000000), "", sigHashType, false)
assert.NoError(t, err)
assert.Equal(t, "e955c2f4fa5077cd0ac724e2f626914c8286896eca30fcde405e051ea3443527", sighash)
signature, err := CfdGoCalculateEcSignature(
sighash, "", privkey, privkeyWifNetworkType, true)
assert.NoError(t, err)
assert.Equal(t, "4c5f91208f79fe7c74a2b5d88573b6150ac1d4f18cef8051dff1260a37c272d81b97ecd5f83d16cfc3cb39d9bdd21d1f77665135c4230a3157d2045450528ff5", signature)
// add signature
txHex, err = CfdGoAddConfidentialTxDerSign(
kTxData, txid, vout, isWitness, signature, sigHashType, false, true)
assert.NoError(t, err)
// add pubkey
txHex, err = CfdGoAddConfidentialTxSign(
txHex, txid, vout, isWitness, pubkey, false)
assert.NoError(t, err)
assert.Equal(t, "0200000000020f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a157000000006a47304402204c5f91208f79fe7c74a2b5d88573b6150ac1d4f18cef8051dff1260a37c272d802201b97ecd5f83d16cfc3cb39d9bdd21d1f77665135c4230a3157d2045450528ff5012103f942716865bb9b62678d99aa34de4632249d066d99de2b5a2e542e54908450d6ffffffff0f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570100008000ffffffffd8bbe31bc590cbb6a47d2e53a956ec25d8890aefd60dcfc93efd34727554890b0683fe0819a4f9770c8a7cd5824e82975c825e017aff8ba0d6a5eb4959cf9c6f010000000023c346000004017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000003b947f6002200d8510dfcf8e2330c0795c771d1e6064daab2f274ac32a6e2708df9bfa893d17a914ef3e40882e17d6e477082fcafeb0f09dc32d377b87010bad521bafdac767421d45b71b29a349c7b2ca2a06b5d8e3b5898c91df2769ed010000000029b9270002cc645552109331726c0ffadccab21620dd7a5a33260c6ac7bd1c78b98cb1e35a1976a9146c22e209d36612e0d9d2a20b814d7d8648cc7a7788ac017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000000000c350000001cdb0ed311810e61036ac9255674101497850f5eee5e4320be07479c05473cbac010000000023c3460003ce4c4eac09fe317f365e45c00ffcf2e9639bc0fd792c10f72cdc173c4e5ed8791976a9149bdcb18911fa9faad6632ca43b81739082b0a19588ac00000000", txHex)
fmt.Printf("%s test done.\n", GetFuncName())
}
func TestCfdGoAddConfidentialTxUnlockingScript_P2PKH(t *testing.T) {
// txHex comes from TestCfdCreateRawTransaction result data
const txHex string = "020000000002bdebed9413554bb95fffbdf436112c923c334a6850509ae7794d410524b061740000000000ffffffffc16d35d26589dfd54634181aa4a290cb9e06a716ea68620be05fbc46f1e197140100000000ffffffff030151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000005f5e10003a630456ab6d50b57981e085abced70e2816289ae2b49a44c2f471b205134c12b1976a914d08f5ba8874d36cf97d19379b370f1f23ba36d5888ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f010000000071475420001976a914fdd725970db682de970e7669646ed7afb8348ea188ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f01000000000007a120000000000000"
// unlockingScript comes from TestCfdParseScript PKH UnlockingScript source data
const unlockingScript string = "47304402204b922f2dafdd926b22b0e669fd774a2d5f10f969b8089a1c3a0384ba7ce95f6e02204e71c2a620cf430fa6d7ceaeb40d5298f20eebae3ecb783714a6adc03c66717d0121038f5d4ee5a661c04de7b715c6b9ac935456419fa9f484470275d1d489f2793301"
txHexByInput, err := CfdGoAddConfidentialTxUnlockingScript(txHex, "7461b02405414d79e79a5050684a333c922c1136f4bdff5fb94b551394edebbd", (uint32)(0), false, unlockingScript, false)
assert.NoError(t, err)
assert.Equal(t, "020000000002bdebed9413554bb95fffbdf436112c923c334a6850509ae7794d410524b06174000000006a47304402204b922f2dafdd926b22b0e669fd774a2d5f10f969b8089a1c3a0384ba7ce95f6e02204e71c2a620cf430fa6d7ceaeb40d5298f20eebae3ecb783714a6adc03c66717d0121038f5d4ee5a661c04de7b715c6b9ac935456419fa9f484470275d1d489f2793301ffffffffc16d35d26589dfd54634181aa4a290cb9e06a716ea68620be05fbc46f1e197140100000000ffffffff030151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000005f5e10003a630456ab6d50b57981e085abced70e2816289ae2b49a44c2f471b205134c12b1976a914d08f5ba8874d36cf97d19379b370f1f23ba36d5888ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f010000000071475420001976a914fdd725970db682de970e7669646ed7afb8348ea188ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f01000000000007a120000000000000", txHexByInput)
// check adding script sig by index func
txHexByIndex, err := CfdGoAddConfidentialTxUnlockingScriptByIndex(txHex, (uint32)(0), false, unlockingScript, false)
assert.NoError(t, err)
assert.Equal(t, txHexByInput, txHexByIndex)
fmt.Printf("%s test done.\n", GetFuncName())
}
func TestCfdGoAddConfidentialTxUnlockingScript_P2MS(t *testing.T) {
// txHex comes from TestCfdCreateRawTransaction result data
const txHex string = "020000000002bdebed9413554bb95fffbdf436112c923c334a6850509ae7794d410524b061740000000000ffffffffc16d35d26589dfd54634181aa4a290cb9e06a716ea68620be05fbc46f1e197140100000000ffffffff030151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000005f5e10003a630456ab6d50b57981e085abced70e2816289ae2b49a44c2f471b205134c12b1976a914d08f5ba8874d36cf97d19379b370f1f23ba36d5888ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f010000000071475420001976a914fdd725970db682de970e7669646ed7afb8348ea188ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f01000000000007a120000000000000"
// unlockingScript comes from TestCfdCreateMultisigScriptSig
const unlockingScript string = "00473044022047ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f0220217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb01473044022047ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f0220217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb0147522102bfd7daa5d113fcbd8c2f374ae58cbb89cbed9570e898f1af5ff989457e2d4d712102715ed9a5f16153c5216a6751b7d84eba32076f0b607550a58b209077ab7c30ad52ae"
txHexByInput, err := CfdGoAddConfidentialTxUnlockingScript(txHex, "7461b02405414d79e79a5050684a333c922c1136f4bdff5fb94b551394edebbd", (uint32)(0), false, unlockingScript, false)
assert.NoError(t, err)
assert.Equal(t, "020000000002bdebed9413554bb95fffbdf436112c923c334a6850509ae7794d410524b0617400000000d900473044022047ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f0220217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb01473044022047ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f0220217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb0147522102bfd7daa5d113fcbd8c2f374ae58cbb89cbed9570e898f1af5ff989457e2d4d712102715ed9a5f16153c5216a6751b7d84eba32076f0b607550a58b209077ab7c30ad52aeffffffffc16d35d26589dfd54634181aa4a290cb9e06a716ea68620be05fbc46f1e197140100000000ffffffff030151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000005f5e10003a630456ab6d50b57981e085abced70e2816289ae2b49a44c2f471b205134c12b1976a914d08f5ba8874d36cf97d19379b370f1f23ba36d5888ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f010000000071475420001976a914fdd725970db682de970e7669646ed7afb8348ea188ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f01000000000007a120000000000000", txHexByInput)
fmt.Printf("%s test done.\n", GetFuncName())
}
func TestCfdGoAddConfidentialTxUnlockingScript_P2SHP2WPKH(t *testing.T) {
// txHex comes from TestCfdGoAddConfidentialTxUnlockingScript/Add_P2MS_UnlockingScript result data
const txHex string = "020000000002bdebed9413554bb95fffbdf436112c923c334a6850509ae7794d410524b0617400000000d900473044022047ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f0220217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb01473044022047ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f0220217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb0147522102bfd7daa5d113fcbd8c2f374ae58cbb89cbed9570e898f1af5ff989457e2d4d712102715ed9a5f16153c5216a6751b7d84eba32076f0b607550a58b209077ab7c30ad52aeffffffffc16d35d26589dfd54634181aa4a290cb9e06a716ea68620be05fbc46f1e197140100000000ffffffff030151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000005f5e10003a630456ab6d50b57981e085abced70e2816289ae2b49a44c2f471b205134c12b1976a914d08f5ba8874d36cf97d19379b370f1f23ba36d5888ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f010000000071475420001976a914fdd725970db682de970e7669646ed7afb8348ea188ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f01000000000007a120000000000000"
// unlockingScript comes from TestCfdCreateMultisigScriptSig
const scriptSig string = "0020fc5acc302aab97f821f9a61e1cc572e7968a603551e95d4ba12b51df6581482f"
// Append ScriptSig
txHexResult, err := CfdGoAddConfidentialTxUnlockingScript(txHex, "7461b02405414d79e79a5050684a333c922c1136f4bdff5fb94b551394edebbd", (uint32)(0), false, scriptSig, true)
assert.NoError(t, err)
assert.Equal(t, "020000000002bdebed9413554bb95fffbdf436112c923c334a6850509ae7794d410524b0617400000000220020fc5acc302aab97f821f9a61e1cc572e7968a603551e95d4ba12b51df6581482fffffffffc16d35d26589dfd54634181aa4a290cb9e06a716ea68620be05fbc46f1e197140100000000ffffffff030151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000005f5e10003a630456ab6d50b57981e085abced70e2816289ae2b49a44c2f471b205134c12b1976a914d08f5ba8874d36cf97d19379b370f1f23ba36d5888ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f010000000071475420001976a914fdd725970db682de970e7669646ed7afb8348ea188ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f01000000000007a120000000000000", txHexResult)
// dummy witness signatrues
const witnessStackScript string = "00473044022047ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f0220217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb01473044022047ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f0220217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb0147522102bfd7daa5d113fcbd8c2f374ae58cbb89cbed9570e898f1af5ff989457e2d4d712102715ed9a5f16153c5216a6751b7d84eba32076f0b607550a58b209077ab7c30ad52ae"
// Append txinwitness
txHexResult, err = CfdGoAddConfidentialTxUnlockingScript(txHexResult, "7461b02405414d79e79a5050684a333c922c1136f4bdff5fb94b551394edebbd", (uint32)(0), true, witnessStackScript, true)
assert.NoError(t, err)
assert.Equal(t, "020000000102bdebed9413554bb95fffbdf436112c923c334a6850509ae7794d410524b0617400000000220020fc5acc302aab97f821f9a61e1cc572e7968a603551e95d4ba12b51df6581482fffffffffc16d35d26589dfd54634181aa4a290cb9e06a716ea68620be05fbc46f1e197140100000000ffffffff030151f799a22a9375b31c2f20edce025f0df5231306e81222a0061bde342dc447ef010000000005f5e10003a630456ab6d50b57981e085abced70e2816289ae2b49a44c2f471b205134c12b1976a914d08f5ba8874d36cf97d19379b370f1f23ba36d5888ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f010000000071475420001976a914fdd725970db682de970e7669646ed7afb8348ea188ac01f38611eb688e6fcd06f25e2faf52b9f98364dc14c379ab085f1b57d56b4b1a6f01000000000007a1200000000000000000040100473044022047ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f0220217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb01473044022047ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f0220217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb0147522102bfd7daa5d113fcbd8c2f374ae58cbb89cbed9570e898f1af5ff989457e2d4d712102715ed9a5f16153c5216a6751b7d84eba32076f0b607550a58b209077ab7c30ad52ae0000000000000000000000", txHexResult)
fmt.Printf("%s test done.\n", GetFuncName())
}
func TestCfdAddMultisigSignConfidentialTx(t *testing.T) {
kTxData := "0200000000020f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570000000000ffffffff0f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570100008000ffffffffd8bbe31bc590cbb6a47d2e53a956ec25d8890aefd60dcfc93efd34727554890b0683fe0819a4f9770c8a7cd5824e82975c825e017aff8ba0d6a5eb4959cf9c6f010000000023c346000004017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000003b947f6002200d8510dfcf8e2330c0795c771d1e6064daab2f274ac32a6e2708df9bfa893d17a914ef3e40882e17d6e477082fcafeb0f09dc32d377b87010bad521bafdac767421d45b71b29a349c7b2ca2a06b5d8e3b5898c91df2769ed010000000029b9270002cc645552109331726c0ffadccab21620dd7a5a33260c6ac7bd1c78b98cb1e35a1976a9146c22e209d36612e0d9d2a20b814d7d8648cc7a7788ac017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000000000c350000001cdb0ed311810e61036ac9255674101497850f5eee5e4320be07479c05473cbac010000000023c3460003ce4c4eac09fe317f365e45c00ffcf2e9639bc0fd792c10f72cdc173c4e5ed8791976a9149bdcb18911fa9faad6632ca43b81739082b0a19588ac00000000"
txid := "57a15002d066ce52573d674df925c9bc0f1164849420705f2cfad8a68111230f"
vout := uint32(0)
pubkey1 := "02715ed9a5f16153c5216a6751b7d84eba32076f0b607550a58b209077ab7c30ad"
privkey1 := "cRVLMWHogUo51WECRykTbeLNbm5c57iEpSegjdxco3oef6o5dbFi"
pubkey2 := "02bfd7daa5d113fcbd8c2f374ae58cbb89cbed9570e898f1af5ff989457e2d4d71"
privkey2 := "cQUTZ8VbWNYBEtrB7xwe41kqiKMQPRZshTvBHmkoJGaUfmS5pxzR"
networkType := (int)(KCfdNetworkRegtest)
sigHashType := (int)(KCfdSigHashAll)
hashType := (int)(KCfdP2sh)
// create multisig address
pubkeys := []string{pubkey2, pubkey1}
addr, multisigScript, _, err := CfdGoCreateMultisigScript(
networkType, hashType, pubkeys, uint32(2))
assert.NoError(t, err)
assert.Equal(t, "2MtG4TZaMXCNdEyUYAyJDraQRFwYC5j4S9U", addr)
assert.Equal(t, "522102bfd7daa5d113fcbd8c2f374ae58cbb89cbed9570e898f1af5ff989457e2d4d712102715ed9a5f16153c5216a6751b7d84eba32076f0b607550a58b209077ab7c30ad52ae", multisigScript)
// sign multisig
multiSignHandle, err := CfdGoInitializeMultisigSign()
assert.NoError(t, err)
if err == nil {
satoshi := int64(13000000000000)
sighash, err := CfdGoCreateConfidentialSighash(kTxData, txid, vout,
hashType, "", multisigScript, satoshi, "", sigHashType, false)
assert.NoError(t, err)
assert.Equal(t, "64878cbcd5c1805659d0747097cbf4b9ec5c187ebd80afa996c8fc95bd650b70", sighash)
// user1
signature1, err := CfdGoCalculateEcSignature(
sighash, "", privkey1, networkType, true)
assert.NoError(t, err)
err = CfdGoAddMultisigSignDataToDer(
multiSignHandle, signature1, sigHashType, false, pubkey1)
assert.NoError(t, err)
// user2
signature2, err := CfdGoCalculateEcSignature(
sighash, "", privkey2, networkType, true)
assert.NoError(t, err)
derSignature2, err := CfdGoEncodeSignatureByDer(signature2, sigHashType, false)
assert.NoError(t, err)
err = CfdGoAddMultisigSignData(multiSignHandle, derSignature2, pubkey2)
assert.NoError(t, err)
// generate
txHex, err := CfdGoFinalizeElementsMultisigSign(
multiSignHandle, kTxData, txid, vout, hashType, "", multisigScript, true)
assert.NoError(t, err)
assert.Equal(t, "0200000000020f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a15700000000d90047304402206fc4cc7e489208a2f4d24f5d35466debab2ce7aa34b5d00e0a9426c9d63529cf02202ec744939ef0b4b629c7d87bc2d017714b52bb86dccb0fd0f10148f62b7a09ba01473044022073ea24720b24c736bcb305a5de2fd8117ca2f0a85d7da378fae5b90dc361d227022004c0088bf1b73a56ae5ec407cf9c330d7206ffbcd0c9bb1c72661726fd4990390147522102bfd7daa5d113fcbd8c2f374ae58cbb89cbed9570e898f1af5ff989457e2d4d712102715ed9a5f16153c5216a6751b7d84eba32076f0b607550a58b209077ab7c30ad52aeffffffff0f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570100008000ffffffffd8bbe31bc590cbb6a47d2e53a956ec25d8890aefd60dcfc93efd34727554890b0683fe0819a4f9770c8a7cd5824e82975c825e017aff8ba0d6a5eb4959cf9c6f010000000023c346000004017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000003b947f6002200d8510dfcf8e2330c0795c771d1e6064daab2f274ac32a6e2708df9bfa893d17a914ef3e40882e17d6e477082fcafeb0f09dc32d377b87010bad521bafdac767421d45b71b29a349c7b2ca2a06b5d8e3b5898c91df2769ed010000000029b9270002cc645552109331726c0ffadccab21620dd7a5a33260c6ac7bd1c78b98cb1e35a1976a9146c22e209d36612e0d9d2a20b814d7d8648cc7a7788ac017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000000000c350000001cdb0ed311810e61036ac9255674101497850f5eee5e4320be07479c05473cbac010000000023c3460003ce4c4eac09fe317f365e45c00ffcf2e9639bc0fd792c10f72cdc173c4e5ed8791976a9149bdcb18911fa9faad6632ca43b81739082b0a19588ac00000000", txHex)
err = CfdGoFreeMultisigSignHandle(multiSignHandle)
assert.NoError(t, err)
// verify der encoded signature
isVerify, err := CfdGoVerifySignature(int(KCfdNetworkLiquidv1), kTxData, derSignature2, hashType, pubkey2, multisigScript, txid, vout, sigHashType, false, satoshi, "")
assert.NoError(t, err)
assert.True(t, isVerify)
}
if err != nil {
fmt.Print("[error message] " + err.Error() + "\n")
}
fmt.Printf("%s test done.\n", GetFuncName())
}
func TestCfdAddMultisigSignConfidentialTxWitness(t *testing.T) {
kTxData := "0200000000020f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570000000000ffffffff0f231181a6d8fa2c5f7020948464110fbcc925f94d673d5752ce66d00250a1570100008000ffffffffd8bbe31bc590cbb6a47d2e53a956ec25d8890aefd60dcfc93efd34727554890b0683fe0819a4f9770c8a7cd5824e82975c825e017aff8ba0d6a5eb4959cf9c6f010000000023c346000004017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000003b947f6002200d8510dfcf8e2330c0795c771d1e6064daab2f274ac32a6e2708df9bfa893d17a914ef3e40882e17d6e477082fcafeb0f09dc32d377b87010bad521bafdac767421d45b71b29a349c7b2ca2a06b5d8e3b5898c91df2769ed010000000029b9270002cc645552109331726c0ffadccab21620dd7a5a33260c6ac7bd1c78b98cb1e35a1976a9146c22e209d36612e0d9d2a20b814d7d8648cc7a7788ac017981c1f171d7973a1fd922652f559f47d6d1506a4be2394b27a54951957f6c1801000000000000c350000001cdb0ed311810e61036ac9255674101497850f5eee5e4320be07479c05473cbac010000000023c3460003ce4c4eac09fe317f365e45c00ffcf2e9639bc0fd792c10f72cdc173c4e5ed8791976a9149bdcb18911fa9faad6632ca43b81739082b0a19588ac00000000"
txid := "57a15002d066ce52573d674df925c9bc0f1164849420705f2cfad8a68111230f"
vout := uint32(0)
pubkey1 := "02715ed9a5f16153c5216a6751b7d84eba32076f0b607550a58b209077ab7c30ad"
privkey1 := "cRVLMWHogUo51WECRykTbeLNbm5c57iEpSegjdxco3oef6o5dbFi"
pubkey2 := "02bfd7daa5d113fcbd8c2f374ae58cbb89cbed9570e898f1af5ff989457e2d4d71"