Skip to content

Instantly share code, notes, and snippets.

@msm595
Created April 13, 2013 04:25
Show Gist options
  • Save msm595/5376933 to your computer and use it in GitHub Desktop.
Save msm595/5376933 to your computer and use it in GitHub Desktop.
Sharelitecoins is a script to send litecoins to many addresses based on shares and share values. It uses litecoin's rpc interface to make this work.
"""
Dependencies:
Python 2.7+
jsonrpclib: https://github.com/joshmarshall/jsonrpclib
Instructions:
Edit the litecoin.conf file to enable rpc (server=1) and set the rpcuser
and rpcpassword to something nontrivial, difficult to guess, and long.
Change the rpcport if you wish; by default litecoin should only accept
rpc connections from localhost, so it is hopefully safe. Change the below
values to match settings put in the config file.
Give the address holding the litecoins to be distributed a unique label,
this will be used to payout (unfortunately litecoin likes to pay via label,
not address). Change addressLabel to match your selection.
Create a text file in the same directory as this .py file to store share information.
Use "address:shares" as the format, one per line. Example:
mp4YaRWkNP8iHYMSvQmtF6Z22qUf4VnrZP:1
mo7RoBMawfcW9JryMTKk7aYEMzv2UQQfim:1
mtoDAWo4ccfLS8xQAw6zNgiFLoBVKqrsZv:1
moqzNPmxChi2kpT6khcxQkqZQ76woM5GQK:1
mq37recpNN7ACmrK1RPfW86GNDZHcEu8MR:10
Change sharesFile to match the name of the file you just created. Run this python file
for every transaction you wish to make.
"""
addressLabel = "poolLTC"
sharesFile = "shareholders.txt"
rpcUser = "h"
rpcPass = "h"
rpcPort = 9332
## Do not edit below this line ##
import jsonrpclib, xmlrpclib
from decimal import Decimal
print "Getting shares from %s..." % sharesFile
sharesList = [(line.strip().split(":")[0], int(line.strip().split(":")[1])) for line in open(sharesFile)]
totalShares = sum(s[1] for s in sharesList)
if raw_input("Is %d shareholders with a total of %d shares correct? [y/N]: " %
(len(sharesList), totalShares)).lower()[0] != "y":
raise Exception("Please correct the shares file")
print "Connecting to litecoin daemon at localhost:%d..." % rpcPort
litecoinClient = jsonrpclib.Server("http://%s:%s@localhost:%d" % (rpcUser, rpcPass, rpcPort))
litecoinClient.help() #make sure we can connect to it
labelAddresses = litecoinClient.getaddressesbyaccount(addressLabel)
if len(labelAddresses) == 0:
raise Exception("No address exists with label '%s'" % addressLabel)
elif len(labelAddresses) > 1:
raise Exception("More than one address exists with label '%s'" % addressLabel)
elif raw_input("Use address %s to send funds? [y/N]: " % labelAddresses[0]).lower()[0] != "y":
raise Exception("Incorrect address label, please change.")
sharePayout = Decimal(raw_input("Payment per share: "))
if sharePayout * (10**9) % 10 != 0:
raise Exception("More that 8 digits of precision given, implicit rounding. Please adjust share payout.")
totalPayout = sharePayout * totalShares
if Decimal(litecoinClient.getbalance(addressLabel)) < totalPayout:
raise Exception("Not enough ltc in '%s', need %s. Please adjust share payout." % (addressLabel, totalPayout))
if raw_input("Is %s LTC per share for %s LTC total correct? [y/N]: " % (sharePayout, totalPayout)).lower()[0] != "y":
raise Exception("Please adjust share payout.")
addressShares = {address: float(shares*sharePayout) for (address, shares) in sharesList}
if sum(addressShares.values()) != totalPayout:
raise Exception("Something went horribly wrong...")
#print addressShares
print "Sending litcoins..."
print "Success! TXID: %s" % litecoinClient.sendmany(addressLabel, addressShares)
raw_input("Press any key to close the window")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment