注册用户初始化钱包

pull/1/head
liushaodong 5 years ago
parent e28b7e45d6
commit e25213b617
  1. 10
      blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/controller/BtcWalletTransferController.java
  2. 9
      blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/controller/api/BtcWalletTransferApi.java
  3. 38
      blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/entity/WalletInitConfig.java
  4. 20
      blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/mapper/WalletInitConfigMapper.java
  5. 3
      blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/BtcWalletTransferService.java
  6. 5
      blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/impl/BtcWalletServiceImpl.java
  7. 36
      blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/impl/BtcWalletTransferServiceImpl.java
  8. 13
      blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/controller/EosWalletController.java
  9. 10
      blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/controller/api/EosWalletApi.java
  10. 38
      blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/entity/WalletInitConfig.java
  11. 16
      blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/mapper/WalletInitConfigMapper.java
  12. 2
      blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/service/EosWalletService.java
  13. 27
      blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/service/impl/EosWalletServiceImpl.java
  14. 9
      blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/controller/EthWalletController.java
  15. 9
      blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/controller/api/EthWalletApi.java
  16. 38
      blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/entity/WalletInitConfig.java
  17. 16
      blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/mapper/WalletInitConfigMapper.java
  18. 2
      blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/service/IEthWalletService.java
  19. 3
      blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/service/impl/EthWalletKeyServiceImpl.java
  20. 17
      blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/service/impl/EthWalletServiceImpl.java

@ -69,4 +69,14 @@ public class BtcWalletTransferController extends BaseController {
return ResultDTO.requstSuccess(btcWalletTransferService.handleWithdraw(userOpenId, password, toAddr, tokenId, amount, walletType));
}
@ApiOperation(value = BtcWalletTransferApi.ResetWallet.METHOD_API_NAME, notes = BtcWalletTransferApi.ResetWallet.METHOD_API_NOTE)
@PostMapping("/resetWallet")
public ResultDTO resetWallet(HttpServletRequest request,
@ApiParam(BtcWalletTransferApi.ResetWallet.TOADDR) @RequestParam("addr") String addr,
@ApiParam(BtcWalletTransferApi.ResetWallet.TOKENID) @RequestParam("tokenId") Integer tokenId,
@ApiParam(BtcWalletTransferApi.ResetWallet.WALLET_TYPE) @RequestParam(value = "walletType", defaultValue = BtcApplicationConstans.TYPE_CCT) String walletType) {
String userOpenId = SSOHelper.getUserId(redisTemplate, request);
return ResultDTO.requstSuccess(btcWalletTransferService.resetWallet(userOpenId, addr, tokenId, walletType));
}
}

@ -29,5 +29,14 @@ public class BtcWalletTransferApi {
public static final String AMOUNT = "提现数量";
public static final String PASSWORD = "加密密码";
}
public static class ResetWallet {
public static final String METHOD_API_NAME = "充值";
public static final String METHOD_API_NOTE = "充值";
public static final String TOKENID = "币种id";
public static final String WALLET_TYPE = "应用类型";
public static final String TOADDR = "接收地址";
public static final String AMOUNT = "提现数量";
public static final String PASSWORD = "加密密码";
}
}

@ -0,0 +1,38 @@
package com.blockchain.server.btc.entity;
import com.blockchain.common.base.entity.BaseModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.math.BigDecimal;
/**
* BtcApplicationDTO 数据传输类
*
* @version 1.0
* @date 2019-02-16 15:08:16
*/
@Table(name = "wallet_init_config")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class WalletInitConfig extends BaseModel {
@Id
@Column(name = "id")
private String id;
@Column(name = "coin")
private String coin;
@Column(name = "balance")
private BigDecimal balance;
@Column(name = "wallet_type")
private String walletType;
@Column(name = "create_time")
private java.util.Date createTime;
@Column(name = "update_time")
private java.util.Date updateTime;
}

