6 namespace org { namespace ldk { namespace structs {
8 public class WitnessProgram : CommonBase {
9 /** The witness program bytes themselves */
10 public readonly byte[] program;
11 /** The witness version */
12 public readonly WitnessVersion version;
14 internal WitnessProgram(object _dummy, long ptr) : base(ptr) {
15 this.program = InternalUtils.decodeUint8Array(bindings.WitnessProgram_get_program(ptr));
16 this.version = new WitnessVersion(bindings.WitnessProgram_get_version(ptr));
18 static private long check_args(byte[] program, WitnessVersion version) {
19 if (program.Length < 2 || program.Length > 40) throw new ArgumentException();
20 if (version.getVal() == 0 && program.Length != 20 && program.Length != 32) throw new ArgumentException();
21 return InternalUtils.encodeUint8Array(program);
23 public WitnessProgram(byte[] program, WitnessVersion version) :
24 this(null, bindings.WitnessProgram_new(version.getVal(), check_args(program, version))) {}
27 if (ptr != 0) { bindings.WitnessProgram_free(ptr); }