bitbot 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -0
- data/bitbot.gemspec +1 -1
- data/lib/bitbot/plugin/common.rb +13 -0
- data/lib/bitbot/plugin/tip.rb +1 -1
- data/lib/bitbot/plugin/withdraw.rb +4 -6
- metadata +2 -2
data/README.md
CHANGED
data/bitbot.gemspec
CHANGED
data/lib/bitbot/plugin/common.rb
CHANGED
@@ -24,6 +24,10 @@ module Bitbot::Common
|
|
24
24
|
@cached_exchange_rates = new
|
25
25
|
end
|
26
26
|
|
27
|
+
def withdrawal_fee
|
28
|
+
config['blockchain']['withdrawal_fee'] || 50000
|
29
|
+
end
|
30
|
+
|
27
31
|
#
|
28
32
|
# Returns a database handle for use in the current thread.
|
29
33
|
#
|
@@ -54,6 +58,15 @@ module Bitbot::Common
|
|
54
58
|
nil
|
55
59
|
end
|
56
60
|
|
61
|
+
#
|
62
|
+
# Takes a string, and returns an int with number of satoshi.
|
63
|
+
# Eventually this could be smart enough to handle specified units too,
|
64
|
+
# rather than just assuming BTC every time.
|
65
|
+
#
|
66
|
+
def str_to_satoshi(str)
|
67
|
+
(str.to_f * 10**8).to_i
|
68
|
+
end
|
69
|
+
|
57
70
|
#
|
58
71
|
# Some number formatting helpers
|
59
72
|
#
|
data/lib/bitbot/plugin/tip.rb
CHANGED
@@ -14,7 +14,7 @@ module Bitbot::Tip
|
|
14
14
|
recipient_user_id = db.get_or_create_user_id_for_username(recipient_ircuser.user)
|
15
15
|
|
16
16
|
# Convert amount to satoshi
|
17
|
-
satoshi = (amount
|
17
|
+
satoshi = str_to_satoshi(amount)
|
18
18
|
if satoshi <= 0
|
19
19
|
m.user.msg("Cannot send a negative amount.")
|
20
20
|
return
|
@@ -1,26 +1,24 @@
|
|
1
1
|
module Bitbot::Withdraw
|
2
2
|
def on_withdraw(m, args)
|
3
3
|
if args =~ /\s+([\d.]+)\s+([13][0-9a-zA-Z]{26,35})/
|
4
|
-
|
4
|
+
satoshi = str_to_satoshi($1)
|
5
5
|
address = $2
|
6
6
|
|
7
7
|
user_id = db.get_or_create_user_id_for_username(m.user.user)
|
8
|
-
satoshi = (amount * 10**8).to_i
|
9
8
|
|
10
9
|
# Perform the local transaction in the database. Note that we
|
11
10
|
# don't do the blockchain update in the transaction, because we
|
12
11
|
# don't want to roll back the transaction if the blockchain update
|
13
12
|
# *appears* to fail. It might look like it failed, but really
|
14
13
|
# succeed, letting someone withdraw money twice.
|
15
|
-
# TODO: don't hardcode fee
|
16
14
|
begin
|
17
|
-
db.create_transaction_from_withdrawal(user_id, satoshi,
|
15
|
+
db.create_transaction_from_withdrawal(user_id, satoshi, withdrawal_fee, address)
|
18
16
|
rescue Bitbot::InsufficientFundsError
|
19
17
|
m.reply "You don't have enough to withdraw #{satoshi_to_str(satoshi)} + 0.0005 fee"
|
20
18
|
return
|
21
19
|
end
|
22
20
|
|
23
|
-
response = blockchain.create_payment(address, satoshi,
|
21
|
+
response = blockchain.create_payment(address, satoshi, withdrawal_fee)
|
24
22
|
if response["tx_hash"]
|
25
23
|
m.reply "Sent #{satoshi_with_usd(satoshi)} to #{address.irc(:bold)} " +
|
26
24
|
"in transaction #{response["tx_hash"].irc(:grey)}."
|
@@ -30,7 +28,7 @@ module Bitbot::Withdraw
|
|
30
28
|
end
|
31
29
|
else
|
32
30
|
m.reply "Usage: withdraw <amount in BTC> <address>"
|
33
|
-
m.reply "
|
31
|
+
m.reply "#{satoshi_to_str(withdrawal_fee)} BTC will also be withdrawn for the transaction fee."
|
34
32
|
end
|
35
33
|
end
|
36
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cinch
|