diff --git a/lnwire/update_fail_htlc.go b/lnwire/update_fail_htlc.go index 37a80bf4..32c2afff 100644 --- a/lnwire/update_fail_htlc.go +++ b/lnwire/update_fail_htlc.go @@ -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