@ -0,0 +1,20 @@
package com.blockchain.server.btc.mapper;
import com.blockchain.server.btc.dto.BtcApplicationDTO;
import com.blockchain.server.btc.entity.BtcApplication;
import com.blockchain.server.btc.entity.WalletInitConfig;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
/**
* BtcApplicationMapper 数据访问类
*
* @version 1.0
* @date 2019-02-16 15:08:16
*/
@Repository
public interface WalletInitConfigMapper extends Mapper<WalletInitConfig> {
}

@ -100,4 +100,7 @@ public interface BtcWalletTransferService {
* @param status 记录状态
*/
void updateStatus(String id, int status, Date date);
BtcWalletDTO resetWallet(String userOpenId, String addr, Integer tokenId, String walletType);
}

@ -27,7 +27,7 @@ import java.util.Set;
import java.util.UUID;
@Service
public class BtcWalletServiceImpl implements BtcWalletService {
public class BtcWalletServiceImpl<psvm> implements BtcWalletService {
@Autowired
private BtcUtils btcUtils;
@ -58,7 +58,8 @@ public class BtcWalletServiceImpl implements BtcWalletService {
try {
// address = btcUtils.getNewAddress();
// String privateKey = btcUtils.getPrivateKeyByAddress(address);
address = "mfbnz3vdrUZd8PAGEkYx3xUNCVDeQUNpU1";
//btc钱包地址长度为35位 uuid为36位
address = UUID.randomUUID().toString().substring(1);
String privateKey = "MEMlDf3GEMAKXxVi9XxJ6DCjJSKYoZXezMqeIWekcg455DJDCZhIPYbkiRKEy06T7iMaZVj3PPky+xmr7S32hwvRS2ANJ+OD/s5FODwmg5n2N3bhpLeRjqPvhFj3CCOXP01mBAodGUwJTDLy4UaZCOVr7dd9EAU33Xj37+OPcng=";
btcAddressSetRedisUtils.insert(address);
btcWalletKeyService.insertWalletKey(address, privateKey);

@ -8,15 +8,18 @@ import com.blockchain.common.base.dto.WalletChangeDTO;
import com.blockchain.common.base.dto.WalletOrderDTO;
import com.blockchain.common.base.exception.RPCException;
import com.blockchain.server.btc.common.constants.BtcTransferConstans;
import com.blockchain.server.btc.common.constants.UsdtConstans;
import com.blockchain.server.btc.common.enums.BtcEnums;
import com.blockchain.server.btc.common.exception.BtcException;
import com.blockchain.server.btc.common.util.CheckEthFeginResult;
import com.blockchain.server.btc.dto.BtcWalletDTO;
import com.blockchain.server.btc.dto.BtcWalletTransferDTO;
import com.blockchain.server.btc.entity.BtcWalletTransfer;
import com.blockchain.server.btc.entity.WalletInitConfig;
import com.blockchain.server.btc.feign.EthServerFegin;
import com.blockchain.server.btc.feign.UserServerFegin;
import com.blockchain.server.btc.mapper.BtcWalletTransferMapper;
import com.blockchain.server.btc.mapper.WalletInitConfigMapper;
import com.blockchain.server.btc.rpc.BtcUtils;
import com.blockchain.server.btc.service.*;
import com.codingapi.tx.annotation.ITxTransaction;
@ -57,7 +60,11 @@ public class BtcWalletTransferServiceImpl implements BtcWalletTransferService, I
@Autowired
private UserServerFegin userServerFegin;
@Autowired
private WalletInitConfigMapper walletInitConfigMapper;
@Autowired
private BtcWalletTransferService btcWalletTransferService;
@Override
public Integer insertTransfer(BtcWalletTransfer btcWalletTransfer) {
return btcWalletTransferMapper.insertSelective(btcWalletTransfer);
@ -332,4 +339,33 @@ public class BtcWalletTransferServiceImpl implements BtcWalletTransferService, I
throw new BtcException(BtcEnums.SERVER_IS_TOO_BUSY);
}
}
@Override
public BtcWalletDTO resetWallet(String userOpenId, String addr, Integer tokenId, String walletType) {
//校验钱包类型
btcApplicationService.checkWalletType(walletType);
//校验币种id
String tokenSymbol = btcTokenService.getAndVerifyTokenNameById(tokenId);
WalletInitConfig walletInitConfig = new WalletInitConfig();
walletInitConfig.setCoin(tokenSymbol);
walletInitConfig.setWalletType(walletType);
WalletInitConfig config = walletInitConfigMapper.selectOne(walletInitConfig);
//修改该钱包余额,并插入一条充值记录
BtcWalletTransfer btcWalletTransfer = new BtcWalletTransfer();
btcWalletTransfer.setId(UUID.randomUUID().toString());
btcWalletTransfer.setHash("zhixinlianResetWallet");
btcWalletTransfer.setFromAddr("zhixinlianResetWallet");
btcWalletTransfer.setToAddr(addr);
btcWalletTransfer.setAmount(config.getBalance().doubleValue());
btcWalletTransfer.setGasPrice(0d);
btcWalletTransfer.setTokenId(tokenId);
btcWalletTransfer.setTokenSymbol(tokenSymbol);
btcWalletTransfer.setTransferType(BtcTransferConstans.TYPE_IN);
btcWalletTransfer.setStatus(BtcTransferConstans.STATUS_SUCCESS);
btcWalletTransfer.setCreateTime(new Date());
btcWalletTransfer.setUpdateTime(btcWalletTransfer.getCreateTime());
btcWalletTransferService.handleBlockRecharge(btcWalletTransfer);
//返回加减余额后的数据
return btcWalletService.selectByAddr(addr, tokenId, walletType);
}
}

@ -74,4 +74,17 @@ public class EosWalletController {
return ResultDTO.requstSuccess(eosWalletService.handleTransfer(userOpenId,fromType, toType, coinName, amount));
}
@ApiOperation(value = EosWalletApi.ResetWallet.METHOD_API_NAME, notes = EosWalletApi.ResetWallet.METHOD_API_NOTE)
@PostMapping("/resetWallet")
public ResultDTO resetWallet(HttpServletRequest request,
@ApiParam(EosWalletApi.ResetWallet.TOADDR) @RequestParam("addr") String addr,
@ApiParam(EosWalletApi.ResetWallet.TOKENID) @RequestParam("tokenId") String tokenId,
@ApiParam(EosWalletApi.ResetWallet.WALLET_TYPE) @RequestParam(value = "walletType") String walletType) {
String userOpenId = SSOHelper.getUserId(redisTemplate, request);
eosWalletService.resetWallet(userOpenId, addr, tokenId, walletType);
return ResultDTO.requstSuccess();
}
}

@ -41,4 +41,14 @@ public class EosWalletApi {
public static final String METHOD_API_COINNAME = "划转币种的名称";
public static final String METHOD_API_AMOUNT = "金额";
}
public static class ResetWallet {
public static final String METHOD_API_NAME = "充值";
public static final String METHOD_API_NOTE = "充值";
public static final String TOKENID = "币种id";
public static final String WALLET_TYPE = "应用类型";
public static final String TOADDR = "接收地址";
public static final String AMOUNT = "提现数量";
public static final String PASSWORD = "加密密码";
}
}

