json-rpc 调用btc、usdt钱包节点 java


前言:

       搭建完钱包节点(节点搭建不作说明^_^),调用其api进行签名转账等操作。

       详细Api地址参考:

       btc:https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list

       usdt:https://github.com/OmniLayer/omnicore/blob/master/src/omnicore/doc/rpc-api.md

        这里使用json-rpc进行客户端构建,以springboot项目为基础:


pom:

    <dependency>  
        <groupId>com.github.briandilley.jsonrpc4j</groupId>  
        <artifactId>jsonrpc4j</artifactId>  
        <version>1.1</version>  
    </dependency>

Client:

@Component
@Configuration 
public class CoinRpcClient {
	
	private Logger LOG = LoggerFactory.getLogger(getClass());
	
	@Value("${btc.rpc.user}")
	public  String user; //验证用户名
	@Value("${btc.rpc.password}")
	public  String password; //验证密码
	@Value("${btc.rpc.allowip}")
	public  String allowip; //验证ip
	@Value("${btc.rpc.port}")
	public  String port; //验证端口
	
	 
	// 比特币身份认证
	public JsonRpcHttpClient getClient() {
		JsonRpcHttpClient client = null;
		try {
			String cred = Base64.encodeBytes((user + ":" + password).getBytes());
			Map<String, String> headers = new HashMap<String, String>(1);
			headers.put("Authorization", "Basic " + cred);
			client = new JsonRpcHttpClient(new URL("http://" + allowip + ":" + port), headers);
		} catch (Exception e) {
			LOG.info("===com.bscoin.bit.env.CoinRpcClient:{} btc client !===",e.getMessage(),e);
		}
		return client;
	}
	 
}

常用接口:

public interface BtcService {
	
	  
	    /**
	     * @throws Throwable 
	     * @throws Exception   
	    * @Title: validateaddress 验证钱包地址是否有效  
	    * @param @param address
	    * @param @return    参数  
	    * @return boolean    返回类型  
	    * @throws  
	    */  
	  boolean validateAddress(String address) throws  CoinException;
	  
	    
	    /**
	     * @throws CoinException   
	    * @Title: getBalance  
	    * @param @param account
	    * @param @return    参数  
	    * @return Object    返回类型  
	    * @throws  
	    */  
	  double getBalance(String  account) throws CoinException;
	
	    
	    /**
	     * @throws CoinException   
	    * @Title: signSendToAddress  
	    * @param @param address
	    * @param @param amount
	    * @param @return    参数  
	    * @return Object    返回类型  
	    * @throws  
	    * <amount>是一个实数,并四舍五入到小数点后8位。如果成功,则返回事务ID <txid>
	    */  
	Object signSendToAddress(String address,double amount) throws CoinException;
	  
	    
	    /**
	     * @throws CoinException   
	    * @Title: multiSendToAddress  
	    * @param @param fromaccount
	    * @param @param target
	    * @param @return    参数  
	    * @return Object    返回类型  
	    * @throws  
	    */  
	Object multiSendToAddress(String fromaccount,Object target) throws CoinException;
	  
	    
	    /**
	     * @throws CoinException   
	    * @Title: getTransaction  
	    * @param @param txId
	 
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值