-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95ff6fe
commit 6d5288a
Showing
4 changed files
with
102 additions
and
102 deletions.
There are no files selected for viewing
42 changes: 21 additions & 21 deletions
42
src/main/java/zerobibim/flory/domain/purchase/controller/NftController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
package zerobibim.flory.domain.purchase.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.web3j.protocol.core.methods.response.TransactionReceipt; | ||
import zerobibim.flory.domain.purchase.dto.request.NFTRequestDto; | ||
import zerobibim.flory.domain.purchase.service.Web3jService; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/nft") | ||
public class NftController { | ||
private final Web3jService web3jService; | ||
// Define your API endpoints here | ||
@PostMapping("/mint") | ||
public TransactionReceipt mintToken() throws Exception { | ||
return web3jService.nftCreate(new NFTRequestDto.MemberNFTInfo("0x06f5ad6ca1fdbba1ac90b64472a36ca58a83b8af", "ipfs://QmVumYTYwP4F1DVLmaE527g7JDfB6Z1tzYFm8VE3zGPo1M")); | ||
} | ||
} | ||
//package zerobibim.flory.domain.purchase.controller; | ||
// | ||
//import lombok.RequiredArgsConstructor; | ||
//import org.springframework.web.bind.annotation.PostMapping; | ||
//import org.springframework.web.bind.annotation.RequestMapping; | ||
//import org.springframework.web.bind.annotation.RestController; | ||
//import org.web3j.protocol.core.methods.response.TransactionReceipt; | ||
//import zerobibim.flory.domain.purchase.dto.request.NFTRequestDto; | ||
//import zerobibim.flory.domain.purchase.service.Web3jService; | ||
// | ||
//@RestController | ||
//@RequiredArgsConstructor | ||
//@RequestMapping("/api/nft") | ||
//public class NftController { | ||
// private final Web3jService web3jService; | ||
// // Define your API endpoints here | ||
// @PostMapping("/mint") | ||
// public TransactionReceipt mintToken() throws Exception { | ||
// return web3jService.nftCreate(new NFTRequestDto.MemberNFTInfo("0x06f5ad6ca1fdbba1ac90b64472a36ca58a83b8af", "ipfs://QmVumYTYwP4F1DVLmaE527g7JDfB6Z1tzYFm8VE3zGPo1M")); | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 25 additions & 25 deletions
50
src/main/java/zerobibim/flory/domain/purchase/service/Web3jService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
package zerobibim.flory.domain.purchase.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.web3j.protocol.core.methods.response.*; | ||
import zerobibim.flory.domain.contract.NFT; | ||
import zerobibim.flory.domain.purchase.dto.request.NFTRequestDto; | ||
|
||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Service | ||
public class Web3jService { | ||
|
||
private final NFT nft; | ||
|
||
public TransactionReceipt nftCreate(NFTRequestDto.MemberNFTInfo memberNFTInfo) throws Exception { | ||
|
||
return nft.create(memberNFTInfo.getWalletAddress(), memberNFTInfo.getIpfsUrl()) | ||
.sendAsync() | ||
.get(); | ||
} | ||
|
||
} | ||
//package zerobibim.flory.domain.purchase.service; | ||
// | ||
//import lombok.RequiredArgsConstructor; | ||
//import lombok.extern.slf4j.Slf4j; | ||
//import org.springframework.stereotype.Service; | ||
//import org.web3j.protocol.core.methods.response.*; | ||
//import zerobibim.flory.domain.contract.NFT; | ||
//import zerobibim.flory.domain.purchase.dto.request.NFTRequestDto; | ||
// | ||
// | ||
//@Slf4j | ||
//@RequiredArgsConstructor | ||
//@Service | ||
//public class Web3jService { | ||
// | ||
// private final NFT nft; | ||
// | ||
// public TransactionReceipt nftCreate(NFTRequestDto.MemberNFTInfo memberNFTInfo) throws Exception { | ||
// | ||
// return nft.create(memberNFTInfo.getWalletAddress(), memberNFTInfo.getIpfsUrl()) | ||
// .sendAsync() | ||
// .get(); | ||
// } | ||
// | ||
//} |
94 changes: 47 additions & 47 deletions
94
src/main/java/zerobibim/flory/global/config/Web3jConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
package zerobibim.flory.global.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.web3j.crypto.Credentials; | ||
import org.web3j.crypto.ECKeyPair; | ||
import org.web3j.protocol.Web3j; | ||
import org.web3j.protocol.http.HttpService; | ||
import org.web3j.tx.Contract; | ||
import org.web3j.tx.gas.StaticGasProvider; | ||
import zerobibim.flory.domain.contract.NFT; | ||
|
||
import java.math.BigInteger; | ||
|
||
@Configuration | ||
public class Web3jConfig { | ||
|
||
@Value("${infura.API_URL}") | ||
private String INFURA_API_URL; | ||
|
||
@Value("${metamask.PRIVATE_KEY}") | ||
private String PRIVATE_KEY; | ||
|
||
@Value("${metamask.CONTRACT_ADDRESS}") | ||
private String CONTRACT_ADDRESS; | ||
|
||
@Bean | ||
public Web3j web3j() { | ||
return Web3j.build(new HttpService(INFURA_API_URL)); | ||
} | ||
|
||
@Bean | ||
public Credentials credentials() { | ||
BigInteger privateKeyInBT = new BigInteger(PRIVATE_KEY, 16); | ||
return Credentials.create(ECKeyPair.create(privateKeyInBT)); | ||
} | ||
|
||
@Bean | ||
public NFT nft() { | ||
BigInteger gasPrice = Contract.GAS_PRICE; | ||
BigInteger gasLimit = Contract.GAS_LIMIT; | ||
//StaticGasProvider gasProvider = new StaticGasProvider(gasPrice, gasLimit); | ||
|
||
return NFT.load(CONTRACT_ADDRESS, web3j(), credentials(), gasPrice, gasLimit); | ||
} | ||
} | ||
//package zerobibim.flory.global.config; | ||
// | ||
//import org.springframework.beans.factory.annotation.Value; | ||
//import org.springframework.context.annotation.Bean; | ||
//import org.springframework.context.annotation.Configuration; | ||
//import org.web3j.crypto.Credentials; | ||
//import org.web3j.crypto.ECKeyPair; | ||
//import org.web3j.protocol.Web3j; | ||
//import org.web3j.protocol.http.HttpService; | ||
//import org.web3j.tx.Contract; | ||
//import org.web3j.tx.gas.StaticGasProvider; | ||
//import zerobibim.flory.domain.contract.NFT; | ||
// | ||
//import java.math.BigInteger; | ||
// | ||
//@Configuration | ||
//public class Web3jConfig { | ||
// | ||
// @Value("${infura.API_URL}") | ||
// private String INFURA_API_URL; | ||
// | ||
// @Value("${metamask.PRIVATE_KEY}") | ||
// private String PRIVATE_KEY; | ||
// | ||
// @Value("${metamask.CONTRACT_ADDRESS}") | ||
// private String CONTRACT_ADDRESS; | ||
// | ||
// @Bean | ||
// public Web3j web3j() { | ||
// return Web3j.build(new HttpService(INFURA_API_URL)); | ||
// } | ||
// | ||
// @Bean | ||
// public Credentials credentials() { | ||
// BigInteger privateKeyInBT = new BigInteger(PRIVATE_KEY, 16); | ||
// return Credentials.create(ECKeyPair.create(privateKeyInBT)); | ||
// } | ||
// | ||
// @Bean | ||
// public NFT nft() { | ||
// BigInteger gasPrice = Contract.GAS_PRICE; | ||
// BigInteger gasLimit = Contract.GAS_LIMIT; | ||
// //StaticGasProvider gasProvider = new StaticGasProvider(gasPrice, gasLimit); | ||
// | ||
// return NFT.load(CONTRACT_ADDRESS, web3j(), credentials(), gasPrice, gasLimit); | ||
// } | ||
//} |