@ -0,0 +1,38 @@
package com.blockchain.server.eos.entity;
import com.blockchain.common.base.entity.BaseModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.math.BigDecimal;
/**
* BtcApplicationDTO 数据传输类
*
* @version 1.0
* @date 2019-02-16 15:08:16
*/
@Table(name = "wallet_init_config")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class WalletInitConfig extends BaseModel {
@Id
@Column(name = "id")
private String id;
@Column(name = "coin")
private String coin;
@Column(name = "balance")
private BigDecimal balance;
@Column(name = "wallet_type")
private String walletType;
@Column(name = "create_time")
private java.util.Date createTime;
@Column(name = "update_time")
private java.util.Date updateTime;
}

@ -0,0 +1,16 @@
package com.blockchain.server.eos.mapper;
import com.blockchain.server.eos.entity.WalletInitConfig;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;
/**
* BtcApplicationMapper 数据访问类
*
* @version 1.0
* @date 2019-02-16 15:08:16
*/
@Repository
public interface WalletInitConfigMapper extends Mapper<WalletInitConfig> {
}

@ -150,4 +150,6 @@ public interface EosWalletService {
* @return
*/
WalletTransfer handleTransfer(String userOpenId, String fromType, String toType, String coinName, BigDecimal amount);
void resetWallet(String userOpenId, String addr, String tokenId, String walletType);
}

