@@ -9,12 +9,12 @@ open ResultUtils
99open ResultUtils.Portability
1010open Newtonsoft.Json
1111
12- type HTLCReceivedParameters = {
12+ type HtlcReceivedParameters = {
1313 LocalHtlcPubKey: HtlcPubKey
1414 RemoteHtlcPubKey: HtlcPubKey
1515}
1616 with
17- static member TryExtractParameters ( scriptPubKey : Script ): Option < HTLCReceivedParameters > =
17+ static member TryExtractParameters ( scriptPubKey : Script ): Option < HtlcReceivedParameters > =
1818 let ops =
1919 scriptPubKey.ToOps()
2020 // we have to collect it into a list and convert back to a seq
@@ -23,7 +23,6 @@ type HTLCReceivedParameters = {
2323 |> List.ofSeq
2424 |> Seq.ofList
2525
26- Console.WriteLine( JsonConvert.SerializeObject( ops))
2726 let checkOpCode ( opcodeType : OpcodeType ) = seqParser< Op> {
2827 let! op = SeqParser.next()
2928 if op.Code = opcodeType then
@@ -94,31 +93,33 @@ type HTLCReceivedParameters = {
9493 | Ok data -> Some data
9594 | Error _ consumeAllError -> None
9695
97- type internal HTLCReceivedExtensions () =
96+ type internal HtlcReceivedExtensions () =
9897 inherit BuilderExtension()
9998 override self.CanGenerateScriptSig ( scriptPubKey : Script ): bool =
100- ( HTLCReceivedParameters .TryExtractParameters scriptPubKey) .IsSome
99+ ( HtlcReceivedParameters .TryExtractParameters scriptPubKey) .IsSome
101100
102101 override self.GenerateScriptSig ( scriptPubKey : Script , keyRepo : IKeyRepository , signer : ISigner ): Script =
103102 let parameters =
104- match ( HTLCReceivedParameters .TryExtractParameters scriptPubKey) with
103+ match ( HtlcReceivedParameters .TryExtractParameters scriptPubKey) with
105104 | Some parameters -> parameters
106105 | None ->
107106 failwith
108107 " NBitcoin should not call this unless CanGenerateScriptSig returns true"
109- let pubKey = keyRepo.FindKey scriptPubKey
108+ let pubKeyOpt =
109+ keyRepo.FindKey scriptPubKey
110+ |> Option.ofObj
110111 // FindKey will return null if it can't find a key for
111112 // scriptPubKey. If we can't find a valid key then this method
112113 // should return null, indicating to NBitcoin that the sigScript
113114 // could not be generated.
114- match pubKey with
115- | null -> null
116- | _ when pubKey = parameters.LocalHtlcPubKey.RawPubKey() ->
115+ match pubKeyOpt with
116+ | None -> null
117+ | Some pubKey when pubKey = parameters.LocalHtlcPubKey.RawPubKey() ->
117118 let localHtlcSig = signer.Sign ( parameters.LocalHtlcPubKey.RawPubKey())
118119 Script [
119120 Op.GetPushOp ( localHtlcSig.ToBytes())
120121 ]
121- | _ when pubKey = parameters.RemoteHtlcPubKey.RawPubKey() ->
122+ | Some pubKey when pubKey = parameters.RemoteHtlcPubKey.RawPubKey() ->
122123 let remoteHtlcSig = signer.Sign ( parameters.RemoteHtlcPubKey.RawPubKey())
123124 Script [
124125 Op.GetPushOp ( remoteHtlcSig.ToBytes())
@@ -144,7 +145,7 @@ type internal HTLCReceivedExtensions() =
144145 raise <| NotSupportedException()
145146
146147 override self.IsCompatibleKey ( pubKey : PubKey , scriptPubKey : Script ): bool =
147- match HTLCReceivedParameters .TryExtractParameters scriptPubKey with
148+ match HtlcReceivedParameters .TryExtractParameters scriptPubKey with
148149 | None -> false
149150 | Some parameters ->
150151 parameters.LocalHtlcPubKey.RawPubKey() = pubKey
0 commit comments