Skip to content

Commit fa130da

Browse files
committed
[C#] Add initial hooks, the C# code compiles, the C not at all
1 parent f30ed1c commit fa130da

File tree

8 files changed

+1544
-62
lines changed

8 files changed

+1544
-62
lines changed

c_sharp/libcode.version

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
global: CS_LDK_*;
3+
local: *;
4+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using org.ldk.util;
3+
4+
internal class InternalUtils {
5+
public static byte[] check_arr_len(byte[] arr, int length) {
6+
if (arr != null && arr.Length != length) {
7+
throw new ArgumentException("Array must be of fixed size " + length + " but was of length " + arr.Length);
8+
}
9+
return arr;
10+
}
11+
12+
public static byte[] convUInt5Array(UInt5[] u5s) {
13+
byte[] res = new byte[u5s.Length];
14+
for (int i = 0; i < u5s.Length; i++) {
15+
res[i] = u5s[i].getVal();
16+
}
17+
return res;
18+
}
19+
20+
public static T[] mapArray<F, T>(F[] arr, Func<F, T> f) {
21+
T[] ret = new T[arr.Length];
22+
for (int i = 0; i < arr.Length; i++) ret[i] = f(arr[i]);
23+
return ret;
24+
}
25+
}

c_sharp/src/org/ldk/util/UInt.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
using System.Linq;
3+
4+
namespace org { namespace ldk { namespace util {
5+
6+
/**
7+
* A 5-bit unsigned integer
8+
*/
9+
public class UInt5 {
10+
byte val;
11+
public UInt5(byte val) {
12+
if (val > 32 || val < 0) {
13+
throw new ArgumentException();
14+
}
15+
this.val = val;
16+
}
17+
18+
/**
19+
* @return the value represented
20+
*/
21+
public byte getVal() {
22+
return val;
23+
}
24+
}
25+
26+
/**
27+
* A 5-bit unsigned integer
28+
*/
29+
public class UInt128 {
30+
private byte[] le_bytes;
31+
32+
/**
33+
* Constructs a 128-bit integer from its little-endian representation
34+
*/
35+
public UInt128(byte[] le_bytes) {
36+
if (le_bytes.Length != 16) {
37+
throw new ArgumentException();
38+
}
39+
this.le_bytes = le_bytes;
40+
}
41+
42+
/**
43+
* Constructs a 128-bit integer from a long, ignoring the sign bit
44+
*/
45+
public UInt128(long val) {
46+
byte[] le_bytes = new byte[16];
47+
for (int i = 0; i < 8; i++)
48+
le_bytes[i] = (byte) ((val >> i*8) & 0xff);
49+
this.le_bytes = le_bytes;
50+
}
51+
52+
/**
53+
* @return The value as 16 little endian bytes
54+
*/
55+
public byte[] getLEBytes() { return le_bytes; }
56+
57+
public override bool Equals(object o) {
58+
if (o == null || !(o is UInt128)) return false;
59+
byte[] o_le_bytes = ((UInt128) o).le_bytes;
60+
return le_bytes.SequenceEqual(o_le_bytes);
61+
}
62+
63+
public override int GetHashCode() { return le_bytes.GetHashCode(); }
64+
}
65+
66+
} } }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace org { namespace ldk { namespace util {
2+
3+
/**
4+
* An type for cases where no additional information is available.
5+
* In general, if you've gotten this far the cause of the error should already be clear.
6+
*/
7+
public class UnqualifiedError {
8+
public UnqualifiedError(int _dummy) {}
9+
}
10+
11+
} } }
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
3+
namespace org { namespace ldk { namespace util {
4+
5+
/**
6+
* A 4-bit unsigned integer representing a Bitcoin SegWit version
7+
*/
8+
public class WitnessVersion {
9+
byte val;
10+
public WitnessVersion(byte val) {
11+
if (val > 16 || val < 0) {
12+
throw new ArgumentException();
13+
}
14+
this.val = val;
15+
}
16+
17+
/**
18+
* @return the value represented
19+
*/
20+
public byte getVal() {
21+
return val;
22+
}
23+
}
24+
25+
} } }

0 commit comments

Comments
 (0)