bitcoin_op_return 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bitcoin_op_return.rb +14 -11
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0c7cdf9a7cfb03cbb4eafafd35585e3f92d1738
4
- data.tar.gz: ed12beeb25a03a976bbdef0fe718f1d7d42d475c
3
+ metadata.gz: f4c1ce61019d32344d98eb9765ed95c445034d45
4
+ data.tar.gz: 7504ba2266bfed6637aaee293c5b5deb37340a55
5
5
  SHA512:
6
- metadata.gz: 522d7927e0017e7ed33f44c8b8c68ad333bdb5be22c9b274f4adcbb2b86ae05529eb28d9dac551abe34e8421ac96a62f087c9a1c06fc806b1f359508bb56d910
7
- data.tar.gz: 4e2d504780ea85d5f3fcef85fc791eeeeef6cbb92014b46dabe60fe038671f8e65912d64d97206d960c246a4ca740562365853b0400d93d7238fa1820cebc6c4
6
+ metadata.gz: 7639b199af87de96c4bc6220f22ef846a660131e065d490d9d5c6df72dd63abc67e61b570fe4c93b9fea04c0d0cfe461f587ec28fd8535f2f1b6fcfa1f5d4f4a
7
+ data.tar.gz: 31f37051009931b23b9ec92253dd66598b661b91bfb69a64876d7f229d337dc62f52c045ddd81748ec3257434bcb883d33b32c8c4ea2df590b71e4c6169d53de
@@ -7,26 +7,26 @@ class String
7
7
  end
8
8
  end
9
9
 
10
- module BitcoinOpReturn
11
- BITCOIND_CMD = "/usr/local/bin/bitcoind"
12
- TRANSACTION_FEE = 0.0001
13
-
10
+ module BitcoinOpReturn
14
11
  class << self
12
+ attr_accessor :bitcoind_cmd, :transaction_fee
13
+
15
14
  def create options
16
15
  send_address = options[:address].to_s
17
16
  send_amount = options[:amount].to_f
18
17
  metadata = options[:metadata].to_s
19
18
  testnet = !options[:testnet].nil?
19
+ transaction_fee = options[:transaction_fee].to_f || self.transaction_fee
20
20
 
21
21
  # convert to hex where possible
22
22
  metadata = [ metadata ].pack("H*") if metadata =~ /\A([0-9A-Fa-f]{2})*\z/
23
23
 
24
- return { "error" => "invalid address" } unless bitcoind("validateaddress", testnet, send_address)["isvalid"]
25
- return { "error" => "metadata too long, limit is 75, recommended is 40 bytes" } if metadata.length > 75
24
+ return { :error => "invalid address" } unless bitcoind("validateaddress", testnet, send_address)["isvalid"]
25
+ return { :error => "metadata too long, limit is 75, recommended is 40 bytes" } if metadata.length > 75
26
26
 
27
27
  # get the unspent inputs
28
28
  unspent_inputs = bitcoind("listunspent", testnet, 0)
29
- return { "error" => "unable to retrieve unspent inputs" } unless unspent_inputs.kind_of? Array
29
+ return { :error => "unable to retrieve unspent inputs" } unless unspent_inputs.kind_of? Array
30
30
 
31
31
  unspent_inputs.each do |input|
32
32
  input["priority"] = input["amount"] * input["confirmations"]
@@ -38,11 +38,11 @@ module BitcoinOpReturn
38
38
  # a follows b => -1
39
39
  # a == b => 0
40
40
  # b follows a => 1
41
- a == b ? 0 : (a < b ? 1 : -1)
41
+ a == b ? 0 : (a < b ? 1 : -1)
42
42
  end
43
43
 
44
44
  inputs_spend = []
45
- output_amount = send_amount + TRANSACTION_FEE
45
+ output_amount = send_amount + self.transaction_fee
46
46
  inputs_amount = 0
47
47
 
48
48
  unspent_inputs.each do |input|
@@ -51,7 +51,7 @@ module BitcoinOpReturn
51
51
  break if inputs_amount >= output_amount
52
52
  end
53
53
 
54
- return { "error" => "insufficient funds to carry out transaction" } if inputs_amount < output_amount
54
+ return { :error => "insufficient funds to carry out transaction" } if inputs_amount < output_amount
55
55
 
56
56
 
57
57
  outputs_hash = {}
@@ -96,7 +96,7 @@ module BitcoinOpReturn
96
96
 
97
97
  private
98
98
  def bitcoind cmd, testnet, *args
99
- command = "#{BITCOIND_CMD} #{testnet ? "-testnet" : ""}"
99
+ command = "#{self.bitcoind_cmd} #{testnet ? "-testnet" : ""}"
100
100
 
101
101
  command += " #{Shellwords.escape(cmd)}"
102
102
 
@@ -249,4 +249,7 @@ module BitcoinOpReturn
249
249
  txn
250
250
  end
251
251
  end
252
+
253
+ self.bitcoind_cmd = "/usr/local/bin/bitcoind"
254
+ self.transaction_fee = 0.0001
252
255
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitcoin_op_return
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - FY Quah
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-24 00:00:00.000000000 Z
11
+ date: 2014-11-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple gem for you to send op_return into the bitcoin blockchain with
14
14
  ruby