Example tag implementation for CoinKeeper
This commit is contained in:
+1
-2
@@ -2,7 +2,6 @@ package types
|
||||
|
||||
import (
|
||||
abci "github.com/tendermint/abci/types"
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
)
|
||||
|
||||
// Result is the union of ResponseDeliverTx and ResponseCheckTx.
|
||||
@@ -31,7 +30,7 @@ type Result struct {
|
||||
ValidatorUpdates []abci.Validator
|
||||
|
||||
// Tags are used for transaction indexing and pubsub.
|
||||
Tags []cmn.KVPair
|
||||
Tags Tags
|
||||
}
|
||||
|
||||
// TODO: In the future, more codes may be OK.
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
)
|
||||
|
||||
type Tag = cmn.KVPair
|
||||
|
||||
type Tags = cmn.KVPairs
|
||||
|
||||
// Append two lists of tags
|
||||
func AppendTags(a, b Tags) Tags {
|
||||
return append(a, b...)
|
||||
}
|
||||
|
||||
// New empty tags
|
||||
func EmptyTags() Tags {
|
||||
return make(Tags, 0)
|
||||
}
|
||||
|
||||
// Single tag to tags
|
||||
func SingleTag(t Tag) Tags {
|
||||
return append(EmptyTags(), t)
|
||||
}
|
||||
|
||||
// Make a tag from a key and a value
|
||||
func MakeTag(k string, v []byte) Tag {
|
||||
return Tag{Key: []byte(k), Value: v}
|
||||
}
|
||||
|
||||
// TODO: Deduplication?
|
||||
@@ -0,0 +1,30 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAppendTags(t *testing.T) {
|
||||
a := SingleTag(MakeTag("a", []byte("1")))
|
||||
b := SingleTag(MakeTag("b", []byte("2")))
|
||||
c := AppendTags(a, b)
|
||||
require.Equal(t, c, Tags{MakeTag("a", []byte("1")), MakeTag("b", []byte("2"))})
|
||||
}
|
||||
|
||||
func TestEmptyTags(t *testing.T) {
|
||||
a := EmptyTags()
|
||||
require.Equal(t, a, Tags{})
|
||||
}
|
||||
|
||||
func TestSingleTag(t *testing.T) {
|
||||
a := MakeTag("a", []byte("1"))
|
||||
b := SingleTag(a)
|
||||
require.Equal(t, b, Tags{MakeTag("a", []byte("1"))})
|
||||
}
|
||||
|
||||
func TestMakeTag(t *testing.T) {
|
||||
a := MakeTag("a", []byte("1"))
|
||||
require.Equal(t, a, Tag{[]byte("a"), []byte("1")})
|
||||
}
|
||||
Reference in New Issue
Block a user