Skip to content

Commit 3456668

Browse files
committed
#51 Fix merge issues, update javadoc
1 parent ac82705 commit 3456668

73 files changed

Lines changed: 1581 additions & 144 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/org/unicitylabs/sdk/StateTransitionClient.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ public CompletableFuture<InclusionProofResponse> getInclusionProof(StateId state
3737
return this.client.getInclusionProof(stateId);
3838
}
3939

40+
/**
41+
* Submits a certification request to the aggregator.
42+
*
43+
* @param certificationData The certification data to submit.
44+
* @return certification response from the aggregator.
45+
*/
4046
public CompletableFuture<CertificationResponse> submitCertificationRequest(CertificationData certificationData) {
4147
return this.client.submitCertificationRequest(certificationData);
4248
}

src/main/java/org/unicitylabs/sdk/api/CertificationData.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public class CertificationData {
4040
this.unlockScript = Arrays.copyOf(unlockScript, unlockScript.length);
4141
}
4242

43+
/**
44+
* Get lock script of certified transaction output.
45+
*
46+
* @return lock script
47+
*/
4348
public Predicate getLockScript() {
4449
return this.lockScript;
4550
}
@@ -62,12 +67,17 @@ public DataHash getTransactionHash() {
6267
return this.transactionHash;
6368
}
6469

70+
/**
71+
* Get unlock script used for certification.
72+
*
73+
* @return unlock script bytes
74+
*/
6575
public byte[] getUnlockScript() {
6676
return Arrays.copyOf(this.unlockScript, this.unlockScript.length);
6777
}
6878

6979
/**
70-
* Create CertificationData from CBOR bytes.
80+
* Deserialize CertificationData from CBOR bytes.
7181
*
7282
* @param bytes CBOR bytes
7383
* @return CertificationData
@@ -83,6 +93,13 @@ public static CertificationData fromCbor(byte[] bytes) {
8393
);
8494
}
8595

96+
/**
97+
* Build certification data for a mint transaction using the deterministic mint signing service.
98+
*
99+
* @param transaction mint transaction
100+
*
101+
* @return certification data
102+
*/
86103
public static CertificationData fromMintTransaction(MintTransaction transaction) {
87104
SigningService signingService = MintSigningService.create(transaction.getTokenId());
88105

@@ -93,10 +110,26 @@ public static CertificationData fromMintTransaction(MintTransaction transaction)
93110
);
94111
}
95112

113+
/**
114+
* Build certification data from a transaction and unlock script object.
115+
*
116+
* @param transaction transaction to certify
117+
* @param unlockScript unlock script
118+
*
119+
* @return certification data
120+
*/
96121
public static CertificationData fromTransaction(Transaction transaction, UnlockScript unlockScript) {
97122
return CertificationData.fromTransaction(transaction, unlockScript.encode());
98123
}
99124

