diff --git a/pkg/client/oniontypes_test.go b/pkg/client/oniontypes_test.go index b7f1a52f..9b24c268 100644 --- a/pkg/client/oniontypes_test.go +++ b/pkg/client/oniontypes_test.go @@ -8,6 +8,7 @@ import ( "github.com/indra-labs/indra/pkg/key/prv" "github.com/indra-labs/indra/pkg/nonce" "github.com/indra-labs/indra/pkg/onion" + "github.com/indra-labs/indra/pkg/payment" "github.com/indra-labs/indra/pkg/service" "github.com/indra-labs/indra/pkg/sha256" "github.com/indra-labs/indra/pkg/slice" @@ -149,7 +150,7 @@ func TestSendKeys(t *testing.T) { }() cnf := nonce.NewID() var sess [5]*session.OnionSkin - var pmt [5]*session.Payment + var pmt [5]*payment.Payment for i := range clients[1:] { // Create a new payment and drop on the payment channel. sess[i] = session.New() diff --git a/pkg/payment/payment.go b/pkg/payment/payment.go new file mode 100644 index 00000000..553b6da8 --- /dev/null +++ b/pkg/payment/payment.go @@ -0,0 +1,13 @@ +package payment + +import ( + "github.com/indra-labs/indra/pkg/lnd/lnwire" + "github.com/indra-labs/indra/pkg/nonce" + "github.com/indra-labs/indra/pkg/sha256" +) + +type Payment struct { + nonce.ID + Preimage sha256.Hash + Amount lnwire.MilliSatoshi +} diff --git a/pkg/traffic/session.go b/pkg/traffic/session.go index ca3d6c85..adddce53 100644 --- a/pkg/traffic/session.go +++ b/pkg/traffic/session.go @@ -10,8 +10,8 @@ import ( "github.com/indra-labs/indra/pkg/lnd/lnwire" log2 "github.com/indra-labs/indra/pkg/log" "github.com/indra-labs/indra/pkg/nonce" + "github.com/indra-labs/indra/pkg/payment" "github.com/indra-labs/indra/pkg/sha256" - "github.com/indra-labs/indra/pkg/wire/session" ) var ( @@ -174,11 +174,11 @@ func (n *Payments) GetSessionByIndex(i int) (s *Session) { return } -type PaymentChan chan *session.Payment +type PaymentChan chan *payment.Payment -type PendingPayments []*session.Payment +type PendingPayments []*payment.Payment -func (p PendingPayments) Add(np *session.Payment) (pp PendingPayments) { +func (p PendingPayments) Add(np *payment.Payment) (pp PendingPayments) { return append(p, np) } @@ -196,7 +196,7 @@ func (p PendingPayments) Delete(preimage sha256.Hash) (pp PendingPayments) { return } -func (p PendingPayments) Find(id nonce.ID) (pp *session.Payment) { +func (p PendingPayments) Find(id nonce.ID) (pp *payment.Payment) { for i := range p { if p[i].ID == id { return p[i] @@ -205,7 +205,7 @@ func (p PendingPayments) Find(id nonce.ID) (pp *session.Payment) { return } -func (p PendingPayments) FindPreimage(pi sha256.Hash) (pp *session.Payment) { +func (p PendingPayments) FindPreimage(pi sha256.Hash) (pp *payment.Payment) { for i := range p { if p[i].Preimage == pi { return p[i] @@ -218,7 +218,7 @@ func (p PendingPayments) FindPreimage(pi sha256.Hash) (pp *session.Payment) { // payments need to be accessed only with the node's mutex locked. func (n *Payments) AddPendingPayment( - np *session.Payment) { + np *payment.Payment) { n.Lock() defer n.Unlock() @@ -232,14 +232,14 @@ func (n *Payments) DeletePendingPayment( n.pendingPayments = n.pendingPayments.Delete(preimage) } func (n *Payments) FindPendingPayment( - id nonce.ID) (pp *session.Payment) { + id nonce.ID) (pp *payment.Payment) { n.Lock() defer n.Unlock() return n.pendingPayments.Find(id) } func (n *Payments) FindPendingPreimage( - pi sha256.Hash) (pp *session.Payment) { + pi sha256.Hash) (pp *payment.Payment) { log.T.F("searching preimage %x", pi) n.Lock() diff --git a/pkg/wire/session/session.go b/pkg/wire/session/session.go index bc06ad75..e73243e8 100644 --- a/pkg/wire/session/session.go +++ b/pkg/wire/session/session.go @@ -6,6 +6,7 @@ import ( "github.com/indra-labs/indra/pkg/lnd/lnwire" log2 "github.com/indra-labs/indra/pkg/log" "github.com/indra-labs/indra/pkg/nonce" + "github.com/indra-labs/indra/pkg/payment" "github.com/indra-labs/indra/pkg/sha256" "github.com/indra-labs/indra/pkg/slice" "github.com/indra-labs/indra/pkg/types" @@ -50,12 +51,6 @@ type OnionSkin struct { types.Onion } -type Payment struct { - nonce.ID - Preimage sha256.Hash - Amount lnwire.MilliSatoshi -} - func New() (x *OnionSkin) { var e error var hdrPrv, pldPrv *prv.Key @@ -79,9 +74,9 @@ func (x *OnionSkin) PreimageHash() sha256.Hash { } func (x *OnionSkin) ToPayment(amount lnwire. - MilliSatoshi) (p *Payment) { + MilliSatoshi) (p *payment.Payment) { - p = &Payment{ + p = &payment.Payment{ ID: nonce.NewID(), Preimage: x.PreimageHash(), Amount: amount,