10 changed files with 1138 additions and 0 deletions
@ -0,0 +1,202 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<parent> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-parent</artifactId> |
||||
<version>2.3.0.RELEASE</version> |
||||
<relativePath/> <!-- lookup parent from repository --> |
||||
</parent> |
||||
<groupId>com.nft</groupId> |
||||
<artifactId>conflux-nft</artifactId> |
||||
<version>1.0-SNAPSHOT</version> |
||||
<name>conflux-nft</name> |
||||
<description>conflux-nft</description> |
||||
<properties> |
||||
<maven.compiler.source>8</maven.compiler.source> |
||||
<maven.compiler.target>8</maven.compiler.target> |
||||
<java.version>1.8</java.version> |
||||
</properties> |
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-aop</artifactId> |
||||
</dependency> |
||||
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> |
||||
<dependency> |
||||
<groupId>io.springfox</groupId> |
||||
<artifactId>springfox-swagger2</artifactId> |
||||
<version>2.8.0</version> |
||||
</dependency> |
||||
|
||||
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui --> |
||||
<dependency> |
||||
<groupId>io.springfox</groupId> |
||||
<artifactId>springfox-swagger-ui</artifactId> |
||||
<version>2.8.0</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>cn.hutool</groupId> |
||||
<artifactId>hutool-all</artifactId> |
||||
<version>5.0.6</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>commons-codec</groupId> |
||||
<artifactId>commons-codec</artifactId> |
||||
<version>1.10</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba</groupId> |
||||
<artifactId>fastjson</artifactId> |
||||
<version>1.2.57</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.web3j</groupId> |
||||
<artifactId>core</artifactId> |
||||
<version>4.5.11</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.bitcoinj</groupId> |
||||
<artifactId>bitcoinj-core</artifactId> |
||||
<version>0.15.3</version> |
||||
<scope>compile</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-data-redis</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.commons</groupId> |
||||
<artifactId>commons-lang3</artifactId> |
||||
<version>3.4</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>commons-collections</groupId> |
||||
<artifactId>commons-collections</artifactId> |
||||
<version>3.2.1</version> |
||||
</dependency> |
||||
|
||||
<!-- mybatisplus与springboot整合 --> |
||||
<dependency> |
||||
<groupId>com.baomidou</groupId> |
||||
<artifactId>mybatisplus-spring-boot-starter</artifactId> |
||||
<version>1.0.5</version> |
||||
</dependency> |
||||
<!-- MP 核心库 --> |
||||
<dependency> |
||||
<groupId>com.baomidou</groupId> |
||||
<artifactId>mybatis-plus</artifactId> |
||||
<version>2.1.8</version> |
||||
</dependency> |
||||
<!-- 模板引擎 代码生成 --> |
||||
<dependency> |
||||
<groupId>org.apache.velocity</groupId> |
||||
<artifactId>velocity</artifactId> |
||||
<version>1.7</version> |
||||
</dependency> |
||||
<!-- druid阿里巴巴数据库连接池 --> |
||||
<dependency> |
||||
<groupId>com.alibaba</groupId> |
||||
<artifactId>druid</artifactId> |
||||
<version>1.0.26</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>mysql</groupId> |
||||
<artifactId>mysql-connector-java</artifactId> |
||||
<version>8.0.19</version> |
||||
</dependency> |
||||
|
||||
|
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-web</artifactId> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>com.google.code.gson</groupId> |
||||
<artifactId>gson</artifactId> |
||||
<version>2.8.2</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.mybatis.spring.boot</groupId> |
||||
<artifactId>mybatis-spring-boot-starter</artifactId> |
||||
<version>1.3.2</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>commons-collections</groupId> |
||||
<artifactId>commons-collections</artifactId> |
||||
<version>3.2.1</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.google.guava</groupId> |
||||
<artifactId>guava</artifactId> |
||||
<version>21.0</version> |
||||
</dependency> |
||||
<!--lombok插件--> |
||||
<dependency> |
||||
<groupId>org.projectlombok</groupId> |
||||
<artifactId>lombok</artifactId> |
||||
<version>1.18.4</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>io.github.conflux-chain</groupId> |
||||
<artifactId>conflux.web3j</artifactId> |
||||
<version>1.1.0</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.squareup.okhttp3</groupId> |
||||
<artifactId>okhttp</artifactId> |
||||
<version>4.9.3</version> |
||||
</dependency> |
||||
<!--ipfs--> |
||||
<!-- <dependency> |
||||
<groupId>com.github.ipfs</groupId> |
||||
<artifactId>java-ipfs-http-client</artifactId> |
||||
<version>1.3.3</version> |
||||
</dependency>--> |
||||
<dependency> |
||||
<groupId>com.github.pagehelper</groupId> |
||||
<artifactId>pagehelper-spring-boot-starter</artifactId> |
||||
<version>1.2.5</version> |
||||
<exclusions> |
||||
<exclusion> |
||||
<groupId>org.mybatis</groupId> |
||||
<artifactId>mybatis</artifactId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-test</artifactId> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>junit</groupId> |
||||
<artifactId>junit</artifactId> |
||||
<version>4.13.2</version> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-surefire-plugin</artifactId> |
||||
<configuration> |
||||
<skipTests>true</skipTests> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
</project> |
@ -0,0 +1,15 @@
|
||||
package com.nft; |
||||
|
||||
import org.mybatis.spring.annotation.MapperScan; |
||||
import org.springframework.boot.SpringApplication; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
import org.springframework.scheduling.annotation.EnableScheduling; |
||||
|
||||
@SpringBootApplication(scanBasePackages = {"com.nft"}) |
||||
@MapperScan({"com.nft.mapper"}) |
||||
@EnableScheduling |
||||
public class ConfluxNftApplication { |
||||
public static void main(String[] args) { |
||||
SpringApplication.run(ConfluxNftApplication.class, args); |
||||
} |
||||
} |
@ -0,0 +1,176 @@
|
||||
package com.nft.util; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import javax.crypto.Cipher; |
||||
import javax.crypto.KeyGenerator; |
||||
import javax.crypto.SecretKey; |
||||
import javax.crypto.spec.SecretKeySpec; |
||||
import java.security.SecureRandom; |
||||
|
||||
/** |
||||
* AES加密解密工具类(提供对称加密) |
||||
*/ |
||||
@Slf4j |
||||
public final class AESUtil { |
||||
// 加密密钥
|
||||
private static String KEY = "zyxXV3mYqgEuXk02IJQnLwQ7cb2LkOSv"; |
||||
// 默认字符集
|
||||
private static final String DEFAULT_CHARSET = "UTF-8"; |
||||
// 加密方式
|
||||
private static final String KEY_AES = "AES"; |
||||
// 加密模式
|
||||
private static final int EN_CODE = Cipher.ENCRYPT_MODE; |
||||
// 解密模式
|
||||
private static final int DE_CODE = Cipher.DECRYPT_MODE; |
||||
|
||||
/** |
||||
* k |
||||
* 加密 |
||||
* |
||||
* @param data 需要加密的数据 |
||||
* @return 返回加密后的结果 |
||||
*/ |
||||
public static String encrypt(String data) throws Exception { |
||||
return doAES(data, KEY, EN_CODE); |
||||
} |
||||
|
||||
/** |
||||
* 解密 |
||||
* |
||||
* @param data 需要解密的数据 |
||||
* @return 返回解密后的结果 |
||||
*/ |
||||
public static String decrypt(String data) throws Exception { |
||||
return doAES(data, KEY, DE_CODE); |
||||
} |
||||
|
||||
/** |
||||
* 加密 |
||||
* |
||||
* @param data 需要加密的数据 |
||||
* @param key 需要加密的密钥 |
||||
* @return 返回解密后的结果 |
||||
*/ |
||||
public static String encrypt(String data, String key) throws Exception { |
||||
return doAES(data, key, EN_CODE); |
||||
} |
||||
|
||||
/** |
||||
* 解密 |
||||
* |
||||
* @param data 需要解密的数据 |
||||
* @param key 需要解密的密钥 |
||||
* @return 返回解密后的结果 |
||||
*/ |
||||
public static String decrypt(String data, String key) throws Exception { |
||||
return doAES(data, key, DE_CODE); |
||||
} |
||||
|
||||
/** |
||||
* 加密或解密方法 |
||||
* |
||||
* @param data 需要加密或解密的内容 |
||||
* @param key 加密或解密的密钥 |
||||
* @param model 处理模式 |
||||
* @return 返回处理结果 |
||||
*/ |
||||
private static String doAES(String data, String key, final int model) throws Exception { |
||||
try { |
||||
data = data == null ? "" : data; |
||||
key = key == null ? "" : key; |
||||
|
||||
if ("".equalsIgnoreCase(data) || "".equalsIgnoreCase(key)) { |
||||
return null; |
||||
} |
||||
|
||||
// 构造密钥生成器,指定为AES方式,不区分大小写
|
||||
KeyGenerator kgen = KeyGenerator.getInstance(KEY_AES); |
||||
|
||||
// 根据EcnodeRules规则初始化密钥生成器
|
||||
// 根据传入的字节数组,生成一个128位的随机源
|
||||
SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); |
||||
random.setSeed(key.getBytes("UTF-8")); |
||||
|
||||
// kgen.init(128, new SecureRandom(key.getBytes(DEFAULT_CHARSET)));
|
||||
|
||||
kgen.init(128, random); |
||||
|
||||
// 产生原始对称密钥
|
||||
SecretKey secretKey = kgen.generateKey(); |
||||
|
||||
// 获得原始对称密钥的字节数组
|
||||
byte[] enCodeFormat = secretKey.getEncoded(); |
||||
|
||||
// 根据字节数组生成AES密钥
|
||||
SecretKeySpec keySpec = new SecretKeySpec(enCodeFormat, KEY_AES); |
||||
|
||||
// 根据指定的AES算法创建密码器
|
||||
Cipher cipher = Cipher.getInstance(KEY_AES); |
||||
|
||||
// 初始化密码器,第一个参数为加密(Encrypt_mode)或者解密解密(Decrypt_mode)操作,第二个参数为使用的KEY
|
||||
cipher.init(model, keySpec); |
||||
|
||||
byte[] content; // 用于存储加密内容
|
||||
byte[] result; |
||||
switch (model) { |
||||
case EN_CODE: |
||||
content = data.getBytes(DEFAULT_CHARSET); |
||||
result = cipher.doFinal(content); |
||||
|
||||
// 将二进制转换成16进制
|
||||
return parseByte2HexStr(result); |
||||
case DE_CODE: |
||||
content = parseHexStr2Byte(data); |
||||
result = cipher.doFinal(content); |
||||
|
||||
// 将二进制转为字符串
|
||||
return new String(result, DEFAULT_CHARSET); |
||||
default: |
||||
throw new RuntimeException("The Encrypt Model Is Wrong!"); |
||||
} |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
log.info("====error" + org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace(e)); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 将二进制转换成16进制 |
||||
* |
||||
* @param buf 二进制数据 |
||||
* @return 返回16进制结果 |
||||
*/ |
||||
public static String parseByte2HexStr(byte[] buf) { |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (int i = 0; i < buf.length; i++) { |
||||
String hex = Integer.toHexString(buf[i] & 0xFF); |
||||
if (hex.length() == 1) { |
||||
hex = '0' + hex; |
||||
} |
||||
sb.append(hex.toUpperCase()); |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
|
||||
/** |
||||
* 将16进制转换为二进制 |
||||
* |
||||
* @param hexStr 16进制字符串 |
||||
* @return 返回二进制数据 |
||||
*/ |
||||
public static byte[] parseHexStr2Byte(String hexStr) { |
||||
if (hexStr.length() < 1) { |
||||
return null; |
||||
} |
||||
byte[] result = new byte[hexStr.length() / 2]; |
||||
for (int i = 0; i < hexStr.length() / 2; i++) { |
||||
int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16); |
||||
int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16); |
||||
result[i] = (byte) (high * 16 + low); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,27 @@
|
||||
package com.nft.util; |
||||
|
||||
public class AddressUtil { |
||||
|
||||
|
||||
public static String getNewTypeAddress(String old, int chainId) { |
||||
conflux.web3j.types.Address a = new conflux.web3j.types.Address(old, chainId); |
||||
return a.getVerboseAddress(); |
||||
} |
||||
|
||||
public static String getNewAddress(String old, int chainId) { |
||||
conflux.web3j.types.Address a = new conflux.web3j.types.Address(old, chainId); |
||||
return a.getAddress(); |
||||
} |
||||
|
||||
public static String getNewAddress(String typeAddress) { |
||||
conflux.web3j.types.Address a = new conflux.web3j.types.Address(typeAddress); |
||||
return a.getAddress(); |
||||
} |
||||
|
||||
|
||||
public static String getHexAddress(String typeAddress) { |
||||
conflux.web3j.types.Address a = new conflux.web3j.types.Address(typeAddress); |
||||
return a.getHexAddress(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,91 @@
|
||||
package com.nft.util; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import conflux.web3j.Account; |
||||
import conflux.web3j.AccountManager; |
||||
import conflux.web3j.Cfx; |
||||
import conflux.web3j.CfxUnit; |
||||
import conflux.web3j.contract.ContractCall; |
||||
import conflux.web3j.response.Receipt; |
||||
import conflux.web3j.response.Transaction; |
||||
import conflux.web3j.types.CfxAddress; |
||||
import conflux.web3j.types.RawTransaction; |
||||
import conflux.web3j.types.TransactionBuilder; |
||||
import conflux.web3j.types.Address; |
||||
import okhttp3.*; |
||||
import org.web3j.abi.datatypes.generated.Uint256; |
||||
|
||||
import java.io.IOException; |
||||
import java.math.BigInteger; |
||||
import java.util.Optional; |
||||
|
||||
public class App { |
||||
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 { |
||||
getinit(); |
||||
|
||||
|
||||
} |
||||
|
||||
/** |
||||
* 获取初始数据 |
||||
*/ |
||||
public static void getinit() { |
||||
// BigInteger currentEpochNumber = cfx.getEpochNumber().sendAndGet();
|
||||
// System.out.printf("Current epoch number %d--------->", currentEpochNumber);
|
||||
// //获取账户余额和随机数
|
||||
// Address addr = new Address("cfxtest:aapjjbzf3bumeatch25bduathv0xz9wk42e8yzd4r1");//onwer
|
||||
// //余额
|
||||
// BigInteger balance = cfx.getBalance(addr).sendAndGet();
|
||||
// // nonce will be used when sending transaction
|
||||
// //随机数
|
||||
// BigInteger nonce = cfx.getNonce(addr).sendAndGet();
|
||||
// System.out.println("余额balance result:"+balance);
|
||||
// System.out.println("随机数result:"+nonce);
|
||||
// //获取交易和收据
|
||||
|
||||
} |
||||
//
|
||||
public static void createAccountManager(){ |
||||
try { |
||||
AccountManager ac = new AccountManager(KeyChainId.CHAINID); |
||||
Address addr = new Address(privateKey); |
||||
String privatekey = ac.exportPrivateKey(addr, "cfxtest"); |
||||
|
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
//创建一个账户
|
||||
public static void createAccount(){ |
||||
Account a1 = Account.create(cfx, privateKey); |
||||
} |
||||
//获取交易和收据
|
||||
public static void getReceipt() { |
||||
String txhash = "0x10c3c6191f2a1960a14899ce01969aee3b1eca519901a7a92cea092769596449";// deploy后的文件下 "stateRoot": "0x10c3c6191f2a1960a14899ce01969aee3b1eca519901a7a92cea092769596449",
|
||||
Optional<Transaction> tx = cfx.getTransactionByHash(txhash).sendAndGet(); |
||||
Optional<Receipt> receipt = cfx.getTransactionReceipt(txhash).sendAndGet(); |
||||
System.out.println("交易:" + tx.toString()); |
||||
System.out.println("收据:" + receipt.toString()); |
||||
} |
||||
|
||||
//用ER721标准
|
||||
public static void getERinit() { |
||||
// ERC721 erc721 = new ERC721(cfx, new CfxAddress(nftAddress), account);
|
||||
|
||||
} |
||||
// //转移资产
|
||||
// public static void move(){
|
||||
// Address addr = new Address("cfxtest:aak2rra2njvd77ezwjvx04kkds9fzagfe6d5r8e957");
|
||||
// // transfer 1 CFX to addr, the transaction hash will returned
|
||||
// //String hash = account.transfer(addr, CfxUnit.cfx2Drip(1));
|
||||
//
|
||||
// // An optional parameter can be used to specify other fields of a transaction
|
||||
// Account.Option op = new Account.Option();
|
||||
// op.withGasPrice(CfxUnit.DEFAULT_GAS_PRICE);
|
||||
// BigInteger nonce = cfx.getNonce(account.getAddress()).sendAndGet();
|
||||
// BigInteger value = CfxUnit.cfx2Drip(1);
|
||||
// BigInteger currentEpochNumber = cfx.getEpochNumber().sendAndGet();
|
||||
// }
|
||||
} |
@ -0,0 +1,149 @@
|
||||
package com.nft.util; |
||||
|
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.web3j.abi.EventEncoder; |
||||
import org.web3j.abi.TypeReference; |
||||
import org.web3j.abi.datatypes.*; |
||||
import org.web3j.abi.datatypes.generated.Bytes32; |
||||
import org.web3j.abi.datatypes.generated.Uint256; |
||||
import org.web3j.abi.datatypes.generated.Uint32; |
||||
import org.web3j.utils.Numeric; |
||||
|
||||
import java.math.BigInteger; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author wangban |
||||
*/ |
||||
public class CfxUtils { |
||||
|
||||
public static final String ADDRESS = "address"; |
||||
public static final String UINT256 = "uint256"; |
||||
public static final String UINT32 = "uint32"; |
||||
public static final String Utf8String = "string"; |
||||
public static final String BOOL = "bool"; |
||||
public static final String BYTES = "bytes"; |
||||
public static final String BYTES32 = "bytes32"; |
||||
public static final String ARRAY = "array"; |
||||
public static final String UINT256_ARRAY = "uint256Array"; |
||||
public static final String ADDRESS_ARRAY = "addressArray"; |
||||
|
||||
public static String getEventKeccak(String method, List<String> inputParams) { |
||||
Event event = new Event(method, getTypes(inputParams)); |
||||
return EventEncoder.encode(event); |
||||
} |
||||
|
||||
public static String getUtf8String(String data) { |
||||
return new String(Numeric.hexStringToByteArray(data)).trim(); |
||||
} |
||||
|
||||
public static List<String> getEventParams(String data) { |
||||
if (data.startsWith("0x")) { |
||||
data = data.substring(2); |
||||
} |
||||
List<String> result = new ArrayList<>(); |
||||
result.add(data); |
||||
int length = data.length() / 64; |
||||
for (int i = 0; i < length; i++) { |
||||
String param = data.substring(i * 64, (i + 1) * 64); |
||||
BigInteger b = new BigInteger(param, 16); |
||||
result.add(b.toString(16)); |
||||
} |
||||
// System.out.println(result);
|
||||
return result; |
||||
} |
||||
|
||||
public static String getAddress(String address) { |
||||
if (address.length() > 42) { |
||||
address = address.substring(26); |
||||
} |
||||
if (address.startsWith("0x")) { |
||||
return address; |
||||
} |
||||
if (StringUtils.isEmpty(address) || "0".equals(address)) { |
||||
return "0x0000000000000000000000000000000000000000"; |
||||
} |
||||
return "0x" + address; |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
System.out.println(getAddress("0x0000000000000000000000001cba0557e0b38e595588b0f8a3d7c89de992e4e3")); |
||||
} |
||||
|
||||
public static BigInteger getChainId(BigInteger chainId){ |
||||
if(chainId.compareTo(BigInteger.ONE)==0){ |
||||
return new BigInteger("10001"); |
||||
}else { |
||||
return new BigInteger("11029"); |
||||
} |
||||
} |
||||
|
||||
public static BigInteger getNumber(String num) { |
||||
if (num.contains("0x")) { |
||||
num = num.substring(2); |
||||
} |
||||
return new BigInteger(num, 16); |
||||
} |
||||
|
||||
public static Integer getIntNumber(String num) { |
||||
if (num.contains("0x")) { |
||||
num = num.substring(2); |
||||
} |
||||
return new BigInteger(num, 16).intValue(); |
||||
} |
||||
|
||||
|
||||
private static List<TypeReference<?>> getTypes(List<String> inputParams) { |
||||
List<TypeReference<?>> parameters = new ArrayList<>(); |
||||
for (int i = 0; i < inputParams.size(); i++) { |
||||
String in = inputParams.get(i); |
||||
switch (in) { |
||||
case ADDRESS: |
||||
parameters.add(new TypeReference<Address>() { |
||||
}); |
||||
break; |
||||
case UINT256: |
||||
parameters.add(new TypeReference<Uint256>() { |
||||
}); |
||||
break; |
||||
case UINT32: |
||||
parameters.add(new TypeReference<Uint32>() { |
||||
}); |
||||
break; |
||||
case Utf8String: |
||||
parameters.add(new TypeReference<org.web3j.abi.datatypes.Utf8String>() { |
||||
}); |
||||
break; |
||||
case BOOL: |
||||
parameters.add(new TypeReference<Bool>() { |
||||
}); |
||||
break; |
||||
case BYTES: |
||||
parameters.add(new TypeReference<Bytes>() { |
||||
}); |
||||
break; |
||||
case BYTES32: |
||||
parameters.add(new TypeReference<Bytes32>() { |
||||
}); |
||||
break; |
||||
case ARRAY: |
||||
parameters.add(new TypeReference<Array>() { |
||||
}); |
||||
break; |
||||
case UINT256_ARRAY: |
||||
parameters.add(new TypeReference<DynamicArray<Uint256>>() { |
||||
}); |
||||
break; |
||||
case ADDRESS_ARRAY: |
||||
parameters.add(new TypeReference<DynamicArray<Address>>() { |
||||
}); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
return parameters; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,7 @@
|
||||
package com.nft.util; |
||||
|
||||
public class KeyChainId { |
||||
//chainid
|
||||
public static final int CHAINID=1; |
||||
|
||||
} |
@ -0,0 +1,370 @@
|
||||
package com.nft.util; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import okhttp3.*; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
|
||||
import javax.net.ssl.*; |
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.io.InputStream; |
||||
import java.net.InetSocketAddress; |
||||
import java.net.Proxy; |
||||
import java.security.cert.X509Certificate; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
import java.util.concurrent.TimeUnit; |
||||
|
||||
|
||||
public class OkHttpsUtils { |
||||
|
||||
private static OkHttpClient mOkHttpClient; |
||||
|
||||
/** |
||||
* 网络访问连接池 |
||||
*/ |
||||
private static ConnectionPool pool; |
||||
|
||||
/** |
||||
* get 请求 |
||||
* |
||||
* @param url 请求地址 |
||||
* @return 返回结果 |
||||
*/ |
||||
public static String getRequest(String url, String appKey) { |
||||
try { |
||||
|
||||
Request.Builder builder = new Request.Builder(); |
||||
if (!StringUtils.isEmpty(appKey)) { |
||||
builder.addHeader("Authorization", "APPCODE" + appKey); |
||||
} |
||||
builder.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36"); |
||||
builder.url(url); |
||||
final Request request = builder.build(); |
||||
//new call
|
||||
Call call = getOkHttpInstance().newCall(request); |
||||
//请求加入调度
|
||||
Response response = call.execute(); |
||||
return response.body().string(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* get 请求 InputStream |
||||
* |
||||
* @param url 请求地址 |
||||
* @return 返回结果 |
||||
*/ |
||||
public static InputStream getInputStreamRequest(String url) { |
||||
try { |
||||
|
||||
Request.Builder builder = new Request.Builder(); |
||||
builder.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36"); |
||||
builder.url(url); |
||||
final Request request = builder.build(); |
||||
//new call
|
||||
Call call = getOkHttpInstance().newCall(request); |
||||
//请求加入调度
|
||||
Response response = call.execute(); |
||||
return response.body().byteStream(); |
||||
} catch (IOException e) { |
||||
System.err.println(e.getMessage()); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
private static OkHttpClient getOkHttpInstance() { |
||||
if (mOkHttpClient == null) { |
||||
synchronized (OkHttpsUtils.class) { |
||||
//创建okHttpClient对象
|
||||
mOkHttpClient = getUnsafeOkHttpClient(); |
||||
} |
||||
} |
||||
return mOkHttpClient; |
||||
} |
||||
|
||||
|
||||
//okHttp3添加信任所有证书
|
||||
|
||||
public static OkHttpClient getUnsafeOkHttpClient() { |
||||
|
||||
X509TrustManager x509 = new X509TrustManager() { |
||||
@Override |
||||
public void checkClientTrusted(X509Certificate[] chain, String authType) { |
||||
} |
||||
|
||||
@Override |
||||
public void checkServerTrusted(X509Certificate[] chain, String authType) { |
||||
} |
||||
|
||||
@Override |
||||
public X509Certificate[] getAcceptedIssuers() { |
||||
return new X509Certificate[]{}; |
||||
} |
||||
}; |
||||
|
||||
try { |
||||
final TrustManager[] trustAllCerts = new TrustManager[]{x509}; |
||||
|
||||
final SSLContext sslContext = SSLContext.getInstance("SSL"); |
||||
sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); |
||||
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); |
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder() |
||||
.connectTimeout(3, TimeUnit.MINUTES) |
||||
.writeTimeout(3, TimeUnit.MINUTES) |
||||
.readTimeout(3, TimeUnit.MINUTES); |
||||
builder.sslSocketFactory(sslSocketFactory, x509); |
||||
|
||||
builder.hostnameVerifier(new HostnameVerifier() { |
||||
@Override |
||||
public boolean verify(String hostname, SSLSession session) { |
||||
return true; |
||||
} |
||||
}); |
||||
|
||||
return builder.build(); |
||||
} catch (Exception e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 获取网络访问连接池 |
||||
* |
||||
* @return |
||||
*/ |
||||
private static ConnectionPool getConnectionPool() { |
||||
if (pool == null) { |
||||
synchronized (OkHttpsUtils.class) { |
||||
pool = new ConnectionPool(5, 10, TimeUnit.MINUTES); |
||||
} |
||||
} |
||||
return pool; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* get 请求 含代理 |
||||
* |
||||
* @param url 请求地址 |
||||
* @return 返回结果 |
||||
*/ |
||||
public static String getRequestByProxy(String url, String host, int port) { |
||||
try { |
||||
//创建okHttpClient对象
|
||||
OkHttpClient.Builder b = new OkHttpClient.Builder(); |
||||
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port)); |
||||
b.proxy(proxy); |
||||
//创建一个Request
|
||||
Request.Builder builder = new Request.Builder(); |
||||
builder.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36"); |
||||
builder.url(url); |
||||
final Request request = builder.build(); |
||||
//new call
|
||||
Call call = getOkHttpInstance().newCall(request); |
||||
//请求加入调度
|
||||
Response response = call.execute(); |
||||
return response.body().string(); |
||||
} catch (IOException e) { |
||||
System.err.println(e.getMessage()); |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
|
||||
public static String uploadObject(String url, File file, String token) throws IOException { |
||||
MediaType mediaType = MediaType.parse("image/*"); |
||||
RequestBody requestBody = RequestBody.create(mediaType, file); |
||||
|
||||
Request request = new Request.Builder() |
||||
.url(url) |
||||
.post(requestBody) |
||||
.addHeader("Authorization", token) |
||||
.build(); |
||||
|
||||
Call call = getOkHttpInstance().newCall(request); |
||||
Response response = call.execute(); |
||||
return response.body().string(); |
||||
} |
||||
|
||||
/** |
||||
* 一般post请求 |
||||
* |
||||
* @param url 请求路径 |
||||
* @param params 请求参数 |
||||
* @param token 消息头 |
||||
* @return 返回结果 |
||||
*/ |
||||
public static String postRequest(String url, Map<String, String> params, String token) { |
||||
try { |
||||
|
||||
FormBody.Builder formBodyBuilder = new FormBody.Builder(); |
||||
Set<String> keySet = params.keySet(); |
||||
for (String key : keySet) { |
||||
String value = params.get(key); |
||||
formBodyBuilder.add(key, value); |
||||
} |
||||
FormBody formBody = formBodyBuilder.build(); |
||||
|
||||
Request.Builder builder = new Request.Builder(); |
||||
if (!StringUtils.isEmpty(token)) { |
||||
builder.addHeader("Authorization", token); |
||||
} |
||||
Request request = builder.url(url) |
||||
.post(formBody).build(); |
||||
|
||||
Call call = getOkHttpInstance().newCall(request); |
||||
|
||||
Response response = call.execute(); |
||||
return response.body().string(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 一般post请求 |
||||
* |
||||
* @param url 请求路径 |
||||
* @param params 请求参数 |
||||
* @param token 消息头 |
||||
* @return 返回结果 |
||||
*/ |
||||
public static JSONObject postRequestObj(String url, Map<String, String> params, String token) { |
||||
try { |
||||
|
||||
FormBody.Builder formBodyBuilder = new FormBody.Builder(); |
||||
Set<String> keySet = params.keySet(); |
||||
for (String key : keySet) { |
||||
String value = params.get(key); |
||||
formBodyBuilder.add(key, value); |
||||
} |
||||
FormBody formBody = formBodyBuilder.build(); |
||||
|
||||
Request.Builder builder = new Request.Builder(); |
||||
if (!StringUtils.isEmpty(token)) { |
||||
builder.addHeader("Authorization", token); |
||||
} |
||||
Request request = builder.url(url) |
||||
.post(formBody).build(); |
||||
|
||||
Call call = getOkHttpInstance().newCall(request); |
||||
|
||||
Response response = call.execute(); |
||||
String s = response.body().string(); |
||||
|
||||
return JSONObject.parseObject(s); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* post传json参数 |
||||
* |
||||
* @param url 请求路径 |
||||
* @param json 请求的json数据 |
||||
* @return 返回结果 |
||||
*/ |
||||
public static String postJsonAuth(String url, String json, String token) { |
||||
try { |
||||
|
||||
//MediaType 设置Content-Type 标头中包含的媒体类型值
|
||||
RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8") |
||||
, json); |
||||
|
||||
Request.Builder builder = new Request.Builder(); |
||||
if (!StringUtils.isEmpty(token)) { |
||||
builder.addHeader("Authorization", token); |
||||
} |
||||
Request request = builder |
||||
//请求的url
|
||||
.url(url) |
||||
.post(requestBody) |
||||
.build(); |
||||
|
||||
//创建/Call
|
||||
Call call = getOkHttpInstance().newCall(request); |
||||
Response response = call.execute(); |
||||
return response.body().string(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* post传json参数 |
||||
* |
||||
* @param url 请求路径 |
||||
* @param json 请求的json数据 |
||||
* @return 返回结果 |
||||
*/ |
||||
public static String postJsonResponse(String url, String json) { |
||||
try { |
||||
|
||||
//MediaType 设置Content-Type 标头中包含的媒体类型值
|
||||
RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8") |
||||
, json); |
||||
|
||||
Request request = new Request.Builder() |
||||
//请求的url
|
||||
.url(url) |
||||
.post(requestBody) |
||||
.build(); |
||||
|
||||
//创建/Call
|
||||
Call call = getOkHttpInstance().newCall(request); |
||||
Response response = call.execute(); |
||||
return response.body().string(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 一般post请求 |
||||
* |
||||
* @param url 请求路径 |
||||
* @param params 请求参数 |
||||
* @return 返回结果 |
||||
*/ |
||||
public static String postRequest(String url, Map<String, String> params) { |
||||
try { |
||||
|
||||
FormBody.Builder formBodyBuilder = new FormBody.Builder(); |
||||
Set<String> keySet = params.keySet(); |
||||
Request.Builder builder = new Request.Builder(); |
||||
for (String key : keySet) { |
||||
String value = params.get(key); |
||||
if (!StringUtils.isEmpty(value)) { |
||||
builder.addHeader(key, value); |
||||
} |
||||
} |
||||
FormBody formBody = formBodyBuilder.build(); |
||||
|
||||
Request request = builder.url(url) |
||||
.post(formBody).build(); |
||||
|
||||
Call call = getOkHttpInstance().newCall(request); |
||||
|
||||
Response response = call.execute(); |
||||
String s = response.body().string(); |
||||
|
||||
return s; |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,56 @@
|
||||
package com.nft.util.swagger2; |
||||
|
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.ComponentScan; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import springfox.documentation.builders.ApiInfoBuilder; |
||||
import springfox.documentation.builders.PathSelectors; |
||||
import springfox.documentation.builders.RequestHandlerSelectors; |
||||
import springfox.documentation.service.ApiInfo; |
||||
import springfox.documentation.service.Contact; |
||||
import springfox.documentation.service.Parameter; |
||||
import springfox.documentation.service.Tag; |
||||
import springfox.documentation.spi.DocumentationType; |
||||
import springfox.documentation.spring.web.plugins.Docket; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
@Configuration |
||||
@ComponentScan("com.nft.api") |
||||
public class Swagger2 { |
||||
@Value("${swagger.show}") |
||||
private boolean swaggerShow; |
||||
|
||||
private Tag[] getTags() { |
||||
Tag[] tags = { |
||||
// new Tag("test", "测试服务"),
|
||||
}; |
||||
return tags; |
||||
} |
||||
|
||||
@Bean |
||||
public Docket createRestApi() { |
||||
List<Parameter> pars = new ArrayList<>(); |
||||
return new Docket(DocumentationType.SWAGGER_2) |
||||
.enable(swaggerShow) |
||||
.apiInfo(apiInfo()) |
||||
// .tags(new Tag("test", "test"), getTags())
|
||||
.select() |
||||
.apis(RequestHandlerSelectors.basePackage("com.nft.api")) |
||||
.paths(PathSelectors.any()) |
||||
.build() |
||||
.globalOperationParameters(pars); |
||||
} |
||||
|
||||
private ApiInfo apiInfo() { |
||||
Contact contact = new Contact("ban", "", ""); |
||||
return new ApiInfoBuilder().title("pl 接口列表") |
||||
.description("API调用") |
||||
.termsOfServiceUrl("http://") |
||||
//.contact(contact)
|
||||
.version("1.0") |
||||
.build(); |
||||
} |
||||
} |
@ -0,0 +1,45 @@
|
||||
server: |
||||
port: 9008 |
||||
spring: |
||||
application: |
||||
name: confluxNft |
||||
redis: |
||||
host: 127.0.0.1 |
||||
port: 6379 |
||||
password: |
||||
jedis: |
||||
pool: |
||||
max-active: 200 |
||||
max-wait: -1 |
||||
max-idle: 10 |
||||
database: 1 |
||||
datasource: |
||||
url: jdbc:mysql://182.92.73.21:3380/conflux_nft?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC |
||||
username: root |
||||
password: guolong09aa@1345225844@.@. |
||||
type: com.alibaba.druid.pool.DruidDataSource |
||||
servlet: |
||||
multipart: |
||||
max-file-size: 100MB |
||||
max-request-size: 100MB |
||||
mybatis: |
||||
mapper-locations: classpath*:/mapper/**/*.xml |
||||
configuration: |
||||
map-underscore-to-camel-case: true |
||||
#测试环境 |
||||
confluxNft: |
||||
#合约 |
||||
contract: cfxtest:acbctakv35gyzcepnh14k239hw6tcw2t7edv34adn3 |
||||
# 执行地址 |
||||
owner: cfxtest:aapjjbzf3bumeatch25bduathv0xz9wk42e8yzd4r1 |
||||
###私钥位置 |
||||
privateKey: 0xa31115fa5cf8fefd57fa0dea7ff013e2d71b8cf13a4d6a7e276c9c5b21bf911b |
||||
swagger: |
||||
show: true |
||||
# mybatis-plus |
||||
mybatis-plus: |
||||
mapper-locations: classpath*:/mapper/**/*.xml |
||||
type-aliases-package: com.nft.entity |
||||
global-config: |
||||
logic-delete-value: 1 |
||||
logic-not-delete-value: 0 |
Loading…
Reference in new issue