mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-19 06:44:23 +01:00
add tag to open channel email
This commit is contained in:
@@ -124,7 +124,9 @@ func sendChannelMismatchNotification(nodeID string, notFakeChannels, closedChann
|
|||||||
func sendOpenChannelEmailNotification(
|
func sendOpenChannelEmailNotification(
|
||||||
paymentHash []byte, incomingAmountMsat int64,
|
paymentHash []byte, incomingAmountMsat int64,
|
||||||
destination []byte, capacity int64,
|
destination []byte, capacity int64,
|
||||||
channelPoint string) error {
|
channelPoint string,
|
||||||
|
tag *string,
|
||||||
|
) error {
|
||||||
var html bytes.Buffer
|
var html bytes.Buffer
|
||||||
|
|
||||||
tpl := `
|
tpl := `
|
||||||
@@ -134,6 +136,7 @@ func sendOpenChannelEmailNotification(
|
|||||||
<tr><td>Destination Node:</td><td>{{ .Destination }}</td></tr>
|
<tr><td>Destination Node:</td><td>{{ .Destination }}</td></tr>
|
||||||
<tr><td>Channel capacity (sat):</td><td>{{ .Capacity }}</td></tr>
|
<tr><td>Channel capacity (sat):</td><td>{{ .Capacity }}</td></tr>
|
||||||
<tr><td>Channel point:</td><td>{{ .ChannelPoint }}</td></tr>
|
<tr><td>Channel point:</td><td>{{ .ChannelPoint }}</td></tr>
|
||||||
|
<tr><td>Tag:</td><td>{{ .Tag }}</td></tr>
|
||||||
</table>
|
</table>
|
||||||
`
|
`
|
||||||
t, err := template.New("OpenChannelEmail").Parse(tpl)
|
t, err := template.New("OpenChannelEmail").Parse(tpl)
|
||||||
@@ -141,12 +144,17 @@ func sendOpenChannelEmailNotification(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tagStr := ""
|
||||||
|
if tag != nil {
|
||||||
|
tagStr = *tag
|
||||||
|
}
|
||||||
if err := t.Execute(&html, map[string]string{
|
if err := t.Execute(&html, map[string]string{
|
||||||
"PaymentHash": hex.EncodeToString(paymentHash),
|
"PaymentHash": hex.EncodeToString(paymentHash),
|
||||||
"IncomingAmountMsat": strconv.FormatUint(uint64(incomingAmountMsat), 10),
|
"IncomingAmountMsat": strconv.FormatUint(uint64(incomingAmountMsat), 10),
|
||||||
"Destination": hex.EncodeToString(destination),
|
"Destination": hex.EncodeToString(destination),
|
||||||
"Capacity": strconv.FormatUint(uint64(capacity), 10),
|
"Capacity": strconv.FormatUint(uint64(capacity), 10),
|
||||||
"ChannelPoint": channelPoint,
|
"ChannelPoint": channelPoint,
|
||||||
|
"Tag": tagStr,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ func NewInterceptor(
|
|||||||
func (i *Interceptor) Intercept(nextHop string, reqPaymentHash []byte, reqOutgoingAmountMsat uint64, reqOutgoingExpiry uint32, reqIncomingExpiry uint32) InterceptResult {
|
func (i *Interceptor) Intercept(nextHop string, reqPaymentHash []byte, reqOutgoingAmountMsat uint64, reqOutgoingExpiry uint32, reqIncomingExpiry uint32) InterceptResult {
|
||||||
reqPaymentHashStr := hex.EncodeToString(reqPaymentHash)
|
reqPaymentHashStr := hex.EncodeToString(reqPaymentHash)
|
||||||
resp, _, _ := i.payHashGroup.Do(reqPaymentHashStr, func() (interface{}, error) {
|
resp, _, _ := i.payHashGroup.Do(reqPaymentHashStr, func() (interface{}, error) {
|
||||||
params, paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat, channelPoint, err := i.store.PaymentInfo(reqPaymentHash)
|
params, paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat, channelPoint, tag, err := i.store.PaymentInfo(reqPaymentHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("paymentInfo(%x) error: %v", reqPaymentHash, err)
|
log.Printf("paymentInfo(%x) error: %v", reqPaymentHash, err)
|
||||||
return InterceptResult{
|
return InterceptResult{
|
||||||
@@ -134,7 +134,7 @@ func (i *Interceptor) Intercept(nextHop string, reqPaymentHash []byte, reqOutgoi
|
|||||||
log.Printf("Intercepted expired payment registration. Opening channel anyway, because it's cheaper at the current rate. %+v", params)
|
log.Printf("Intercepted expired payment registration. Opening channel anyway, because it's cheaper at the current rate. %+v", params)
|
||||||
}
|
}
|
||||||
|
|
||||||
channelPoint, err = i.openChannel(reqPaymentHash, destination, incomingAmountMsat)
|
channelPoint, err = i.openChannel(reqPaymentHash, destination, incomingAmountMsat, tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("openChannel(%x, %v) err: %v", destination, incomingAmountMsat, err)
|
log.Printf("openChannel(%x, %v) err: %v", destination, incomingAmountMsat, err)
|
||||||
return InterceptResult{
|
return InterceptResult{
|
||||||
@@ -297,7 +297,7 @@ func (i *Interceptor) isCurrentChainFeeCheaper(params *OpeningFeeParams) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Interceptor) openChannel(paymentHash, destination []byte, incomingAmountMsat int64) (*wire.OutPoint, error) {
|
func (i *Interceptor) openChannel(paymentHash, destination []byte, incomingAmountMsat int64, tag *string) (*wire.OutPoint, error) {
|
||||||
capacity := incomingAmountMsat/1000 + i.config.AdditionalChannelCapacity
|
capacity := incomingAmountMsat/1000 + i.config.AdditionalChannelCapacity
|
||||||
if capacity == i.config.PublicChannelAmount {
|
if capacity == i.config.PublicChannelAmount {
|
||||||
capacity++
|
capacity++
|
||||||
@@ -348,6 +348,7 @@ func (i *Interceptor) openChannel(paymentHash, destination []byte, incomingAmoun
|
|||||||
destination,
|
destination,
|
||||||
capacity,
|
capacity,
|
||||||
channelPoint.String(),
|
channelPoint.String(),
|
||||||
|
tag,
|
||||||
)
|
)
|
||||||
err = i.store.SetFundingTx(paymentHash, channelPoint)
|
err = i.store.SetFundingTx(paymentHash, channelPoint)
|
||||||
return channelPoint, err
|
return channelPoint, err
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ type OpeningFeeParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type InterceptStore interface {
|
type InterceptStore interface {
|
||||||
PaymentInfo(htlcPaymentHash []byte) (*OpeningFeeParams, []byte, []byte, []byte, int64, int64, *wire.OutPoint, error)
|
PaymentInfo(htlcPaymentHash []byte) (*OpeningFeeParams, []byte, []byte, []byte, int64, int64, *wire.OutPoint, *string, error)
|
||||||
SetFundingTx(paymentHash []byte, channelPoint *wire.OutPoint) error
|
SetFundingTx(paymentHash []byte, channelPoint *wire.OutPoint) error
|
||||||
RegisterPayment(params *OpeningFeeParams, destination, paymentHash, paymentSecret []byte, incomingAmountMsat, outgoingAmountMsat int64, tag string) error
|
RegisterPayment(params *OpeningFeeParams, destination, paymentHash, paymentSecret []byte, incomingAmountMsat, outgoingAmountMsat int64, tag string) error
|
||||||
InsertChannel(initialChanID, confirmedChanId uint64, channelPoint string, nodeID []byte, lastUpdate time.Time) error
|
InsertChannel(initialChanID, confirmedChanId uint64, channelPoint string, nodeID []byte, lastUpdate time.Time) error
|
||||||
|
|||||||
@@ -23,24 +23,24 @@ func NewPostgresInterceptStore(pool *pgxpool.Pool) *PostgresInterceptStore {
|
|||||||
return &PostgresInterceptStore{pool: pool}
|
return &PostgresInterceptStore{pool: pool}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PostgresInterceptStore) PaymentInfo(htlcPaymentHash []byte) (*interceptor.OpeningFeeParams, []byte, []byte, []byte, int64, int64, *wire.OutPoint, error) {
|
func (s *PostgresInterceptStore) PaymentInfo(htlcPaymentHash []byte) (*interceptor.OpeningFeeParams, []byte, []byte, []byte, int64, int64, *wire.OutPoint, *string, error) {
|
||||||
var (
|
var (
|
||||||
p *string
|
p, tag *string
|
||||||
paymentHash, paymentSecret, destination []byte
|
paymentHash, paymentSecret, destination []byte
|
||||||
incomingAmountMsat, outgoingAmountMsat int64
|
incomingAmountMsat, outgoingAmountMsat int64
|
||||||
fundingTxID []byte
|
fundingTxID []byte
|
||||||
fundingTxOutnum pgtype.Int4
|
fundingTxOutnum pgtype.Int4
|
||||||
)
|
)
|
||||||
err := s.pool.QueryRow(context.Background(),
|
err := s.pool.QueryRow(context.Background(),
|
||||||
`SELECT payment_hash, payment_secret, destination, incoming_amount_msat, outgoing_amount_msat, funding_tx_id, funding_tx_outnum, opening_fee_params
|
`SELECT payment_hash, payment_secret, destination, incoming_amount_msat, outgoing_amount_msat, funding_tx_id, funding_tx_outnum, opening_fee_params, tag
|
||||||
FROM payments
|
FROM payments
|
||||||
WHERE payment_hash=$1 OR sha256('probing-01:' || payment_hash)=$1`,
|
WHERE payment_hash=$1 OR sha256('probing-01:' || payment_hash)=$1`,
|
||||||
htlcPaymentHash).Scan(&paymentHash, &paymentSecret, &destination, &incomingAmountMsat, &outgoingAmountMsat, &fundingTxID, &fundingTxOutnum, &p)
|
htlcPaymentHash).Scan(&paymentHash, &paymentSecret, &destination, &incomingAmountMsat, &outgoingAmountMsat, &fundingTxID, &fundingTxOutnum, &p, &tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == pgx.ErrNoRows {
|
if err == pgx.ErrNoRows {
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
return nil, nil, nil, nil, 0, 0, nil, err
|
return nil, nil, nil, nil, 0, 0, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var cp *wire.OutPoint
|
var cp *wire.OutPoint
|
||||||
@@ -56,10 +56,10 @@ func (s *PostgresInterceptStore) PaymentInfo(htlcPaymentHash []byte) (*intercept
|
|||||||
err = json.Unmarshal([]byte(*p), ¶ms)
|
err = json.Unmarshal([]byte(*p), ¶ms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to unmarshal OpeningFeeParams '%s': %v", *p, err)
|
log.Printf("Failed to unmarshal OpeningFeeParams '%s': %v", *p, err)
|
||||||
return nil, nil, nil, nil, 0, 0, nil, err
|
return nil, nil, nil, nil, 0, 0, nil, nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return params, paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat, cp, nil
|
return params, paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat, cp, tag, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PostgresInterceptStore) SetFundingTx(paymentHash []byte, channelPoint *wire.OutPoint) error {
|
func (s *PostgresInterceptStore) SetFundingTx(paymentHash []byte, channelPoint *wire.OutPoint) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user