Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update go-events.md #214

Open
wants to merge 4 commits into
base: staging
Choose a base branch
from
Open

Conversation

andreipope
Copy link
Collaborator

update go-events.md

update go-events.md
@gakonst
Copy link
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

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

Ref PR: loomnetwork/go-loom#383

added go and js examples
docs/en/go-events.md Outdated Show resolved Hide resolved
updating the go example
@gakonst
Copy link
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
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
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
Collaborator Author

@pathornteng Could you help?

@mattkanwisher
Copy link
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