2019-11-06 16:23:11 +00:00
|
|
|
package whisper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"math/big"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2019-11-06 16:23:11 +00:00
|
|
|
)
|
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
func createMessagesRequest(from, to uint32, cursor []byte, topics []types.TopicType) types.MessagesRequest {
|
2019-11-06 16:23:11 +00:00
|
|
|
aUUID := uuid.New()
|
2019-11-23 17:57:05 +00:00
|
|
|
// uuid is 16 bytes, converted to hex it's 32 bytes as expected by types.MessagesRequest
|
2019-11-06 16:23:11 +00:00
|
|
|
id := []byte(hex.EncodeToString(aUUID[:]))
|
2019-11-23 17:57:05 +00:00
|
|
|
return types.MessagesRequest{
|
2019-11-06 16:23:11 +00:00
|
|
|
ID: id,
|
|
|
|
From: from,
|
|
|
|
To: to,
|
2020-01-13 19:17:30 +00:00
|
|
|
Limit: 100,
|
2019-11-06 16:23:11 +00:00
|
|
|
Cursor: cursor,
|
|
|
|
Bloom: topicsToBloom(topics...),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
func topicsToBloom(topics ...types.TopicType) []byte {
|
2019-11-06 16:23:11 +00:00
|
|
|
i := new(big.Int)
|
|
|
|
for _, topic := range topics {
|
2019-11-23 17:57:05 +00:00
|
|
|
bloom := types.TopicToBloom(topic)
|
2019-11-06 16:23:11 +00:00
|
|
|
i.Or(i, new(big.Int).SetBytes(bloom[:]))
|
|
|
|
}
|
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
combined := make([]byte, types.BloomFilterSize)
|
2019-11-06 16:23:11 +00:00
|
|
|
data := i.Bytes()
|
2019-11-23 17:57:05 +00:00
|
|
|
copy(combined[types.BloomFilterSize-len(data):], data[:])
|
2019-11-06 16:23:11 +00:00
|
|
|
|
|
|
|
return combined
|
|
|
|
}
|