Stratum protocol – problem with implementation in python : Bitcoin

Hello everyone 🙂

For a couple of days I’m trying to write simple script in python to communicate with stratum pool server. I’m using simplified code of NightMiner (https://github.com/ricmoo/nightminer/) and some testnet I’ve foud ( stratum+tcp://pool.bitcoincloud.net:4008), but I can’t get the proper result. Maybe someone more experienced could help me. Below I show each step of my script (step, no python source code).

1. connect to the server, authorize, get the job data

After connecting to the server I send this requests:

b'{"id": 1, "method": "mining.subscribe", "params": []}n'
b'{"params": ["testuser", "anything"], "id": 2, "method": "mining.authorize"}n'

and get the following response:

{"id":1,"result":[[["mining.set_difficulty","deadbeefcafebabe4000000000000000"],["mining.notify","deadbeefcafebabe4000000000000000"]],"1000003e",4],"error":null}
{"id":null,"method":"mining.set_difficulty","params":[0.01]}
{"id":null,"method":"mining.notify","params":["53b5","21039cb098cb473758861d7c0ea32145df033e6c008dacad0000022200000000","01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff25031c7614042a82135e08","122f626974636f696e636c6f75642e6e65742f0000000002793e9c04000000001976a91423e020eacd64acfe093150331d44fdbcc0c7ce0688acf1eb0b00000000001976a91400bf6d61c2a34df5a9ea338fcad188c31bb4a52388ac00000000",["12ae2555f80b865bac89fa3aeb4df41b730422670fb80d1a0536276b481fab53","e1f7983af4815cb2116f16c6af916f0a139ad5a7588fd029572c6e403f9fed5d","6d5861e558d057993fdae3007ff5b49807d6f43b218e1ef85ed81223747278f1","847e7a24328302a2a8dbdad177d44d5a20916a0ba36edf2dc667c01a09da298c"],"20000000","1a03550b","5e13824a",false]}

2. get the coinbase and merkle root

With this data and extranounce=’00000000′ I can build the coinbase (in byte form, but I will show as hex in this example):

Source Link