Source file script_witnessscripthash.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
open Script;;
open Address;;

module Input = struct 
  type t = int;;
  let check v = true;;
  let encode v = Script.empty;;
  let decode v = 0;;
end

module Output = struct 
  type t = string;;

  let check s = 
    match fst s with
    | OP_0 :: OP_DATA (32, wsh) :: [] -> true
    | _ -> false
  ;;

  let encode wsh = Script.of_opcodes [ OP_0; OP_DATA (32, wsh) ];;

  let decode s = 
    match fst s with
    | OP_0 :: OP_DATA (32, wsh) :: [] -> wsh
    | _ -> ""
  ;;

  let spendable_by s prefix = decode s |> Address.of_witness prefix.hrp 0x00;;
end


(*
module Script_witnessscripthash = Script_template.Make_template
  (Input)
  (Output)  
;;
*)