2
0
mirror of https://github.com/edouardparis/lntop synced 2024-11-19 21:25:34 +00:00
lntop/network/backend/mock/mock.go

134 lines
3.4 KiB
Go
Raw Normal View History

2019-03-15 16:02:16 +00:00
package mock
import (
"context"
"crypto/sha256"
"fmt"
"sync"
"time"
"github.com/gofrs/uuid"
"github.com/pkg/errors"
"github.com/edouardparis/lntop/config"
"github.com/edouardparis/lntop/network/models"
"github.com/edouardparis/lntop/network/options"
)
type Backend struct {
invoices map[string]models.Invoice
count uint64
cfg *config.Network
sync.RWMutex
}
2019-04-05 15:00:25 +00:00
func (b *Backend) Ping() error {
return nil
}
2019-03-22 16:20:41 +00:00
func (b *Backend) Info(ctx context.Context) (*models.Info, error) {
return nil, nil
}
2019-03-15 16:02:16 +00:00
func (l *Backend) SendPayment(ctx context.Context, payreq *models.PayReq) (*models.Payment, error) {
return nil, nil
}
func (b *Backend) NodeName() string {
2019-03-25 08:31:04 +00:00
return b.cfg.Name
2019-03-15 16:02:16 +00:00
}
func (b *Backend) SubscribeInvoice(ctx context.Context, ChannelInvoice chan *models.Invoice) error {
return nil
}
2019-03-27 12:32:23 +00:00
func (b *Backend) SubscribeChannels(context.Context, chan *models.ChannelUpdate) error {
return nil
}
func (b *Backend) SubscribeTransactions(ctx context.Context, channel chan *models.Transaction) error {
return nil
}
2021-05-09 21:37:01 +00:00
func (b *Backend) SubscribeRoutingEvents(ctx context.Context, channel chan *models.RoutingEvent) error {
return nil
}
2022-09-02 20:14:05 +00:00
func (b *Backend) SubscribeGraphEvents(ctx context.Context, channel chan *models.ChannelEdgeUpdate) error {
return nil
}
func (b *Backend) GetNode(ctx context.Context, pubkey string, includeChannels bool) (*models.Node, error) {
2019-04-04 11:06:38 +00:00
return &models.Node{}, nil
}
2019-03-15 16:02:16 +00:00
func (b *Backend) GetWalletBalance(ctx context.Context) (*models.WalletBalance, error) {
return &models.WalletBalance{}, nil
}
func (b *Backend) GetTransactions(ctx context.Context) ([]*models.Transaction, error) {
return []*models.Transaction{}, nil
}
2019-03-29 11:38:09 +00:00
func (b *Backend) GetChannelsBalance(ctx context.Context) (*models.ChannelsBalance, error) {
return &models.ChannelsBalance{}, nil
2019-03-15 16:02:16 +00:00
}
func (b *Backend) ListChannels(ctx context.Context, opt ...options.Channel) ([]*models.Channel, error) {
return []*models.Channel{}, nil
}
2019-04-04 08:09:58 +00:00
func (b *Backend) GetChannelInfo(ctx context.Context, channel *models.Channel) error {
return nil
}
2019-03-15 16:02:16 +00:00
func (b *Backend) DecodePayReq(ctx context.Context, payreq string) (*models.PayReq, error) {
return &models.PayReq{}, nil
}
2022-11-08 23:52:31 +00:00
func (b *Backend) GetForwardingHistory(ctx context.Context, startTime string, maxNumEvents uint32) ([]*models.ForwardingEvent, error) {
return []*models.ForwardingEvent{}, nil
}
2019-03-15 16:02:16 +00:00
func (b *Backend) CreateInvoice(ctx context.Context, amt int64, desc string) (*models.Invoice, error) {
b.Lock()
defer b.Unlock()
b.count++
key := uuid.Must(uuid.NewV4()).String()
preimage := []byte(fmt.Sprintf("preimage %s", key))
hash := sha256.Sum256([]byte(preimage))
invoice := &models.Invoice{
Index: b.count,
RPreImage: preimage,
RHash: hash[:],
Amount: amt,
Description: desc,
CreationDate: time.Now().Unix(),
Expiry: 3600,
PaymentRequest: "lnbc28600u1pw9n7g7pp5enjn8exsyymyl6mlxmcvy7fdcwuh04z96swfmtasznppglgdyvsqdqqcqzysc8rve6vdwuvketcn7yp8gu3ltvq29vj588erp3at9z2msqj0yhhjdwsf7qtfy5lwf8favm6u3wr5qklvprlhrz89pknpdfxnc55wy6sqnrxjh7",
}
b.invoices[string(invoice.RHash)] = *invoice
return invoice, nil
}
func (b *Backend) GetInvoice(ctx context.Context, hash string) (*models.Invoice, error) {
invoice, ok := b.invoices[hash]
if !ok {
return nil, errors.New("unable to locate invoice")
}
return &invoice, nil
}
func New(c *config.Network) *Backend {
return &Backend{
invoices: make(map[string]models.Invoice),
cfg: c,
}
}