-
Notifications
You must be signed in to change notification settings - Fork 1
/
channel.go
57 lines (46 loc) · 1.3 KB
/
channel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package rpc
import (
"context"
"github.com/c13n-io/c13n-go/app"
"github.com/c13n-io/c13n-go/model"
pb "github.com/c13n-io/c13n-go/rpc/services"
"github.com/c13n-io/c13n-go/slog"
)
type channelServiceServer struct {
Log *slog.Logger
App *app.App
pb.UnimplementedChannelServiceServer
}
func (s *channelServiceServer) logError(err error) error {
if err != nil {
s.Log.Errorf("%+v", err)
}
return err
}
// Interface implementation
// OpenChannel opens a channel with a node
// and returns the published funding transaction.
func (s *channelServiceServer) OpenChannel(ctx context.Context,
req *pb.OpenChannelRequest) (*pb.OpenChannelResponse, error) {
channel, err := s.App.OpenChannel(ctx, req.GetAddress(),
req.GetAmtMsat(), req.GetPushAmtMsat(), req.GetMinInputConfs(),
model.TxFeeOptions{
SatPerVByte: req.GetSatPerVbyte(),
TargetConfBlock: req.GetTargetConfirmationBlock(),
},
)
if err != nil {
return nil, associateStatusCode(s.logError(err))
}
return &pb.OpenChannelResponse{
FundingTxid: channel.FundingTxid,
OutputIndex: channel.OutputIndex,
}, nil
}
// NewChannelServiceServer initializes a new channel service.
func NewChannelServiceServer(app *app.App) pb.ChannelServiceServer {
return &channelServiceServer{
Log: slog.NewLogger("channel-service"),
App: app,
}
}