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 CHANGED
@@ -87,6 +87,7 @@ blockchain:
87
87
  wallet_id: <long guid>
88
88
  password1: <password>
89
89
  password2: <secondary password>
90
+ withdrawal_fee: <fee in satoshi, default: 50000>
90
91
 
91
92
  data:
92
93
  path: /home/me/.bitbot
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{bitbot}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Zach Wily"]
8
8
  s.email = ["zach@zwily.com"]
@@ -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
  #
@@ -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.to_f * 10**8).to_i
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
- amount = $1.to_f
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, 50000, address)
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, 50000)
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 "0.0005 BTC will also be withdrawn for the transaction fee."
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.2
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-26 00:00:00.000000000 Z
12
+ date: 2013-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cinch