lnwire: add reason to fail code conversion method

This commit is contained in:
Andrey Samokhvalov 2017-05-01 17:47:21 +03:00 committed by Olaoluwa Osuntokun
parent 07afcad6de
commit 84f94bdf4f

@ -1,6 +1,9 @@
package lnwire
import "io"
import (
"errors"
"io"
)
// FailCode specifies the precise reason that an upstream HTLC was cancelled.
// Each UpdateFailHTLC message carries a FailCode which is to be passed back
@ -72,6 +75,17 @@ func (c FailCode) String() string {
// slice can only be decrypted by the sender of the original HTLC.
type OpaqueReason []byte
// ToFailCode converts the reason in fail code.
// TODO(andrew.shvv) Future version of this method should implement
// decryption opaque reason logic.
func (r OpaqueReason) ToFailCode() (FailCode, error) {
if len(r) != 1 {
return 0, errors.New("wrong opaque code length")
}
return FailCode(r[0]), nil
}
// UpdateFailHTLC is sent by Alice to Bob in order to remove a previously added
// HTLC. Upon receipt of an UpdateFailHTLC the HTLC should be removed from the
// next commitment transaction, with the UpdateFailHTLC propagated backwards in