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

go-kosu: use TM Events correctly #248

Merged
merged 2 commits into from Aug 29, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

go-kosu: use TM Events correctly

  • Loading branch information
gchaincl committed Aug 29, 2019
commit f8fedb97b43aa614b123913b555a61daf8a98386
@@ -70,7 +70,7 @@ func (app *App) deliverOrderTx(tx *types.TransactionOrder) abci.ResponseDeliverT
return abci.ResponseDeliverTx{
Code: 0,
Events: []abci.Event{
{Type: "tags", Attributes: NewTagsFromOrderInfo(orderID, posterAddress, poster.Limit)},
{Type: "tags", Attributes: NewKVPairFromOrderInfo(orderID, posterAddress, poster.Limit)},
},
}
}
@@ -19,22 +19,27 @@ func NewTagsFromRoundInfo(info *types.RoundInfo) []common.KVPair {
}
}

// NewRoundInfoFromTags parses a set of tags and returns a state.RoundInfo
func NewRoundInfoFromTags(tags map[string]string) (*types.RoundInfo, error) {
// NewRoundInfoFromEvents parses a set of tags and returns a state.RoundInfo
func NewRoundInfoFromEvents(events map[string][]string) (*types.RoundInfo, error) {
var info types.RoundInfo
var err error

fields := []struct {
tag string
val *uint64
}{
{"round.number", &info.Number},
{"round.start", &info.StartsAt},
{"round.end", &info.EndsAt},
{"tags.round.number", &info.Number},
{"tags.round.start", &info.StartsAt},
{"tags.round.end", &info.EndsAt},
}

for _, field := range fields {
*field.val, err = strconv.ParseUint(tags[field.tag], 10, 64)
tags := events[field.tag]
if len(tags) == 0 {
continue
}

*field.val, err = strconv.ParseUint(tags[0], 10, 64)
if err != nil {
return nil, err
}
@@ -44,7 +49,7 @@ func NewRoundInfoFromTags(tags map[string]string) (*types.RoundInfo, error) {
}

// NewTagsFromOrderInfo returns the KVPairs necessary to make up Order transaction tags
func NewTagsFromOrderInfo(orderID []byte, posterAddress store.Address, newLimit uint64) []common.KVPair {
func NewKVPairFromOrderInfo(orderID []byte, posterAddress store.Address, newLimit uint64) []common.KVPair {
return []common.KVPair{
{Key: []byte("tx.type"), Value: []byte("order")},
{Key: []byte("order.id"), Value: orderID},
@@ -33,7 +33,7 @@ require (
github.com/spf13/cobra v0.0.5
github.com/spf13/viper v1.3.2
github.com/stretchr/testify v1.3.0
github.com/tendermint/tendermint v0.32.2
github.com/tendermint/tendermint v0.32.3
github.com/tendermint/tm-db v0.1.1
github.com/tidwall/gjson v1.3.0
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734
@@ -261,6 +261,7 @@ github.com/tendermint/tendermint v0.32.1/go.mod h1:jmPDAKuNkev9793/ivn/fTBnfpA9m
github.com/tendermint/tendermint v0.32.2 h1:FvZWdksfDg/65vKKr5Lgo57keARFnmhrUEXHwyrV1QY=
github.com/tendermint/tendermint v0.32.2/go.mod h1:NwMyx58S8VJ7tEpFKqRVlVWKO9N9zjTHu+Dx96VsnOE=
github.com/tendermint/tendermint v0.32.3 h1:GEnWpGQ795h5oTFNbfBLsY0LW/CW2j6p6HtiYNfxsgg=
github.com/tendermint/tendermint v0.32.3/go.mod h1:ZK2c29jl1QRYznIRyRWRDsmm1yvtPzBRT00x4t1JToY=
github.com/tendermint/tm-db v0.1.1 h1:G3Xezy3sOk9+ekhjZ/kjArYIs1SmwV+1OUgNkj7RgV0=
github.com/tendermint/tm-db v0.1.1/go.mod h1:0cPKWu2Mou3IlxecH+MEUSYc1Ch537alLe6CpFrKzgw=
github.com/tidwall/gjson v1.3.0 h1:kfpsw1W3trbg4Xm6doUtqSl9+LhLB6qJ9PkltVAQZYs=
@@ -1,7 +1,7 @@
{
"name": "@kosu/go-kosu",
"private": true,
"version": "0.1.0-beta.3",
"version": "0.1.1-beta.3",
"description": "Development and CI docker images and supporting scripts for Kosu.",
"repository": "https://github.com/ParadigmFoundation/kosu-monorepo/blob/master/packages/go-kosu",
"license": "MIT",
@@ -3,7 +3,6 @@ package witness
import (
"context"
"encoding/hex"
"fmt"
"os"
"sync"

@@ -112,15 +111,11 @@ func (w *Witness) subscribe(ctx context.Context) error {

go func() {
for e := range sub {
fmt.Printf("e.Events = %+v\n", e.Events)
/*
info, err := abci.NewRoundInfoFromTags(e.Events["tags"])
if err != nil {
w.log.Error("subscribe: invalid tags", "err", err)
continue
}
*/
info := &types.RoundInfo{}
info, err := abci.NewRoundInfoFromEvents(e.Events)
if err != nil {
w.log.Error("subscribe: invalid tags", "err", err)
continue
}

// TODO: validate that n == this.round + 1
w.roundMutex.Lock()
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.