medialni-odbor-f181/pirati-pouzivaji-sv ... tr#p120836
jsem hledal alternativu, jak mikrodarcovstvi (mit hafo projektu co chci podporit, ale nechtit milionkrat mesicne vypisovat nejaky platebni prikazy, spekulovat kolik komu dat...)
vyresit pres bitcoin a decentralizovane. A nic jsem nenasel. Na https://bitcointalk.org/index.php?topic=1762.40 je videt jak to funguje. Dycky vyleze nejakej napad na kool centralizovanou sluzbu,
ale zadna z nich uz nezije.
Tak jsem si to zbastlil sam. Je to primitivni ruby script, kterej pres json-RPC komunikuje z ofiko bitcoind nebo bitcoin-qt, spustim ho jednou za mesic a dela presne to co chci. Zadnou centralizovanou sluzbu k tomu nepotrebuju. Takze jsem zkrouhnul sve flattr predplatny na polovinu a vsechny projekty, ktery jsem pres Flattr podporoval a prijimaji BTC, ted ode me budou dostavat BTC.
By me zajimalo, zda by to treba nekomu z TO prislo natolik zajimavy, ze bychom to vyvesili na nas github. Uvitam jakekoli napady na vylepseni. Je to proof of concept, da se k tomu vymyslet spousta ficur, jako treba, extensiony do prohlizece, ktery by right-clickem na BTC verejny klic na strance plnily polozky v souborech subscriptions a single-clicks, do kterejch to ted rvu rucne. Jinak se mi klidne vysmejte za prasarny, kterejch tam je urcite hafo, unesu to, Ruby jsem se ucil od nuly za pochodu
Kód: Vybrat vše
#!/bin/ruby
#
# Bitcoin mothly contribute
# =========================
#
# ♡ Initial version written by Filip Krska in June 2013
# Choose whatever useless (and thus not affected by the fall of the corrupted copy monopolies)
# license you want, e.g. CC0, Public domain, WTFPL, ♡ copyheart
# Be free. Use, study, modify, share, profit, make love and art, not law and war.
#
#
# Uses BitcoinRPC ruby class fetched from https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)#Ruby
#
# Requires ./bitcoin_monthly_contribute.conf.rb in the form
#
# module BitcoinMonthly
# Monthly_amount_in_currency = 500
# Currency = "CZK"
# Usd_in_currency = `lynx --dump http://www.cnb.cz/cs/financni_trhy/devizovy_trh/kurzy_devizoveho_trhu/denni_kurz.txt\
# |grep USD|sed 's/^.*|//;s/,/./'`
# end
#
# Requires ./subscriptions and ./single_donations files with recors like
#
# 12345678910PublicAddress4567890123 Recipient description
# 22345678910PublicAddress4567890123 Another recipient description
#
# Requires running bitcoind or bitcoin-qt -server on localhost
# and rpcuser, rpcpassword set in your ~/.bitcoin/bitcoin.conf,
# see https://en.bitcoin.it/wiki/Running_Bitcoin
#
require './BitcoinRPC.rb'
require './bitcoin_monthly_contribute.conf.rb'
require 'io/console'
unless (defined?(BitcoinMonthly::Monthly_amount_in_currency))
abort "\nmonthly_amount_in_currency undefined\n"
else
monthly_amount_in_currency = BitcoinMonthly::Monthly_amount_in_currency
end
subscriptions = []
single_donations = []
File.open('./subscriptions').each_line do |line|
if (match = /^([[:alnum:]]{34})\s+(.*)$/.match(line.chomp)) then
subscriptions.push([match[1], match[2]])
end
end
File.open('./single_donations').each_line do |line|
if (match = /^([[:alnum:]]{34})\s+(.*)$/.match(line.chomp)) then
single_donations.push([match[1], match[2]])
end
end
rpcuser = ""
rpcpassword = ""
File.open(File.expand_path('~/.bitcoin/bitcoin.conf')).each_line do |line|
if (match = /^rpcuser=(.*)$/.match(line.chomp)) then
rpcuser = match[1]
end
if (match = /^rpcpassword=(.*)$/.match(line.chomp)) then
rpcpassword = match[1]
end
end
if (rpcuser.empty? or rpcpassword.empty?)
abort "\nrpcuser or rpcpassword not defined.\n"
end
btc_in_usd = `lynx --dump http://data.mtgox.com/api/1/BTCUSD/ticker\
|sed 's/^.*buy":{"value":"//;s/".*$//'`
begin
btc_in_usd = Float(btc_in_usd)
rescue
abort "\nproblem fetching http://data.mtgox.com/api/1/BTCUSD/ticker\n"
end
begin
usd_in_currency = Float(BitcoinMonthly::Usd_in_currency)
rescue
abort "\nproblem fetching http://www.cnb.cz/cs/financni_trhy/devizovy_trh/kurzy_devizoveho_trhu/denni_kurz.txt\n"
end
items_no = subscriptions.size + single_donations.size
btc_in_currency = btc_in_usd * usd_in_currency
monthly_amount_in_btc = monthly_amount_in_currency / btc_in_currency
btc_per_item = (monthly_amount_in_btc / items_no).round(8)
currency_per_item = monthly_amount_in_currency / items_no
puts '================================================================'
printf("MONTHLY_AMOUNT_IN_CURRENCY: %18.8f #{BitcoinMonthly::Currency}\n", monthly_amount_in_currency)
printf("MONTHLY_AMOUNT_IN_BTC: %18.8f\n", monthly_amount_in_btc)
puts '================================================================'
printf("BTC_IN_USD: %18.8f\n", btc_in_usd)
printf("BTC_IN_CURRENCY: %18.8f #{BitcoinMonthly::Currency}\n", btc_in_currency)
puts '================================================================'
printf("USD_IN_CURRENCY: %18.8f #{BitcoinMonthly::Currency}\n", usd_in_currency)
puts '================================================================'
puts "\nSubscriptions:\n\n"
subscriptions.each {|line| puts line.join("\t\t\t")}
puts '================================================================'
puts "\nSingle donations:\n\n"
single_donations.each {|line| puts line.join("\t\t\t")}
puts '================================================================'
printf("ITEMS_NO: %18.8f\n", items_no)
printf("BTC_PER_ITEM: %18.8f\n", btc_per_item)
printf("CURRENCY_PER_ITEM: %18.8f #{BitcoinMonthly::Currency}\n", currency_per_item)
puts '================================================================'
client = BitcoinRPC.new("http://#{rpcuser}:#{rpcpassword}@127.0.0.1:8332")
if ((balance = client.getbalance) < monthly_amount_in_btc) then
abort "\nBalance #{balance} < monthly_amount #{monthly_amount_in_btc} BTC\n"
else
puts "\nYour balance is #{balance} and you're going to spend #{items_no * btc_per_item} BTC\n\n\
\nDo you want to proceed?(yes/[whatever else])\n"
end
want_to_proceed = gets.chomp
if (want_to_proceed == "yes")
puts "\nOK, please, supply your wallet passphrase\n\nPassphrase: "
else
abort "\nOK, bye...\n"
end
walletpassphrase = STDIN.noecho(&:gets).chomp
if (client.settxfee(0.0)) then
puts "\nFee successfully set to 0\n"
else
abort "\nError setting transaction fee\n"
end
client.walletpassphrase(walletpassphrase, 10)
subscriptions.each {|line|
puts "Sending #{btc_per_item} to #{line.last}. Transaction: #{client.sendtoaddress(line.first, btc_per_item)}\n"
}
single_donations.each {|line|
puts "Sending #{btc_per_item} to #{line.last}. Transaction: #{client.sendtoaddress(line.first, btc_per_item)}\n"
}
Kód: Vybrat vše
require 'net/http'
require 'uri'
require 'json'
class BitcoinRPC
def initialize(service_url)
@uri = URI.parse(service_url)
end
def method_missing(name, *args)
post_body = { 'method' => name, 'params' => args, 'id' => 'jsonrpc' }.to_json
resp = JSON.parse( http_post_request(post_body) )
raise JSONRPCError, resp['error'] if resp['error']
resp['result']
end
def http_post_request(post_body)
http = Net::HTTP.new(@uri.host, @uri.port)
request = Net::HTTP::Post.new(@uri.request_uri)
request.basic_auth @uri.user, @uri.password
request.content_type = 'application/json'
request.body = post_body
http.request(request).body
end
class JSONRPCError < RuntimeError; end
end
