69 lines
1.6 KiB
C#
69 lines
1.6 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
|
|
using sharp.jsonrpc;
|
|
using sharp.extensions;
|
|
|
|
namespace sharp.cryptonote.rpc
|
|
{
|
|
public class Daemon
|
|
{
|
|
RPCConnector rpc;
|
|
|
|
public Daemon(string host,int port)
|
|
{
|
|
this.rpc = new RPCConnector(host, port);
|
|
}
|
|
|
|
|
|
public int GetBlockCount(){
|
|
Response response = rpc.Call("getblockcount");
|
|
if (response.Success()){
|
|
return Convert.ToInt32(response.result["count"].ToObject<int>());
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public BlockTemplate getBlockTemplate(CryptoNoteAddress wallet,uint reserve_size){
|
|
BlockTemplate bt = null;
|
|
Response response = this.rpc.Call()
|
|
.method("getblocktemplate")
|
|
.parameter("wallet_address", wallet.ToString())
|
|
.parameter("reserve_size", reserve_size)
|
|
.execute();
|
|
|
|
if (response.Success()){
|
|
byte[] blob = HexString.toBytes(response.result["blocktemplate_blob"].ToString());
|
|
bt = new BlockTemplate(
|
|
blob,
|
|
response.result["difficulty"].ToObject<UInt64>(),
|
|
response.result["height"].ToObject<UInt64>(),
|
|
response.result["prev_hash"].ToObject<string>(),
|
|
response.result["reserved_offset"].ToObject<Int64>(),
|
|
reserve_size
|
|
);
|
|
}
|
|
return bt;
|
|
}
|
|
|
|
public bool check(){
|
|
return this.rpc.Call("get_info").Success();
|
|
|
|
}
|
|
|
|
public Int64 getTargetHeight(){
|
|
Response response = rpc.Call("get_info");
|
|
if (response.Success()){
|
|
return response.result["target_height"].ToObject<int>();
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
|
|
}
|
|
}
|