2023-08-10 13:30:38 +00:00
|
|
|
package gowaku
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/waku-org/go-waku/library"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RelayEnoughPeers determines if there are enough peers to publish a message on a topic
|
2023-12-15 14:46:21 +00:00
|
|
|
func RelayEnoughPeers(instanceID uint, topic string) string {
|
|
|
|
instance, err := library.GetInstance(instanceID)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
response, err := library.RelayEnoughPeers(instance, topic)
|
2023-08-10 13:30:38 +00:00
|
|
|
return prepareJSONResponse(response, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RelayPublish publishes a message using waku relay and returns the message ID
|
2023-12-15 14:46:21 +00:00
|
|
|
func RelayPublish(instanceID uint, messageJSON string, topic string, ms int) string {
|
|
|
|
instance, err := library.GetInstance(instanceID)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
hash, err := library.RelayPublish(instance, messageJSON, topic, ms)
|
2023-08-10 13:30:38 +00:00
|
|
|
return prepareJSONResponse(hash, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RelaySubscribe subscribes to a WakuRelay topic.
|
2023-12-15 14:46:21 +00:00
|
|
|
func RelaySubscribe(instanceID uint, topic string) string {
|
|
|
|
instance, err := library.GetInstance(instanceID)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = library.RelaySubscribe(instance, topic)
|
2023-08-10 13:30:38 +00:00
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RelayTopics returns a list of pubsub topics the node is subscribed to in WakuRelay
|
2023-12-15 14:46:21 +00:00
|
|
|
func RelayTopics(instanceID uint) string {
|
|
|
|
instance, err := library.GetInstance(instanceID)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
topics, err := library.RelayTopics(instance)
|
2023-08-10 13:30:38 +00:00
|
|
|
return prepareJSONResponse(topics, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RelayUnsubscribe closes the pubsub subscription to a pubsub topic
|
2023-12-15 14:46:21 +00:00
|
|
|
func RelayUnsubscribe(instanceID uint, topic string) string {
|
|
|
|
instance, err := library.GetInstance(instanceID)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = library.RelayUnsubscribe(instance, topic)
|
2023-08-10 13:30:38 +00:00
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|