Skip to content

Instantly share code, notes, and snippets.

@ender503
Created October 4, 2019 02:24
Show Gist options
  • Save ender503/7e942c14951991a8899ec141c8af50df to your computer and use it in GitHub Desktop.
Save ender503/7e942c14951991a8899ec141c8af50df to your computer and use it in GitHub Desktop.
import json
import random
import threading
import time
import urllib2
# Static variables
tipsFile="tips"
randomFile="random"
threadNum=1
threadNumPerSec=50
bundleSize=2
iri="http://node1.puyuma.org:14265"
# Dynamic variables
tips = json.loads(open(tipsFile, "r").read())["hashes"]
tipsNum = len(tips)
def attRequest(index1, index2):
trunk = tips[index1]
branch = tips[index2]
command = {
"command": "attachToTangle",
"trunkTransaction": trunk,
"branchTransaction": branch,
"minWeightMagnitude": 14,
"trytes": [
"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999TDZSTWLNTKQSTPEKEPDHIXBECECXIAPQFAXBUJCQC9VPNUOHQAZAYECQFIN9SQSWFCHLDTCZJOJPQWZJS999999999999999999999999999AC9999999999999999999999999MVOETAD99999999999A99999999ABBXQDA9JRRKASZXRGIGIEPEAXQJVZWLZUQLNHHJLTLADDSTBKCPOTPGCMXIKUNTTHAKUBTIHKEILCOFX"
+"VFKKRTFSJNZFDT9Y9NREEHWVEBTYVEZCOZXXWVZX9STJHTXEALGFHGLMNLBKFJPZDLEQQSZDTV9JA9999"
+branch
+"IONONZOXVGTNGVEOCXPUI999999VIPN9RENF999999999MMMMMMMMMNZ99999999UGG99999999999999",
"BKAADEZMUMBLADSDQ9PRXZZ99WIZNEQBOWRYGW9QK9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999TDZSTWLNTKQSTPEKEPDHIXBECECXIAPQFAXBUJCQC9VPNUOHQAZAYECQFIN9SQSWFCHLDTCZJOJPQWZJS999999999999999999999999999999999999999999999999999999MVOETAD99A99999999A99999999ABBXQDA9JRRKASZXRGIGIEPEAXQJVZWLZUQLNHHJLTLADDSTBKCPOTPGCMXIKUNTTHAKUBTIHKEILCOFX"
+trunk
+branch
+"IONONZOXVGTNGVEOCXPUIZ99999LCON9RENF999999999MMMMMMMMM9OA9999999UAL99999999999999"
]
}
stringified = json.dumps(command)
headers = {
'content-type': 'application/json',
'X-IOTA-API-Version': '1'
}
#print "ready to start"
request = urllib2.Request(url=iri, data=stringified, headers=headers)
#print "send done"
returnData = urllib2.urlopen(request).read()
jsonData = json.loads(returnData)
print jsonData
def randomIndex():
# Count the line number of the file
f = open(randomFile, "a+")
lineNum = sum(1 for line in f)
# Add new random index if they are not enough
if lineNum < threadNum * bundleSize:
for i in range(threadNum * bundleSize - lineNum):
index = random.randint(0, tipsNum - 1)
f.write(str(index) + "\n")
f.close()
print "line number: " + str(lineNum)
if __name__ == '__main__':
randomIndex()
f = open(randomFile, "r")
count = 0
for times in range(threadNum):
index1 = int(f.readline())
index2 = int(f.readline())
print index1
print index2
thread = threading.Thread(target = attRequest, args=(index1, index2))
thread.start()
count += 1
if count % threadNumPerSec == 0:
time.sleep(2)
#thread.join()
f.close()
#print("Done.")
@marktwtn
Copy link

marktwtn commented Oct 4, 2019

Parsing returned result Python script:

#!/usr/bin/python

import json

transactionNum=200

if __name__ == '__main__':
    f = open("iri-coach-local", "r")
    for idx in range(transactionNum):
        jsonData = eval(f.readline())
        print jsonData['duration']
    f.close()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment