go-waku/library/mobile/api_relay.go

61 lines
1.7 KiB
Go
Raw Normal View History

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
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
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.
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
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
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)
}