Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import typing
- import json
- from http.server import BaseHTTPRequestHandler, HTTPServer
- import requests
- class JSONClient:
- def __init__(self, host, port):
- self.url = "http://{}:{}".format(host, port)
- def call(self, method: str, params: typing.List=None, headers=None):
- payload = {
- "method": method,
- "params": params,
- "jsonrpc": "2.0",
- "id": 1,
- }
- return requests.post(self.url, data=json.dumps(payload), headers=headers).json()
- client = JSONClient('localhost', '18332')
- class JSONRPCServer(BaseHTTPRequestHandler):
- def do_POST(self):
- request = json.loads(self.rfile.read(int(self.headers['Content-Length'])).decode())
- result = {
- "id": request.get("id"),
- "result": None,
- "error": None
- }
- headers = {'content-type': 'application/json', 'Authorization': self.headers['Authorization']}
- print('Received Request %s' % request)
- response = client.call(request['method'], request['params'], headers=headers)
- if request['method'] == 'getblocktemplate':
- response['result']['transactions'] = [
- {
- "txid": "fb7a8658ec015133e36e2cf7ddf7e8c887c3a5becec2f30f24ebfe43e72f4b59",
- "data": "010000000a594b2fe743feeb240ff3c2cebea5c387c8e8f7ddf72c6ee3335101ec58867afb000000008a47304402200447ab31b9b503bf42f32ae6862fc5c8a204b317a0bc25fa64863dbe8df79bcc02200644bd09a48b2f2ed77bd5
- c961ed80e264529e44161fdcfe91756c169f28b5c701410455fd1c1a6cbfb25b5bba1cf6f850de00d79852be3de51e50c0da683613303c533d079e147dfe07ce4d40df2b776b35184698d14fa107a61e0976b0d9416880c8ffffffff594b2fe743feeb240ff3c2cebea5c
- 387c8e8f7ddf72c6ee3335101ec58867afb000000008a4730440220507820553c1ece1d85637bc56b1f569d486232b3f089a7a971a78de75de9ff2302204ecce80d8664b244a91ef4ece4c9b15caafa862e611e3464c53cd40370f5250f01410455fd1c1a6cbfb25b5bba
- 1cf6f850de00d79852be3de51e50c0da683613303c533d079e147dfe07ce4d40df2b776b35184698d14fa107a61e0976b0d9416880c8ffffffff594b2fe743feeb240ff3c2cebea5c387c8e8f7ddf72c6ee3335101ec58867afb000000008b483045022100e4e2fad5e49
- 2d43028c24369f32ed401bff5b7b8091494645a85574f7f43d388022057e41e16887094ad81c7c693c6a91660cbfd6e03dcdb5f2db522c2a18718e20201410455fd1c1a6cbfb25b5bba1cf6f850de00d79852be3de51e50c0da683613303c533d079e147dfe07ce4d40df
- 2b776b35184698d14fa107a61e0976b0d9416880c8ffffffff594b2fe743feeb240ff3c2cebea5c387c8e8f7ddf72c6ee3335101ec58867afb000000008b483045022100fe79d350f6419f10097cb094fa783135c0bfe996e7bc33a766eb4db6bbebd4fd022078d9c0933
- 3fdf1be816b01271c819a29643550b119fed3fac0ee7f4b796bc3a101410455fd1c1a6cbfb25b5bba1cf6f850de00d79852be3de51e50c0da683613303c533d079e147dfe07ce4d40df2b776b35184698d14fa107a61e0976b0d9416880c8ffffffff594b2fe743feeb24
- 0ff3c2cebea5c387c8e8f7ddf72c6ee3335101ec58867afb000000008b483045022100f8141cb972d989bb69dc40a07e3158ee02065c3040a3415c7e1cb0cb7b326c1602205f80c7b6f8517f0d14162980fb6f0f9b8564929bc34b541e014ca94756d4062901410455fd1
- c1a6cbfb25b5bba1cf6f850de00d79852be3de51e50c0da683613303c533d079e147dfe07ce4d40df2b776b35184698d14fa107a61e0976b0d9416880c8ffffffff594b2fe743feeb240ff3c2cebea5c387c8e8f7ddf72c6ee3335101ec58867afb000000008a47304402
- 2021a4cf7f40ea947694f5545f4f57492630ddbb710e85ed9f7b1eee330fdc068d02201db5766cf7d78666e3bbc9af42cdebb3e7a26bdb7c9affca36bdeae6c3fa972101410455fd1c1a6cbfb25b5bba1cf6f850de00d79852be3de51e50c0da683613303c533d079e147
- dfe07ce4d40df2b776b35184698d14fa107a61e0976b0d9416880c8ffffffff594b2fe743feeb240ff3c2cebea5c387c8e8f7ddf72c6ee3335101ec58867afb000000008b4830450221009cb14db295216a01820dc0d72fe26d824355ede8d72b722e514d114894c18ed5
- 022079a88ae3eecf6b2b943b9d227c4d26f37e999ecdc86e0edefd052706ca56b25c01410455fd1c1a6cbfb25b5bba1cf6f850de00d79852be3de51e50c0da683613303c533d079e147dfe07ce4d40df2b776b35184698d14fa107a61e0976b0d9416880c8ffffffff594
- b2fe743feeb240ff3c2cebea5c387c8e8f7ddf72c6ee3335101ec58867afb000000008b4830450221009850edd2d30c9a5f104ff645754a6bc40c2a18b40cd9cf2029fa6bc039b2b9a102206aae1b271a3f798bb263ddac931abe96cba37acf3756aa728c714e7b6a7476
- b701410455fd1c1a6cbfb25b5bba1cf6f850de00d79852be3de51e50c0da683613303c533d079e147dfe07ce4d40df2b776b35184698d14fa107a61e0976b0d9416880c8ffffffff594b2fe743feeb240ff3c2cebea5c387c8e8f7ddf72c6ee3335101ec58867afb00000
- 0008b483045022100db63a0753f6c2e88abfeb9f110777e64cbc0885d12b2ddcbee0f76a99186a2e4022024fc9e1c69c0d71c46ee406e838cf2d91893aef81a4d6c3767536c17a9ef44e401410455fd1c1a6cbfb25b5bba1cf6f850de00d79852be3de51e50c0da683613
- 303c533d079e147dfe07ce4d40df2b776b35184698d14fa107a61e0976b0d9416880c8ffffffff594b2fe743feeb240ff3c2cebea5c387c8e8f7ddf72c6ee3335101ec58867afb000000008a4730440220579435bc544e909cc65a6f628d8160ba7343b828278b4ea15db
- 05fe845cd3b16022002bfef77308bb3179cbf5e49e1635b87aa19ad49f1ec55f9414a4fa7d1a13d6f01410455fd1c1a6cbfb25b5bba1cf6f850de00d79852be3de51e50c0da683613303c533d079e147dfe07ce4d40df2b776b35184698d14fa107a61e0976b0d9416880
- c8ffffffff012018e505000000001976a914c8b876680fef08df5278a9df92df7e30b83cbb7188ac00000000",
- "hash": "fb7a8658ec015133e36e2cf7ddf7e8c887c3a5becec2f30f24ebfe43e72f4b59",
- "depends": [],
- "fee": 100000,
- "sigops": 80,
- "weight": 9040
- }
- ]
- result.update(response)
- self.send_response(200)
- self.send_header('Content-type', 'application/json')
- self.end_headers()
- self.wfile.write(json.dumps(response).encode())
- if __name__ == '__main__':
- HTTPServer(('localhost', 18161), JSONRPCServer).serve_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement