openassets-ruby 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/lib/openassets.rb +2 -0
- data/lib/openassets/api.rb +12 -1
- data/lib/openassets/medhod_filter.rb +55 -0
- data/lib/openassets/util.rb +7 -1
- data/lib/openassets/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 162e453da0e910ff8ed1b9a6b18236b8ceb06c34
|
4
|
+
data.tar.gz: 2c6da11a79ce5a7bacf9818f6698bbe76423588d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09400c1d32f9349b61f5b682c7af2f39c82af361fe8aa549be3600f7e6a46bf29da7bd6117cf458560c8e9a6fcdc529403314e8eb4c40f1ce1642580ed506239
|
7
|
+
data.tar.gz: e09e86b7d3ab64d94b09d0b3d956ad65d364ba1344a870824318b659b143b26c270e39143d7f195780e277468495baac0742f0821e5f3f2c70022871acdd7772
|
data/README.md
CHANGED
@@ -11,6 +11,7 @@ gem install openassets-ruby
|
|
11
11
|
|
12
12
|
Initialize the connection information to the Bitcoin Core server.
|
13
13
|
|
14
|
+
* **use mainnet**
|
14
15
|
```ruby
|
15
16
|
require 'openassets'
|
16
17
|
|
@@ -20,6 +21,17 @@ api = OpenAssets::Api.new({:network => 'mainnet',
|
|
20
21
|
:rpc => {:user => 'xxx', :password => 'xxx', :schema => 'http', :port => 8332, :host => 'localhost'}})
|
21
22
|
```
|
22
23
|
|
24
|
+
* **use testnet**
|
25
|
+
change :network and :port(depends on your server setting).
|
26
|
+
```ruby
|
27
|
+
require 'openassets'
|
28
|
+
|
29
|
+
api = OpenAssets::Api.new({:network => 'testnet',
|
30
|
+
:provider => 'bitcoind',
|
31
|
+
:dust_limit => 600,
|
32
|
+
:rpc => {:user => 'xxx', :password => 'xxx', :schema => 'http', :port => 18332, :host => 'localhost'}})
|
33
|
+
```
|
34
|
+
|
23
35
|
## API
|
24
36
|
|
25
37
|
Currently openassets-ruby support the following API.
|
data/lib/openassets.rb
CHANGED
@@ -5,7 +5,9 @@ module OpenAssets
|
|
5
5
|
autoload :Transaction, 'openassets/transaction'
|
6
6
|
autoload :VERSION, 'openassets/version'
|
7
7
|
autoload :Util, 'openassets/util'
|
8
|
+
autoload :MethodFilter, 'openassets/medhod_filter'
|
8
9
|
autoload :Api, 'openassets/api'
|
9
10
|
autoload :Provider, 'openassets/provider'
|
10
11
|
autoload :Error, 'openassets/error'
|
12
|
+
|
11
13
|
end
|
data/lib/openassets/api.rb
CHANGED
@@ -4,7 +4,10 @@ module OpenAssets
|
|
4
4
|
|
5
5
|
class Api
|
6
6
|
|
7
|
-
include
|
7
|
+
include Util
|
8
|
+
include MethodFilter
|
9
|
+
|
10
|
+
before_filter :change_network, {:include => [:list_unspent, :get_balance, :issue_asset, :send_asset]}
|
8
11
|
|
9
12
|
attr_reader :config
|
10
13
|
attr_reader :provider
|
@@ -283,6 +286,14 @@ module OpenAssets
|
|
283
286
|
end
|
284
287
|
end
|
285
288
|
|
289
|
+
def change_network
|
290
|
+
if is_testnet?
|
291
|
+
Bitcoin.network = :testnet
|
292
|
+
else
|
293
|
+
Bitcoin.network = :bitcoin
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
286
297
|
end
|
287
298
|
|
288
299
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module OpenAssets
|
2
|
+
module MethodFilter
|
3
|
+
|
4
|
+
module Filters
|
5
|
+
|
6
|
+
def before_filter(method, options = {})
|
7
|
+
@before_filters ||= {}
|
8
|
+
@before_filters[method] = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def filtered_method?(method, options)
|
12
|
+
if options.has_key? :include
|
13
|
+
return true if options[:include].include? method.intern
|
14
|
+
false
|
15
|
+
elsif options.has_key? :exclude
|
16
|
+
return false if options[:exclude].include? method.intern
|
17
|
+
true
|
18
|
+
else
|
19
|
+
true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def method_added(name)
|
25
|
+
@before_filters ||= {}
|
26
|
+
@modified_methods ||= []
|
27
|
+
return if @modified_methods.include?(name)
|
28
|
+
return if @before_filters.include?(name)
|
29
|
+
return if /with_filters$/ =~ name.to_s
|
30
|
+
return if /without_filters$/ =~ name.to_s
|
31
|
+
@modified_methods << name
|
32
|
+
|
33
|
+
name = name.to_s
|
34
|
+
alias_method( "#{name}_without_filters", name)
|
35
|
+
before_filters = @before_filters
|
36
|
+
|
37
|
+
define_method("#{name}_with_filters") do |*args|
|
38
|
+
before_filters.each do |filter_name, options|
|
39
|
+
method(filter_name).call if self.class.filtered_method?(name, options)
|
40
|
+
end
|
41
|
+
result = method("#{name}_without_filters").call(*args)
|
42
|
+
result
|
43
|
+
end
|
44
|
+
|
45
|
+
alias_method(name, "#{name}_with_filters")
|
46
|
+
@modified_methods.delete_if { |x| name == x }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.included(receiver)
|
51
|
+
receiver.extend(Filters)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
data/lib/openassets/util.rb
CHANGED
@@ -8,6 +8,7 @@ module OpenAssets
|
|
8
8
|
|
9
9
|
# version byte for Open Assets Address
|
10
10
|
OA_VERSION_BYTE = 23
|
11
|
+
OA_VERSION_BYTE_TESTNET = 115
|
11
12
|
|
12
13
|
# convert bitcoin address to open assets address
|
13
14
|
# @param [String] btc_address The Bitcoin address.
|
@@ -41,7 +42,7 @@ module OpenAssets
|
|
41
42
|
# P2PKH script = OP_DUP OP_HASH160 <PubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
|
42
43
|
# (76=OP_DUP, a9=OP_HASH160, 14=Bytes to push, 88=OP_EQUALVERIFY, ac=OP_CHECKSIG)
|
43
44
|
script = hash160(["76", "a9", "14", hash, "88", "ac"].join)
|
44
|
-
script =
|
45
|
+
script = oa_version_byte.to_s(16) + script # add version byte to script hash
|
45
46
|
encode_base58(script + checksum(script)) # add checksum & encode
|
46
47
|
end
|
47
48
|
|
@@ -89,5 +90,10 @@ module OpenAssets
|
|
89
90
|
raise ArgumentError, "#{a} is invalid bitcoin address. " unless valid_address?(a)
|
90
91
|
}
|
91
92
|
end
|
93
|
+
|
94
|
+
private
|
95
|
+
def oa_version_byte
|
96
|
+
Bitcoin.network[:address_version] == "6f" ? OA_VERSION_BYTE_TESTNET : OA_VERSION_BYTE
|
97
|
+
end
|
92
98
|
end
|
93
99
|
end
|
data/lib/openassets/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- azuchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bitcoin-ruby
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- lib/openassets.rb
|
117
117
|
- lib/openassets/api.rb
|
118
118
|
- lib/openassets/error.rb
|
119
|
+
- lib/openassets/medhod_filter.rb
|
119
120
|
- lib/openassets/protocol.rb
|
120
121
|
- lib/openassets/protocol/asset_definition.rb
|
121
122
|
- lib/openassets/protocol/marker_output.rb
|