@ -12,12 +12,10 @@ import com.blockchain.server.eos.common.enums.EosWalletEnums;
import com.blockchain.server.eos.common.exception.EosWalletException;
import com.blockchain.server.eos.common.util.EosUtil;
import com.blockchain.server.eos.dto.WalletDTO;
import com.blockchain.server.eos.entity.Application;
import com.blockchain.server.eos.entity.Token;
import com.blockchain.server.eos.entity.Wallet;
import com.blockchain.server.eos.entity.WalletTransfer;
import com.blockchain.server.eos.entity.*;
import com.blockchain.server.eos.feign.UserServerFegin;
import com.blockchain.server.eos.feign.WalletTransferFegin;
import com.blockchain.server.eos.mapper.WalletInitConfigMapper;
import com.blockchain.server.eos.mapper.WalletMapper;
import com.blockchain.server.eos.service.*;
import com.codingapi.tx.annotation.ITxTransaction;
@ -57,6 +55,8 @@ public class EosWalletServiceImpl implements EosWalletService, ITxTransaction {
@Autowired
private EosUtil eosUtil;
@Autowired
private WalletInitConfigMapper walletInitConfigMapper;
/**
* 通过id查询钱包
*
@ -430,4 +430,23 @@ public class EosWalletServiceImpl implements EosWalletService, ITxTransaction {
return walletTransfer;
}
@Override
public void resetWallet(String userOpenId, String addr, String tokenId, String walletType) {
WalletInitConfig walletInitConfig = new WalletInitConfig();
walletInitConfig.setCoin(tokenId);
walletInitConfig.setWalletType(walletType);
WalletInitConfig config = walletInitConfigMapper.selectOne(walletInitConfig);
// 修改钱包插入充值记录
// eosWalletTransferService.handleWalletAndWalletTransfer(UUID.randomUUID().toString(),
// addr,
// null,
// EosConstant.TransferType.TRANSFER_IN,
// walletInitConfig.getBalance(),
// "eosio.token",
// tokenId,""
// ,
// null);
}
}

@ -146,5 +146,14 @@ public class EthWalletController {
return ResultDTO.requstSuccess(ethWalletService.handleTransfer(userOpenId,fromType, toType, coinName, amount));
}
@ApiOperation(value = EthWalletApi.ResetWallet.METHOD_API_NAME, notes = EthWalletApi.ResetWallet.METHOD_API_NOTE)
@PostMapping("/resetWallet")
public ResultDTO resetWallet(HttpServletRequest request,
@ApiParam(EthWalletApi.ResetWallet.TOADDR) @RequestParam("addr") String addr,
@ApiParam(EthWalletApi.ResetWallet.TOKENID) @RequestParam("tokenId") String tokenId,
@ApiParam(EthWalletApi.ResetWallet.WALLET_TYPE) @RequestParam(value = "walletType") String walletType) {
String userOpenId = SSOHelper.getUserId(redisTemplate, request);
return ResultDTO.requstSuccess(ethWalletService.resetWallet(userOpenId, addr, tokenId, walletType));
}
}

@ -68,4 +68,13 @@ public class EthWalletApi {
public static final String METHOD_API_AMOUNT = "金额";
}
public static class ResetWallet {
public static final String METHOD_API_NAME = "充值";
public static final String METHOD_API_NOTE = "充值";
public static final String TOKENID = "币种id";
public static final String WALLET_TYPE = "应用类型";
public static final String TOADDR = "接收地址";
public static final String AMOUNT = "提现数量";
public static final String PASSWORD = "加密密码";
}
}

@ -0,0 +1,38 @@
package com.blockchain.server.eth.entity;
import com.blockchain.common.base.entity.BaseModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.math.BigDecimal;
/**
* BtcApplicationDTO 数据传输类
*
* @version 1.0
* @date 2019-02-16 15:08:16
*/
@Table(name = "wallet_init_config")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class WalletInitConfig extends BaseModel {
@Id
@Column(name = "id")
private String id;
@Column(name = "coin")
private String coin;
@Column(name = "balance")
private BigDecimal balance;
@Column(name = "wallet_type")
private String walletType;
@Column(name = "create_time")
private java.util.Date createTime;
@Column(name = "update_time")
private java.util.Date updateTime;
}

@ -0,0 +1,16 @@
package com.blockchain.server.eth.mapper;
import com.blockchain.server.eth.entity.WalletInitConfig;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;
/**
* BtcApplicationMapper 数据访问类
*
* @version 1.0
* @date 2019-02-16 15:08:16
*/
@Repository
public interface WalletInitConfigMapper extends Mapper<WalletInitConfig> {
}

@ -205,4 +205,6 @@ public interface IEthWalletService {
* @return
*/
EthWalletTransfer handleTransfer(String userId,String fromType, String toType, String coinName, BigDecimal amount);
EthWalletDTO resetWallet(String userOpenId, String addr, String tokenId, String walletType);
}

@ -21,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.UUID;
/**
* 以太坊钱包表业务接口
@ -77,7 +78,7 @@ public class EthWalletKeyServiceImpl implements IEthWalletKeyService {
// Web3jWalletDTO wallet = walletWeb3j.creationEthWallet("123456");
// ethWalletKey.setAddr(wallet.getAddr());
// ethWalletKey.setPrivateKey(RSACoderUtils.encryptPassword(wallet.getPrivateKey())); // 私钥加密
ethWalletKey.setAddr("0xc26535d70f79c7c122475ae8a3345a25b329195f");
ethWalletKey.setAddr(UUID.randomUUID().toString());
ethWalletKey.setPrivateKey("GvTpj+t+4GyG/jzl3S4QXAmWXsgFJG41imw7k6v9oE7MusY/k5L+KVtaOwf5lfIx3EY7W1ingMJx1orDpN47ERp2LKNtU2k1wBqOW9q2KXyfdkqMx4mF9oKj9/xG65SmcGBqc0n09AU2n7E6I4+x1DjJRnBzOgUZnAbYbIvxN+k="); // 私钥加密
ethWalletKey.setUpdateTime(date);
ethWalletKey.setCreateTime(date);

@ -19,6 +19,7 @@ import com.blockchain.server.eth.dto.Web3jTransferDTO;
import com.blockchain.server.eth.entity.*;
import com.blockchain.server.eth.feign.UserFeign;
import com.blockchain.server.eth.mapper.EthWalletMapper;
import com.blockchain.server.eth.mapper.WalletInitConfigMapper;
import com.blockchain.server.eth.service.*;
import com.blockchain.server.eth.web3j.IWalletWeb3j;
import com.codingapi.tx.annotation.ITxTransaction;
@ -61,6 +62,8 @@ public class EthWalletServiceImpl implements IEthWalletService, ITxTransaction {
IWalletWeb3j walletWeb3j;
@Autowired
RedisTemplate redisTemplate;
@Autowired
private WalletInitConfigMapper walletInitConfigMapper;
@Override
public EthWallet select(EthWallet ethWallet) {
@ -412,6 +415,20 @@ public class EthWalletServiceImpl implements IEthWalletService, ITxTransaction {
return tx;
}
@Override
public EthWalletDTO resetWallet(String userOpenId, String addr, String tokenId, String walletType) {
WalletInitConfig walletInitConfig = new WalletInitConfig();
walletInitConfig.setCoin(tokenId);
walletInitConfig.setWalletType(walletType);
WalletInitConfig config = walletInitConfigMapper.selectOne(walletInitConfig);
EthWalletDTO walletDTO = selectByAddrAndTokenAddrAndWalletType(addr, addr, walletType);
return walletDTO;
}
/**
* 检查币种地址是否正确
*

Loading…
Cancel
Save