Skip to content

Commit

Permalink
Merge pull request #258 from dapperlabs/judez/add-events-validation
Browse files Browse the repository at this point in the history
Added events validation
  • Loading branch information
judezhu authored Aug 12, 2024
2 parents 08687dd + 9920f49 commit 043f9c8
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 25 deletions.
9 changes: 7 additions & 2 deletions lib/go/events/deposit.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package events

import (
"fmt"
"github.com/dapperlabs/nba-smart-contracts/lib/go/events/decoder"
)

var (
const (
// This variable specifies that there is a Deposit Event on a TopShot Contract located at address 0x04
EventDeposit = "TopShot.Deposit"
)
Expand Down Expand Up @@ -37,10 +38,14 @@ func (evt depositEvent) Owner() string {
}

func DecodeDepositEvent(b []byte) (DepositEvent, error) {
eventMap, err := decoder.DecodeToEventMap(b)
cadenceValue, err := decoder.GetCadenceEvent(b)
if err != nil {
return nil, err
}
if cadenceValue.EventType.QualifiedIdentifier != EventDeposit {
return nil, fmt.Errorf("unexpected event type: %s", cadenceValue.EventType.QualifiedIdentifier)
}
eventMap, err := decoder.ConvertEvent(cadenceValue)
event := depositEvent(eventMap)
return event, nil
}
9 changes: 7 additions & 2 deletions lib/go/events/moment_destroy.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package events

import (
"fmt"
"github.com/dapperlabs/nba-smart-contracts/lib/go/events/decoder"
)

var (
const (
EventMomentDestroyed = "TopShot.MomentDestroyed"
)

Expand All @@ -19,10 +20,14 @@ func (evt momentDestroyedEvent) Id() uint64 {
}

func DecodeMomentDestroyedEvent(b []byte) (MomentDestroyedEvent, error) {
eventMap, err := decoder.DecodeToEventMap(b)
cadenceValue, err := decoder.GetCadenceEvent(b)
if err != nil {
return nil, err
}
if cadenceValue.EventType.QualifiedIdentifier != EventMomentDestroyed {
return nil, fmt.Errorf("unexpected event type: %s", cadenceValue.EventType.QualifiedIdentifier)
}
eventMap, err := decoder.ConvertEvent(cadenceValue)
event := momentDestroyedEvent(eventMap)
return event, nil
}
7 changes: 6 additions & 1 deletion lib/go/events/moment_locked.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package events

import (
"fmt"
"github.com/dapperlabs/nba-smart-contracts/lib/go/events/decoder"
)

Expand Down Expand Up @@ -31,10 +32,14 @@ func (evt momentLockedEvent) ExpiryTimestamp() float64 {
var _ MomentLockedEvent = (*momentLockedEvent)(nil)

func DecodeMomentLockedEvent(b []byte) (MomentLockedEvent, error) {
eventMap, err := decoder.DecodeToEventMap(b)
cadenceValue, err := decoder.GetCadenceEvent(b)
if err != nil {
return nil, err
}
if cadenceValue.EventType.QualifiedIdentifier != MomentLocked {
return nil, fmt.Errorf("unexpected event type: %s", cadenceValue.EventType.QualifiedIdentifier)
}
eventMap, err := decoder.ConvertEvent(cadenceValue)

event := momentLockedEvent(eventMap)

Expand Down
9 changes: 7 additions & 2 deletions lib/go/events/moment_minted.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package events

import (
"fmt"
"github.com/dapperlabs/nba-smart-contracts/lib/go/events/decoder"
)

var (
const (
// This variable specifies that there is a MomentMinted Event on a TopShot Contract located at address 0x04
EventMomentMinted = "TopShot.MomentMinted"
)
Expand Down Expand Up @@ -45,10 +46,14 @@ func (evt momentMintedEvent) SubeditionId() uint32 {
var _ MomentMintedEvent = (*momentMintedEvent)(nil)

func DecodeMomentMintedEvent(b []byte) (MomentMintedEvent, error) {
eventMap, err := decoder.DecodeToEventMap(b)
cadenceValue, err := decoder.GetCadenceEvent(b)
if err != nil {
return nil, err
}
if cadenceValue.EventType.QualifiedIdentifier != EventMomentMinted {
return nil, fmt.Errorf("unexpected event type: %s", cadenceValue.EventType.QualifiedIdentifier)
}
eventMap, err := decoder.ConvertEvent(cadenceValue)
event := momentMintedEvent(eventMap)
return event, nil
}
9 changes: 7 additions & 2 deletions lib/go/events/moment_unlocked.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package events

import (
"fmt"
"github.com/dapperlabs/nba-smart-contracts/lib/go/events/decoder"
)

var (
const (
MomentUnlocked = "TopShotLocking.MomentUnlocked"
)

Expand All @@ -21,10 +22,14 @@ func (evt momentUnlockedEvent) FlowID() uint64 {
var _ MomentUnlockedEvent = (*momentUnlockedEvent)(nil)

func DecodeMomentUnlockedEvent(b []byte) (MomentUnlockedEvent, error) {
eventMap, err := decoder.DecodeToEventMap(b)
cadenceValue, err := decoder.GetCadenceEvent(b)
if err != nil {
return nil, err
}
if cadenceValue.EventType.QualifiedIdentifier != MomentUnlocked {
return nil, fmt.Errorf("unexpected event type: %s", cadenceValue.EventType.QualifiedIdentifier)
}
eventMap, err := decoder.ConvertEvent(cadenceValue)

event := momentUnlockedEvent(eventMap)
return event, nil
Expand Down
9 changes: 7 additions & 2 deletions lib/go/events/play.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package events

import (
"fmt"
"github.com/dapperlabs/nba-smart-contracts/lib/go/events/decoder"
)

var (
const (
EventPlayCreated = "TopShot.PlayCreated"
)

Expand All @@ -24,10 +25,14 @@ func (evt playCreatedEvent) MetaData() map[interface{}]interface{} {
}

func DecodePlayCreatedEvent(b []byte) (PlayCreatedEvent, error) {
eventMap, err := decoder.DecodeToEventMap(b)
cadenceValue, err := decoder.GetCadenceEvent(b)
if err != nil {
return nil, err
}
if cadenceValue.EventType.QualifiedIdentifier != EventPlayCreated {
return nil, fmt.Errorf("unexpected event type: %s", cadenceValue.EventType.QualifiedIdentifier)
}
eventMap, err := decoder.ConvertEvent(cadenceValue)
event := playCreatedEvent(eventMap)
return event, nil
}
7 changes: 6 additions & 1 deletion lib/go/events/revealed.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package events

import (
"fmt"
"github.com/dapperlabs/nba-smart-contracts/lib/go/events/decoder"
"strings"
)
Expand Down Expand Up @@ -37,10 +38,14 @@ func parseNFTs(nft string) []string {
}

func DecodeRevealedEvent(b []byte) (RevealedEvent, error) {
eventMap, err := decoder.DecodeToEventMap(b)
cadenceValue, err := decoder.GetCadenceEvent(b)
if err != nil {
return nil, err
}
if cadenceValue.EventType.QualifiedIdentifier != EventRevealed {
return nil, fmt.Errorf("unexpected event type: %s", cadenceValue.EventType.QualifiedIdentifier)
}
eventMap, err := decoder.ConvertEvent(cadenceValue)
event := revealedEvent(eventMap)
return event, nil
}
9 changes: 7 additions & 2 deletions lib/go/events/set.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package events

import (
"fmt"
"github.com/dapperlabs/nba-smart-contracts/lib/go/events/decoder"
)

var (
const (
EventSetCreated = "TopShot.SetCreated"
)

Expand All @@ -26,10 +27,14 @@ func (evt setCreatedEvent) Series() uint32 {
var _ SetCreatedEvent = (*setCreatedEvent)(nil)

func DecodeSetCreatedEvent(b []byte) (SetCreatedEvent, error) {
eventMap, err := decoder.DecodeToEventMap(b)
cadenceValue, err := decoder.GetCadenceEvent(b)
if err != nil {
return nil, err
}
if cadenceValue.EventType.QualifiedIdentifier != EventSetCreated {
return nil, fmt.Errorf("unexpected event type: %s", cadenceValue.EventType.QualifiedIdentifier)
}
eventMap, err := decoder.ConvertEvent(cadenceValue)
event := setCreatedEvent(eventMap)
return event, nil
}
9 changes: 7 additions & 2 deletions lib/go/events/set_locked.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package events

import (
"fmt"
"github.com/dapperlabs/nba-smart-contracts/lib/go/events/decoder"
)

var (
const (
EventSetLocked = "TopShot.SetLocked"
)

Expand All @@ -21,10 +22,14 @@ func (evt setLockedEvent) SetID() uint32 {
}

func DecodeSetLockedEvent(b []byte) (SetLockedEvent, error) {
eventMap, err := decoder.DecodeToEventMap(b)
cadenceValue, err := decoder.GetCadenceEvent(b)
if err != nil {
return nil, err
}
if cadenceValue.EventType.QualifiedIdentifier != EventSetLocked {
return nil, fmt.Errorf("unexpected event type: %s", cadenceValue.EventType.QualifiedIdentifier)
}
eventMap, err := decoder.ConvertEvent(cadenceValue)
event := setLockedEvent(eventMap)
return event, nil
}
9 changes: 7 additions & 2 deletions lib/go/events/set_play.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package events

import (
"fmt"
"github.com/dapperlabs/nba-smart-contracts/lib/go/events/decoder"
)

var (
const (
EventPlayAddedToSet = "TopShot.PlayAddedToSet"
)

Expand All @@ -26,10 +27,14 @@ func (evt playAddedToSetEvent) PlayID() uint32 {
var _ PlayAddedToSetEvent = (*playAddedToSetEvent)(nil)

func DecodePlayAddedToSetEvent(b []byte) (PlayAddedToSetEvent, error) {
eventMap, err := decoder.DecodeToEventMap(b)
cadenceValue, err := decoder.GetCadenceEvent(b)
if err != nil {
return nil, err
}
if cadenceValue.EventType.QualifiedIdentifier != EventPlayAddedToSet {
return nil, fmt.Errorf("unexpected event type: %s", cadenceValue.EventType.QualifiedIdentifier)
}
eventMap, err := decoder.ConvertEvent(cadenceValue)
event := playAddedToSetEvent(eventMap)
return event, nil
}
9 changes: 7 additions & 2 deletions lib/go/events/set_play_retired.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package events

import (
"fmt"
"github.com/dapperlabs/nba-smart-contracts/lib/go/events/decoder"
)

var (
const (
EventPlayRetiredFromSet = "TopShot.PlayRetiredFromSet"
)

Expand All @@ -31,10 +32,14 @@ func (evt setPlayRetiredEvent) NumMoments() uint32 {
var _ SetPlayRetiredEvent = (*setPlayRetiredEvent)(nil)

func DecodeSetPlayRetiredEvent(b []byte) (SetPlayRetiredEvent, error) {
eventMap, err := decoder.DecodeToEventMap(b)
cadenceValue, err := decoder.GetCadenceEvent(b)
if err != nil {
return nil, err
}
if cadenceValue.EventType.QualifiedIdentifier != EventPlayRetiredFromSet {
return nil, fmt.Errorf("unexpected event type: %s", cadenceValue.EventType.QualifiedIdentifier)
}
eventMap, err := decoder.ConvertEvent(cadenceValue)
event := setPlayRetiredEvent(eventMap)
return event, nil
}
9 changes: 7 additions & 2 deletions lib/go/events/subedition.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package events

import (
"fmt"
"github.com/dapperlabs/nba-smart-contracts/lib/go/events/decoder"
)

var (
const (
EventSubeditionCreated = "TopShot.SubeditionCreated"
)

Expand Down Expand Up @@ -34,10 +35,14 @@ func (evt subeditionCreatedEvent) MetaData() map[string]interface{} {
}

func DecodeSubeditionCreatedEvent(b []byte) (SubeditionCreatedEvent, error) {
eventMap, err := decoder.DecodeToEventMap(b)
cadenceValue, err := decoder.GetCadenceEvent(b)
if err != nil {
return nil, err
}
if cadenceValue.EventType.QualifiedIdentifier != EventSubeditionCreated {
return nil, fmt.Errorf("unexpected event type: %s", cadenceValue.EventType.QualifiedIdentifier)
}
eventMap, err := decoder.ConvertEvent(cadenceValue)
event := subeditionCreatedEvent(eventMap)
return event, nil
}
7 changes: 6 additions & 1 deletion lib/go/events/subedition_added_to_moment.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package events

import (
"fmt"
"github.com/dapperlabs/nba-smart-contracts/lib/go/events/decoder"
)

Expand All @@ -24,10 +25,14 @@ func (evt subeditionAddedToMomentEvent) SubeditionID() uint32 {
}

func DecodeSubeditionAddedToMomentEvent(b []byte) (SubeditionAddedToMomentEvent, error) {
eventMap, err := decoder.DecodeToEventMap(b)
cadenceValue, err := decoder.GetCadenceEvent(b)
if err != nil {
return nil, err
}
if cadenceValue.EventType.QualifiedIdentifier != EventSubeditionAddedToMoment {
return nil, fmt.Errorf("unexpected event type: %s", cadenceValue.EventType.QualifiedIdentifier)
}
eventMap, err := decoder.ConvertEvent(cadenceValue)
event := subeditionAddedToMomentEvent(eventMap)
return event, nil
}
9 changes: 7 additions & 2 deletions lib/go/events/withdraw.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package events

import (
"fmt"
"github.com/dapperlabs/nba-smart-contracts/lib/go/events/decoder"
)

var (
const (
EventWithdraw = "TopShot.Withdraw"
)

Expand Down Expand Up @@ -35,10 +36,14 @@ func (evt withdrawEvent) Owner() string {
}

func DecodeWithdrawEvent(b []byte) (WithdrawEvent, error) {
eventMap, err := decoder.DecodeToEventMap(b)
cadenceValue, err := decoder.GetCadenceEvent(b)
if err != nil {
return nil, err
}
if cadenceValue.EventType.QualifiedIdentifier != EventWithdraw {
return nil, fmt.Errorf("unexpected event type: %s", cadenceValue.EventType.QualifiedIdentifier)
}
eventMap, err := decoder.ConvertEvent(cadenceValue)
event := withdrawEvent(eventMap)
return event, nil
}

0 comments on commit 043f9c8

Please sign in to comment.