Skip to content

Commit abd523a

Browse files
Tíghearnán CarrollMark Robson
Tíghearnán Carroll
and
Mark Robson
authored
working with peer channel path (#136)
Co-authored-by: Mark Robson <[email protected]>
1 parent af6f3bc commit abd523a

10 files changed

+21
-5
lines changed

config/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const (
4040
EnvTransportHTTPEnabled = "transport.http.enabled"
4141
EnvTransportSocketsEnabled = "transport.sockets.enabled"
4242
EnvPeerChannelsHost = "peerchannels.host"
43+
EnvPeerChannelsPath = "peerchannels.path"
4344
EnvPeerChannelsTTL = "peerchannels.ttl.minutes"
4445

4546
LogDebug = "debug"
@@ -164,6 +165,8 @@ type Wallet struct {
164165
type PeerChannels struct {
165166
// Host the peer channels host.
166167
Host string
168+
// Path to peer channels.
169+
Path string
167170
// TTL the life of the peer channel.
168171
TTL time.Duration
169172
}

config/defaults.go

+1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ func SetupDefaults() {
5858

5959
// Peer channels
6060
viper.SetDefault(EnvPeerChannelsTTL, 120)
61+
viper.SetDefault(EnvPeerChannelsPath, "")
6162
}

config/viper.go

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func (v *ViperConfig) WithTransports() ConfigurationLoader {
121121
func (v *ViperConfig) WithPeerChannels() ConfigurationLoader {
122122
v.PeerChannels = &PeerChannels{
123123
Host: viper.GetString(EnvPeerChannelsHost),
124+
Path: viper.GetString(EnvPeerChannelsPath),
124125
TTL: time.Duration(viper.GetInt64(EnvPeerChannelsTTL)) * time.Minute,
125126
}
126127
return v

data/sqlite/migrations/1_initial.up.sql

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ CREATE TABLE peerchannels(
4545
,peerchannels_account_id INTEGER NOT NULL
4646
,channel_id VARCHAR NOT NULL
4747
,channel_host VARCHAR NOT NULL
48+
,channel_path VARCHAR NOT NULL
4849
,channel_type VARCHAR NOT NULL
4950
,created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
5051
,closed BOOLEAN NOT NULL DEFAULT 0

data/sqlite/peerchannels.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const sqlPeerChannelAccountSelect = `
1414
`
1515

1616
const sqlPeerChannelInsert = `
17-
INSERT INTO peerchannels (peerchannels_account_id, channel_id, channel_host, channel_type, created_at)
18-
VALUES (:peerchannels_account_id, :channel_id, :channel_host, :channel_type, :created_at)
17+
INSERT INTO peerchannels (peerchannels_account_id, channel_id, channel_host, channel_path, channel_type, created_at)
18+
VALUES (:peerchannels_account_id, :channel_id, :channel_host, :channel_path, :channel_type, :created_at)
1919
`
2020

2121
const sqlPeerChannelsAPITokInsert = `
@@ -30,7 +30,7 @@ const sqlPeerChannelsCloseUpdate = `
3030
`
3131

3232
const sqlPeerChannelsOpenSelect = `
33-
SELECT pc.channel_host, pc.channel_id, pc.channel_type, pc.created_at, pt.tok
33+
SELECT pc.channel_host, pc.channel_path, pc.channel_id, pc.channel_type, pc.created_at, pt.tok
3434
FROM peerchannels pc
3535
JOIN peerchannels_toks pt ON pc.channel_id = pt.peerchannels_channel_id
3636
WHERE pc.closed = 0 AND pc.channel_type = :channel_type

peerchannels.go

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type PeerChannel struct {
3131
ID string `db:"channel_id"`
3232
Token string `db:"tok"`
3333
Host string `db:"channel_host"`
34+
Path string `db:"channel_path"`
3435
CreatedAt time.Time `db:"created_at"`
3536
Type PeerChannelHandlerType `db:"channel_type"`
3637
}
@@ -52,6 +53,7 @@ type PeerChannelCreateArgs struct {
5253
PeerChannelAccountID int64 `db:"peerchannels_account_id"`
5354
ChannelType PeerChannelHandlerType `db:"channel_type"`
5455
ChannelHost string `db:"channel_host"`
56+
ChannelPath string `db:"channel_path"`
5557
ChannelID string `db:"channel_id"`
5658
CreatedAt time.Time `db:"created_at"`
5759
}

service/pay.go

+2
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ func (p *pay) Pay(ctx context.Context, req payd.PayRequest) (*dpp.PaymentACK, er
129129
PeerChannelAccountID: 0,
130130
ChannelID: ack.PeerChannel.ChannelID,
131131
ChannelHost: ack.PeerChannel.Host,
132+
ChannelPath: ack.PeerChannel.Path,
132133
ChannelType: payd.PeerChannelHandlerTypeProof,
133134
}); err != nil {
134135
return nil, errors.Wrapf(err, "failed to store channel %s/%s in db", ack.PeerChannel.Host, ack.PeerChannel.ChannelID)
@@ -147,6 +148,7 @@ func (p *pay) Pay(ctx context.Context, req payd.PayRequest) (*dpp.PaymentACK, er
147148
ID: ack.PeerChannel.ChannelID,
148149
Token: ack.PeerChannel.Token,
149150
Host: ack.PeerChannel.Host,
151+
Path: ack.PeerChannel.Path,
150152
Type: payd.PeerChannelHandlerTypeProof,
151153
}); err != nil {
152154
log.Err(err)

service/payments.go

+2
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ func (p *payments) PaymentCreate(ctx context.Context, args payd.PaymentCreateArg
241241
if err := p.pcNotif.Subscribe(ctx, &payd.PeerChannel{
242242
ID: ch.ID,
243243
Token: tokens[1].Token,
244+
Host: p.pCfg.Host,
244245
CreatedAt: ch.CreatedAt,
245246
Type: payd.PeerChannelHandlerTypeProof,
246247
}); err != nil {
@@ -301,6 +302,7 @@ func (p *payments) Ack(ctx context.Context, args payd.AckArgs, req payd.Ack) err
301302
if err := p.pcStr.PeerChannelCreate(ctx, &payd.PeerChannelCreateArgs{
302303
PeerChannelAccountID: 0,
303304
ChannelHost: args.PeerChannel.Host,
305+
ChannelPath: args.PeerChannel.Path,
304306
ChannelID: args.PeerChannel.ID,
305307
ChannelType: args.PeerChannel.Type,
306308
}); err != nil {

service/peerchannels.go

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func (p *peerChannelsSvc) PeerChannelCreate(ctx context.Context, req spvchannels
2929
spvchannels.WithPassword("password"),
3030
spvchannels.WithVersion("v1"),
3131
spvchannels.WithBaseURL(p.cfg.Host),
32+
spvchannels.WithPath(p.cfg.Path),
3233
spvchannels.WithNoTLS(),
3334
)
3435
ch, err := c.ChannelCreate(ctx, req)
@@ -40,6 +41,7 @@ func (p *peerChannelsSvc) PeerChannelCreate(ctx context.Context, req spvchannels
4041
if err := p.str.PeerChannelCreate(ctx, &payd.PeerChannelCreateArgs{
4142
PeerChannelAccountID: req.AccountID,
4243
ChannelHost: p.cfg.Host,
44+
ChannelPath: p.cfg.Path,
4345
ChannelID: ch.ID,
4446
ChannelType: payd.PeerChannelHandlerTypeProof,
4547
CreatedAt: createdAt,
@@ -61,6 +63,7 @@ func (p peerChannelsSvc) PeerChannelAPITokensCreate(ctx context.Context, reqs ..
6163
spvchannels.WithPassword("password"),
6264
spvchannels.WithVersion("v1"),
6365
spvchannels.WithBaseURL(p.cfg.Host),
66+
spvchannels.WithPath(p.cfg.Path),
6467
spvchannels.WithNoTLS(),
6568
)
6669

@@ -94,6 +97,7 @@ func (p *peerChannelsSvc) PeerChannelsMessage(ctx context.Context, args *payd.Pe
9497
spvchannels.WithChannelID(args.ChannelID),
9598
spvchannels.WithVersion("v1"),
9699
spvchannels.WithBaseURL(p.cfg.Host),
100+
spvchannels.WithPath(p.cfg.Path),
97101
spvchannels.WithNoTLS(),
98102
)
99103
msgs, err := c.Messages(ctx, spvchannels.MessagesRequest{

service/peerchannels_notify.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ func (p *peerChannelsNotifySvc) Subscribe(ctx context.Context, channel *payd.Pee
4949

5050
u := url.URL{
5151
Scheme: "ws",
52-
Host: p.cfg.Host,
53-
Path: path.Join("/api/v1/channel", channel.ID, "/notify"),
52+
Host: channel.Host,
53+
Path: path.Join(channel.Path, "/api/v1/channel", channel.ID, "/notify"),
5454
}
5555
q := u.Query()
5656
q.Set("token", channel.Token)

0 commit comments

Comments
 (0)