-
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
a8bfcd3
commit e7fee8b
Showing
6 changed files
with
102 additions
and
82 deletions.
There are no files selected for viewing
25 changes: 0 additions & 25 deletions
25
src/main/java/zerobibim/flory/domain/contract/service/Web3jService.java
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
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 |
---|---|---|
@@ -0,0 +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")); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ry/domain/contract/dto/NFTRequestDto.java → ...n/purchase/dto/request/NFTRequestDto.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
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
25 changes: 25 additions & 0 deletions
25
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 |
---|---|---|
@@ -0,0 +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(); | ||
} | ||
|
||
} |
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); | ||
} | ||
} |