-
Notifications
You must be signed in to change notification settings - Fork 4
/
send.py
executable file
·48 lines (41 loc) · 1.39 KB
/
send.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
import sys
import codecs
import requests
import time
import getconf
import readline
ORCLID = sys.argv[2]
CHAIN = sys.argv[1]
while True:
message = "[" + str(int(time.time())) + " ,\"" + input("Type message: ") + "\"]"
#convert message to hex
rawhex = codecs.encode(message).hex()
#get length in bytes of hex in decimal
bytelen = int(len(rawhex) / int(2))
hexlen = format(bytelen, 'x')
#get length in big endian hex
if bytelen < 16:
bigend = "000" + str(hexlen)
elif bytelen < 256:
bigend = "00" + str(hexlen)
elif bytelen < 4096:
bigend = "0" + str(hexlen)
elif bytelen < 65536:
bigend = str(hexlen)
else:
print("message too large, must be less than 65536 characters")
continue
#convert big endian length to little endian, append rawhex to little endian length
lilend = bigend[2] + bigend[3] + bigend[0] + bigend[1]
fullhex = lilend + rawhex
#print(fullhex)
oraclesdata_result = getconf.oraclesdata_rpc(CHAIN, ORCLID, fullhex)
#print(oraclesdata_result)
result = oraclesdata_result['result']
if result == 'error':
print('ERROR:' + oraclesdata_result['error'] + ', try using oraclesregister if you have not already')
continue
rawtx = oraclesdata_result['hex']
sendrawtx_result = getconf.sendrawtx_rpc(CHAIN, rawtx)
#print(sendrawtx_result)