-
Notifications
You must be signed in to change notification settings - Fork 1
/
bindings.go
3464 lines (2903 loc) · 109 KB
/
bindings.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
// This file was generated by seer: https://github.com/moonstream-to/seer.
// seer version: 0.0.5
// seer command: seer starknet abigentypes --package main
// Warning: Edit at your own risk. Any edits you make will NOT survive the next code generation.
package main
import (
"context"
"encoding/hex"
"encoding/json"
"errors"
"math/big"
"time"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/starknet.go/rpc"
"github.com/consensys/gnark-crypto/ecc/stark-curve/fp"
)
var ErrIncorrectParameters error = errors.New("incorrect parameters")
func ParseUint64(parameters []*felt.Felt) (uint64, int, error) {
if len(parameters) < 1 {
return 0, 0, ErrIncorrectParameters
}
return parameters[0].Uint64(), 1, nil
}
func ParseBigInt(parameters []*felt.Felt) (*big.Int, int, error) {
if len(parameters) < 1 {
return nil, 0, ErrIncorrectParameters
}
result := big.NewInt(0)
result = parameters[0].BigInt(result)
return result, 1, nil
}
func ParseString(parameters []*felt.Felt) (string, int, error) {
if len(parameters) < 1 {
return "", 0, ErrIncorrectParameters
}
return parameters[0].String(), 1, nil
}
func ParseArray[T any](parser func(parameters []*felt.Felt) (T, int, error)) func(parameters []*felt.Felt) ([]T, int, error) {
return func(parameters []*felt.Felt) ([]T, int, error) {
if len(parameters) < 1 {
return nil, 0, ErrIncorrectParameters
}
arrayLengthRaw := parameters[0].Uint64()
arrayLength := int(arrayLengthRaw)
if len(parameters) < arrayLength+1 {
return nil, 0, ErrIncorrectParameters
}
result := make([]T, arrayLength)
currentIndex := 1
for i := 0; i < arrayLength; i++ {
parsed, consumed, err := parser(parameters[currentIndex:])
if err != nil {
return nil, 0, err
}
result[i] = parsed
currentIndex += consumed
}
return result, currentIndex, nil
}
}
var ErrIncorrectEventKey error = errors.New("incorrect event key")
type RawEvent struct {
BlockNumber uint64
BlockHash *felt.Felt
TransactionHash *felt.Felt
FromAddress *felt.Felt
PrimaryKey *felt.Felt
Keys []*felt.Felt
Parameters []*felt.Felt
}
func FeltFromHexString(hexString string) (*felt.Felt, error) {
fieldAdditiveIdentity := fp.NewElement(0)
if hexString[:2] == "0x" {
hexString = hexString[2:]
}
decodedString, decodeErr := hex.DecodeString(hexString)
if decodeErr != nil {
return nil, decodeErr
}
derivedFelt := felt.NewFelt(&fieldAdditiveIdentity)
derivedFelt.SetBytes(decodedString)
return derivedFelt, nil
}
func AllEventsFilter(fromBlock, toBlock uint64, contractAddress string) (*rpc.EventFilter, error) {
result := rpc.EventFilter{FromBlock: rpc.BlockID{Number: &fromBlock}, ToBlock: rpc.BlockID{Number: &toBlock}}
fieldAdditiveIdentity := fp.NewElement(0)
if contractAddress != "" {
if contractAddress[:2] == "0x" {
contractAddress = contractAddress[2:]
}
decodedAddress, decodeErr := hex.DecodeString(contractAddress)
if decodeErr != nil {
return &result, decodeErr
}
result.Address = felt.NewFelt(&fieldAdditiveIdentity)
result.Address.SetBytes(decodedAddress)
}
result.Keys = [][]*felt.Felt{{}}
return &result, nil
}
func ContractEvents(ctx context.Context, provider *rpc.Provider, contractAddress string, outChan chan<- RawEvent, hotThreshold int, hotInterval, coldInterval time.Duration, fromBlock, toBlock uint64, confirmations, batchSize int) error {
defer func() { close(outChan) }()
type CrawlCursor struct {
FromBlock uint64
ToBlock uint64
ContinuationToken string
Interval time.Duration
Heat int
}
cursor := CrawlCursor{FromBlock: fromBlock, ToBlock: toBlock, ContinuationToken: "", Interval: hotInterval, Heat: 0}
count := 0
for {
select {
case <-ctx.Done():
return nil
case <-time.After(cursor.Interval):
count++
if cursor.ToBlock == 0 {
currentblock, blockErr := provider.BlockNumber(ctx)
if blockErr != nil {
return blockErr
}
cursor.ToBlock = currentblock - uint64(confirmations)
}
if cursor.ToBlock <= cursor.FromBlock {
// Crawl is cold, slow things down.
cursor.Interval = coldInterval
if toBlock == 0 {
// If the crawl is continuous, breaks out of select, not for loop.
// This effects a wait for the given interval.
break
} else {
// If crawl is not continuous, just ends the crawl.
return nil
}
}
filter, filterErr := AllEventsFilter(cursor.FromBlock, cursor.ToBlock, contractAddress)
if filterErr != nil {
return filterErr
}
eventsInput := rpc.EventsInput{
EventFilter: *filter,
ResultPageRequest: rpc.ResultPageRequest{ChunkSize: batchSize, ContinuationToken: cursor.ContinuationToken},
}
eventsChunk, getEventsErr := provider.Events(ctx, eventsInput)
if getEventsErr != nil {
return getEventsErr
}
for _, event := range eventsChunk.Events {
crawledEvent := RawEvent{
BlockNumber: event.BlockNumber,
BlockHash: event.BlockHash,
TransactionHash: event.TransactionHash,
FromAddress: event.FromAddress,
PrimaryKey: event.Keys[0],
Keys: event.Keys,
Parameters: event.Data,
}
outChan <- crawledEvent
}
if eventsChunk.ContinuationToken != "" {
cursor.ContinuationToken = eventsChunk.ContinuationToken
cursor.Interval = hotInterval
} else {
cursor.FromBlock = cursor.ToBlock + 1
cursor.ToBlock = toBlock
cursor.ContinuationToken = ""
if len(eventsChunk.Events) > 0 {
cursor.Heat++
if cursor.Heat >= hotThreshold {
cursor.Interval = hotInterval
}
} else {
cursor.Heat = 0
cursor.Interval = coldInterval
}
}
}
}
}
// ABI: game::Game::PlayerReward
// Game_Game_PlayerReward is the Go struct corresponding to the game::Game::PlayerReward struct.
type Game_Game_PlayerReward struct {
AdventurerId string
Rank uint64
Amount *big.Int
Address string
}
// ParseGame_Game_PlayerReward parses a Game_Game_PlayerReward struct from a list of felts. This function returns a tuple of:
// 1. The parsed Game_Game_PlayerReward struct
// 2. The number of field elements consumed in the parse
// 3. An error if the parse failed, nil otherwise
func ParseGame_Game_PlayerReward(parameters []*felt.Felt) (Game_Game_PlayerReward, int, error) {
currentIndex := 0
result := Game_Game_PlayerReward{}
value0, consumed, err := ParseString(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.AdventurerId = value0
currentIndex += consumed
value1, consumed, err := ParseUint64(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.Rank = value1
currentIndex += consumed
value2, consumed, err := ParseBigInt(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.Amount = value2
currentIndex += consumed
value3, consumed, err := ParseString(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.Address = value3
currentIndex += consumed
return result, currentIndex, nil
}
// ABI: game::Game::AdventurerLeveledUp
// ABI name for event
var Event_Game_Game_AdventurerLeveledUp string = "game::Game::AdventurerLeveledUp"
// Starknet hash for the event, as it appears in Starknet event logs.
var Hash_Game_Game_AdventurerLeveledUp string = "016b747f083a5bc0eb62f1465891cc9b6ce061c09e77556f949348af4e7a608a"
// Game_Game_AdventurerLeveledUp is the Go struct corresponding to the game::Game::AdventurerLeveledUp event.
type Game_Game_AdventurerLeveledUp struct {
AdventurerState Game_Game_AdventurerState
PreviousLevel uint64
NewLevel uint64
}
// ParseGame_Game_AdventurerLeveledUp parses a Game_Game_AdventurerLeveledUp event from a list of felts. This function returns a tuple of:
// 1. The parsed Game_Game_AdventurerLeveledUp struct representing the event
// 2. The number of field elements consumed in the parse
// 3. An error if the parse failed, nil otherwise
func ParseGame_Game_AdventurerLeveledUp(parameters []*felt.Felt) (Game_Game_AdventurerLeveledUp, int, error) {
currentIndex := 0
result := Game_Game_AdventurerLeveledUp{}
value0, consumed, err := ParseGame_Game_AdventurerState(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.AdventurerState = value0
currentIndex += consumed
value1, consumed, err := ParseUint64(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.PreviousLevel = value1
currentIndex += consumed
value2, consumed, err := ParseUint64(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.NewLevel = value2
currentIndex += consumed
return result, currentIndex + 1, nil
}
// ABI: game::Game::PurchasedPotions
// ABI name for event
var Event_Game_Game_PurchasedPotions string = "game::Game::PurchasedPotions"
// Starknet hash for the event, as it appears in Starknet event logs.
var Hash_Game_Game_PurchasedPotions string = "015a142c8e70a4bcecff9338b254db8b1240d0dda34c8163e098bb5b550f2ccf"
// Game_Game_PurchasedPotions is the Go struct corresponding to the game::Game::PurchasedPotions event.
type Game_Game_PurchasedPotions struct {
AdventurerState Game_Game_AdventurerState
Quantity uint64
Cost uint64
Health uint64
}
// ParseGame_Game_PurchasedPotions parses a Game_Game_PurchasedPotions event from a list of felts. This function returns a tuple of:
// 1. The parsed Game_Game_PurchasedPotions struct representing the event
// 2. The number of field elements consumed in the parse
// 3. An error if the parse failed, nil otherwise
func ParseGame_Game_PurchasedPotions(parameters []*felt.Felt) (Game_Game_PurchasedPotions, int, error) {
currentIndex := 0
result := Game_Game_PurchasedPotions{}
value0, consumed, err := ParseGame_Game_AdventurerState(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.AdventurerState = value0
currentIndex += consumed
value1, consumed, err := ParseUint64(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.Quantity = value1
currentIndex += consumed
value2, consumed, err := ParseUint64(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.Cost = value2
currentIndex += consumed
value3, consumed, err := ParseUint64(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.Health = value3
currentIndex += consumed
return result, currentIndex + 1, nil
}
// ABI: game::Game::RewardDistribution
// ABI name for event
var Event_Game_Game_RewardDistribution string = "game::Game::RewardDistribution"
// Starknet hash for the event, as it appears in Starknet event logs.
var Hash_Game_Game_RewardDistribution string = "02945361ab13c4fbed57e3e6c2330d6bdd49335c8f123424a35cee08c7011747"
// Game_Game_RewardDistribution is the Go struct corresponding to the game::Game::RewardDistribution event.
type Game_Game_RewardDistribution struct {
FirstPlace Game_Game_PlayerReward
SecondPlace Game_Game_PlayerReward
ThirdPlace Game_Game_PlayerReward
Client Game_Game_ClientReward
Dao *big.Int
}
// ParseGame_Game_RewardDistribution parses a Game_Game_RewardDistribution event from a list of felts. This function returns a tuple of:
// 1. The parsed Game_Game_RewardDistribution struct representing the event
// 2. The number of field elements consumed in the parse
// 3. An error if the parse failed, nil otherwise
func ParseGame_Game_RewardDistribution(parameters []*felt.Felt) (Game_Game_RewardDistribution, int, error) {
currentIndex := 0
result := Game_Game_RewardDistribution{}
value0, consumed, err := ParseGame_Game_PlayerReward(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.FirstPlace = value0
currentIndex += consumed
value1, consumed, err := ParseGame_Game_PlayerReward(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.SecondPlace = value1
currentIndex += consumed
value2, consumed, err := ParseGame_Game_PlayerReward(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.ThirdPlace = value2
currentIndex += consumed
value3, consumed, err := ParseGame_Game_ClientReward(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.Client = value3
currentIndex += consumed
value4, consumed, err := ParseBigInt(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.Dao = value4
currentIndex += consumed
return result, currentIndex + 1, nil
}
var EVENT_UNKNOWN = "UNKNOWN"
type ParsedEvent struct {
Name string
Event interface{}
}
type PartialEvent struct {
Name string
Event json.RawMessage
}
type EventParser struct {
Event_Game_Game_StartGame_Felt *felt.Felt
Event_Game_Game_UpgradesAvailable_Felt *felt.Felt
Event_Game_Game_DiscoveredHealth_Felt *felt.Felt
Event_Game_Game_DiscoveredGold_Felt *felt.Felt
Event_Game_Game_DodgedObstacle_Felt *felt.Felt
Event_Game_Game_HitByObstacle_Felt *felt.Felt
Event_Game_Game_AmbushedByBeast_Felt *felt.Felt
Event_Game_Game_DiscoveredBeast_Felt *felt.Felt
Event_Game_Game_AttackedBeast_Felt *felt.Felt
Event_Game_Game_AttackedByBeast_Felt *felt.Felt
Event_Game_Game_SlayedBeast_Felt *felt.Felt
Event_Game_Game_FleeFailed_Felt *felt.Felt
Event_Game_Game_FleeSucceeded_Felt *felt.Felt
Event_Game_Game_AdventurerLeveledUp_Felt *felt.Felt
Event_Game_Game_PurchasedItems_Felt *felt.Felt
Event_Game_Game_PurchasedPotions_Felt *felt.Felt
Event_Game_Game_AdventurerUpgraded_Felt *felt.Felt
Event_Game_Game_EquippedItems_Felt *felt.Felt
Event_Game_Game_DroppedItems_Felt *felt.Felt
Event_Game_Game_ItemsLeveledUp_Felt *felt.Felt
Event_Game_Game_AdventurerDied_Felt *felt.Felt
Event_Game_Game_NewHighScore_Felt *felt.Felt
Event_Game_Game_IdleDeathPenalty_Felt *felt.Felt
Event_Game_Game_RewardDistribution_Felt *felt.Felt
Event_Game_Game_GameEntropyRotatedEvent_Felt *felt.Felt
Event_Game_Game_PriceChangeEvent_Felt *felt.Felt
}
func NewEventParser() (*EventParser, error) {
var feltErr error
parser := &EventParser{}
parser.Event_Game_Game_StartGame_Felt, feltErr = FeltFromHexString(Hash_Game_Game_StartGame)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_UpgradesAvailable_Felt, feltErr = FeltFromHexString(Hash_Game_Game_UpgradesAvailable)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_DiscoveredHealth_Felt, feltErr = FeltFromHexString(Hash_Game_Game_DiscoveredHealth)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_DiscoveredGold_Felt, feltErr = FeltFromHexString(Hash_Game_Game_DiscoveredGold)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_DodgedObstacle_Felt, feltErr = FeltFromHexString(Hash_Game_Game_DodgedObstacle)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_HitByObstacle_Felt, feltErr = FeltFromHexString(Hash_Game_Game_HitByObstacle)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_AmbushedByBeast_Felt, feltErr = FeltFromHexString(Hash_Game_Game_AmbushedByBeast)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_DiscoveredBeast_Felt, feltErr = FeltFromHexString(Hash_Game_Game_DiscoveredBeast)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_AttackedBeast_Felt, feltErr = FeltFromHexString(Hash_Game_Game_AttackedBeast)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_AttackedByBeast_Felt, feltErr = FeltFromHexString(Hash_Game_Game_AttackedByBeast)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_SlayedBeast_Felt, feltErr = FeltFromHexString(Hash_Game_Game_SlayedBeast)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_FleeFailed_Felt, feltErr = FeltFromHexString(Hash_Game_Game_FleeFailed)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_FleeSucceeded_Felt, feltErr = FeltFromHexString(Hash_Game_Game_FleeSucceeded)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_AdventurerLeveledUp_Felt, feltErr = FeltFromHexString(Hash_Game_Game_AdventurerLeveledUp)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_PurchasedItems_Felt, feltErr = FeltFromHexString(Hash_Game_Game_PurchasedItems)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_PurchasedPotions_Felt, feltErr = FeltFromHexString(Hash_Game_Game_PurchasedPotions)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_AdventurerUpgraded_Felt, feltErr = FeltFromHexString(Hash_Game_Game_AdventurerUpgraded)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_EquippedItems_Felt, feltErr = FeltFromHexString(Hash_Game_Game_EquippedItems)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_DroppedItems_Felt, feltErr = FeltFromHexString(Hash_Game_Game_DroppedItems)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_ItemsLeveledUp_Felt, feltErr = FeltFromHexString(Hash_Game_Game_ItemsLeveledUp)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_AdventurerDied_Felt, feltErr = FeltFromHexString(Hash_Game_Game_AdventurerDied)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_NewHighScore_Felt, feltErr = FeltFromHexString(Hash_Game_Game_NewHighScore)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_IdleDeathPenalty_Felt, feltErr = FeltFromHexString(Hash_Game_Game_IdleDeathPenalty)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_RewardDistribution_Felt, feltErr = FeltFromHexString(Hash_Game_Game_RewardDistribution)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_GameEntropyRotatedEvent_Felt, feltErr = FeltFromHexString(Hash_Game_Game_GameEntropyRotatedEvent)
if feltErr != nil {
return parser, feltErr
}
parser.Event_Game_Game_PriceChangeEvent_Felt, feltErr = FeltFromHexString(Hash_Game_Game_PriceChangeEvent)
if feltErr != nil {
return parser, feltErr
}
return parser, nil
}
func (p *EventParser) Parse(event RawEvent) (ParsedEvent, error) {
defaultResult := ParsedEvent{Name: EVENT_UNKNOWN, Event: event}
if p.Event_Game_Game_StartGame_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_StartGame(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_StartGame, Event: parsedEvent}, nil
}
if p.Event_Game_Game_UpgradesAvailable_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_UpgradesAvailable(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_UpgradesAvailable, Event: parsedEvent}, nil
}
if p.Event_Game_Game_DiscoveredHealth_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_DiscoveredHealth(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_DiscoveredHealth, Event: parsedEvent}, nil
}
if p.Event_Game_Game_DiscoveredGold_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_DiscoveredGold(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_DiscoveredGold, Event: parsedEvent}, nil
}
if p.Event_Game_Game_DodgedObstacle_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_DodgedObstacle(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_DodgedObstacle, Event: parsedEvent}, nil
}
if p.Event_Game_Game_HitByObstacle_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_HitByObstacle(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_HitByObstacle, Event: parsedEvent}, nil
}
if p.Event_Game_Game_AmbushedByBeast_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_AmbushedByBeast(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_AmbushedByBeast, Event: parsedEvent}, nil
}
if p.Event_Game_Game_DiscoveredBeast_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_DiscoveredBeast(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_DiscoveredBeast, Event: parsedEvent}, nil
}
if p.Event_Game_Game_AttackedBeast_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_AttackedBeast(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_AttackedBeast, Event: parsedEvent}, nil
}
if p.Event_Game_Game_AttackedByBeast_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_AttackedByBeast(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_AttackedByBeast, Event: parsedEvent}, nil
}
if p.Event_Game_Game_SlayedBeast_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_SlayedBeast(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_SlayedBeast, Event: parsedEvent}, nil
}
if p.Event_Game_Game_FleeFailed_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_FleeFailed(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_FleeFailed, Event: parsedEvent}, nil
}
if p.Event_Game_Game_FleeSucceeded_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_FleeSucceeded(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_FleeSucceeded, Event: parsedEvent}, nil
}
if p.Event_Game_Game_AdventurerLeveledUp_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_AdventurerLeveledUp(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_AdventurerLeveledUp, Event: parsedEvent}, nil
}
if p.Event_Game_Game_PurchasedItems_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_PurchasedItems(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_PurchasedItems, Event: parsedEvent}, nil
}
if p.Event_Game_Game_PurchasedPotions_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_PurchasedPotions(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_PurchasedPotions, Event: parsedEvent}, nil
}
if p.Event_Game_Game_AdventurerUpgraded_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_AdventurerUpgraded(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_AdventurerUpgraded, Event: parsedEvent}, nil
}
if p.Event_Game_Game_EquippedItems_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_EquippedItems(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_EquippedItems, Event: parsedEvent}, nil
}
if p.Event_Game_Game_DroppedItems_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_DroppedItems(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_DroppedItems, Event: parsedEvent}, nil
}
if p.Event_Game_Game_ItemsLeveledUp_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_ItemsLeveledUp(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_ItemsLeveledUp, Event: parsedEvent}, nil
}
if p.Event_Game_Game_AdventurerDied_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_AdventurerDied(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_AdventurerDied, Event: parsedEvent}, nil
}
if p.Event_Game_Game_NewHighScore_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_NewHighScore(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_NewHighScore, Event: parsedEvent}, nil
}
if p.Event_Game_Game_IdleDeathPenalty_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_IdleDeathPenalty(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_IdleDeathPenalty, Event: parsedEvent}, nil
}
if p.Event_Game_Game_RewardDistribution_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_RewardDistribution(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_RewardDistribution, Event: parsedEvent}, nil
}
if p.Event_Game_Game_GameEntropyRotatedEvent_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_GameEntropyRotatedEvent(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_GameEntropyRotatedEvent, Event: parsedEvent}, nil
}
if p.Event_Game_Game_PriceChangeEvent_Felt.Cmp(event.PrimaryKey) == 0 {
parsedEvent, _, parseErr := ParseGame_Game_PriceChangeEvent(event.Parameters)
if parseErr != nil {
return defaultResult, parseErr
}
return ParsedEvent{Name: Event_Game_Game_PriceChangeEvent, Event: parsedEvent}, nil
}
return defaultResult, nil
}
// ABI: combat::constants::CombatEnums::Tier
// Combat_Constants_CombatEnums_Tier is an alias for uint64
type Combat_Constants_CombatEnums_Tier = uint64
// ParseCombat_Constants_CombatEnums_Tier parses a Combat_Constants_CombatEnums_Tier from a list of felts. This function returns a tuple of:
// 1. The parsed Combat_Constants_CombatEnums_Tier
// 2. The number of field elements consumed in the parse
// 3. An error if the parse failed, nil otherwise
func ParseCombat_Constants_CombatEnums_Tier(parameters []*felt.Felt) (Combat_Constants_CombatEnums_Tier, int, error) {
if len(parameters) < 1 {
return 0, 0, ErrIncorrectParameters
}
return Combat_Constants_CombatEnums_Tier(parameters[0].Uint64()), 1, nil
}
// This function returns the string representation of a Combat_Constants_CombatEnums_Tier enum. This is the enum value from the ABI definition of the enum.
func EvaluateCombat_Constants_CombatEnums_Tier(raw Combat_Constants_CombatEnums_Tier) string {
switch raw {
case 0:
return "None"
case 1:
return "T-1"
case 2:
return "T0"
case 3:
return "T1"
case 4:
return "T2"
case 5:
return "T3"
}
return "UNKNOWN"
}
// ABI: game::Game::ObstacleDetails
// Game_Game_ObstacleDetails is the Go struct corresponding to the game::Game::ObstacleDetails struct.
type Game_Game_ObstacleDetails struct {
Id uint64
Level uint64
DamageTaken uint64
DamageLocation uint64
CriticalHit Core_Bool
AdventurerXpReward uint64
ItemXpReward uint64
}
// ParseGame_Game_ObstacleDetails parses a Game_Game_ObstacleDetails struct from a list of felts. This function returns a tuple of:
// 1. The parsed Game_Game_ObstacleDetails struct
// 2. The number of field elements consumed in the parse
// 3. An error if the parse failed, nil otherwise
func ParseGame_Game_ObstacleDetails(parameters []*felt.Felt) (Game_Game_ObstacleDetails, int, error) {
currentIndex := 0
result := Game_Game_ObstacleDetails{}
value0, consumed, err := ParseUint64(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.Id = value0
currentIndex += consumed
value1, consumed, err := ParseUint64(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.Level = value1
currentIndex += consumed
value2, consumed, err := ParseUint64(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.DamageTaken = value2
currentIndex += consumed
value3, consumed, err := ParseUint64(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.DamageLocation = value3
currentIndex += consumed
value4, consumed, err := ParseCore_Bool(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.CriticalHit = value4
currentIndex += consumed
value5, consumed, err := ParseUint64(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.AdventurerXpReward = value5
currentIndex += consumed
value6, consumed, err := ParseUint64(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.ItemXpReward = value6
currentIndex += consumed
return result, currentIndex, nil
}
// ABI: game::Game::PurchasedItems
// ABI name for event
var Event_Game_Game_PurchasedItems string = "game::Game::PurchasedItems"
// Starknet hash for the event, as it appears in Starknet event logs.
var Hash_Game_Game_PurchasedItems string = "0127e97eb6a3822aeea793175c23d1dab98c510ce54a317e530ac3891cc076fd"
// Game_Game_PurchasedItems is the Go struct corresponding to the game::Game::PurchasedItems event.
type Game_Game_PurchasedItems struct {
AdventurerStateWithBag Game_Game_AdventurerStateWithBag
Purchases []Market_Market_LootWithPrice
}
// ParseGame_Game_PurchasedItems parses a Game_Game_PurchasedItems event from a list of felts. This function returns a tuple of:
// 1. The parsed Game_Game_PurchasedItems struct representing the event
// 2. The number of field elements consumed in the parse
// 3. An error if the parse failed, nil otherwise
func ParseGame_Game_PurchasedItems(parameters []*felt.Felt) (Game_Game_PurchasedItems, int, error) {
currentIndex := 0
result := Game_Game_PurchasedItems{}
value0, consumed, err := ParseGame_Game_AdventurerStateWithBag(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.AdventurerStateWithBag = value0
currentIndex += consumed
value1, consumed, err := ParseArray[Market_Market_LootWithPrice](ParseMarket_Market_LootWithPrice)(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.Purchases = value1
currentIndex += consumed
return result, currentIndex + 1, nil
}
// ABI: market::market::ItemPurchase
// Market_Market_ItemPurchase is the Go struct corresponding to the market::market::ItemPurchase struct.
type Market_Market_ItemPurchase struct {
ItemId uint64
Equip Core_Bool
}
// ParseMarket_Market_ItemPurchase parses a Market_Market_ItemPurchase struct from a list of felts. This function returns a tuple of:
// 1. The parsed Market_Market_ItemPurchase struct
// 2. The number of field elements consumed in the parse
// 3. An error if the parse failed, nil otherwise
func ParseMarket_Market_ItemPurchase(parameters []*felt.Felt) (Market_Market_ItemPurchase, int, error) {
currentIndex := 0
result := Market_Market_ItemPurchase{}
value0, consumed, err := ParseUint64(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.ItemId = value0
currentIndex += consumed
value1, consumed, err := ParseCore_Bool(parameters[currentIndex:])
if err != nil {
return result, 0, err
}
result.Equip = value1
currentIndex += consumed
return result, currentIndex, nil
}
// ABI: game::Game::DiscoveredGold
// ABI name for event
var Event_Game_Game_DiscoveredGold string = "game::Game::DiscoveredGold"
// Starknet hash for the event, as it appears in Starknet event logs.
var Hash_Game_Game_DiscoveredGold string = "15b7d298d615bc8a7f835a151be6f79848d7a28abba637e6608feac27255a2"
// Game_Game_DiscoveredGold is the Go struct corresponding to the game::Game::DiscoveredGold event.
type Game_Game_DiscoveredGold struct {
Discovery Game_Game_Discovery
}
// ParseGame_Game_DiscoveredGold parses a Game_Game_DiscoveredGold event from a list of felts. This function returns a tuple of:
// 1. The parsed Game_Game_DiscoveredGold struct representing the event
// 2. The number of field elements consumed in the parse
// 3. An error if the parse failed, nil otherwise
func ParseGame_Game_DiscoveredGold(parameters []*felt.Felt) (Game_Game_DiscoveredGold, int, error) {
currentIndex := 0
result := Game_Game_DiscoveredGold{}
value0, consumed, err := ParseGame_Game_Discovery(parameters[currentIndex:])
if err != nil {
return result, 0, err
}