X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=csharp_strings.py;h=b25549a9aa80b5862f41f3649b879082e340ee1d;hb=7e0420c715587d17a796246c0c12ace40af546c5;hp=c1873f3d8aefdd1a1f584db301d80d725875de72;hpb=49be9f346217a25fc099abfaac392d4b6236f22f;p=ldk-java diff --git a/csharp_strings.py b/csharp_strings.py index c1873f3d..b25549a9 100644 --- a/csharp_strings.py +++ b/csharp_strings.py @@ -150,6 +150,28 @@ public class CommonBase { } }""" + self.witness_program_defn = """public class WitnessProgram : CommonBase { + /** The witness program bytes themselves */ + public readonly byte[] program; + /** The witness version */ + public readonly WitnessVersion version; + + internal WitnessProgram(object _dummy, long ptr) : base(ptr) { + this.program = InternalUtils.decodeUint8Array(bindings.WitnessProgram_get_program(ptr)); + this.version = new WitnessVersion(bindings.WitnessProgram_get_version(ptr)); + } + static private long check_args(byte[] program, WitnessVersion version) { + if (program.Length < 2 || program.Length > 40) throw new ArgumentException(); + if (version.getVal() == 0 && program.Length != 20 && program.Length != 32) throw new ArgumentException(); + return InternalUtils.encodeUint8Array(program); + } + public WitnessProgram(byte[] program, WitnessVersion version) : + this(null, bindings.WitnessProgram_new(version.getVal(), check_args(program, version))) {} + + ~WitnessProgram() { + if (ptr != 0) { bindings.WitnessProgram_free(ptr); } + } +}""" self.c_file_pfx = """ // On OSX jlong (ie long long) is not equivalent to int64_t, so we override here