|
|
@ -216,16 +216,16 @@ public class BtcWalletTransferServiceImpl implements BtcWalletTransferService, I |
|
|
|
CheckEthFeginResult.checkIsPassword(ethServerFegin.isPassword(password)); |
|
|
|
CheckEthFeginResult.checkIsPassword(ethServerFegin.isPassword(password)); |
|
|
|
|
|
|
|
|
|
|
|
//验证提现地址是否有效
|
|
|
|
//验证提现地址是否有效
|
|
|
|
JSONObject vaObj = null; |
|
|
|
// JSONObject vaObj = null;
|
|
|
|
try { |
|
|
|
// try {
|
|
|
|
vaObj = btcUtils.validateAddress(toAddress); |
|
|
|
// vaObj = btcUtils.validateAddress(toAddress);
|
|
|
|
} catch (Exception e) { |
|
|
|
// } catch (Exception e) {
|
|
|
|
throw new BtcException(BtcEnums.ADDRESS_ERROR); |
|
|
|
// throw new BtcException(BtcEnums.ADDRESS_ERROR);
|
|
|
|
} |
|
|
|
// }
|
|
|
|
//验证提现地址是否有效
|
|
|
|
// //验证提现地址是否有效
|
|
|
|
if (!vaObj.getBoolean("isvalid")) { |
|
|
|
// if (!vaObj.getBoolean("isvalid")) {
|
|
|
|
throw new BtcException(BtcEnums.ADDRESS_ERROR); |
|
|
|
// throw new BtcException(BtcEnums.ADDRESS_ERROR);
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
//获取钱包余额
|
|
|
|
//获取钱包余额
|
|
|
|
BtcWalletDTO btcWalletDTO = btcWalletService.selectByUserOpenId(userOpenId, tokenId, walletType); |
|
|
|
BtcWalletDTO btcWalletDTO = btcWalletService.selectByUserOpenId(userOpenId, tokenId, walletType); |
|
|
@ -237,80 +237,80 @@ public class BtcWalletTransferServiceImpl implements BtcWalletTransferService, I |
|
|
|
|
|
|
|
|
|
|
|
Date now = new Date(); |
|
|
|
Date now = new Date(); |
|
|
|
|
|
|
|
|
|
|
|
//判断是否属于节点钱包
|
|
|
|
//*********** 是,快速转账,数据库划转 ***********
|
|
|
|
if (vaObj.getBoolean("ismine")) { |
|
|
|
|
|
|
|
//*********** 是,快速转账,数据库划转 ***********
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//该用户减去提现可用余额、总额
|
|
|
|
|
|
|
|
int countUb = btcWalletService.updateBalanceByAddrInRowLock(fromAddress, tokenId, -amount, 0.0, -amount, now); |
|
|
|
|
|
|
|
if (countUb != 1) { |
|
|
|
|
|
|
|
throw new BtcException(BtcEnums.WITHDRAW_ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//接收用户加上可用余额、总额
|
|
|
|
|
|
|
|
int countUbR = btcWalletService.updateBalanceByAddrInRowLock(toAddress, tokenId, amount, 0.0, amount, now); |
|
|
|
|
|
|
|
if (countUbR != 1) { |
|
|
|
|
|
|
|
throw new BtcException(BtcEnums.WITHDRAW_ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//并插入一条提现记录,站内快速转账
|
|
|
|
//该用户减去提现可用余额、总额
|
|
|
|
BtcWalletTransfer btcWalletTransfer = new BtcWalletTransfer(); |
|
|
|
int countUb = btcWalletService.updateBalanceByAddrInRowLock(fromAddress, tokenId, -amount, 0.0, -amount, now); |
|
|
|
btcWalletTransfer.setId(UUID.randomUUID().toString()); |
|
|
|
if (countUb != 1) { |
|
|
|
|
|
|
|
throw new BtcException(BtcEnums.WITHDRAW_ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// //接收用户加上可用余额、总额
|
|
|
|
|
|
|
|
// int countUbR = btcWalletService.updateBalanceByAddrInRowLock(toAddress, tokenId, amount, 0.0, amount, now);
|
|
|
|
|
|
|
|
// if (countUbR != 1) {
|
|
|
|
|
|
|
|
// throw new BtcException(BtcEnums.WITHDRAW_ERROR);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//不走链上,快速到账。
|
|
|
|
|
|
|
|
//并插入一条提现记录,站内快速转账
|
|
|
|
|
|
|
|
BtcWalletTransfer btcWalletTransfer = new BtcWalletTransfer(); |
|
|
|
|
|
|
|
btcWalletTransfer.setId(UUID.randomUUID().toString()); |
|
|
|
// btcWalletTransfer.setHash(null);
|
|
|
|
// btcWalletTransfer.setHash(null);
|
|
|
|
btcWalletTransfer.setFromAddr(fromAddress); |
|
|
|
btcWalletTransfer.setFromAddr(fromAddress); |
|
|
|
btcWalletTransfer.setToAddr(toAddress); |
|
|
|
btcWalletTransfer.setToAddr(toAddress); |
|
|
|
btcWalletTransfer.setAmount(Math.abs(amount)); |
|
|
|
btcWalletTransfer.setAmount(Math.abs(amount)); |
|
|
|
// btcWalletTransfer.setGasPrice(null);
|
|
|
|
// btcWalletTransfer.setGasPrice(null);
|
|
|
|
btcWalletTransfer.setTokenId(tokenId); |
|
|
|
btcWalletTransfer.setTokenId(tokenId); |
|
|
|
btcWalletTransfer.setTokenSymbol(tokenSymbol); |
|
|
|
btcWalletTransfer.setTokenSymbol(tokenSymbol); |
|
|
|
btcWalletTransfer.setTransferType(BtcTransferConstans.TYPE_FAST); |
|
|
|
btcWalletTransfer.setTransferType(BtcTransferConstans.TYPE_FAST); |
|
|
|
btcWalletTransfer.setStatus(BtcTransferConstans.STATUS_SUCCESS); |
|
|
|
btcWalletTransfer.setStatus(BtcTransferConstans.STATUS_SUCCESS); |
|
|
|
btcWalletTransfer.setCreateTime(now); |
|
|
|
btcWalletTransfer.setCreateTime(now); |
|
|
|
btcWalletTransfer.setUpdateTime(now); |
|
|
|
btcWalletTransfer.setUpdateTime(now); |
|
|
|
int countIt = insertTransfer(btcWalletTransfer); |
|
|
|
int countIt = insertTransfer(btcWalletTransfer); |
|
|
|
if (countIt != 1) { |
|
|
|
if (countIt != 1) { |
|
|
|
throw new BtcException(BtcEnums.WITHDRAW_ERROR); |
|
|
|
throw new BtcException(BtcEnums.WITHDRAW_ERROR); |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
//*********** 否,区块链转账 ***********
|
|
|
|
|
|
|
|
// 查询是否存在提现黑名单中
|
|
|
|
|
|
|
|
// 抛出错误表示用户禁止提现
|
|
|
|
|
|
|
|
userServerFegin.verifyBanWithdraw(userOpenId); |
|
|
|
|
|
|
|
// 判断用户是否存在提现白名单中
|
|
|
|
|
|
|
|
ResultDTO<Boolean> resultDTO = userServerFegin.verifyFreeWithdraw(userOpenId); |
|
|
|
|
|
|
|
if (resultDTO.getCode() != BaseConstant.REQUEST_SUCCESS) |
|
|
|
|
|
|
|
throw new RPCException(resultDTO.getCode(), resultDTO.getMsg()); |
|
|
|
|
|
|
|
// 用户存在提现白名单中,设置提现手续费为零
|
|
|
|
|
|
|
|
if (resultDTO.getData()) gasDTO.setGasPrice(BigDecimal.ZERO); |
|
|
|
|
|
|
|
// 余额加上扣除手续费
|
|
|
|
|
|
|
|
//该用户减去提现可用余额、加上冻结余额
|
|
|
|
|
|
|
|
int countUb = btcWalletService.updateBalanceByAddrInRowLock(fromAddress, tokenId, -amount, amount, 0.0, now); |
|
|
|
|
|
|
|
if (countUb != 1) { |
|
|
|
|
|
|
|
throw new BtcException(BtcEnums.WITHDRAW_ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//并插入一条提现记录
|
|
|
|
|
|
|
|
BtcWalletTransfer btcWalletTransfer = new BtcWalletTransfer(); |
|
|
|
|
|
|
|
btcWalletTransfer.setId(UUID.randomUUID().toString()); |
|
|
|
|
|
|
|
// btcWalletTransfer.setHash(null);
|
|
|
|
|
|
|
|
btcWalletTransfer.setFromAddr(fromAddress); |
|
|
|
|
|
|
|
btcWalletTransfer.setToAddr(toAddress); |
|
|
|
|
|
|
|
btcWalletTransfer.setAmount(Math.abs(amount)); |
|
|
|
|
|
|
|
btcWalletTransfer.setTokenId(tokenId); |
|
|
|
|
|
|
|
btcWalletTransfer.setTokenSymbol(tokenSymbol); |
|
|
|
|
|
|
|
//设置手续费
|
|
|
|
|
|
|
|
//TODO 扣减不同币种手续费
|
|
|
|
|
|
|
|
btcWalletTransfer.setGasPrice(gasDTO.getGasPrice().doubleValue()); |
|
|
|
|
|
|
|
btcWalletTransfer.setGasTokenType(gasDTO.getGasTokenType()); |
|
|
|
|
|
|
|
btcWalletTransfer.setGasTokenSymbol(gasDTO.getGasTokenSymbol()); |
|
|
|
|
|
|
|
btcWalletTransfer.setGasTokenName(gasDTO.getGasTokenName()); |
|
|
|
|
|
|
|
btcWalletTransfer.setTransferType(BtcTransferConstans.TYPE_OUT); |
|
|
|
|
|
|
|
btcWalletTransfer.setStatus(BtcTransferConstans.STATUS_FIRST_TRIAL); |
|
|
|
|
|
|
|
btcWalletTransfer.setCreateTime(now); |
|
|
|
|
|
|
|
btcWalletTransfer.setUpdateTime(now); |
|
|
|
|
|
|
|
int countIt = insertTransfer(btcWalletTransfer); |
|
|
|
|
|
|
|
if (countIt != 1) { |
|
|
|
|
|
|
|
throw new BtcException(BtcEnums.WITHDRAW_ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//判断是否属于节点钱包
|
|
|
|
|
|
|
|
// if (vaObj.getBoolean("ismine")) {
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// //*********** 否,区块链转账 ***********
|
|
|
|
|
|
|
|
// // 查询是否存在提现黑名单中
|
|
|
|
|
|
|
|
// // 抛出错误表示用户禁止提现
|
|
|
|
|
|
|
|
// userServerFegin.verifyBanWithdraw(userOpenId);
|
|
|
|
|
|
|
|
// // 判断用户是否存在提现白名单中
|
|
|
|
|
|
|
|
// ResultDTO<Boolean> resultDTO = userServerFegin.verifyFreeWithdraw(userOpenId);
|
|
|
|
|
|
|
|
// if (resultDTO.getCode() != BaseConstant.REQUEST_SUCCESS)
|
|
|
|
|
|
|
|
// throw new RPCException(resultDTO.getCode(), resultDTO.getMsg());
|
|
|
|
|
|
|
|
// // 用户存在提现白名单中,设置提现手续费为零
|
|
|
|
|
|
|
|
// if (resultDTO.getData()) gasDTO.setGasPrice(BigDecimal.ZERO);
|
|
|
|
|
|
|
|
// // 余额加上扣除手续费
|
|
|
|
|
|
|
|
// //该用户减去提现可用余额、加上冻结余额
|
|
|
|
|
|
|
|
// int countUb = btcWalletService.updateBalanceByAddrInRowLock(fromAddress, tokenId, -amount, amount, 0.0, now);
|
|
|
|
|
|
|
|
// if (countUb != 1) {
|
|
|
|
|
|
|
|
// throw new BtcException(BtcEnums.WITHDRAW_ERROR);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// //并插入一条提现记录
|
|
|
|
|
|
|
|
// BtcWalletTransfer btcWalletTransfer = new BtcWalletTransfer();
|
|
|
|
|
|
|
|
// btcWalletTransfer.setId(UUID.randomUUID().toString());
|
|
|
|
|
|
|
|
//// btcWalletTransfer.setHash(null);
|
|
|
|
|
|
|
|
// btcWalletTransfer.setFromAddr(fromAddress);
|
|
|
|
|
|
|
|
// btcWalletTransfer.setToAddr(toAddress);
|
|
|
|
|
|
|
|
// btcWalletTransfer.setAmount(Math.abs(amount));
|
|
|
|
|
|
|
|
// btcWalletTransfer.setTokenId(tokenId);
|
|
|
|
|
|
|
|
// btcWalletTransfer.setTokenSymbol(tokenSymbol);
|
|
|
|
|
|
|
|
// //设置手续费
|
|
|
|
|
|
|
|
// //TODO 扣减不同币种手续费
|
|
|
|
|
|
|
|
// btcWalletTransfer.setGasPrice(gasDTO.getGasPrice().doubleValue());
|
|
|
|
|
|
|
|
// btcWalletTransfer.setGasTokenType(gasDTO.getGasTokenType());
|
|
|
|
|
|
|
|
// btcWalletTransfer.setGasTokenSymbol(gasDTO.getGasTokenSymbol());
|
|
|
|
|
|
|
|
// btcWalletTransfer.setGasTokenName(gasDTO.getGasTokenName());
|
|
|
|
|
|
|
|
// btcWalletTransfer.setTransferType(BtcTransferConstans.TYPE_OUT);
|
|
|
|
|
|
|
|
// btcWalletTransfer.setStatus(BtcTransferConstans.STATUS_FIRST_TRIAL);
|
|
|
|
|
|
|
|
// btcWalletTransfer.setCreateTime(now);
|
|
|
|
|
|
|
|
// btcWalletTransfer.setUpdateTime(now);
|
|
|
|
|
|
|
|
// int countIt = insertTransfer(btcWalletTransfer);
|
|
|
|
|
|
|
|
// if (countIt != 1) {
|
|
|
|
|
|
|
|
// throw new BtcException(BtcEnums.WITHDRAW_ERROR);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
//返回加减余额后的数据
|
|
|
|
//返回加减余额后的数据
|
|
|
|
return btcWalletService.selectByAddr(fromAddress, tokenId, walletType); |
|
|
|
return btcWalletService.selectByAddr(fromAddress, tokenId, walletType); |
|
|
|