diff --git a/app/src/main/java/eu/_5gzorro/manager/api/controller/SpectokenController.java b/app/src/main/java/eu/_5gzorro/manager/api/controller/SpectokenController.java index e703731..d2cb509 100644 --- a/app/src/main/java/eu/_5gzorro/manager/api/controller/SpectokenController.java +++ b/app/src/main/java/eu/_5gzorro/manager/api/controller/SpectokenController.java @@ -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; @@ -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 nftResponses = primitiveSpectokenDriver.getNfts(); + return ResponseEntity.ok().body(nftResponses); + } + @ApiResponses(value = { @ApiResponse( responseCode = "200", diff --git a/corda-driver/driver-impl/src/main/java/eu/_5gzorro/manager/dlt/corda/service/spectoken/CordaPrimitiveSpectokenDriver.java b/corda-driver/driver-impl/src/main/java/eu/_5gzorro/manager/dlt/corda/service/spectoken/CordaPrimitiveSpectokenDriver.java index 2e54ce9..e689ea0 100644 --- a/corda-driver/driver-impl/src/main/java/eu/_5gzorro/manager/dlt/corda/service/spectoken/CordaPrimitiveSpectokenDriver.java +++ b/corda-driver/driver-impl/src/main/java/eu/_5gzorro/manager/dlt/corda/service/spectoken/CordaPrimitiveSpectokenDriver.java @@ -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; @@ -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; @@ -144,6 +146,16 @@ public void invalidatePrimitiveSpectoken(String licenseId) { } } + @Override + public List getNfts() { + Vault.Page nonFungibleTokenPage = rpcClient.vaultQuery(NonFungibleToken.class); + List nfts = new ArrayList<>(); + for (StateAndRef nonFungibleToken : nonFungibleTokenPage.getStates()) { + nfts.add(convertToNftResponse(nonFungibleToken.getState().getData())); + } + return nfts; + } + private GetPrimitiveSpectokenResponse convertToResponse(PrimitiveSpecTokenType primitiveSpecTokenType) { return new GetPrimitiveSpectokenResponse( primitiveSpecTokenType.getLinearId().toString(), @@ -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 primitiveSpecTokenTypeStateAndRef; private UpdateType updateType; diff --git a/dlt-driver-api/src/main/java/eu/_5gzorro/manager/service/PrimitiveSpectokenDriver.java b/dlt-driver-api/src/main/java/eu/_5gzorro/manager/service/PrimitiveSpectokenDriver.java index 2ee5893..3b7a08e 100644 --- a/dlt-driver-api/src/main/java/eu/_5gzorro/manager/service/PrimitiveSpectokenDriver.java +++ b/dlt-driver-api/src/main/java/eu/_5gzorro/manager/service/PrimitiveSpectokenDriver.java @@ -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; @@ -30,4 +31,6 @@ void createPrimitiveSpectoken( List getPrimitiveSpectokens() throws ExecutionException, InterruptedException; void invalidatePrimitiveSpectoken(String licenseId); + + List getNfts(); } diff --git a/tm-forum/src/main/java/eu/_5gzorro/tm_forum/models/spectoken/NftResponse.java b/tm-forum/src/main/java/eu/_5gzorro/tm_forum/models/spectoken/NftResponse.java new file mode 100644 index 0000000..e7ae7c8 --- /dev/null +++ b/tm-forum/src/main/java/eu/_5gzorro/tm_forum/models/spectoken/NftResponse.java @@ -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; + } + +}