Open wantsliveforever opened 5 years ago
And i change in daemonbase MakeHttpRequest from stream to httpclient, because first in getrequeststream process get 500 internal server error.
I change it to this function.
public async Task<string> MakeMyHttpRequest(DaemonRequest walletRequest)
{
Socket NewSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
var handler = new HttpClientHandler();
handler.Credentials = new NetworkCredential(RpcUser, RpcPassword);
HttpClient httpClient = new HttpClient(handler);
HttpContent content = new StringContent(JsonConvert.SerializeObject(walletRequest));
HttpRequestMessage request = new HttpRequestMessage();
HttpResponseMessage responce = new HttpResponseMessage();
string answer = "Empty";
httpClient.Timeout = TimeSpan.FromSeconds(5);
var headerVal = Convert.ToBase64String(Encoding.UTF8.GetBytes(RpcUser + ":" + RpcPassword));
var header = new AuthenticationHeaderValue("Basic", headerVal);
httpClient.DefaultRequestHeaders.Authorization = header;
try
{
request.RequestUri = new Uri(RpcUrl);
request.Method = HttpMethod.Post;
request.Headers.Add("Accept", "application/json-rpc");
request.Content = content;
responce = await httpClient.SendAsync(request);
if (responce.StatusCode == HttpStatusCode.OK)
{
HttpContent responseContent = responce.Content;
var json = await responseContent.ReadAsStringAsync();
var statusCoder = responce.StatusCode;
answer = json.ToString();
}
else answer = "";
httpClient.Dispose();
NewSocket.Close();
request.Dispose();
content.Dispose();
responce.Dispose();
}
catch
{
answer = "No response";
httpClient.Dispose();
NewSocket.Close();
request.Dispose();
content.Dispose();
responce.Dispose();
}
return answer;
}
Maybe the SerializeHeader for Litecoin not like in Bitcoin?
public static byte[] SerializeHeader(IJob job, byte[] merkleRoot, UInt32 nTime, UInt32 nonce)
{
byte[] result;
using (var stream = new MemoryStream())
{
stream.WriteValueU32(nonce.BigEndian());
stream.WriteValueU32(Convert.ToUInt32(job.EncodedDifficulty, 16).BigEndian());
stream.WriteValueU32(nTime.BigEndian());
stream.WriteBytes(merkleRoot);
stream.WriteBytes(job.PreviousBlockHash.HexToByteArray());
stream.WriteValueU32(job.BlockTemplate.Version.BigEndian());
result = stream.ToArray();
result = result.ReverseBytes();
}
return result;
}
In Bitcoin all ok!
No, in Litecoin the same serializer. This is from wiki. Data is broken down to: Version - 00000001 (4 bytes) Previous hash - 05e9a54b7f65b46864bc90f55d67cccd8b6404a02f5e064a6df69282adf6e2e5 (32 bytes) Merkle root - f7f953b0632b25b099858b717bb7b24084148cfa841a89f106bc6b655b18d2ed (32 bytes) Timestamp - 4ebb191a (4 bytes) Bits (target in compact form) - 1d018ea7 (4 bytes) Nonce - 00000000 (4 bytes)
I fix it. I rewrite Scrypt hash function to:
byte[] output = new byte[1000];
SCrypt.ComputeKey(input, input, _n, _r, _p, null, output);
return output;
this correct!
byte[] output = new byte[32];
SCrypt.ComputeKey(input, input, _n, _r, _p, null, output);
return output;
Hello! When the shares is calculation i always get 0 in diffculty. //Share.cs//
Difficulty = ((double)new BigRational(AlgorithmManager.Diff1, HeaderValue)) * Job.HashAlgorithm.Multiplier;
This is happend because HeaderValue number is much bigger then Diff1.
HeaderValue is 18308077285001432591051232479151417023503193169085591643374867018805384739984244496185794225130565092309796298774140748600129783667459792256869114562603531892631582144809521832133231839772552517288545984562640620319395336069752474029856204078897738313795754567094976692792776956735682032683460561039138235237814485106733650535664915813007227650836155329148277280989133876297908513993043401312904942732771747328492245052054430595748069033567464691692573879579536735426675474155516689119551940355474807520670955300739311016466797296691267560003389805507272301081809833986714325296663821845529662946589109195837187298290629148752012190685203386709999308220700681284001469830539923181235023125164024873190112407198598159618522922963652511469812643686326050078072235294751329805556980232739745811973641461875804940430354572869447352340420652723419877092124466206562357218392476083792588392106800220652373565377709410314872065779348127324218696011354564442870473893506478120462021940268002804357539322068836488834987951974917167735736119752766836476780731333959103276440606900359621652134830176836908391888248191183646374884962003546534735044358198268401216400414874571600796720156575629475124354005865153606781665540208221215308223141241798807883885299713733656382631440704274387343501479162396863379850287552134906816703366439281213574055917554623635192730766458001309688991060700867626544892155311329731151969204886611203584538722460345899931875738572313101828495899825324579374814688649743698352953192572283576967483444334728229102086627834745813692711424030203749959152103044195028223727518924973742742023788086146493849918857319361445982741237790283399352227083181219214342932008782520818233817919860431964579850981598148526939687729167139245276333111298370905435813764723675264361931423246929960209250384126245468901057060350782886860888740743636178490986049780145702335644946967639965146091860372859144642551310996900380952672266048265251180407077943542413633425625688691473596040643044697398699544278440344881537936863182605073965429614511621871501368145596652855882899297618077841380860175517697474120762258328152637845770971200841281829602913481897264034125598502553113927737543538288478967373527957428784050444372779567116956988456042955147338403019585670333085524837390528251841797638416769800100646736431756690710842689668395590884534205484671348983453243072837269953662640936470408108645769603374989
Diff1 is 13479767645505654746578238172361995668005449369287082043068886548480
0 happend when BigRational try to convert in (double) in this row: //BigRational.cs converter to double//
value.sign == 1; s_bnDoublePrecision={100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000} Always return 0 Where to find, I do not know.
I try to rewrite to this way calculation share (from zcoiniumserv) // create the block headers
Such result.