forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 4
/
messages.go
77 lines (67 loc) · 1.89 KB
/
messages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package pubsub
import (
"github.com/MetalBlockchain/metalgo/api"
"github.com/MetalBlockchain/metalgo/utils/formatting/address"
"github.com/MetalBlockchain/metalgo/utils/json"
)
// NewBloom command for a new bloom filter
//
// Deprecated: The pubsub server is deprecated.
type NewBloom struct {
// MaxElements size of bloom filter
MaxElements json.Uint64 `json:"maxElements"`
// CollisionProb expected error rate of filter
CollisionProb json.Float64 `json:"collisionProb"`
}
// NewSet command for a new map set
//
// Deprecated: The pubsub server is deprecated.
type NewSet struct{}
// AddAddresses command to add addresses
//
// Deprecated: The pubsub server is deprecated.
type AddAddresses struct {
api.JSONAddresses
// addressIds array of addresses, kept as a [][]byte for use in the bloom filter
addressIds [][]byte
}
// Command execution command
//
// Deprecated: The pubsub server is deprecated.
type Command struct {
NewBloom *NewBloom `json:"newBloom,omitempty"`
NewSet *NewSet `json:"newSet,omitempty"`
AddAddresses *AddAddresses `json:"addAddresses,omitempty"`
}
func (c *Command) String() string {
switch {
case c.NewBloom != nil:
return "newBloom"
case c.NewSet != nil:
return "newSet"
case c.AddAddresses != nil:
return "addAddresses"
default:
return "unknown"
}
}
func (c *NewBloom) IsParamsValid() bool {
p := float64(c.CollisionProb)
return c.MaxElements > 0 && 0 < p && p <= 1
}
// parseAddresses converts the bech32 addresses to their byte format.
func (c *AddAddresses) parseAddresses() error {
if c.addressIds == nil {
c.addressIds = make([][]byte, len(c.Addresses))
}
for i, addrStr := range c.Addresses {
_, _, addrBytes, err := address.Parse(addrStr)
if err != nil {
return err
}
c.addressIds[i] = addrBytes
}
return nil
}