openassets-ruby 0.2.9 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5a79cc924492696e02f90d9b2921b0753d9e619
4
- data.tar.gz: 875977bc89c76903f923b20f1ca15da38e881345
3
+ metadata.gz: df555d501074ff3123dd20893a71c026c753e2a1
4
+ data.tar.gz: a5f587c0e401e37786ea6a64e6b3174de48c15a3
5
5
  SHA512:
6
- metadata.gz: 6f27081be1ef5c68114410337396fb78e65ca3f7535ab40758111971fc66b72760ce7bcdb7ff899d467bfbd90dc60a0b21d5484e6d74eeb573e80579493e4822
7
- data.tar.gz: dfc1b43a7acb7f8a8191c2c938f88cb3446fc8e5575381ead4574fda5c69caaf7d1ec00be5237dadb40a02e5e35bb9dd2a72dd31441ea4e64ee9ea7c42a99fab
6
+ metadata.gz: 65ddfb8975cff61316d66156f47504e9c3347328003ca9cf444a6c195327eb3177b1cd8c83ac1229640028ae17d7da8b2881d31ee04355e4fe11a1d3fc14fdb8
7
+ data.tar.gz: 180b5d0a683c19dc0546e5f492dbc6acbde091f0e9aa3a872411634b90805c96447d831ef724fca64095d815b34da32f239543de58dcbecad1ec0fb8dd745924
data/README.md CHANGED
@@ -208,6 +208,25 @@ Creates a transaction for sending **multiple** asset from the open asset address
208
208
  tx = api.send_assets(from, params)
209
209
  ```
210
210
 
211
+
212
+ ## Command line interface
213
+
214
+ Openassets-ruby comes with a `openassets` command line interface that allows easy interaction with OpenAssets.
215
+
216
+ ### Usage
217
+
218
+ openassets [options] [command]
219
+
220
+ Options:
221
+ -c path to config JSON which is passed to OpenAssets::Api.new - see Configuration for details
222
+ -e load conifg from ENV variables (look at the exe/openassets file for details)
223
+
224
+ commands:
225
+ * console runs an IRB console and gives you an initialized Api instance to interact with OpenAssets
226
+ * any method on the API instance, helpful for get_balance, list_unspent
227
+
228
+
229
+
211
230
  ## License
212
231
 
213
232
  The MIT License (MIT)
data/exe/openassets ADDED
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "openassets"
5
+ require 'optparse'
6
+ require 'json'
7
+
8
+ options = {}
9
+ OptionParser.new do |opts|
10
+ opts.banner = "Usage: openassets [options] [command]"
11
+
12
+ opts.on("-c PATH", "--config PATH", "config load path") do |path|
13
+ options[:config] = path
14
+ end
15
+ opts.on("-e", "--env", "load config from ENV variablse") do |env|
16
+ options[:env] = env
17
+ end
18
+ opts.on("-v", "--verbose", "verbose output") do |v|
19
+ options[:verbose] = v
20
+ end
21
+ end.parse!
22
+
23
+ puts "Welcome to OpenAssets\n\n"
24
+ if options[:env]
25
+ rpc = {
26
+ :host => ENV['OA_RPC_HOST'] || 'localhost',
27
+ :port => ENV['OA_RPC_PORT'] || 8332,
28
+ :user => ENV['OA_RPC_USER'] || '',
29
+ :password => ENV['OA_RPC_PASSWORD'] || '',
30
+ :schema => ENV['OA_RPC_SCHEMA'] || 'http'
31
+ }
32
+ config = {
33
+ :network => ENV['OA_NETWORK'] || 'mainnet',
34
+ :provider => 'bitcoind',
35
+ :dust_limit => (ENV['OA_DUST_LIMIT'] || 600).to_i,
36
+ :default_fees => (ENV['OA_DEFAULT_FEES'] || 10000).to_i,
37
+ :rpc => rpc
38
+ }
39
+ elsif options[:config]
40
+ if !File.exists?(options[:config])
41
+ puts "File not found: #{options[:config]}"
42
+ exit(1)
43
+ end
44
+ config = JSON.parse(File.read(options[:config]), {symbolize_names: true})
45
+ end
46
+
47
+ if options[:verbose]
48
+ puts "using config:"
49
+ puts config.inspect
50
+ end
51
+ $oa = $api = OpenAssets::Api.new(config)
52
+
53
+ command = ARGV.shift
54
+
55
+ if command == 'console'
56
+ require "irb"
57
+ puts "API is available as $oa:"
58
+ IRB.start
59
+ puts "bye, bye"
60
+ elsif command && $oa.respond_to?(command)
61
+ puts "running command '#{command}'"
62
+ puts $oa.send(command, *ARGV).inspect
63
+ else
64
+ puts "use 'openassets --help' for help"
65
+ end
@@ -17,7 +17,7 @@ module OpenAssets
17
17
  @cache = {}
18
18
  @config = {:network => 'mainnet',
19
19
  :provider => 'bitcoind',
20
- :dust_limit => 600, :default_fees => 10000,
20
+ :dust_limit => 600, :default_fees => 10000, :min_confirmation => 1, :max_confirmation => 9999999,
21
21
  :rpc => { :host => 'localhost', :port => 8332 , :user => '', :password => '', :schema => 'https'}}
22
22
  if config
23
23
  @config.update(config)
@@ -163,7 +163,7 @@ module OpenAssets
163
163
  # @return [Array[OpenAssets::Transaction::SpendableOutput]] The array of unspent outputs.
164
164
  def get_unspent_outputs(addresses)
165
165
  validate_address(addresses)
166
- unspent = provider.list_unspent(addresses)
166
+ unspent = provider.list_unspent(addresses, @config[:min_confirmation], @config[:max_confirmation])
167
167
  result = unspent.map{|item|
168
168
  output_result = get_output(item['txid'], item['vout'])
169
169
  output_result.account = item['account']
@@ -65,15 +65,17 @@ module OpenAssets
65
65
 
66
66
  # Convert Asset Definition to json format.
67
67
  def to_json
68
- hash = {}
69
- self.instance_variables.each do |var|
68
+ to_hash.to_json
69
+ end
70
+
71
+ def to_hash
72
+ instance_variables.inject({}) do |result, var|
70
73
  key = var.to_s
71
74
  key.slice!(0) if key.start_with?('@')
72
- hash[key] = self.instance_variable_get var
75
+ result.update(key => instance_variable_get(var))
73
76
  end
74
- hash.to_json
75
77
  end
76
78
  end
77
79
 
78
80
  end
79
- end
81
+ end
@@ -1,3 +1,4 @@
1
+ require 'bigdecimal'
1
2
  module OpenAssets
2
3
  module Util
3
4
  extend ::Bitcoin::Util
@@ -73,6 +74,13 @@ module OpenAssets
73
74
  "%.8f" % (satoshi / 100000000.0)
74
75
  end
75
76
 
77
+ # Convert coin unit to satoshi.
78
+ # @param [String] coin The amount of bitcoin
79
+ # @return [String] The amount of satoshi.
80
+ def coin_to_satoshi(coin)
81
+ BigDecimal(coin) * BigDecimal(100000000)
82
+ end
83
+
76
84
  # Get address from script.
77
85
  # @param [Bitcoin::Script] script The output script.
78
86
  # @return [String] The Bitcoin address. if the script dose not contains address, return nil.
@@ -1,3 +1,3 @@
1
1
  module OpenAssets
2
- VERSION = '0.2.9'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openassets-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-21 00:00:00.000000000 Z
11
+ date: 2016-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bitcoin-ruby
@@ -97,7 +97,8 @@ dependencies:
97
97
  description: The implementation of the Open Assets Protocol for Ruby.
98
98
  email:
99
99
  - azuchi@haw.co.jp
100
- executables: []
100
+ executables:
101
+ - openassets
101
102
  extensions: []
102
103
  extra_rdoc_files: []
103
104
  files:
@@ -113,6 +114,7 @@ files:
113
114
  - Rakefile
114
115
  - bin/console
115
116
  - bin/setup
117
+ - exe/openassets
116
118
  - lib/openassets.rb
117
119
  - lib/openassets/api.rb
118
120
  - lib/openassets/error.rb