Last active
July 8, 2019 13:29
-
-
Save click2install/20ea1577b8571a96c0bb1a16f1a7b711 to your computer and use it in GitHub Desktop.
Multiple masternode address setup and collateral send
This file contains 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
#!/usr/bin/python | |
# usage: | |
# ensure wallet config has these items without the # prefix, restart the wallet | |
# if they need to be added to the config: | |
# | |
# server=1 | |
# rpcuser=anrpcusername | |
# rpcpassword=apassword | |
# | |
# ./setup.py <host:port> <rpcuser> <rpcpassword> <collateral> <count> <startindex> | |
# e.g., to setup 10 nodes starting at mn-6 | |
# ./setup.py 127.0.0.1:13512 user pass 1000 10 6 | |
# output of masternode key and transaction id will be in transactions.txt in the form | |
# MN-<number> ip:port <privkey> <transaction id> | |
# NOTE: you will need to add the ip:portand the tx output index to each line, then merge it into your masternode.conf file | |
# pip install python-bitcoinrpc | |
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException | |
import os, sys, time, json, hashlib, traceback | |
print '' | |
if len(sys.argv) < 6: | |
print 'usage: '+sys.argv[0]+' <host:port> <user> <pass> <collateral> <count> <startindex>' | |
sys.exit() | |
host=str(sys.argv[1]) | |
rpcuser=str(sys.argv[2]) | |
rpcpass=str(sys.argv[3]) | |
collateral=int(sys.argv[4]) | |
count=int(sys.argv[5]) | |
start=int(sys.argv[6]) | |
f=open("transactions.txt", "w+") | |
try: | |
rpcpipe=AuthServiceProxy('http://'+rpcuser+':'+rpcpass+'@'+host) | |
rpcpipe.getblockcount() | |
print 'rpc ok' | |
except: | |
print 'missing rpc details' | |
traceback.print_exc() | |
sys.exit() | |
for i in range(start, count+start): | |
try: | |
name='MN-'+str(i + 1) | |
# generate a privkey | |
key=rpcpipe.masternode('genkey') | |
# create a new address like MN-<index> | |
addr=rpcpipe.getnewaddress(name) | |
# send the collateral | |
txid=rpcpipe.sendtoaddress(addr, collateral) | |
# lock the transaction so we can keep sending without issues | |
res=rpcpipe.lockunspent(False, [{ 'txid': txid, 'vout': 0 }]) | |
if res == True: | |
f.write(name+' host:port '+key+' '+txid+'\r\n') | |
print('updated'+name) | |
except: | |
print 'error forming transaction' | |
traceback.print_exc() | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment