Skip to content

Commit 38611c8

Browse files
authored
Add API documentation for methods
* Improved maxClick() and sendClick() error handling * Edited Grammar * Updated build.gradle and wrote documentation for the BitcoinKit package. Documented classes included BitcoinKit.kt, MainNet.kt, RegTest.kt, and TestNet.kt. * Fixed Typo * Added passphrase to properties * Dust Calculator documentation * HashUtils documentation * Utils documentation and formatting. utils package documentation is completed * BitcoinInput documentation * BitcoinInputMarkable documentation * BitcoinOutput documentation and completion of the IO package
1 parent 3d57571 commit 38611c8

File tree

12 files changed

+264
-33
lines changed

12 files changed

+264
-33
lines changed

bitcoincore/src/main/java/io/horizontalsystems/bitcoincore/DustCalculator.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@ package io.horizontalsystems.bitcoincore
33
import io.horizontalsystems.bitcoincore.transactions.TransactionSizeCalculator
44
import io.horizontalsystems.bitcoincore.transactions.scripts.ScriptType
55

6+
/**
7+
* Calculates the minimum amount of BTC or "dust" required to broadcast a transaction and pay miner fees.
8+
* @param dustRelayTxFee
9+
* @param sizeCalculator
10+
*
11+
*/
612
class DustCalculator(dustRelayTxFee: Int, val sizeCalculator: TransactionSizeCalculator) {
713
val minFeeRate = dustRelayTxFee / 1000
8-
14+
/**
15+
*@param type The ScriptType (Ex: P2PKH, P2WPKH, P2SH, etc.)
16+
*@return The minimum amount of satoshis required to make a transaction.
17+
*/
918
fun dust(type: ScriptType): Int {
1019
// https://github.com/bitcoin/bitcoin/blob/c536dfbcb00fb15963bf5d507b7017c241718bf6/src/policy/policy.cpp#L18
1120

bitcoincore/src/main/java/io/horizontalsystems/bitcoincore/io/BitcoinInput.java

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public int read() throws IOException {
6262

6363
/**
6464
* Read and fill bytes into byte array.
65+
*
66+
* @param b Arbitrary byte array
67+
* @throws IOException
6568
*/
6669
public void readFully(byte b[]) throws IOException {
6770
int off = 0;
@@ -76,22 +79,36 @@ public void readFully(byte b[]) throws IOException {
7679
}
7780
}
7881

82+
/**
83+
* Read and castes the read value to byte
84+
* @return The converted int
85+
* @throws IOException
86+
*/
7987
public byte readByte() throws IOException {
8088
int ch = in.read();
8189
if (ch < 0) {
8290
throw new EOFException();
8391
}
8492
return (byte) (ch);
8593
}
86-
94+
/**
95+
* Read and return
96+
* @return The read value
97+
* @throws IOException
98+
*/
8799
public int readUnsignedByte() throws IOException {
88100
int ch = in.read();
89101
if (ch < 0) {
90102
throw new EOFException();
91103
}
92104
return ch;
93105
}
94-
106+
/**
107+
* Read and create a short
108+
*
109+
* @return Converted Byte Array
110+
* @throws IOException
111+
*/
95112
public short readShort() throws IOException {
96113
int ch1 = in.read();
97114
int ch2 = in.read();
@@ -100,7 +117,12 @@ public short readShort() throws IOException {
100117
}
101118
return (short) ((ch2 << 8) + (ch1 << 0));
102119
}
103-
120+
/**
121+
* Read and create an unsigned short
122+
*
123+
* @return Converted Byte Array
124+
* @throws IOException
125+
*/
104126
public int readUnsignedShort() throws IOException {
105127
int ch1 = in.read();
106128
int ch2 = in.read();
@@ -118,7 +140,12 @@ public char readChar() throws IOException {
118140
}
119141
return (char) ((ch2 << 8) + (ch1 << 0));
120142
}
121-
143+
/**
144+
* Read and create an int
145+
*
146+
* @return Converted Byte Array
147+
* @throws IOException
148+
*/
122149
public int readInt() throws IOException {
123150
int ch1 = in.read();
124151
int ch2 = in.read();
@@ -129,7 +156,12 @@ public int readInt() throws IOException {
129156
}
130157
return ((ch4 << 24) + (ch3 << 16) + (ch2 << 8) + (ch1 << 0));
131158
}
132-
159+
/**
160+
* Read and create an unsigned int
161+
*
162+
* @return Converted Byte Array
163+
* @throws IOException
164+
*/
133165
public long readUnsignedInt() throws IOException {
134166
int ch1 = in.read();
135167
int ch2 = in.read();
@@ -141,7 +173,12 @@ public long readUnsignedInt() throws IOException {
141173
long ln4 = ch4 & 0x00000000ffffffffL;
142174
return (ln4 << 24) + (ch3 << 16) + (ch2 << 8) + (ch1 << 0);
143175
}
144-
176+
/**
177+
* Read and create a long
178+
*
179+
* @return Converted Byte Array
180+
* @throws IOException
181+
*/
145182
public long readLong() throws IOException {
146183
readFully(bufferOf8bytes);
147184
return (((long) bufferOf8bytes[7] << 56) + ((long) (bufferOf8bytes[6] & 255) << 48)
@@ -150,6 +187,12 @@ public long readLong() throws IOException {
150187
+ ((bufferOf8bytes[1] & 255) << 8) + ((bufferOf8bytes[0] & 255) << 0));
151188
}
152189

190+
/**
191+
* Read and create a String
192+
*
193+
* @return Converted Byte Array with Charset UTF-8 format
194+
* @throws IOException
195+
*/
153196
public String readString() throws IOException {
154197
long len = readVarInt();
155198
if (len == 0) {
@@ -160,6 +203,13 @@ public String readString() throws IOException {
160203
return new String(buffer, StandardCharsets.UTF_8);
161204
}
162205

206+
/**
207+
* Read and put values into a byte array
208+
*
209+
* @param len The desired length of the byte array
210+
* @return A byte array with a length of len
211+
* @throws IOException
212+
*/
163213
public byte[] readBytes(int len) throws IOException {
164214
if (len == 0) {
165215
return EMPTY_BYTES;

bitcoincore/src/main/java/io/horizontalsystems/bitcoincore/io/BitcoinInputMarkable.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,31 @@
33
import java.io.ByteArrayInputStream;
44
import java.io.IOException;
55

6+
/**
7+
* A child class of BitcoinInput and extends its functionality.
8+
* @see BitcoinInput
9+
*/
610
public final class BitcoinInputMarkable extends BitcoinInput {
7-
11+
//Stores the length of the data byte array.
812
public int count;
9-
13+
/**
14+
@param data Byte array that is going to by read by the InputStream
15+
*/
1016
public BitcoinInputMarkable(byte[] data) {
1117
super(new ByteArrayInputStream(data));
1218
this.count = data.length;
1319
}
1420

21+
/**
22+
*Marks the InputStream
23+
*/
1524
public void mark() {
1625
// since the readlimit for ByteArrayInputStream has no meaning set it to 0
1726
in.mark(0);
1827
}
19-
28+
/**
29+
*Resets the InputStream
30+
*/
2031
public void reset() throws IOException {
2132
in.reset();
2233
}

bitcoincore/src/main/java/io/horizontalsystems/bitcoincore/io/BitcoinOutput.java

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,24 @@
88
* Output "stream" for bitcoin protocol.
99
*
1010
* @author Michael Liao
11+
*
1112
*/
1213
public final class BitcoinOutput {
1314

1415
private UnsafeByteArrayOutputStream out;
1516

17+
/**
18+
* Creates an instance of UnsafeByteArrayOutputStream of size 1024.
19+
*/
1620
public BitcoinOutput() {
1721
this.out = new UnsafeByteArrayOutputStream(1024);
1822
}
1923

24+
/**
25+
* Writes a byte array to the OutputStream.
26+
* @param bytes Byte array that's to be written.
27+
* @return The newly written OutputStream.
28+
*/
2029
public BitcoinOutput write(byte[] bytes) {
2130
try {
2231
out.write(bytes);
@@ -25,26 +34,42 @@ public BitcoinOutput write(byte[] bytes) {
2534
}
2635
return this;
2736
}
28-
37+
/**
38+
* Writes a byte to the OutputStream.
39+
* @param v The byte to be written.
40+
* @return The newly written OutputStream.
41+
*/
2942
public BitcoinOutput writeByte(int v) {
3043
out.write(v);
3144
return this;
3245
}
33-
46+
/**
47+
* Writes a short to the OutputStream.
48+
* @param v The short to be written.
49+
* @return The newly written OutputStream.
50+
*/
3451
public BitcoinOutput writeShort(short v) {
3552
out.write(0xff & v);
3653
out.write(0xff & (v >> 8));
3754
return this;
3855
}
39-
56+
/**
57+
* Writes an int to the OutputStream.
58+
* @param v Int value.
59+
* @return The newly written OutputStream.
60+
*/
4061
public BitcoinOutput writeInt(int v) {
4162
out.write(0xff & v);
4263
out.write(0xff & (v >> 8));
4364
out.write(0xff & (v >> 16));
4465
out.write(0xff & (v >> 24));
4566
return this;
4667
}
47-
68+
/**
69+
* Writes a 32-bit int to the OutputStream.
70+
* @param v Long value to be converted.
71+
* @return The newly written OutputStream.
72+
*/
4873
public BitcoinOutput writeInt32(long v) {
4974
out.write((int)(0xff & v));
5075
out.write((int)(0xff & (v >> 8)));
@@ -53,6 +78,11 @@ public BitcoinOutput writeInt32(long v) {
5378
return this;
5479
}
5580

81+
/**
82+
* Writes a Long to the OutputStream.
83+
* @param v Long value to be converted.
84+
* @return The newly written OutputStream.
85+
*/
5686
public BitcoinOutput writeLong(long v) {
5787
out.write((int) (0xff & v));
5888
out.write((int) (0xff & (v >> 8)));
@@ -65,6 +95,11 @@ public BitcoinOutput writeLong(long v) {
6595
return this;
6696
}
6797

98+
/**
99+
* Writes a var int to the OutputStream.
100+
* @param n Long value to be converted.
101+
* @return The newly written OutputStream.
102+
*/
68103
public BitcoinOutput writeVarInt(long n) {
69104
if (n < 0xfd) {
70105
writeByte((int) n);
@@ -82,18 +117,33 @@ public BitcoinOutput writeVarInt(long n) {
82117
return this;
83118
}
84119

120+
/**
121+
* Writes an unsigned int to the OutputStream.
122+
* @param ln Long value to be converted.
123+
* @return The newly written OutputStream.
124+
*/
85125
public BitcoinOutput writeUnsignedInt(long ln) {
86126
int n = (int) (0xffffffff & ln);
87127
writeInt(n);
88128
return this;
89129
}
90130

131+
/**
132+
* Writes an unsigned short to the OutputStream.
133+
* @param i integer value to be casted as an unsigned short.
134+
* @return The newly written OutputStream.
135+
*/
91136
public BitcoinOutput writeUnsignedShort(int i) {
92137
short n = (short) (0xffff & i);
93138
writeShort(n);
94139
return this;
95140
}
96141

142+
/**
143+
* Writes a String to the OutputStream.
144+
* @param str String value to be written.
145+
* @return The newly written OutputStream.
146+
*/
97147
public BitcoinOutput writeString(String str) {
98148
byte[] bs = str.getBytes(StandardCharsets.UTF_8);
99149
writeVarInt(bs.length);

0 commit comments

Comments
 (0)