chia/xch rpc形式充提生成地址

这里暂时用的都是rpc,只用到了 wallet模块,个人觉得比较复杂的是节点的搭建与维护,官方也经常更新,我代码后续也会进行优化改进,有偿咨询(加的人有点多了,回复不过来) qq:284466315

1.生成地址: 

 JSONObject post = post("https://localhost:9256/get_next_address", "{\"wallet_id\": 1, \"new_address\":true}", AUTH_WALLET_FILE_URL, AUTH_KEYWORDS);
            if (post != null && post.getBoolean("success")) {
                return post.getString("address");
            }

2.查询充值,这里暂时没有用扫块,后续会更新

 JSONObject transactions = post("https://localhost:9256/get_transactions", "{\"wallet_id\": 1}", AUTH_WALLET_FILE_URL, AUTH_KEYWORDS);
            Boolean success = transactions.getBoolean("success");
            if (transactions != null && success) {
                AddressUtil addressUtil = AddressUtil.getInstance();
                JSONArray transactionsList = transactions.getJSONArray("transactions");
                for (Object transaction :
                        transactionsList) {
                    JSONObject jsonObject = JSONObject.parseObject(transaction.toString());
                    // 0接收记录 1 提币记录
                    Integer sent = jsonObject.getInteger("sent");
                    // 区块确认高度
                    Integer confirmedAtHeight = jsonObject.getInteger("confirmed_at_height");
                    //是否被确认
                    Boolean confirmed = jsonObject.getBoolean("confirmed");
                    // hash值
                    JSONObject coinIdVo = jsonObject.getJSONArray("additions").getJSONObject(0);
                        String hash = getHash(coinIdVo.getBigInteger("amount"), coinIdVo.getString("parent_coin_info"), coinIdVo.getString("puzzle_hash"));
                    // 接收地址
                    String toAddress = jsonObject.getString("to_address");
                    BigDecimal amount = jsonObject.getBigDecimal("amount").divide(BigDecimal.TEN.pow(12), 8, BigDecimal.ROUND_DOWN);

3.提币 

JSONObject requestBody = new JSONObject();
        requestBody.put("wallet_id", 1);
        requestBody.put("amount", amount.multiply(BigDecimal.TEN.pow(12)).toBigInteger());
        requestBody.put("fee", 0);
        requestBody.put("address", toAddress);

        JSONObject post = post("https://localhost:9256/send_transaction", requestBody.toJSONString(), AUTH_WALLET_FILE_URL, AUTH_KEYWORDS);
        Boolean success = post.getBoolean("success");

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值