Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion swapwallet/credit_projector.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,23 @@ func creditEntryFromSummary(op credit.CreditOpSummary) (
return nil, false
}

// A SEND is an outflow, so it carries a negative amount to match the
// sign convention of every other outgoing row (normal swap sends are
// normalized to negative by swapEntryFromSummary). Credit-only sends
// reach the feed only through this projector, so without the flip a
// sub-dust pay renders as positive and looks like an incoming transfer
// (issue #829).
amountSat := op.AmountSat
if kind == walletdkrpc.EntryKind_ENTRY_KIND_SEND {
amountSat = -op.AmountSat
}

now := nowUnix()
entry := &walletdkrpc.WalletEntry{
Id: id,
Kind: kind,
Status: walletdkrpc.EntryStatus_ENTRY_STATUS_PENDING,
AmountSat: op.AmountSat,
AmountSat: amountSat,
Counterparty: creditCounterparty,
UpdatedAtUnix: now,
Progress: &walletdkrpc.WalletEntryProgress{
Expand Down
2 changes: 1 addition & 1 deletion swapwallet/credit_projector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestCreditProjectorProjectsOwnedTerminals(t *testing.T) {
t, walletdkrpc.EntryStatus_ENTRY_STATUS_COMPLETE,
pay.GetStatus(),
)
require.Equal(t, int64(500), pay.GetAmountSat())
require.Equal(t, int64(-500), pay.GetAmountSat())
require.Equal(
t, walletdkrpc.WalletEntryPhase_WALLET_ENTRY_PHASE_CONFIRMED,
pay.GetProgress().GetPhase(),
Expand Down
12 changes: 8 additions & 4 deletions swapwallet/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,14 @@ func creditPayEntry(intent *preparedSendIntent,
paymentHashHex := hex.EncodeToString(paymentHash[:])

return &walletdkrpc.WalletEntry{
Id: paymentHashHex,
Kind: walletdkrpc.EntryKind_ENTRY_KIND_SEND,
Status: walletdkrpc.EntryStatus_ENTRY_STATUS_PENDING,
AmountSat: int64(intent.amountSat),
Id: paymentHashHex,
Kind: walletdkrpc.EntryKind_ENTRY_KIND_SEND,
Status: walletdkrpc.EntryStatus_ENTRY_STATUS_PENDING,

// A SEND is an outflow, so the pending credit-pay row carries a
// negative amount to match every other outgoing row; otherwise
// a sub-dust send renders as an incoming transfer (issue #829).
AmountSat: -int64(intent.amountSat),
Counterparty: "credit",
CreatedAtUnix: now,
UpdatedAtUnix: now,
Expand Down
4 changes: 4 additions & 0 deletions swapwallet/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ func TestRouterSendInvoiceHandsCreditPayToRegistry(t *testing.T) {
t, walletdkrpc.EntryStatus_ENTRY_STATUS_PENDING,
resp.GetEntry().GetStatus(),
)

// A SEND is an outflow, so the pending row carries a negative amount
// (issue #829).
require.Equal(t, int64(-500), resp.GetEntry().GetAmountSat())
}

// TestRouterSendOnchainSelectsVTXOsAndCallsLeave confirms that an onchain
Expand Down
Loading