Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,18 @@ MintCommitment<?> commitment = MintCommitment.create(
);

// Submit mint transaction using StateTransitionClient
SubmitCommitmentResponse response = client
CertificationResponse response = client
.submitCommitment(commitment)
.get();

if (response.getStatus() != SubmitCommitmentStatus.SUCCESS) {
if (response.getStatus() != CertificationStatus.SUCCESS) {
throw new Exception(
String.format(
"Failed to submit mint commitment: %s",
response.getStatus()
)
);
}
String.format(
"Failed to submit mint commitment: %s",
response.getStatus()
)
);
}

// Wait for inclusion proof
InclusionProof inclusionProof = InclusionProofUtils.waitInclusionProof(
Expand Down Expand Up @@ -187,8 +187,8 @@ TransferCommitment transferCommitment = TransferCommitment.create(
SigningService.createFromMaskedSecret(senderSecret, senderNonce)
);

SubmitCommitmentResponse transferResponse = this.client.submitCommitment(transferCommitment).get();
if (transferResponse.getStatus() != SubmitCommitmentStatus.SUCCESS) {
CertificationResponse transferResponse = this.client.submitCommitment(transferCommitment).get();
if (transferResponse.getStatus() != CertificationStatus.SUCCESS) {
throw new Exception(
String.format(
"Failed to submit transfer commitment: %s",
Expand Down Expand Up @@ -245,8 +245,8 @@ MintCommitment<?> nametagMintCommitment = MintCommitment.create(
);

// Submit nametag mint transaction using StateTransitionClient
SubmitCommitmentResponse nametagMintResponse = client.submitCommitment(nametagMintCommitment).get();
if (nametagMintResponse.getStatus() != SubmitCommitmentStatus.SUCCESS) {
CertificationResponse nametagMintResponse = client.submitCommitment(nametagMintCommitment).get();
if (nametagMintResponse.getStatus() != CertificationStatus.SUCCESS) {
throw new Exception(
String.format(
"Failed to submit nametag mint commitment: %s",
Expand Down Expand Up @@ -294,7 +294,6 @@ Token<?> finalizedToken = client.finalizeTransaction(
transaction,
List.of(nametagToken)
);

```

## Building from Source
Expand Down Expand Up @@ -410,7 +409,7 @@ Located in `src/test/java/org/unicitylabs/sdk/`:
./gradlew integrationTest

# Specific test class
./gradlew test --tests "org.unicitylabs.sdk.api.RequestIdTest"
./gradlew test --tests "org.unicitylabs.sdk.api.StateIdTest"
```

## License
Expand Down
43 changes: 18 additions & 25 deletions src/main/java/org/unicitylabs/sdk/StateTransitionClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import java.util.concurrent.CompletableFuture;
import org.unicitylabs.sdk.api.AggregatorClient;
import org.unicitylabs.sdk.api.InclusionProofResponse;
import org.unicitylabs.sdk.api.RequestId;
import org.unicitylabs.sdk.api.SubmitCommitmentResponse;
import org.unicitylabs.sdk.api.StateId;
import org.unicitylabs.sdk.api.CertificationResponse;
import org.unicitylabs.sdk.bft.RootTrustBase;
import org.unicitylabs.sdk.predicate.Predicate;
import org.unicitylabs.sdk.predicate.PredicateEngineService;
Expand Down Expand Up @@ -50,12 +50,8 @@ public StateTransitionClient(AggregatorClient client) {
* @return A CompletableFuture that resolves to the response from the aggregator.
*/
public <R extends MintTransactionReason>
CompletableFuture<SubmitCommitmentResponse> submitCommitment(MintCommitment<R> commitment) {
return this.client.submitCommitment(
commitment.getRequestId(),
commitment.getTransactionData().calculateHash(),
commitment.getAuthenticator()
);
CompletableFuture<CertificationResponse> submitCommitment(MintCommitment<R> commitment) {
return this.client.submitCertificationRequest(commitment.getCertificationData(), false);
}

/**
Expand All @@ -65,20 +61,17 @@ CompletableFuture<SubmitCommitmentResponse> submitCommitment(MintCommitment<R> c
* @return A CompletableFuture that resolves to the response from the aggregator.
* @throws IllegalArgumentException if ownership verification fails.
*/
public CompletableFuture<SubmitCommitmentResponse> submitCommitment(
TransferCommitment commitment
) {
public CompletableFuture<CertificationResponse> submitCommitment(TransferCommitment commitment) {
if (
!PredicateEngineService.createPredicate(
commitment.getTransactionData().getSourceState().getPredicate()
).isOwner(commitment.getAuthenticator().getPublicKey())
).isOwner(commitment.getCertificationData().getPublicKey())
) {
throw new IllegalArgumentException(
"Ownership verification failed: Authenticator does not match source state predicate.");
}

return this.client.submitCommitment(commitment.getRequestId(), commitment.getTransactionData()
.calculateHash(), commitment.getAuthenticator());
return this.client.submitCertificationRequest(commitment.getCertificationData(), false);
}

/**
Expand Down Expand Up @@ -126,26 +119,26 @@ public <R extends MintTransactionReason> Token<R> finalizeTransaction(
}

/**
* Retrieves the inclusion proof for a given request id.
* Retrieves the inclusion proof for a given state id.
*
* @param requestId The request ID of inclusion proof to retrieve.
* @param stateId The state ID of inclusion proof to retrieve.
* @return A CompletableFuture that resolves to the inclusion proof response from the aggregator.
*/
public CompletableFuture<InclusionProofResponse> getInclusionProof(RequestId requestId) {
return this.client.getInclusionProof(requestId);
public CompletableFuture<InclusionProofResponse> getInclusionProof(StateId stateId) {
return this.client.getInclusionProof(stateId);
}

/**
* Check if state is already spent for given request id.
* Check if state is already spent for given state id.
*
* @param requestId request id
* @param stateId state id
* @param trustBase root trust base
* @return A CompletableFuture that resolves to true if state is spent, false otherwise.
*/
public CompletableFuture<Boolean> isStateSpent(RequestId requestId, RootTrustBase trustBase) {
return this.getInclusionProof(requestId)
public CompletableFuture<Boolean> isStateSpent(StateId stateId, RootTrustBase trustBase) {
return this.getInclusionProof(stateId)
.thenApply(inclusionProof -> {
InclusionProofVerificationStatus result = inclusionProof.getInclusionProof().verify(requestId, trustBase);
InclusionProofVerificationStatus result = inclusionProof.getInclusionProof().verify(trustBase, stateId);
switch (result) {
case OK:
return true;
Expand Down Expand Up @@ -178,7 +171,7 @@ public CompletableFuture<Boolean> isStateSpent(
throw new IllegalArgumentException("Given key is not owner of the token.");
}

return this.isStateSpent(RequestId.create(publicKey, token.getState()), trustBase);
return this.isStateSpent(StateId.create(publicKey, token.getState()), trustBase);
}

/**
Expand All @@ -190,7 +183,7 @@ public CompletableFuture<Boolean> isStateSpent(
*/
public CompletableFuture<Boolean> isMinted(TokenId tokenId, RootTrustBase trustBase) {
return this.isStateSpent(
RequestId.create(
StateId.create(
MintSigningService.create(tokenId).getPublicKey(),
MintTransactionState.create(tokenId)
),
Expand Down
24 changes: 11 additions & 13 deletions src/main/java/org/unicitylabs/sdk/api/AggregatorClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,31 @@
package org.unicitylabs.sdk.api;

import java.util.concurrent.CompletableFuture;
import org.unicitylabs.sdk.hash.DataHash;

/**
* Aggregator client structure.
*/
public interface AggregatorClient {

/**
* Submit commitment.
* Submit certification request.
*
* @param requestId request id
* @param transactionHash transaction hash
* @param authenticator authenticator
* @return submit commitment response
* @param certificationData certification data
* @param receipt whether to request a receipt
* @return certification response
*/
CompletableFuture<SubmitCommitmentResponse> submitCommitment(
RequestId requestId,
DataHash transactionHash,
Authenticator authenticator);
CompletableFuture<CertificationResponse> submitCertificationRequest(
CertificationData certificationData,
boolean receipt
);

/**
* Get inclusion proof for request id.
* Get inclusion proof for state id.
*
* @param requestId request id
* @param stateId state id
* @return inclusion / non inclusion proof
*/
CompletableFuture<InclusionProofResponse> getInclusionProof(RequestId requestId);
CompletableFuture<InclusionProofResponse> getInclusionProof(StateId stateId);

/**
* Get block height.
Expand Down
Loading
Loading