Skip to content

update go-events.md#214

Open
andreipope wants to merge 4 commits intostagingfrom
Document-querying-the-event-store
Open

update go-events.md#214
andreipope wants to merge 4 commits intostagingfrom
Document-querying-the-event-store

Conversation

@andreipope
Copy link
Copy Markdown
Collaborator

update go-events.md

update go-events.md
@andreipope andreipope requested review from gakonst and pathornteng May 21, 2019 13:47
@gakonst
Copy link
Copy Markdown
Contributor

gakonst commented May 21, 2019

So far so good, can we additionally add some golang and js examples of polling and watching events?

@pathornteng
Copy link
Copy Markdown

pathornteng commented May 22, 2019

I just create a new method GetContractEvents in go-loom. It is not done yet. But once it is merged, the following is the example of how to query and decode events

type MyEvent struct {
	Owner  string
	Method string
	Addr   []byte
}

rpcClient := client.NewDAppChainRPCClient("default", "http://plasma.dappchains.com:80/rpc", "http://plasma.dappchains.com:80/query")
fromBlock := uint64(5216300)
toBlock := uint64(5216320)
result, err := rpcClient.GetContractEvents(fromBlock, toBlock, "")
if err != nil {
	panic(err)
}
for _, event := range result.Events {
	var decodedEvent MyEvent
	if err := json.Unmarshal(event.EncodedBody, &decodedEvent); err != nil {
		panic(err)
	}
}

@pathornteng
Copy link
Copy Markdown

Ref PR: loomnetwork/go-loom#383

added go and js examples
updating the go example
@gakonst
Copy link
Copy Markdown
Contributor

gakonst commented May 29, 2019

Good work so far! It'd be better if you could include a full code snippet that compiles, so change the example to:

package main

import (
	"encoding/json"
	"github.com/loomnetwork/go-loom/client"
)

type MyEvent struct {
	Owner  string
	Method string
	Addr   []byte
}

func main() {
	rpcClient := client.NewDAppChainRPCClient("default", "http://plasma.dappchains.com:80/rpc", "http://plasma.dappchains.com:80/query")
	fromBlock := uint64(5216300)
	toBlock := uint64(5216320)
	result, err := rpcClient.GetContractEvents(fromBlock, toBlock, "")
	if err != nil {
		panic(err)

	}
	for _, event := range result.Events {
		var decodedEvent MyEvent
		if err := json.Unmarshal(event.EncodedBody, &decodedEvent); err != nil {
			panic(err)

		}

	}
}

2 things:

  • Can we somehow filter for events that only come from a specific contract?
  • Your example also panics, so may want to give an example which provides some more intuitive result.

Copy link
Copy Markdown
Contributor

@gakonst gakonst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change as per above comment

updated the go example
@andreipope
Copy link
Copy Markdown
Collaborator Author

Change as per above comment

Updated the example.
@pathornteng can you help with these:

  1. Can we somehow filter for events that only come from a specific contract?
  2. Your example also panics, so may want to give an example which provides some more intuitive result.

@andreipope
Copy link
Copy Markdown
Collaborator Author

@pathornteng Could you help?

@mattkanwisher
Copy link
Copy Markdown
Contributor

Not super high priority but when we get a chance lets see if we can fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants