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.
- checksums.yaml +4 -4
- data/lib/bitcoin_op_return.rb +14 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4c1ce61019d32344d98eb9765ed95c445034d45
|
4
|
+
data.tar.gz: 7504ba2266bfed6637aaee293c5b5deb37340a55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7639b199af87de96c4bc6220f22ef846a660131e065d490d9d5c6df72dd63abc67e61b570fe4c93b9fea04c0d0cfe461f587ec28fd8535f2f1b6fcfa1f5d4f4a
|
7
|
+
data.tar.gz: 31f37051009931b23b9ec92253dd66598b661b91bfb69a64876d7f229d337dc62f52c045ddd81748ec3257434bcb883d33b32c8c4ea2df590b71e4c6169d53de
|
data/lib/bitcoin_op_return.rb
CHANGED
@@ -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 {
|
25
|
-
return {
|
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 {
|
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
|
-
|
41
|
+
a == b ? 0 : (a < b ? 1 : -1)
|
42
42
|
end
|
43
43
|
|
44
44
|
inputs_spend = []
|
45
|
-
output_amount = send_amount +
|
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 {
|
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 = "#{
|
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.
|
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-
|
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
|