openblockchain-ruby 0.0.1 → 0.0.2

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openblockchain-ruby.rb +89 -5
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd1743b3ac4ef1f44af61340245637200b8fafe5
4
- data.tar.gz: 808b1c061a9b9cf8f6210086baeedd04fc6d56cc
3
+ metadata.gz: 1e65b018c95d303cf342450a410d4ed1b54c078e
4
+ data.tar.gz: c9c8332cd3bc18e995e1f6e1a38d5536ea1891ba
5
5
  SHA512:
6
- metadata.gz: 351af6079528fae20bbd27020ed3e1b0eda1d04f5a032372ccfb10b9bcceed173b81c1de37f1ac2596ba963d6ba5f892a4acc621968caf49efbf561361fa8a29
7
- data.tar.gz: 5df1bcbb29084d9fcea9023c9854964da506f2650e3f8d8e991c6cd48c9e672e0f0ad4a6b483eba0a573b6082955968ebdb683bef2b25d9056aa4df7c4fa9e16
6
+ metadata.gz: 0b76f5acc29ec1f450122923a3cb44a80ce74308b3431fc8b2a12598f9e6cf397478e956088c756e3e92046a590bb8c485235d14ded7f18a479cb639d38bf876
7
+ data.tar.gz: 66d186c60da8640295f8fb7a4c2099d11d7e98d9e957571591533f4442f22b8569de1e1f9e26684660c14c881e1324bc0a9a9f989ca21406c6dcb075f107268e
@@ -1,9 +1,93 @@
1
- class OBC
1
+ require 'net/http'
2
2
 
3
- attr_reader :params
3
+ module OBC
4
+ class Connection
4
5
 
5
- def initialize(config_params)
6
- @params = config_params
7
- end
6
+ def post_registrar
7
+ post('/registrar', registrar_payload)
8
+ end
9
+
10
+ def deploy(path, *init_args) # "github.com/openblockchain/obc-peer/openchain/example/chaincode/chaincode_example02", "a", "1000", "b", "2000"
11
+ post('/devops/deploy', deploy_payload(path, *init_args))
12
+ end
13
+
14
+ def invoke(chaincode_name, *args)
15
+ post('/devops/invoke', invoke_payload(chaincode_name, *args))
16
+ end
17
+
18
+ def query(chaincode_name, *args)
19
+ post('/devops/query', query_payload(chaincode_name, *args))
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :http, :user
25
+
26
+ def initialize(config)
27
+ @http = Net::HTTP.new(config[:api][:host], config[:api][:port])
28
+ @user = config[:enroll]
29
+ end
8
30
 
31
+ def post(action, to_send)
32
+ request_data = Net::HTTP::Post.new(action, initheader = {'Content-Type' =>'application/json'})
33
+ request_data.body = to_send.to_json
34
+ http.request(request_data)
35
+ end
36
+
37
+ def registrar_payload
38
+ {
39
+ enrollId: user[:id],
40
+ enrollSecret: user[:secret]
41
+ }
42
+ end
43
+
44
+ def deploy_payload(path, *init_args)
45
+ {
46
+ type: "GOLANG",
47
+ chaincodeID:{
48
+ path: path
49
+ },
50
+ ctorMsg: {
51
+ function:"init",
52
+ args: init_args.map(&:to_s)
53
+ },
54
+ secureContext: user[:id]
55
+ }
56
+ end
57
+
58
+ def invoke_payload(chaincode_name, *args)
59
+ {
60
+ chaincodeSpec:
61
+ {
62
+ type: "GOLANG",
63
+ chaincodeID:{
64
+ name: chaincode_name
65
+ },
66
+ ctorMsg: {
67
+ function:"invoke",
68
+ args: args.map(&:to_s)
69
+ },
70
+ secureContext: user[:id]
71
+ }
72
+ }
73
+ end
74
+
75
+ def query_payload(chaincode_name, *args)
76
+ {
77
+ chaincodeSpec:
78
+ {
79
+ type: "GOLANG",
80
+ chaincodeID:{
81
+ name: chaincode_name
82
+ },
83
+ ctorMsg: {
84
+ function:"query",
85
+ args:args.map(&:to_s)
86
+ },
87
+ secureContext: user[:id]
88
+ }
89
+ }
90
+ end
91
+
92
+ end
9
93
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openblockchain-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Savitski
@@ -37,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
37
  version: '0'
38
38
  requirements: []
39
39
  rubyforge_project:
40
- rubygems_version: 2.4.8
40
+ rubygems_version: 2.2.5
41
41
  signing_key:
42
42
  specification_version: 4
43
43
  summary: Ruby Interface for OpenBlockChain interactions