From 724ee542461ed56709ac734ed0cb6c120292ced9 Mon Sep 17 00:00:00 2001
From: long <18782126717@163.com>
Date: Fri, 27 May 2022 14:41:24 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=93=B8=E9=80=A0=E6=9C=8D?=
=?UTF-8?q?=E5=8A=A1=E5=86=85=E5=AE=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 7 +++
src/main/java/com/nft/api/NftApi.java | 23 +++++++++
src/main/java/com/nft/config/NftConfig.java | 25 ++++++++++
.../com/nft/service/NftCastingService.java | 13 +++++
.../service/impl/NftCastingServiceImpl.java | 49 +++++++++++++++++++
.../com/nft/util/{App.java => TestMint.java} | 5 +-
src/main/resources/application.yml | 8 ++-
7 files changed, 126 insertions(+), 4 deletions(-)
create mode 100644 src/main/java/com/nft/api/NftApi.java
create mode 100644 src/main/java/com/nft/config/NftConfig.java
create mode 100644 src/main/java/com/nft/service/NftCastingService.java
create mode 100644 src/main/java/com/nft/service/impl/NftCastingServiceImpl.java
rename src/main/java/com/nft/util/{App.java => TestMint.java} (96%)
diff --git a/pom.xml b/pom.xml
index c97918c..a226091 100644
--- a/pom.xml
+++ b/pom.xml
@@ -182,6 +182,13 @@
4.13.2
test
+
diff --git a/src/main/java/com/nft/api/NftApi.java b/src/main/java/com/nft/api/NftApi.java
new file mode 100644
index 0000000..8a04cf7
--- /dev/null
+++ b/src/main/java/com/nft/api/NftApi.java
@@ -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();
+ }
+}
diff --git a/src/main/java/com/nft/config/NftConfig.java b/src/main/java/com/nft/config/NftConfig.java
new file mode 100644
index 0000000..012f69c
--- /dev/null
+++ b/src/main/java/com/nft/config/NftConfig.java
@@ -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;
+}
diff --git a/src/main/java/com/nft/service/NftCastingService.java b/src/main/java/com/nft/service/NftCastingService.java
new file mode 100644
index 0000000..46d8785
--- /dev/null
+++ b/src/main/java/com/nft/service/NftCastingService.java
@@ -0,0 +1,13 @@
+package com.nft.service;
+
+/**
+ * 铸造接口
+ */
+
+public interface NftCastingService {
+ /**
+ * 开始铸造
+ * @return
+ */
+ String startCasting();
+}
diff --git a/src/main/java/com/nft/service/impl/NftCastingServiceImpl.java b/src/main/java/com/nft/service/impl/NftCastingServiceImpl.java
new file mode 100644
index 0000000..0dcfe43
--- /dev/null
+++ b/src/main/java/com/nft/service/impl/NftCastingServiceImpl.java
@@ -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;
+ }
+}
diff --git a/src/main/java/com/nft/util/App.java b/src/main/java/com/nft/util/TestMint.java
similarity index 96%
rename from src/main/java/com/nft/util/App.java
rename to src/main/java/com/nft/util/TestMint.java
index dd0201f..8d3f442 100644
--- a/src/main/java/com/nft/util/App.java
+++ b/src/main/java/com/nft/util/TestMint.java
@@ -6,6 +6,7 @@ import conflux.web3j.AccountManager;
import conflux.web3j.Cfx;
import conflux.web3j.CfxUnit;
import conflux.web3j.contract.ContractCall;
+import conflux.web3j.contract.ERC20;
import conflux.web3j.response.Receipt;
import conflux.web3j.response.Transaction;
import conflux.web3j.types.CfxAddress;
@@ -19,7 +20,7 @@ import java.io.IOException;
import java.math.BigInteger;
import java.util.Optional;
-public class App {
+public class TestMint {
public static final Cfx cfx = Cfx.create("https://test.confluxrpc.com");
public static final String privateKey="cfxtest:aapjjbzf3bumeatch25bduathv0xz9wk42e8yzd4r1";
public static void main(String[] args) throws Exception {
@@ -73,7 +74,7 @@ public class App {
//用ER721标准
public static void getERinit() {
// ERC721 erc721 = new ERC721(cfx, new CfxAddress(nftAddress), account);
-
+// ERC20 erc20=new ERC20(Cfx cfx, CfxAddress address, Account account);
}
// //转移资产
// public static void move(){
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 38aba91..538f405 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -27,13 +27,17 @@ mybatis:
configuration:
map-underscore-to-camel-case: true
#测试环境
-confluxNft:
+conflux:
#合约
contract: cfxtest:acbctakv35gyzcepnh14k239hw6tcw2t7edv34adn3
- # 执行地址
+ # 执行地址 (拥有者)
owner: cfxtest:aapjjbzf3bumeatch25bduathv0xz9wk42e8yzd4r1
###私钥位置
privateKey: 0xa31115fa5cf8fefd57fa0dea7ff013e2d71b8cf13a4d6a7e276c9c5b21bf911b
+ ###chainId
+ chainId: 1
+ ###上链地址
+ nodeUrl: https://test.confluxrpc.com
swagger:
show: true
# mybatis-plus