Skip to content

Commit

Permalink
Merge pull request #34 from 5GZORRO/feature/spectoken
Browse files Browse the repository at this point in the history
Get NFTs end point
  • Loading branch information
Dabami authored Oct 20, 2022
2 parents 41f65d3 + 0f000c1 commit 4c4b4b7
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import eu._5gzorro.manager.service.PrimitiveSpectokenDriver;
import eu._5gzorro.tm_forum.models.spectoken.GetDerivativeSpectokenResponse;
import eu._5gzorro.tm_forum.models.spectoken.GetPrimitiveSpectokenResponse;
import eu._5gzorro.tm_forum.models.spectoken.NftResponse;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand Down Expand Up @@ -70,6 +71,18 @@ public ResponseEntity<?> getPrimitiveSpectokens() {
return ResponseEntity.ok().body(primitiveSpectokens);
}

@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "Retrieved Spectoken NFTs"
)
})
@GetMapping("/nfts")
public ResponseEntity<?> getNfts() {
List<NftResponse> nftResponses = primitiveSpectokenDriver.getNfts();
return ResponseEntity.ok().body(nftResponses);
}

@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu._5gzorro.manager.dlt.corda.service.spectoken;

import com.r3.corda.lib.tokens.contracts.states.NonFungibleToken;
import eu._5gzorro.manager.dlt.corda.flows.spectoken.*;
import eu._5gzorro.manager.dlt.corda.service.rpc.NodeRPC;
import eu._5gzorro.manager.dlt.corda.service.rpc.RPCSyncService;
Expand All @@ -8,6 +9,7 @@
import eu._5gzorro.manager.service.PrimitiveSpectokenDriver;
import eu._5gzorro.manager.service.identity.DIDToDLTIdentityService;
import eu._5gzorro.tm_forum.models.spectoken.GetPrimitiveSpectokenResponse;
import eu._5gzorro.tm_forum.models.spectoken.NftResponse;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.subjects.ReplaySubject;
import net.corda.core.contracts.StateAndRef;
Expand Down Expand Up @@ -144,6 +146,16 @@ public void invalidatePrimitiveSpectoken(String licenseId) {
}
}

@Override
public List<NftResponse> getNfts() {
Vault.Page<NonFungibleToken> nonFungibleTokenPage = rpcClient.vaultQuery(NonFungibleToken.class);
List<NftResponse> nfts = new ArrayList<>();
for (StateAndRef<NonFungibleToken> nonFungibleToken : nonFungibleTokenPage.getStates()) {
nfts.add(convertToNftResponse(nonFungibleToken.getState().getData()));
}
return nfts;
}

private GetPrimitiveSpectokenResponse convertToResponse(PrimitiveSpecTokenType primitiveSpecTokenType) {
return new GetPrimitiveSpectokenResponse(
primitiveSpecTokenType.getLinearId().toString(),
Expand All @@ -162,6 +174,15 @@ private GetPrimitiveSpectokenResponse convertToResponse(PrimitiveSpecTokenType p
);
}

private NftResponse convertToNftResponse(NonFungibleToken nonFungibleToken) {
return new NftResponse(
nonFungibleToken.getLinearId().toString(),
nonFungibleToken.getIssuer().getName().toString(),
nonFungibleToken.getHolder().toString(),
nonFungibleToken.getToken().getTokenType().toString()
);
}

public static class UpdateWrapper {
private StateAndRef<PrimitiveSpecTokenType> primitiveSpecTokenTypeStateAndRef;
private UpdateType updateType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu._5gzorro.manager.service;

import eu._5gzorro.tm_forum.models.spectoken.GetPrimitiveSpectokenResponse;
import eu._5gzorro.tm_forum.models.spectoken.NftResponse;

import javax.validation.constraints.NotNull;
import java.util.Date;
Expand Down Expand Up @@ -30,4 +31,6 @@ void createPrimitiveSpectoken(
List<GetPrimitiveSpectokenResponse> getPrimitiveSpectokens() throws ExecutionException, InterruptedException;

void invalidatePrimitiveSpectoken(String licenseId);

List<NftResponse> getNfts();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package eu._5gzorro.tm_forum.models.spectoken;

public class NftResponse {

private final String id;

private final String issuer;

private final String holder;

private final String tokenType;

public NftResponse(String id, String issuer, String holder, String tokenType) {
this.id = id;
this.issuer = issuer;
this.holder = holder;
this.tokenType = tokenType;
}

public String getId() {
return id;
}

public String getIssuer() {
return issuer;
}

public String getHolder() {
return holder;
}

public String getTokenType() {
return tokenType;
}

}

0 comments on commit 4c4b4b7

Please sign in to comment.