125+
/**
126+
* Build certification data from a transaction and encoded unlock script bytes.
127+
*
128+
* @param transaction transaction to certify
129+
* @param unlockScript encoded unlock script bytes
130+
*
131+
* @return certification data
132+
*/
100133
public static CertificationData fromTransaction(Transaction transaction, byte[] unlockScript) {
101134
return new CertificationData(
102135
transaction.getLockScript(),
@@ -118,7 +151,7 @@ public DataHash calculateLeafValue() {
118151
}
119152

120153
/**
121-
* Convert the certification data to CBOR bytes.
154+
* Serialize certification data to CBOR bytes.
122155
*
123156
* @return CBOR bytes
124157
*/

src/main/java/org/unicitylabs/sdk/api/CertificationRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public static CertificationRequest create(CertificationData certificationData) {
5454
}
5555

5656
/**
57-
* Convert the request to a CBOR bytes.
57+
* Serialize request to a CBOR bytes.
5858
*
5959
* @return CBOR bytes
6060
*/
61-
public byte[] toCBOR() {
61+
public byte[] toCbor() {
6262
return CborSerializer.encodeArray(
6363
this.stateId.toCbor(),
6464
this.certificationData.toCbor(),

src/main/java/org/unicitylabs/sdk/api/InclusionProof.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@ public class InclusionProof {
2222
CertificationData certificationData,
2323
UnicityCertificate unicityCertificate
2424
) {
25-
Objects.requireNonNull(merkleTreePath, "Merkle tree path cannot be null.");
26-
Objects.requireNonNull(unicityCertificate, "Unicity certificate cannot be null.");
27-
28-
this.merkleTreePath = merkleTreePath;
25+
this.merkleTreePath = Objects.requireNonNull(merkleTreePath, "Merkle tree path cannot be null.");;
2926
this.certificationData = certificationData;
30-
this.unicityCertificate = unicityCertificate;
27+
this.unicityCertificate = Objects.requireNonNull(unicityCertificate, "Unicity certificate cannot be null.");;
3128
}
3229

3330
/**
@@ -58,7 +55,7 @@ public Optional<CertificationData> getCertificationData() {
5855
}
5956

6057
/**
61-
* Create inclusion proof from CBOR bytes.
58+
* Deserialize inclusion proof from CBOR bytes.
6259
*
6360
* @param bytes CBOR bytes
6461
* @return inclusion proof
@@ -74,7 +71,7 @@ public static InclusionProof fromCbor(byte[] bytes) {
7471
}
7572

7673
/**
77-
* Convert inclusion proof to CBOR bytes.
74+
* Serialize inclusion proof to CBOR bytes.
7875
*
7976
* @return CBOR bytes
8077
*/

src/main/java/org/unicitylabs/sdk/api/InclusionProofRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public InclusionProofRequest(
2626
this.stateId = stateId.getData();
2727
}
2828

29+
/**
30+
* Get state id.
31+
*
32+
* @return state id
33+
*/
2934
public byte[] getStateId() {
3035
return Arrays.copyOf(this.stateId, this.stateId.length);
3136
}

src/main/java/org/unicitylabs/sdk/api/InclusionProofResponse.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public InclusionProof getInclusionProof() {
3535
}
3636

3737
/**
38-
* Create response from CBOR bytes.
38+
* Deserialize response from CBOR bytes.
3939
*
4040
* @param bytes CBOR bytes
4141
* @return inclusion proof response
@@ -48,6 +48,11 @@ public static InclusionProofResponse fromCbor(byte[] bytes) {
4848
);
4949
}
5050

51+
/**
52+
* Serialize inclusion proof response to CBOR bytes.
53+
*
54+
* @return CBOR bytes
55+
*/
5156
public byte[] toCbor() {
5257
return CborSerializer.encodeArray(
5358
CborSerializer.encodeUnsignedInteger(this.blockNumber),

src/main/java/org/unicitylabs/sdk/api/JsonRpcAggregatorClient.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,31 @@ public JsonRpcAggregatorClient(String url) {
3535
*
3636
*/
3737
public JsonRpcAggregatorClient(String url, String apiKey) {
38-
Objects.requireNonNull(url, "url cannot be null");
39-
40-
this.transport = new JsonRpcHttpTransport(url);
38+
this.transport = new JsonRpcHttpTransport(Objects.requireNonNull(url, "url cannot be null"));
4139
this.apiKey = apiKey;
4240
}
4341

42+
/**
43+
* Submit a certification request for a transaction state transition.
44+
*
45+
* @param certificationData certification payload
46+
*
47+
* @return asynchronous certification response
48+
*/
49+
@Override
4450
public CompletableFuture<CertificationResponse> submitCertificationRequest(
4551
CertificationData certificationData
4652
) {
47-
Objects.requireNonNull(certificationData, "certificationData cannot be null");
48-
49-
CertificationRequest request = CertificationRequest.create(certificationData);
53+
CertificationRequest request = CertificationRequest.create(
54+
Objects.requireNonNull(certificationData, "certificationData cannot be null"));
5055

5156
Map<String, List<String>> headers = this.apiKey == null
5257
? Map.of()
5358
: Map.of(AUTHORIZATION, List.of(String.format("Bearer %s", this.apiKey)));
5459

5560
return this.transport.request(
5661
"certification_request",
57-
HexConverter.encode(request.toCBOR()),
62+
HexConverter.encode(request.toCbor()),
5863
CertificationResponse.class,
5964
headers
6065
);
@@ -66,10 +71,10 @@ public CompletableFuture<CertificationResponse> submitCertificationRequest(
6671
* @param stateId state id
6772
* @return inclusion / non inclusion proof
6873
*/
74+
@Override
6975
public CompletableFuture<InclusionProofResponse> getInclusionProof(StateId stateId) {
70-
Objects.requireNonNull(stateId, "stateId cannot be null");
71-
72-
InclusionProofRequest request = new InclusionProofRequest(stateId);
76+
InclusionProofRequest request = new InclusionProofRequest(
77+
Objects.requireNonNull(stateId, "stateId cannot be null"));
7378

7479
return this.transport
7580
.request("get_inclusion_proof.v2", request, String.class)
@@ -81,8 +86,9 @@ public CompletableFuture<InclusionProofResponse> getInclusionProof(StateId state
8186
*
8287
* @return block height
8388
*/
89+
@Override
8490
public CompletableFuture<Long> getBlockHeight() {
8591
return this.transport.request("get_block_height", Map.of(), BlockHeightResponse.class)
8692
.thenApply(BlockHeightResponse::getBlockNumber);
8793
}
88-
}
94+
}

src/main/java/org/unicitylabs/sdk/api/StateId.java

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,67 @@
1212
import org.unicitylabs.sdk.util.BitString;
1313
import org.unicitylabs.sdk.util.HexConverter;
1414

15-
public class StateId {
15+
/**
16+
* Represents a state identifier for requests.
17+
*/
18+
public final class StateId {
1619

1720
private final DataHash hash;
1821

1922
private StateId(DataHash hash) {
2023
this.hash = hash;
2124
}
2225

26+
/**
27+
* Returns the raw hash bytes of this state id.
28+
*
29+
* @return state id hash bytes
30+
*/
2331
public byte[] getData() {
2432
return this.hash.getData();
2533
}
2634

35+
/**
36+
* Returns the hash imprint bytes.
37+
*
38+
* @return state id imprint bytes
39+
*/
2740
public byte[] getImprint() {
2841
return this.hash.getImprint();
2942
}
3043

44+
/**
45+
* Deserializes a state id from CBOR.
46+
*
47+
* @param bytes CBOR byte string containing SHA-256 hash bytes
48+
* @return decoded state id
49+
*/
3150
public static StateId fromCbor(byte[] bytes) {
3251
return new StateId(
3352
new DataHash(HashAlgorithm.SHA256, CborDeserializer.decodeByteString(bytes)));
3453
}
3554

55+
/**
56+
* Creates a state id from certification data.
57+
*
58+
* @param certificationData certification data carrying lock script and source state hash
59+
* @return created state id
60+
* @throws NullPointerException if {@code certificationData} is {@code null}
61+
*/
3662
public static StateId fromCertificationData(CertificationData certificationData) {
3763
Objects.requireNonNull(certificationData, "Certification data cannot be null");
3864

3965
return StateId.create(certificationData.getLockScript(),
4066
certificationData.getSourceStateHash());
4167
}
4268

69+
/**
70+
* Creates a state id from transaction data.
71+
*
72+
* @param transaction transaction carrying lock script and source state hash
73+
* @return created state id
74+
* @throws NullPointerException if {@code transaction} is {@code null}
75+
*/
4376
public static StateId fromTransaction(Transaction transaction) {
4477
Objects.requireNonNull(transaction, "Transaction cannot be null");
4578

@@ -59,17 +92,22 @@ private static StateId create(Predicate predicate, DataHash stateHash) {
5992
return new StateId(hash);
6093
}
6194

95+
/**
96+
* Serializes this state id as a CBOR bytes.
97+
*
98+
* @return CBOR-encoded state id
99+
*/
62100
public byte[] toCbor() {
63101
return CborSerializer.encodeByteString(this.getData());
64102
}
65103

66104
/**
67-
* Converts the StateId to a BitString.
105+
* Converts this state id to a {@link BitString}.
68106
*
69-
* @return The BitString representation of the StateId.
107+
* @return bit string representation of this state id
70108
*/
71109
public BitString toBitString() {
72-
return BitString.fromStateId(this);
110+
return new BitString(this.getImprint());
73111
}
74112

75113
@Override
@@ -86,13 +124,8 @@ public int hashCode() {
86124
return Objects.hashCode(this.hash);
87125
}
88126

89-
/**
90-
* Returns a string representation of the StateId.
91-
*
92-
* @return The string representation.
93-
*/
94127
@Override
95128
public String toString() {
96129
return String.format("StateId[%s]", HexConverter.encode(this.getImprint()));
97130
}
98-
}
131+
}

src/main/java/org/unicitylabs/sdk/api/bft/InputRecord.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public byte[] getExecutedTransactionsHash() {
144144
}
145145

146146
/**
147-
* Create InputRecord from CBOR bytes.
147+
* Deserialize InputRecord from CBOR bytes.
148148
*
149149
* @param bytes CBOR bytes
150150
* @return input record
@@ -168,7 +168,7 @@ public static InputRecord fromCbor(byte[] bytes) {
168168
}
169169

170170
/**
171-
* Convert InputRecord to CBOR bytes.
171+
* Serialize InputRecord to CBOR bytes.
172172
*
173173
* @return CBOR bytes
174174
*/

src/main/java/org/unicitylabs/sdk/api/bft/ShardTreeCertificate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public List<byte[]> getSiblingHashList() {
4747
}
4848

4949
/**
50-
* Create shard tree certificate from CBOR bytes.
50+
* Deserialize shard tree certificate from CBOR bytes.
5151
*
5252
* @param bytes CBOR bytes
5353
* @return shard tree certificate
@@ -64,7 +64,7 @@ public static ShardTreeCertificate fromCbor(byte[] bytes) {
6464
}
6565

6666
/**
67-
* Convert shard tree certificate to CBOR bytes.
67+
* Serialize shard tree certificate to CBOR bytes.
6868
*
6969
* @return CBOR bytes
7070
*/

0 commit comments

Comments
 (0)