Skip to content

Commit

Permalink
#18 WIP on binary graph serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronc committed Mar 28, 2019
1 parent 3a5c43a commit 4b9da06
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions xrb/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/regen-network/regen-ledger/types"
"github.com/regen-network/regen-ledger/x/schema"
"golang.org/x/crypto/blake2b"
"net/url"
"strconv"
)
Expand All @@ -22,6 +23,7 @@ type Graph interface {
Nodes() []types.HasURI
RootNode() Node
GetNode(id types.HasURI) Node
Hash() []byte
fmt.Stringer
}

Expand Down Expand Up @@ -81,6 +83,15 @@ func (g graph) String() string {
return w.String()
}

func (g graph) Hash() []byte {
h, err := blake2b.New256(nil)
if err != nil {
panic(err)
}
h.Write([]byte(g.String()))
return h.Sum(nil)
}

type node struct {
id types.HasURI
// TODO classes []string
Expand Down
6 changes: 5 additions & 1 deletion xrb/xrb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/leanovate/gopter/gen"
"github.com/leanovate/gopter/prop"
"github.com/regen-network/regen-ledger/types"
"github.com/regen-network/regen-ledger/util"
"github.com/regen-network/regen-ledger/x/schema"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -109,7 +110,10 @@ func (s *TestSuite) TestGenGraph() {
gs, ok := gen.SliceOfN(3, s.GenGraph()).Sample()
if ok {
for _, g := range gs.([]*graph) {
s.T().Log(g.String())
s.T().Logf("Graph %s:\n %s",
util.MustEncodeBech32(types.Bech32DataAddressPrefix, g.Hash()),
g.String(),
)
}
}
}
Expand Down

0 comments on commit 4b9da06

Please sign in to comment.