Browse Source

Avoid handling hex encoding in work2d

Luke Dashjr 12 years ago
parent
commit
642ef7bd0e
3 changed files with 7 additions and 5 deletions
  1. 3 1
      driver-stratum.c
  2. 3 3
      work2d.c
  3. 1 1
      work2d.h

+ 3 - 1
driver-stratum.c

@@ -367,6 +367,7 @@ void stratumsrv_mining_submit(struct bufferevent *bev, json_t *params, const cha
 	const char * const extranonce2 = __json_array_string(params, 2);
 	const char * const ntime = __json_array_string(params, 3);
 	const char * const nonce = __json_array_string(params, 4);
+	uint8_t xnonce2[work2d_xnonce2sz];
 	uint32_t nonce_n;
 	
 	if (unlikely(!client))
@@ -390,7 +391,8 @@ void stratumsrv_mining_submit(struct bufferevent *bev, json_t *params, const cha
 	
 	// Generate dummy work
 	work = &_work;
-	_ssm_gen_dummy_work(work, &ssj->swork, &ssj->tv_prepared, extranonce2, *xnonce1_p);
+	hex2bin(xnonce2, extranonce2, work2d_xnonce2sz);
+	work2d_gen_dummy_work(work, &ssj->swork, &ssj->tv_prepared, xnonce2, *xnonce1_p);
 	
 	// Submit nonce
 	hex2bin(&work->data[68], ntime, 4);

+ 3 - 3
work2d.c

@@ -48,7 +48,7 @@ void release_work2d_(uint32_t xnonce1)
 	work2d_reserved[xnonce1] = false;
 }
 
-void work2d_gen_dummy_work(struct work * const work, struct stratum_work * const swork, const struct timeval * const tvp_prepared, const char * const extranonce2, const uint32_t xnonce1)
+void work2d_gen_dummy_work(struct work * const work, struct stratum_work * const swork, const struct timeval * const tvp_prepared, const void * const xnonce2, const uint32_t xnonce1)
 {
 	uint8_t *p, *s;
 	
@@ -60,8 +60,8 @@ void work2d_gen_dummy_work(struct work * const work, struct stratum_work * const
 	bytes_resize(&work->nonce2, swork->n2size);
 	s = bytes_buf(&work->nonce2);
 	p = &s[swork->n2size - work2d_xnonce2sz];
-	if (extranonce2)
-		hex2bin(p, extranonce2, work2d_xnonce2sz);
+	if (xnonce2)
+		memcpy(p, xnonce2, work2d_xnonce2sz);
 #ifndef __OPTIMIZE__
 	else
 		memset(p, '\0', work2d_xnonce2sz);

+ 1 - 1
work2d.h

@@ -11,6 +11,6 @@ extern void work2d_init();
 extern bool reserve_work2d_(uint32_t *xnonce1_p);
 extern void release_work2d_(uint32_t xnonce1);
 
-extern void work2d_gen_dummy_work(struct work *, struct stratum_work *, const struct timeval *tvp_prepared, const char *extranonce2, uint32_t xnonce1);
+extern void work2d_gen_dummy_work(struct work *, struct stratum_work *, const struct timeval *tvp_prepared, const void *xnonce2, uint32_t xnonce1);
 
 #endif