Skip to content

Commit

Permalink
Merge pull request #85 from junjie-bianjie/master
Browse files Browse the repository at this point in the history
Support latest nft proto
  • Loading branch information
prolenking authored Aug 18, 2022
2 parents a6a71df + 5efb117 commit b06fa9e
Show file tree
Hide file tree
Showing 14 changed files with 296 additions and 178 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.bianjieai</groupId>
<artifactId>opb-sdk</artifactId>
<version>0.1.12-rc4</version>
<version>0.1.12-rc5</version>
<url>https://github.com/bianjieai/opb-sdk-java</url>
<name>opb-sdk</name>
<licenses>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/irita/sdk/module/nft/EditNFTRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class EditNFTRequest {
private String id = "";
private String name = "";
private String uri = "";
private String uriHash = "";
private String data = "";

public String getDenom() {
Expand Down Expand Up @@ -43,6 +44,15 @@ public EditNFTRequest setUri(String uri) {
return this;
}

public String getUriHash() {
return uriHash;
}

public EditNFTRequest setUriHash(String uriHash) {
this.uriHash = uriHash;
return this;
}

public String getData() {
return data;
}
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/irita/sdk/module/nft/IssueDenomRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ public class IssueDenomRequest {
private String symbol = "";
private boolean mintRestricted;
private boolean updateRestricted;
private String uri = "";
private String uriHash = "";
private String Data = "";

public String getId() {
return id;
Expand Down Expand Up @@ -61,4 +64,31 @@ public IssueDenomRequest setUpdateRestricted(boolean updateRestricted) {
this.updateRestricted = updateRestricted;
return this;
}

public String getUri() {
return uri;
}

public IssueDenomRequest setUri(String uri) {
this.uri = uri;
return this;
}

public String getUriHash() {
return uriHash;
}

public IssueDenomRequest setUriHash(String uriHash) {
this.uriHash = uriHash;
return this;
}

public String getData() {
return Data;
}

public IssueDenomRequest setData(String data) {
Data = data;
return this;
}
}
10 changes: 10 additions & 0 deletions src/main/java/irita/sdk/module/nft/MintNFTRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class MintNFTRequest {
private String id = "";
private String name = "";
private String uri = "";
private String uriHash = "";
private String data = "";
private String recipient = "";

Expand Down Expand Up @@ -44,6 +45,15 @@ public MintNFTRequest setUri(String uri) {
return this;
}

public String getUriHash() {
return uriHash;
}

public MintNFTRequest setUriHash(String uriHash) {
this.uriHash = uriHash;
return this;
}

public String getData() {
return data;
}
Expand Down
33 changes: 28 additions & 5 deletions src/main/java/irita/sdk/module/nft/NftClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public ResultTx issueDenom(IssueDenomRequest req, BaseTx baseTx) throws IOExcept
.setSymbol(req.getSymbol())
.setMintRestricted(req.isMintRestricted())
.setUpdateRestricted(req.isUpdateRestricted())
.setUri(req.getUri())
.setUriHash(req.getUriHash())
.setData(req.getData())
.setSender(account.getAddress())
.build();
List<GeneratedMessageV3> msgs = Collections.singletonList(msg);
Expand All @@ -65,6 +68,7 @@ public ResultTx mintNft(MintNFTRequest req, BaseTx baseTx) throws IOException {
.setId(req.getId())
.setName(req.getName())
.setUri(req.getUri())
.setUriHash(req.getUriHash())
.setData(req.getData())
.setSender(account.getAddress());

Expand All @@ -88,6 +92,9 @@ public ResultTx editNft(EditNFTRequest req, BaseTx baseTx) throws IOException {
if (StringUtils.isEmpty(req.getName())) {
req.setName(DO_NOT_MODIFY);
}
if (StringUtils.isEmpty(req.getUriHash())) {
req.setUriHash(DO_NOT_MODIFY);
}

Account account = baseClient.queryAccount(baseTx);
Tx.MsgEditNFT msg = Tx.MsgEditNFT
Expand All @@ -96,6 +103,7 @@ public ResultTx editNft(EditNFTRequest req, BaseTx baseTx) throws IOException {
.setId(req.getId())
.setName(req.getName())
.setUri(req.getUri())
.setUriHash(req.getUriHash())
.setData(req.getData())
.setSender(account.getAddress())
.build();
Expand All @@ -113,6 +121,9 @@ public ResultTx transferNFt(TransferNFTRequest req, BaseTx baseTx) throws IOExce
if (StringUtils.isEmpty(req.getName())) {
req.setName(DO_NOT_MODIFY);
}
if (StringUtils.isEmpty(req.getUriHash())) {
req.setUriHash(DO_NOT_MODIFY);
}

Account account = baseClient.queryAccount(baseTx);
Tx.MsgTransferNFT.Builder builder = Tx.MsgTransferNFT
Expand All @@ -122,6 +133,7 @@ public ResultTx transferNFt(TransferNFTRequest req, BaseTx baseTx) throws IOExce
.setUri(req.getUri())
.setData(req.getData())
.setName(req.getName())
.setUriHash(req.getUriHash())
.setSender(account.getAddress());

if (StringUtils.isEmpty(req.getRecipient())) {
Expand Down Expand Up @@ -159,14 +171,21 @@ public long querySupply(String denomID, String owner) {
return resp.getAmount();
}

public QueryOwnerResp queryOwner(String denomID, String owner) {
public QueryOwnerResp queryOwner(String denomID, String owner, Pagination.PageRequest page) {
Channel channel = baseClient.getGrpcClient();
QueryOuterClass.QueryOwnerRequest req = QueryOuterClass.QueryOwnerRequest
QueryOuterClass.QueryOwnerRequest.Builder builder = QueryOuterClass.QueryOwnerRequest
.newBuilder()
.setDenomId(Optional.ofNullable(denomID).orElse(""))
.setOwner(owner)
.build();
.setOwner(owner);

if (page == null) {
page = Pagination.PageRequest.newBuilder()
.setOffset(0)
.setLimit(100)
.build();
}
builder.setPagination(page);
QueryOuterClass.QueryOwnerRequest req = builder.build();
QueryOuterClass.QueryOwnerResponse resp = QueryGrpc.newBlockingStub(channel).owner(req);
return Convert.toQueryOwnerResp(resp.getOwner());
}
Expand Down Expand Up @@ -256,7 +275,7 @@ public static QueryCollectionResp toQueryCollectionResp(Nft.Collection collectio
}

QueryCollectionResp res = new QueryCollectionResp();
res.setDenom(new QueryDenomResp(denom.getId(), denom.getName(), denom.getSchema(), denom.getCreator(),denom.getSymbol(),denom.getMintRestricted(),denom.getUpdateRestricted()));
res.setDenom(new QueryDenomResp(denom.getId(), denom.getName(), denom.getSchema(), denom.getSymbol(), denom.getMintRestricted(), denom.getUpdateRestricted(), denom.getUri(), denom.getUriHash(), denom.getData(), denom.getCreator()));
res.setNfts(nfts);
return res;
}
Expand All @@ -268,6 +287,9 @@ public static QueryDenomResp toQueryDenomResp(Nft.Denom denom) {
res.setSchema(denom.getSchema());
res.setCreator(denom.getCreator());
res.setSymbol(denom.getSymbol());
res.setUri(denom.getUri());
res.setUriHash(denom.getUriHash());
res.setData(denom.getData());
res.setMintRestricted(denom.getMintRestricted());
res.setUpdateRestricted(denom.getUpdateRestricted());
return res;
Expand All @@ -287,6 +309,7 @@ public static QueryNFTResp toQueryNFTResp(Nft.BaseNFT baseNFT) {
res.setId(baseNFT.getId());
res.setName(baseNFT.getName());
res.setUri(baseNFT.getUri());
res.setUriHash(baseNFT.getUriHash());
res.setData(baseNFT.getData());
res.setOwner(baseNFT.getOwner());
return res;
Expand Down
55 changes: 39 additions & 16 deletions src/main/java/irita/sdk/module/nft/QueryDenomResp.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,24 @@ public class QueryDenomResp {
private String symbol;
private boolean mintRestricted;
private boolean updateRestricted;
private String uri;
private String uriHash;
private String data;
private String creator;

public QueryDenomResp() {
}

public QueryDenomResp(String id, String name, String schema, String creator) {
this.id = id;
this.name = name;
this.schema = schema;
this.creator = creator;
}

public QueryDenomResp(String id, String name, String schema, String creator, String symbol, boolean mintRestricted, boolean updateRestricted) {
public QueryDenomResp(String id, String name, String schema, String symbol, boolean mintRestricted, boolean updateRestricted, String uri, String uriHash, String data, String creator) {
this.id = id;
this.name = name;
this.schema = schema;
this.symbol = symbol;
this.mintRestricted = mintRestricted;
this.updateRestricted = updateRestricted;
this.uri = uri;
this.uriHash = uriHash;
this.data = data;
this.creator = creator;
}

Expand Down Expand Up @@ -53,14 +52,6 @@ public void setSchema(String schema) {
this.schema = schema;
}

public String getCreator() {
return creator;
}

public void setCreator(String creator) {
this.creator = creator;
}

public String getSymbol() {
return symbol;
}
Expand All @@ -84,4 +75,36 @@ public boolean isUpdateRestricted() {
public void setUpdateRestricted(boolean updateRestricted) {
this.updateRestricted = updateRestricted;
}

public String getUri() {
return uri;
}

public void setUri(String uri) {
this.uri = uri;
}

public String getUriHash() {
return uriHash;
}

public void setUriHash(String uriHash) {
this.uriHash = uriHash;
}

public String getData() {
return data;
}

public void setData(String data) {
this.data = data;
}

public String getCreator() {
return creator;
}

public void setCreator(String creator) {
this.creator = creator;
}
}
9 changes: 9 additions & 0 deletions src/main/java/irita/sdk/module/nft/QueryNFTResp.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class QueryNFTResp {
private String id;
private String name;
private String uri;
private String uriHash;
private String data;
private String owner;

Expand Down Expand Up @@ -31,6 +32,14 @@ public void setUri(String uri) {
this.uri = uri;
}

public String getUriHash() {
return uriHash;
}

public void setUriHash(String uriHash) {
this.uriHash = uriHash;
}

public String getData() {
return data;
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/irita/sdk/module/nft/TransferNFTRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class TransferNFTRequest {
private String denom = "";
private String id = "";
private String uri = "";
private String uriHash = "";
private String data = "";
private String name = "";
private String recipient = "";
Expand Down Expand Up @@ -35,6 +36,15 @@ public TransferNFTRequest setUri(String uri) {
return this;
}

public String getUriHash() {
return uriHash;
}

public TransferNFTRequest setUriHash(String uriHash) {
this.uriHash = uriHash;
return this;
}

public String getData() {
return data;
}
Expand Down
12 changes: 0 additions & 12 deletions src/main/proto/nft/genesis.proto

This file was deleted.

Loading

0 comments on commit b06fa9e

Please sign in to comment.