Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- draft first nft contract #70

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/main/java/org/unichain/core/actuator/ActuatorFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ private static Actuator getActuatorByContract(final BlockCapsule block, final Co
return new AccountPermissionUpdateActuator(contract.getParameter(), manager);
case UpdateBrokerageContract:
return new UpdateBrokerageActuator(contract.getParameter(), manager);
case CreateNftTemplateContract:
return new NftCreateTemplateActuator(contract.getParameter(), manager);
default:
break;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/unichain/core/db/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
@Slf4j(topic = "DB")
@Component
public class Manager {
@Autowired
@Getter
private NftTemplateStore nftTemplateStore;

@Getter
@Autowired
private DelegationStore delegationStore;
Expand Down Expand Up @@ -1844,6 +1848,7 @@ public void setAccountIndexStore(AccountIndexStore indexStore) {

public void closeAllStore() {
logger.warn("******** begin to close db ********");
closeOneStore(nftTemplateStore);
closeOneStore(accountStore);
closeOneStore(blockStore);
closeOneStore(blockIndexStore);
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/unichain/core/services/RpcApiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,19 @@ public void withdrawBalance(Contract.WithdrawBalanceContract request, StreamObse
responseObserver.onCompleted();
}

/**
*/
@Override
public void createNftTemplate(Contract.CreateNftTemplateContract request, StreamObserver<Transaction> responseObserver) {
try {
responseObserver.onNext(createTransactionCapsule(request, ContractType.CreateNftTemplateContract).getInstance());
} catch (ContractValidateException e) {
responseObserver.onNext(null);
logger.debug(CONTRACT_VALIDATE_EXCEPTION, e.getMessage());
}
responseObserver.onCompleted();
}

/**
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class FullNodeHttpApiService implements Service {
@Autowired
private CreateAssetIssueServlet createAssetIssueServlet;

@Autowired
private CreateNftTemplateServlet createNftTemplateServlet;

@Autowired
private CreateTokenServlet createTokenServlet;
@Autowired
Expand Down Expand Up @@ -257,6 +260,8 @@ public void start() {
context.addServlet(new ServletHolder(createAssetIssueServlet), "/createassetissue");


context.addServlet(new ServletHolder(createNftTemplateServlet), "/createnfttemplate");

context.addServlet(new ServletHolder(createTokenServlet), "/createtoken");
context.addServlet(new ServletHolder(transferTokenOwnerServlet), "/transfertokenowner");
context.addServlet(new ServletHolder(exchangeTokenServlet), "/exchangetoken");
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/unichain/core/services/http/utils/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ public static JSONObject printTransactionToJSON(Transaction transaction, boolean
WithdrawFutureTokenContract withdrawFutureTokenContract = contractParameter.unpack(WithdrawFutureTokenContract.class);
contractJson = JSONObject.parseObject(JsonFormat.printToString(withdrawFutureTokenContract, selfType));
break;
case CreateNftTemplateContract:
CreateNftTemplateContract createNftTemplateContract = contractParameter.unpack(CreateNftTemplateContract.class);
contractJson = JSONObject.parseObject(JsonFormat.printToString(createNftTemplateContract, selfType));
break;
default:
}
JSONObject parameter = new JSONObject();
Expand Down Expand Up @@ -575,6 +579,11 @@ public static Transaction packTransaction(String strTransaction, boolean selfTyp
JsonFormat.merge(parameter.getJSONObject(VALUE).toJSONString(), withdrawFutureTokenContractBuilder, selfType);
any = Any.pack(withdrawFutureTokenContractBuilder.build());
break;
case "CreateNftTemplateContract":
CreateNftTemplateContract.Builder createNftTemplateContractBuilder = CreateNftTemplateContract.newBuilder();
JsonFormat.merge(parameter.getJSONObject(VALUE).toJSONString(), createNftTemplateContractBuilder, selfType);
any = Any.pack(createNftTemplateContractBuilder.build());
break;
default:
}
if (any != null) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/protos/api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ service Wallet {
rpc CreateAssetIssue2 (AssetIssueContract) returns (TransactionExtention) {
};

rpc CreateNftTemplate (CreateNftTemplateContract) returns (Transaction) {
option (google.api.http) = {
post: "/wallet/createnfttemplate"
body: "*"
additional_bindings {
get: "/wallet/createnfttemplate"
}
};
};

rpc CreateToken (CreateTokenContract) returns (Transaction) {
option (google.api.http) = {
post: "/wallet/createtoken"
Expand Down
17 changes: 17 additions & 0 deletions src/main/protos/core/Contract.proto
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,21 @@ message AccountPermissionUpdateContract {
message UpdateBrokerageContract {
bytes owner_address = 1;
int32 brokerage = 2; // 1 mean 1%
}

message CreateNftTemplateContract{
string symbol = 1;
string name = 2;
int64 total_supply = 3;
bytes minter = 4;
bytes owner = 5;
}

message MintNftTokenContract{
bytes owner_address = 1;
bytes to_address = 2;
int64 token_id = 3;
string uri = 4;
string metadata = 5;
int64 available_time = 6;
}
67 changes: 66 additions & 1 deletion src/main/protos/core/Unichain.proto
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ message Transaction {
WithdrawFutureTokenContract = 60;
TransferTokenOwnerContract = 61;
ExchangeTokenContract = 62;
CreateNftTemplateContract = 63;
}
ContractType type = 1;
google.protobuf.Any parameter = 2;
Expand Down Expand Up @@ -767,4 +768,68 @@ message NodeInfo {
string stackTrace = 7;
}
}
}
}

message NftTemplate{
string symbol = 1;
string name = 2;
int64 total_supply = 3;
int64 token_index = 4;
bytes minter = 5;
bytes owner = 6;
int64 last_operation = 7;
}

message NftToken{
string nft_template_id = 1;
int64 id = 2;
bytes owner_address = 3;
bytes approval = 4;
string uri = 5;
string metadata = 6;
int64 last_operation = 7;
int64 expire_time = 8;
}

message NftAccountTokenRelation{
bytes prev = 1;
bytes next = 2;
bytes token_id = 3;
bytes approval_all = 4;
int64 total = 5;
}

message NftAccountTemplateRelation{
bytes prev = 1;
bytes next = 2;
bytes template_id = 3;
int64 total = 5;
}

message NftTemplateQuery{
bytes owner_address = 1;
int64 page_size = 2;
int64 page_index = 3;
}

message NftTemplateQueryResult{
bytes owner_address = 1;
int64 page_size = 2;
int64 page_index = 3;
int64 total = 4;
repeated NftTemplate templates = 5;
}

message NftTokenQuery{
bytes owner_address = 1;
string symbol = 2;
int64 page_size = 3;
int64 page_index = 4;
}

message NftTokenQueryResult{
int64 page_size = 1;
int64 page_index = 2;
int64 total = 3;
repeated NftToken tokens = 4;
}