Search in sources :

Example 1 with EthereumAddress

use of com.whoiszxl.common.EthereumAddress in project shopzz by whoiszxl.

the class ShopzzFeignClientImpl method giveAddress.

@Override
@Transactional
public ResponseResult<RechargeResponse> giveAddress(String orderId, String amount) {
    // 1. 获取货币信息
    Currency ethInfo = currencyService.getCurrencyByName(currencyName);
    AssertUtils.isNotNull(ethInfo, "数据库未配置货币信息:" + currencyName);
    // 2. 通过keystore的方式生成一个以太坊地址
    EthereumAddress ethereumAddress = ethereumService.createAddressByFile();
    String qrCodeData = getQrCodeData(amount, ethereumAddress.getAddress());
    // 3. 保存keystore文件与地址的对应关系
    CurrencyAccount account = new CurrencyAccount();
    account.setAddress(ethereumAddress.getAddress());
    account.setCurrencyId(ethInfo.getId());
    account.setCurrencyName(ethInfo.getCurrencyName());
    account.setKeystoreName(ethereumAddress.getKeystoreName());
    account.setMnemonic(ethereumAddress.getMnemonic());
    currencyAccountService.save(account);
    return ResponseResult.buildSuccess(new RechargeResponse(ethInfo.getId(), ethereumAddress.getAddress(), qrCodeData));
}
Also used : EthereumAddress(com.whoiszxl.common.EthereumAddress) CurrencyAccount(com.whoiszxl.entity.CurrencyAccount) RechargeResponse(com.whoiszxl.entity.response.RechargeResponse) Currency(com.whoiszxl.entity.Currency) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with EthereumAddress

use of com.whoiszxl.common.EthereumAddress in project shopzz by whoiszxl.

the class EthereumService method createAddressByFile.

/**
 * 通过keystore文件生成地址
 * @return 地址与keystore文件名
 */
public EthereumAddress createAddressByFile() {
    try {
        String fileName = WalletUtils.generateNewWalletFile(keystorePassword, new File(keystorePath), false);
        Credentials credentials = WalletUtils.loadCredentials(keystorePassword, keystorePath + File.separator + fileName);
        String address = credentials.getAddress();
        return new EthereumAddress(address, fileName, null);
    } catch (Exception e) {
        log.error("通过keystore文件生成地址发生异常:", e);
        return null;
    }
}
Also used : EthereumAddress(com.whoiszxl.common.EthereumAddress) File(java.io.File) Credentials(org.web3j.crypto.Credentials) IOException(java.io.IOException)

Example 3 with EthereumAddress

use of com.whoiszxl.common.EthereumAddress in project shopzz by whoiszxl.

the class EthFeignClientImpl method giveAddress.

@Override
@Transactional
@PostMapping("/createRecharge/{orderId}/{amount}")
public ResponseResult<RechargeResponse> giveAddress(String orderId, String amount) {
    // 1. 获取货币信息
    Currency ethInfo = currencyService.getCurrencyByName(currencyName);
    AssertUtils.isNotNull(ethInfo, "数据库未配置货币信息:" + currencyName);
    // 2. 通过keystore的方式生成一个以太坊地址
    EthereumAddress ethereumAddress = ethereumService.createAddressByFile();
    String qrCodeData = getQrCodeData(amount, ethereumAddress.getAddress());
    // 3. 保存keystore文件与地址的对应关系
    CurrencyAccount account = new CurrencyAccount();
    account.setAddress(ethereumAddress.getAddress());
    account.setCurrencyId(ethInfo.getId());
    account.setCurrencyName(ethInfo.getCurrencyName());
    account.setKeystoreName(ethereumAddress.getKeystoreName());
    account.setMnemonic(ethereumAddress.getMnemonic());
    currencyAccountService.save(account);
    return ResponseResult.buildSuccess(new RechargeResponse(ethInfo.getId(), ethereumAddress.getAddress(), qrCodeData));
}
Also used : EthereumAddress(com.whoiszxl.common.EthereumAddress) CurrencyAccount(com.whoiszxl.entity.CurrencyAccount) RechargeResponse(com.whoiszxl.entity.response.RechargeResponse) Currency(com.whoiszxl.entity.Currency) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with EthereumAddress

use of com.whoiszxl.common.EthereumAddress in project shopzz by whoiszxl.

the class ZXLFeignClientImpl method giveAddress.

@Override
@Transactional
public ResponseResult<RechargeResponse> giveAddress(String orderId, String amount) {
    // 1. 获取货币信息
    Currency ethInfo = currencyService.getCurrencyByName(currencyName);
    AssertUtils.isNotNull(ethInfo, "数据库未配置货币信息:" + currencyName);
    // 2. 通过keystore的方式生成一个以太坊地址
    EthereumAddress ethereumAddress = ethereumService.createAddressByFile();
    String qrCodeData = getQrCodeData(amount, ethereumAddress.getAddress());
    // 3. 保存keystore文件与地址的对应关系
    CurrencyAccount account = new CurrencyAccount();
    account.setAddress(ethereumAddress.getAddress());
    account.setCurrencyId(ethInfo.getId());
    account.setCurrencyName(ethInfo.getCurrencyName());
    account.setKeystoreName(ethereumAddress.getKeystoreName());
    account.setMnemonic(ethereumAddress.getMnemonic());
    currencyAccountService.save(account);
    return ResponseResult.buildSuccess(new RechargeResponse(ethInfo.getId(), ethereumAddress.getAddress(), qrCodeData));
}
Also used : EthereumAddress(com.whoiszxl.common.EthereumAddress) CurrencyAccount(com.whoiszxl.entity.CurrencyAccount) RechargeResponse(com.whoiszxl.entity.response.RechargeResponse) Currency(com.whoiszxl.entity.Currency) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

EthereumAddress (com.whoiszxl.common.EthereumAddress)4 Currency (com.whoiszxl.entity.Currency)3 CurrencyAccount (com.whoiszxl.entity.CurrencyAccount)3 RechargeResponse (com.whoiszxl.entity.response.RechargeResponse)3 Transactional (org.springframework.transaction.annotation.Transactional)3 File (java.io.File)1 IOException (java.io.IOException)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 Credentials (org.web3j.crypto.Credentials)1