diff --git a/proxy/client.go b/proxy/client.go index b402dee..04b9bd6 100644 --- a/proxy/client.go +++ b/proxy/client.go @@ -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 -} diff --git a/proxy/feature.go b/proxy/feature.go new file mode 100644 index 0000000..61a2b53 --- /dev/null +++ b/proxy/feature.go @@ -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 +} diff --git a/proxy/server.go b/proxy/server.go index e385682..5c29ecf 100644 --- a/proxy/server.go +++ b/proxy/server.go @@ -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) {