diff --git a/lnrpc/invoicesrpc/invoices_server.go b/lnrpc/invoicesrpc/invoices_server.go index 85eb9a96..a9cd9bf0 100644 --- a/lnrpc/invoicesrpc/invoices_server.go +++ b/lnrpc/invoicesrpc/invoices_server.go @@ -163,12 +163,12 @@ func (s *Server) RegisterWithRootServer(grpcServer *grpc.Server) error { func (s *Server) SubscribeSingleInvoice(req *lnrpc.PaymentHash, updateStream Invoices_SubscribeSingleInvoiceServer) error { - hash, err := lntypes.NewHash(req.RHash) + hash, err := lntypes.MakeHash(req.RHash) if err != nil { return err } - invoiceClient := s.cfg.InvoiceRegistry.SubscribeSingleInvoice(*hash) + invoiceClient := s.cfg.InvoiceRegistry.SubscribeSingleInvoice(hash) defer invoiceClient.Cancel() for { @@ -197,12 +197,12 @@ func (s *Server) SubscribeSingleInvoice(req *lnrpc.PaymentHash, func (s *Server) CancelInvoice(ctx context.Context, in *CancelInvoiceMsg) (*CancelInvoiceResp, error) { - paymentHash, err := lntypes.NewHash(in.PaymentHash) + paymentHash, err := lntypes.MakeHash(in.PaymentHash) if err != nil { return nil, err } - err = s.cfg.InvoiceRegistry.CancelInvoice(*paymentHash) + err = s.cfg.InvoiceRegistry.CancelInvoice(paymentHash) if err != nil { return nil, err } diff --git a/lntypes/hash.go b/lntypes/hash.go index 32214489..d2498f9c 100644 --- a/lntypes/hash.go +++ b/lntypes/hash.go @@ -17,33 +17,33 @@ func (hash Hash) String() string { return hex.EncodeToString(hash[:]) } -// NewHash returns a new Hash from a byte slice. An error is returned if +// MakeHash returns a new Hash from a byte slice. An error is returned if // the number of bytes passed in is not HashSize. -func NewHash(newHash []byte) (*Hash, error) { +func MakeHash(newHash []byte) (Hash, error) { nhlen := len(newHash) if nhlen != HashSize { - return nil, fmt.Errorf("invalid hash length of %v, want %v", + return Hash{}, fmt.Errorf("invalid hash length of %v, want %v", nhlen, HashSize) } var hash Hash copy(hash[:], newHash) - return &hash, nil + return hash, nil } -// NewHashFromStr creates a Hash from a hex hash string. -func NewHashFromStr(newHash string) (*Hash, error) { +// MakeHashFromStr creates a Hash from a hex hash string. +func MakeHashFromStr(newHash string) (Hash, error) { // Return error if hash string is of incorrect length. if len(newHash) != HashSize*2 { - return nil, fmt.Errorf("invalid hash string length of %v, "+ + return Hash{}, fmt.Errorf("invalid hash string length of %v, "+ "want %v", len(newHash), HashSize*2) } hash, err := hex.DecodeString(newHash) if err != nil { - return nil, err + return Hash{}, err } - return NewHash(hash) + return MakeHash(hash) }