dbchain_client 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8bbc767c04668e2a61263dca178a4b957c754859e4319dec14048d230d639c26
4
- data.tar.gz: 5f5eb7aed816a764524b3c50f0ae74fa54626595eefdfcf6f228bceb238c196e
3
+ metadata.gz: cdfb23b555a6bed97d0cd6b0319790e2f4981c67c68620abbe67dafcfc9fb4d5
4
+ data.tar.gz: a90eb57f298cb018332163c5f249580fda1034d780a0d4b2886ec945f86da646
5
5
  SHA512:
6
- metadata.gz: eadc63b8c3a2a771bcb1845103bf86a35ae9a2af2273f89a1a680f779d95ca2732752957314874be431072c7c10dd0e7ed4f548334091c4b86fb50fd1b270ef2
7
- data.tar.gz: 5996ecbe45d93d40a9b9beee5fdb1c3f621af2585d70dde2b9fb9bdde8b2748685f2b2b36ac4e0ffc9d20231def53cf656fef982db6543f54f4f3815acd01600
6
+ metadata.gz: 9dd09463ccc1d6ce78e58f223f99a07c5e90c4f182c2801108334ca5a4bb41d54de60356c9dc6eae62bc6f8e7bb790e6bb980f5b44381adb263619cefc014e1e
7
+ data.tar.gz: 29e92508eb43a2158c0c5b2548607eef4763973ca8b53273f1b25fb4a1404338c6301134de7da305546ae061df9b5fb78588c7bec9d99b76c83dca7161cf7749
@@ -0,0 +1,106 @@
1
+ module DbchainClient
2
+ class Querier
3
+ def initialize(base_url, private_key, app_code=nil)
4
+ @base_url = base_url
5
+
6
+ if private_key.instance_of? String
7
+ @private_key = PrivateKey.new(private_key)
8
+ else
9
+ @private_key = private_key
10
+ end
11
+
12
+ set_app_code unless app_code.nil?
13
+ @single_value = false
14
+ end
15
+
16
+ def set_app_code(app_code)
17
+ initialize_internal_querier if @q.nil?
18
+ @q[:app_code] = app_code
19
+ end
20
+
21
+ def table(table_name)
22
+ h = {
23
+ method: 'table',
24
+ table: table_name
25
+ }
26
+ finish(h)
27
+ end
28
+
29
+ def find(id)
30
+ @single_value = true
31
+ h = {
32
+ method: 'find',
33
+ id: id
34
+ }
35
+ finish(h)
36
+ end
37
+
38
+ def find_first
39
+ @single_value = true
40
+ h = {
41
+ method: 'first',
42
+ }
43
+ finish(h)
44
+ end
45
+
46
+ def find_last
47
+ @single_value = true
48
+ h = {
49
+ method: 'last',
50
+ }
51
+ finish(h)
52
+ end
53
+
54
+ def select(*args)
55
+ h = {
56
+ method: 'select',
57
+ fields: args.join(',')
58
+ }
59
+ finish(h)
60
+ end
61
+
62
+ def where(field_name, value, operator)
63
+ h = {
64
+ method: 'where',
65
+ field: field_name,
66
+ value: value,
67
+ operator: operator
68
+ }
69
+ finish(h)
70
+ end
71
+
72
+ def equal(field_name, value)
73
+ where(field_name, value, '=')
74
+ end
75
+
76
+ def own()
77
+ from_address = @private_key.public_key.address
78
+ equal('created_by', from_address)
79
+ end
80
+
81
+ def run
82
+ reader = DbchainClient::Reader.new(@base_url, @private_key)
83
+ result = reader.querier(@q[:app_code], @q[:commands])
84
+ if @single_value
85
+ if result.size > 0
86
+ result[0]
87
+ else
88
+ nil
89
+ end
90
+ else
91
+ result
92
+ end
93
+ end
94
+
95
+ private
96
+
97
+ def initialize_internal_querier
98
+ @q = {commands: []}
99
+ end
100
+
101
+ def finish(h)
102
+ @q[:commands].push(h)
103
+ self
104
+ end
105
+ end
106
+ end
@@ -1,5 +1,5 @@
1
1
  require 'json'
2
- require 'base58'
2
+ require 'base58-alphabets'
3
3
 
4
4
  module DbchainClient
5
5
  class Reader
@@ -25,11 +25,20 @@ module DbchainClient
25
25
  return h['result']
26
26
  end
27
27
 
28
+ def querier(app_code, query_hash)
29
+ query = query_hash.to_json
30
+ query = Base58.encode_bin(query)
31
+ uri = uri_builder("querier", app_code, query)
32
+ response = @rest_lib.rest_get(uri)
33
+ h = JSON.parse(response.body)
34
+ return h['result']
35
+ end
36
+
28
37
  def generate_access_code(time=nil)
29
- encoded_public_key = Base58.binary_to_base58(@public_key.to_raw, :bitcoin)
38
+ encoded_public_key = Base58.encode_bin(@public_key.to_raw)
30
39
  time ||= (Time.now.to_f * 1000).to_i.to_s
31
40
  signature = @private_key.sign(time)
32
- encoded_signature = Base58.binary_to_base58(signature.compact, :bitcoin)
41
+ encoded_signature = Base58.encode_bin(signature.compact)
33
42
  "#{encoded_public_key}:#{time}:#{encoded_signature}"
34
43
  end
35
44
 
@@ -8,6 +8,7 @@ module DbchainClient
8
8
  autoload :Transaction, "dbchain_client/transaction"
9
9
  autoload :Writer, "dbchain_client/writer"
10
10
  autoload :Reader, "dbchain_client/reader"
11
+ autoload :Querier, "dbchain_client/querier"
11
12
  autoload :KeyEscrow, "dbchain_client/key_escrow"
12
13
  autoload :AESCrypt, "dbchain_client/aes"
13
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbchain_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan Zhang
@@ -24,6 +24,7 @@ files:
24
24
  - lib/dbchain_client/key_escrow.rb
25
25
  - lib/dbchain_client/message_generator.rb
26
26
  - lib/dbchain_client/mnemonics.rb
27
+ - lib/dbchain_client/querier.rb
27
28
  - lib/dbchain_client/reader.rb
28
29
  - lib/dbchain_client/rest_lib.rb
29
30
  - lib/dbchain_client/transaction.rb