Skip to content

Commit

Permalink
Fix based on feedback from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
nozim committed Sep 6, 2023
1 parent e4d8927 commit 155a11e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
18 changes: 9 additions & 9 deletions event_name_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,37 @@ import (
"fmt"
)

type eventNameFactory struct {
type eventTypeFactory struct {
address string
contractName string
eventName string
}

func (f eventNameFactory) WithAddressString(address string) eventNameFactory {
func (f eventTypeFactory) WithAddressString(address string) eventTypeFactory {
f.address = address
return f
}

func (f eventNameFactory) WithAddress(address Address) eventNameFactory {
func (f eventTypeFactory) WithAddress(address Address) eventTypeFactory {
f.address = address.Hex()
return f
}

func (f eventNameFactory) WithContractName(contract string) eventNameFactory {
func (f eventTypeFactory) WithContractName(contract string) eventTypeFactory {
f.contractName = contract
return f
}

func (f eventNameFactory) WithEventName(event string) eventNameFactory {
func (f eventTypeFactory) WithEventName(event string) eventTypeFactory {
f.eventName = event
return f
}

func (f eventNameFactory) Build() string {
func (f eventTypeFactory) String() string {
return fmt.Sprintf("A.%s.%s.%s", f.address, f.contractName, f.eventName)
}

// NewEvent helper function for constructing event names
func NewEvent() eventNameFactory {
return eventNameFactory{}
// NewEventTypeFactory helper function for constructing event names
func NewEventTypeFactory() eventTypeFactory {
return eventTypeFactory{}
}
4 changes: 2 additions & 2 deletions event_name_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
)

func TestEventNameFactory(t *testing.T) {
assert.Equal(t, "A.7e60df042a9c0868.FlowToken.AccountCreated", NewEvent().
assert.Equal(t, "A.7e60df042a9c0868.FlowToken.AccountCreated", NewEventTypeFactory().
WithEventName("AccountCreated").
WithAddressString("7e60df042a9c0868").
WithContractName("FlowToken").
Build())
String())
}
7 changes: 2 additions & 5 deletions examples/get_events/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,11 @@ func demo(deployedContract *flow.Account, runScriptTx *flow.Transaction) {
result, err := flowClient.GetEventsForHeightRange(ctx, "flow.AccountCreated", 0, 30)
printEvents(result, err)

// Query for our custom event by type
//customType := fmt.Sprintf("AC.%s.EventDemo.EventDemo.Add", deployedContract.Address.Hex())

customType := flow.NewEvent().
customType := flow.NewEventTypeFactory().
WithEventName("Add").
WithContractName("EventDemo").
WithAddress(deployedContract.Address).
Build()
String()

result, err = flowClient.GetEventsForHeightRange(ctx, customType, 0, 10)
printEvents(result, err)
Expand Down

0 comments on commit 155a11e

Please sign in to comment.