-
-
Save willcl-ark/89bd4731c6d074f5e98ac3332286926a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cbor | |
import json | |
import socket | |
PORT = 50001 | |
HOST = 'localhost' | |
class Client: | |
def __init__(self): | |
self.s = socket.create_connection((HOST, PORT)) | |
self.f = self.s.makefile('r') | |
self.id = 0 | |
def call(self, method, *args): | |
req = { | |
'id': self.id, | |
'method': method, | |
'params': list(args), | |
'jsonrpc': '2.0', | |
} | |
msg = json.dumps(req) + '\n' | |
self.s.sendall(msg.encode('ascii')) | |
self.id += 1 | |
return json.loads(self.f.readline()) | |
def ping(self) -> bytes: | |
return self.call("server.ping") | |
def identify(self) -> bytes: | |
return self.call("server.version", "", "1.4") | |
def check_transaction(self): | |
# Testnet ? | |
# return self.call('blockchain.transaction.get', '40e877718adbe002b5da45222f96b203be8169686b946e157ec88844c68e0cf5') | |
# Signet | |
return self.call('blockchain.transaction.get', 'd8cf417bd59b438620a8ba5fed88b77a070f6e753003695372980b61f0b11939') | |
def stop(self) -> None: | |
self.s.close() | |
if __name__ == "__main__": | |
c = Client() | |
print(c.identify()) | |
print(c.ping()) | |
print(c.check_transaction()) | |
print(c.stop()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment