Improvements
This commit is contained in:
parent
5c71cdc81e
commit
2078467db4
@ -1,17 +1,12 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/deroproject/derohe/block"
|
||||
"github.com/deroproject/derohe/rpc"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
@ -32,7 +27,7 @@ func Start_client(v string, w string) {
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
|
||||
fmt.Println("Connect to node", v, "using wallet address", w)
|
||||
fmt.Println(time.Now().Format(time.Stamp), "Connected to node", v, "using wallet address", w)
|
||||
connection, _, err = websocket.DefaultDialer.Dial(u.String(), nil)
|
||||
if err != nil {
|
||||
time.Sleep(5 * time.Second)
|
||||
@ -59,38 +54,3 @@ func SendToDaemon(buffer []byte) {
|
||||
connection.SetWriteDeadline(time.Now().Add(100 * time.Millisecond))
|
||||
connection.WriteMessage(websocket.TextMessage, buffer)
|
||||
}
|
||||
|
||||
func edit_blob(input []byte) (output []byte) {
|
||||
var err error
|
||||
var params rpc.GetBlockTemplate_Result
|
||||
var mbl block.MiniBlock
|
||||
var raw_hex []byte
|
||||
var out bytes.Buffer
|
||||
|
||||
if err = json.Unmarshal(input, ¶ms); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if raw_hex, err = hex.DecodeString(params.Blockhashing_blob); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if mbl.Deserialize(raw_hex); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for i := range mbl.Nonce {
|
||||
mbl.Nonce[i] = rand.Uint32()
|
||||
}
|
||||
|
||||
params.Blockhashing_blob = fmt.Sprintf("%x", mbl.Serialize())
|
||||
|
||||
encoder := json.NewEncoder(&out)
|
||||
if err = encoder.Encode(params); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
output = out.Bytes()
|
||||
|
||||
return
|
||||
}
|
||||
|
47
proxy/feature.go
Normal file
47
proxy/feature.go
Normal file
@ -0,0 +1,47 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/deroproject/derohe/block"
|
||||
"github.com/deroproject/derohe/rpc"
|
||||
)
|
||||
|
||||
func edit_blob(input []byte) (output []byte) {
|
||||
var err error
|
||||
var params rpc.GetBlockTemplate_Result
|
||||
var mbl block.MiniBlock
|
||||
var raw_hex []byte
|
||||
var out bytes.Buffer
|
||||
|
||||
if err = json.Unmarshal(input, ¶ms); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if raw_hex, err = hex.DecodeString(params.Blockhashing_blob); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if mbl.Deserialize(raw_hex); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for i := range mbl.Nonce {
|
||||
mbl.Nonce[i] = rand.Uint32()
|
||||
}
|
||||
|
||||
params.Blockhashing_blob = fmt.Sprintf("%x", mbl.Serialize())
|
||||
|
||||
encoder := json.NewEncoder(&out)
|
||||
if err = encoder.Encode(params); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
output = out.Bytes()
|
||||
|
||||
return
|
||||
}
|
@ -24,6 +24,7 @@ import (
|
||||
)
|
||||
|
||||
var server *nbhttp.Server
|
||||
var results uint
|
||||
|
||||
var memPool = sync.Pool{
|
||||
New: func() interface{} {
|
||||
@ -166,7 +167,9 @@ func newUpgrader() *websocket.Upgrader {
|
||||
defer client_list_mutex.Unlock()
|
||||
|
||||
SendToDaemon(data)
|
||||
fmt.Println("Submit result to node")
|
||||
fmt.Println(time.Now().Format(time.Stamp), "Submitting result")
|
||||
results++
|
||||
fmt.Println("Submitted results:", results)
|
||||
})
|
||||
|
||||
u.OnClose(func(c *websocket.Conn, err error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user