web3j GasUsed GasPrice Transaction Input 交易是否成功

//        EthGetTransactionReceipt send = Web3JClient.getWeb3j().ethGetTransactionReceipt(txhash).send();
//        EthTransaction send1 = Web3JClient.getWeb3j().ethGetTransactionByHash(txhash).send();
//        BigInteger transactionReceipt = send1.getTransaction().get().getGasPrice();
//        BigInteger gasUsed = send.getTransactionReceipt().get().getGasUsed();
 public void parseInput(){
        String inputData = "0xa9059cbb0000000000000000000000006a2972e43f38f0b8217c119394d9b5a4cd116e9c000000000000000000000000000000000000000000000001bc16d674ec800000";
        String method = inputData.substring(0,10);
        String to = inputData.substring(10,74);
        String value = inputData.substring(74);
        Method refMethod = null;
        try {
            refMethod = TypeDecoder.class.getDeclaredMethod("decode",String.class,int.class,Class.class);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        refMethod.setAccessible(true);
        Address address = null;
        try {
            address = (Address)refMethod.invoke(null,to,0,Address.class);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        Uint256 amount = null;
        try {
            amount = (Uint256) refMethod.invoke(null,value,0,Uint256.class);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        System.out.println("method="+method+"\nto="+to+"\nvalue="+value+"\naddress="+address.getValue()+"\namount="+amount.getValue());
    }
   /**
     *
     * @param web3j
     * @param txhash
     * @return
     * 0失败 1成功
     */
    public static String getStatus(Web3j web3j,String txhash){
        String status = "0";
        try {
            EthGetTransactionReceipt ethGetTransactionReceipt = web3j.ethGetTransactionReceipt(txhash).sendAsync().get();
            String status1 = ethGetTransactionReceipt.getTransactionReceipt().get().getStatus();
            if(!Strings.isNullOrEmpty(status1)){
                status = status1.substring(2);
                System.out.println(status);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return status;
    }


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值