Files
mpc/pkg/messaging/pubsub.go
T
zeekay 821bd09da5 chore: remove bridge stub, fix all TODOs with real implementations
- Remove lux-mpc-bridge command (bridge is in T-Chain, not MPC)
- Remove empty pkg/bridge directory
- Fix sign.go: remove stale TODO (ECDSA/EdDSA already supported)
- Fix pubsub.go: remove obsolete subscription TODO
- Fix benchmark_test.go: implement real protocol benchmarks
- Fix xrpl_test.go: implement full XRPL E2E tests
- Update goreleaser: remove bridge build target
- Update docker-compose: remove bridge-compat services

MPC is now a clean standalone threshold signature tool.
2025-12-25 10:44:16 -08:00

66 lines
1.5 KiB
Go

package messaging
import (
"github.com/nats-io/nats.go"
"github.com/luxfi/mpc/pkg/logger"
)
type Subscription interface {
Unsubscribe() error
}
type PubSub interface {
Publish(topic string, message []byte) error
PublishWithReply(topic, reply string, data []byte, headers map[string]string) error
Subscribe(topic string, handler func(msg *nats.Msg)) (Subscription, error)
}
type natsPubSub struct {
natsConn *nats.Conn
}
type natsSubscription struct {
subscription *nats.Subscription
}
func (ns *natsSubscription) Unsubscribe() error {
return ns.subscription.Unsubscribe()
}
func NewNATSPubSub(natsConn *nats.Conn) PubSub {
return &natsPubSub{natsConn}
}
func (n *natsPubSub) Publish(topic string, message []byte) error {
logger.Debug("[NATS] Publishing message", "topic", topic)
return n.natsConn.Publish(topic, message)
}
func (n *natsPubSub) PublishWithReply(topic, reply string, data []byte, headers map[string]string) error {
msg := &nats.Msg{
Subject: topic,
Reply: reply,
Data: data,
Header: nats.Header{},
}
for k, v := range headers {
msg.Header.Set(k, v)
}
err := n.natsConn.PublishMsg(msg)
return err
}
func (n *natsPubSub) Subscribe(topic string, handler func(msg *nats.Msg)) (Subscription, error) {
// Subscribe and forward the full nats.Msg to the handler
// Handler receives complete message including Subject, Reply, Data, Header fields
sub, err := n.natsConn.Subscribe(topic, func(msg *nats.Msg) {
handler(msg)
})
if err != nil {
return nil, err
}
return &natsSubscription{subscription: sub}, nil
}