You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
590 B

  1. package factory
  2. import (
  3. "encoding/hex"
  4. "strings"
  5. "github.com/tendermint/tendermint/libs/rand"
  6. "github.com/tendermint/tendermint/types"
  7. )
  8. // NodeID returns a valid NodeID based on an inputted string
  9. func NodeID(str string) types.NodeID {
  10. id, err := types.NewNodeID(strings.Repeat(str, 2*types.NodeIDByteLength))
  11. if err != nil {
  12. panic(err)
  13. }
  14. return id
  15. }
  16. // RandomNodeID returns a randomly generated valid NodeID
  17. func RandomNodeID() types.NodeID {
  18. id, err := types.NewNodeID(hex.EncodeToString(rand.Bytes(types.NodeIDByteLength)))
  19. if err != nil {
  20. panic(err)
  21. }
  22. return id
  23. }