7 changed files with 126 additions and 4 deletions
@ -0,0 +1,23 @@
|
||||
package com.nft.api; |
||||
|
||||
import com.nft.service.NftCastingService; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
/** |
||||
* @Author _007long |
||||
* @Date 2022 05 27 |
||||
**/ |
||||
@RequestMapping("/conflux") |
||||
@RestController |
||||
public class NftApi { |
||||
@Autowired |
||||
private NftCastingService castingService; |
||||
|
||||
@GetMapping("getUrl") |
||||
public String getUrl() { |
||||
return castingService.startCasting(); |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
package com.nft.config; |
||||
|
||||
import lombok.Data; |
||||
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
/** |
||||
* @Author _007long |
||||
* @Date 2022 05 27 |
||||
**/ |
||||
@Data |
||||
@Component |
||||
@ConfigurationProperties(prefix ="conflux") |
||||
public class NftConfig { |
||||
//合约
|
||||
private String contract; |
||||
//拥有者
|
||||
private String owner; |
||||
//私钥
|
||||
private String privateKey; |
||||
//chainId
|
||||
private String chainId; |
||||
//上链地址
|
||||
private String nodeUrl; |
||||
} |
@ -0,0 +1,13 @@
|
||||
package com.nft.service; |
||||
|
||||
/** |
||||
* 铸造接口 |
||||
*/ |
||||
|
||||
public interface NftCastingService { |
||||
/** |
||||
* 开始铸造 |
||||
* @return |
||||
*/ |
||||
String startCasting(); |
||||
} |
@ -0,0 +1,49 @@
|
||||
package com.nft.service.impl; |
||||
|
||||
import com.nft.config.NftConfig; |
||||
import com.nft.service.NftCastingService; |
||||
import com.nft.util.AESUtil; |
||||
import conflux.web3j.Account; |
||||
import conflux.web3j.Cfx; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.math.BigInteger; |
||||
|
||||
/** |
||||
* @Author _007long |
||||
* @Date 2022 05 27 |
||||
**/ |
||||
@Service |
||||
@Slf4j |
||||
public class NftCastingServiceImpl implements NftCastingService { |
||||
@Autowired |
||||
private NftConfig config; |
||||
|
||||
@Override |
||||
public String startCasting() { |
||||
try { |
||||
Cfx cfx = Cfx.create(config.getNodeUrl(), 3, 1000); |
||||
Account account = Account.create(cfx, AESUtil.decrypt(config.getPrivateKey())); |
||||
Account.Option opt = new Account.Option(); |
||||
opt.withValue(BigInteger.ZERO); |
||||
opt.withChainId(new BigInteger(config.getChainId())); |
||||
opt.withEpochHeight(cfx.getEpochNumber().sendAndGet()); |
||||
opt.withGasPrice(new BigInteger("1000000000")); |
||||
//获取余额
|
||||
BigInteger balance = cfx.getBalance(account.getAddress()).sendAndGet(); |
||||
log.info("[mintNft][balance]{}", balance); |
||||
if (balance.compareTo(new BigInteger("100000000000000000000")) < 0) { |
||||
log.info("[mintNft][balance not enough 100]{}", balance); |
||||
//sms notice
|
||||
//余额不足
|
||||
return null; |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return null; |
||||
} |
||||
} |
Loading…
Reference in new issue