Skip to content

Instantly share code, notes, and snippets.

@vertoe
Created November 24, 2014 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vertoe/e45899a007e39990fb22 to your computer and use it in GitHub Desktop.
Save vertoe/e45899a007e39990fb22 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
class Float
def floor_to(x)
(self * 10**x).floor.to_f / 10**x
end
end
class Transaction
@@m_holders = nil
@@m_sharessum = 0
@@m_masternodes = 0
@@m_balance = 0
@@m_account = "main"
@@m_failure = false
def initialize(holders)
@@m_holders = holders
@@m_holders.each do |bag|
@@m_sharessum += bag.last['shares']
end
balance = `darkcoind getbalance`.to_f
@@m_masternodes = (balance / 1000.0).floor_to(0)
@@m_balance = balance - @@m_masternodes * 1000.0 - 0.1
end
def nodes
return @@m_masternodes.to_i
end
def shares
return @@m_sharessum.to_i
end
def balance
if (@@m_balance > 1000.0)
@@m_failure = true
end
return @@m_balance.to_f.round(8)
end
def account
return @@m_account
end
def set_account(address)
account = account()
result = `darkcoind setaccount #{address} #{account}`
return result
end
def gen_tx
account = account()
tx = "sendmany '#{account}' '{"
@@m_holders.each_with_index do |bag, num|
name = bag.first
status = bag.last
address = status["address"]
shares = status["shares"]
value = shares.to_f / shares().to_f * balance().to_f * 0.8 # give 80% to shareholders
if name.eql? "vertoe" # give 20% to vertoe
value += balance().to_f * 0.2
end
if (value.round(8) > 0.0)
tx += "\"#{address}\":#{sprintf("%.8f", value.round(8))},"
end
if (value.round(8) > nodes.to_f)
@@m_failure = true
puts "WARNING value #{sprintf("%.8f", value.round(8))} above limit - aborting."
end
end
tx = tx.chomp(',')
tx += "}'"
if (@@m_failure)
tx = "getinfo"
end
return tx
end
end
holders = {
'user1' => {
'address' => 'Xgm3i1sMXARDCd1AKzp5BdciWURsq7ru5K',
'shares' => 13337,
},
'user2' => {
'address' => 'XsMrrXFRd3JnD6EwFe4NtCL5VkoZ4abkss',
'shares' => 1337,
},
'userasdf' => {
'address' => 'Xv5GjfZ9JQgV3YDhrQFd2QnxeVf2eNiHDX',
'shares' => 137,
},
}
tx = Transaction.new(holders)
pubkeys = [
'XnB7gao3Wb3KRwCmYEkYJW6rmtpmRSZaLt', # all masternode public keys of masterwallet
'XfwrYxygKkp4FaxDgDdQn89HAnLzD9hSQN',
'XpdEK5YMzsycoVkNhFHomCvCGyKGx2UyfT',
'XkjjwF6umwvBzx9SYjDdeZoWg4m4YPzYvP',
'Xx6JvxkZVbzNpni9keuWuAcsjMmDNMvg1N',
]
pubkeys.each do |pub|
if (false)
tx.set_account(pub)
end
end
puts `date`
puts "Running #{tx.nodes} masternodes with #{tx.shares} shares sold and earned #{sprintf("%.8f", tx.balance.round(8))} DRK today."
puts "\nThis is the transaction preview:"
puts tx.gen_tx + "\n"
if (tx.balance > 10.0 and tx.balance < 100.0)
puts "\nEnter wallet passphrase to send it:"
send = `darkcoind walletpassphrase \`head -1\` 60`
puts send
send = `darkcoind #{tx.gen_tx}`
puts send
send = `darkcoind walletlock`
puts send
else
puts "Blance below threshold: #{sprintf("%.8f", tx.balance.round(8))} - aborting."
end
puts "\n + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment