Skip to content

Commit 9d0eb00

Browse files
authored
Merge pull request #141 from libsv/fix/more-host-pc
Fix: Query subscription peer channel on notification, not own.
2 parents 5e255a7 + ce5c062 commit 9d0eb00

6 files changed

+17
-4
lines changed

peerchannels.go

+2
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,7 @@ type PeerChannelAPITokenStoreArgs struct {
7777
// PeerChannelMessageArgs for quering a peer channel message.
7878
type PeerChannelMessageArgs struct {
7979
ChannelID string
80+
Host string
81+
Path string
8082
Token string
8183
}

peerchannels_notify.go

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ type PeerChannelsMessageHandler interface {
2828

2929
// PeerChannelSubscription for subscribing to channel notifications.
3030
type PeerChannelSubscription struct {
31+
Host string
32+
Path string
3133
ChannelID string
3234
Token string
3335
ChannelType PeerChannelHandlerType

service/pay.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (p *pay) Pay(ctx context.Context, req payd.PayRequest) (*dpp.PaymentACK, er
151151
Path: ack.PeerChannel.Path,
152152
Type: payd.PeerChannelHandlerTypeProof,
153153
}); err != nil {
154-
log.Err(err)
154+
log.Error().Err(err)
155155
}
156156
if err := p.storeTx.Commit(ctx); err != nil {
157157
return nil, errors.Wrap(err, "failed to commit tx")

service/peerchannels.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ func (p *peerChannelsSvc) PeerChannelsMessage(ctx context.Context, args *payd.Pe
9696
spvchannels.WithToken(args.Token),
9797
spvchannels.WithChannelID(args.ChannelID),
9898
spvchannels.WithVersion("v1"),
99-
spvchannels.WithBaseURL(p.cfg.Host),
100-
spvchannels.WithPath(p.cfg.Path),
99+
spvchannels.WithBaseURL(args.Host),
100+
spvchannels.WithPath(args.Path),
101101
spvchannels.WithNoTLS(),
102102
)
103103
msgs, err := c.Messages(ctx, spvchannels.MessagesRequest{

service/peerchannels_notify.go

+9
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ func (p *peerChannelsNotifySvc) Subscribe(ctx context.Context, channel *payd.Pee
4747
channel.CreatedAt = time.Now()
4848
}
4949

50+
log.Debug().Msgf("subscribing to channel %s with token %s at %s%s", channel.ID, channel.Token, channel.Host, channel.Path)
51+
5052
u := url.URL{
5153
Scheme: "ws",
5254
Host: channel.Host,
@@ -76,6 +78,8 @@ func (p *peerChannelsNotifySvc) Subscribe(ctx context.Context, channel *payd.Pee
7678
}()
7779

7880
sub := payd.PeerChannelSubscription{
81+
Host: channel.Host,
82+
Path: channel.Path,
7983
ChannelID: channel.ID,
8084
ChannelType: channel.Type,
8185
Token: channel.Token,
@@ -107,6 +111,7 @@ func (p *peerChannelsNotifySvc) listen(ctx context.Context, sub *payd.PeerChanne
107111
log.Error().Err(errors.WithStack(err))
108112
}
109113

114+
log.Debug().Msgf("message received on channel %s", sub.ChannelID)
110115
in <- true
111116
}()
112117

@@ -124,13 +129,17 @@ func (p *peerChannelsNotifySvc) listen(ctx context.Context, sub *payd.PeerChanne
124129
func (p *peerChannelsNotifySvc) handleNotification(ctx context.Context, sub *payd.PeerChannelSubscription, cancel context.CancelFunc) error {
125130
msgs, err := p.pcSvc.PeerChannelsMessage(ctx, &payd.PeerChannelMessageArgs{
126131
ChannelID: sub.ChannelID,
132+
Host: sub.Host,
133+
Path: sub.Path,
127134
Token: sub.Token,
128135
})
129136
if err != nil {
130137
log.Error().Err(errors.WithStack(err))
131138
return err
132139
}
133140

141+
log.Debug().Msgf("channel %s fetched messages: %#v", sub.ChannelID, msgs)
142+
134143
hdlr := p.handlers[sub.ChannelType]
135144
finished, err := hdlr.HandlePeerChannelsMessage(ctx, msgs)
136145
if err != nil {

service/proofs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (p *proofs) HandlePeerChannelsMessage(ctx context.Context, msgs spvchannels
6767
}
6868

6969
if mm["callbackReason"].(string) != "merkleProof" {
70-
log.Info().Msg("skipping msg")
70+
log.Debug().Msgf("skipping msg %#v", msg)
7171
continue
7272
}
7373

0 commit comments

Comments
 (0)