universa 0.1.8 → 0.1.9
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 +4 -4
- data/Gemfile +3 -0
- data/bin/umi/bin/umi +1 -1
- data/bin/umi/bin/umi.bat +1 -1
- data/bin/umi/lib/{com.icodici.umi-0.8.12.jar → com.icodici.umi-0.8.17.jar} +0 -0
- data/lib/universa/binder.rb +94 -0
- data/lib/universa/client.rb +24 -15
- data/lib/universa/contract.rb +48 -28
- data/lib/universa/umi.rb +8 -1
- data/lib/universa/version.rb +1 -1
- data/lib/universa.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3393ecdb08b1b7fe37288be48d86b47a740cf7e923575caa45295c8cdb861247
|
|
4
|
+
data.tar.gz: 76a9a13bdf1a39c8d5e9a0e838a3faf18283d9b357cd3bca18c75f076dbcc65f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 44c450550570eb0e447f7824dae25129cfd59ead09cac86c19b8d3b261d226d7964b88ca3304fc19790ca7512509c5ae3575c0aed09da608133de588d1d1548c
|
|
7
|
+
data.tar.gz: 5b093f28766e602653ad3c9797f4ce6d6a63796c8cd45ab9252b4bd78e145a43aa9510c51370d210d23a97eeab7d4cd14049466f3bc3de0fd933db3b3c1a3467
|
data/Gemfile
CHANGED
data/bin/umi/bin/umi
CHANGED
|
@@ -344,7 +344,7 @@ declare -r lib_dir="$(realpath "${app_home}/../lib")"
|
|
|
344
344
|
declare -a app_mainclass=(com.icodici.farcallscala.Main)
|
|
345
345
|
|
|
346
346
|
declare -r script_conf_file="${app_home}/../conf/application.ini"
|
|
347
|
-
declare -r app_classpath="$lib_dir/com.icodici.umi-0.8.
|
|
347
|
+
declare -r app_classpath="$lib_dir/com.icodici.umi-0.8.17.jar:$lib_dir/org.scala-lang.scala-library-2.12.7.jar:$lib_dir/com.icodici.universa_core-3.8.7.jar:$lib_dir/org.yaml.snakeyaml-1.18.jar:$lib_dir/net.sf.jopt-simple.jopt-simple-4.9.jar:$lib_dir/org.postgresql.postgresql-42.1.4.jar:$lib_dir/org.xerial.sqlite-jdbc-3.8.9.1.jar:$lib_dir/com.icodici.nanohttpd-2.1.0.jar:$lib_dir/com.icodici.common_tools-3.8.7.jar:$lib_dir/com.eclipsesource.minimal-json.minimal-json-0.9.4.jar:$lib_dir/net.java.dev.jna.jna-4.5.1.jar:$lib_dir/org.checkerframework.checker-qual-2.3.2.jar:$lib_dir/com.icodici.crypto-3.8.7.jar:$lib_dir/com.madgag.spongycastle.core-1.58.0.0.jar:$lib_dir/com.squareup.jnagmp.jnagmp-2.0.0.jar:$lib_dir/com.typesafe.play.play-json_2.12-2.6.10.jar:$lib_dir/com.typesafe.play.play-functional_2.12-2.6.10.jar:$lib_dir/org.scala-lang.scala-reflect-2.12.7.jar:$lib_dir/org.typelevel.macro-compat_2.12-1.1.1.jar:$lib_dir/joda-time.joda-time-2.9.9.jar:$lib_dir/com.fasterxml.jackson.core.jackson-core-2.8.11.jar:$lib_dir/com.fasterxml.jackson.core.jackson-annotations-2.8.11.jar:$lib_dir/com.fasterxml.jackson.datatype.jackson-datatype-jdk8-2.8.11.jar:$lib_dir/com.fasterxml.jackson.core.jackson-databind-2.8.11.1.jar:$lib_dir/com.fasterxml.jackson.datatype.jackson-datatype-jsr310-2.8.11.jar:$lib_dir/org.scala-sbt.ipcsocket.ipcsocket-1.0.0.jar:$lib_dir/net.java.dev.jna.jna-platform-4.5.0.jar"
|
|
348
348
|
|
|
349
349
|
# java_cmd is overrode in process_args when -java-home is used
|
|
350
350
|
declare java_cmd=$(get_java_cmd)
|
data/bin/umi/bin/umi.bat
CHANGED
|
@@ -80,7 +80,7 @@ rem "-J" is stripped, "-D" is left as is, and everything is appended to JAVA_OPT
|
|
|
80
80
|
set _JAVA_PARAMS=
|
|
81
81
|
set _APP_ARGS=
|
|
82
82
|
|
|
83
|
-
set "APP_CLASSPATH=%APP_LIB_DIR%\com.icodici.umi-0.8.
|
|
83
|
+
set "APP_CLASSPATH=%APP_LIB_DIR%\com.icodici.umi-0.8.17.jar;%APP_LIB_DIR%\org.scala-lang.scala-library-2.12.7.jar;%APP_LIB_DIR%\com.icodici.universa_core-3.8.7.jar;%APP_LIB_DIR%\org.yaml.snakeyaml-1.18.jar;%APP_LIB_DIR%\net.sf.jopt-simple.jopt-simple-4.9.jar;%APP_LIB_DIR%\org.postgresql.postgresql-42.1.4.jar;%APP_LIB_DIR%\org.xerial.sqlite-jdbc-3.8.9.1.jar;%APP_LIB_DIR%\com.icodici.nanohttpd-2.1.0.jar;%APP_LIB_DIR%\com.icodici.common_tools-3.8.7.jar;%APP_LIB_DIR%\com.eclipsesource.minimal-json.minimal-json-0.9.4.jar;%APP_LIB_DIR%\net.java.dev.jna.jna-4.5.1.jar;%APP_LIB_DIR%\org.checkerframework.checker-qual-2.3.2.jar;%APP_LIB_DIR%\com.icodici.crypto-3.8.7.jar;%APP_LIB_DIR%\com.madgag.spongycastle.core-1.58.0.0.jar;%APP_LIB_DIR%\com.squareup.jnagmp.jnagmp-2.0.0.jar;%APP_LIB_DIR%\com.typesafe.play.play-json_2.12-2.6.10.jar;%APP_LIB_DIR%\com.typesafe.play.play-functional_2.12-2.6.10.jar;%APP_LIB_DIR%\org.scala-lang.scala-reflect-2.12.7.jar;%APP_LIB_DIR%\org.typelevel.macro-compat_2.12-1.1.1.jar;%APP_LIB_DIR%\joda-time.joda-time-2.9.9.jar;%APP_LIB_DIR%\com.fasterxml.jackson.core.jackson-core-2.8.11.jar;%APP_LIB_DIR%\com.fasterxml.jackson.core.jackson-annotations-2.8.11.jar;%APP_LIB_DIR%\com.fasterxml.jackson.datatype.jackson-datatype-jdk8-2.8.11.jar;%APP_LIB_DIR%\com.fasterxml.jackson.core.jackson-databind-2.8.11.1.jar;%APP_LIB_DIR%\com.fasterxml.jackson.datatype.jackson-datatype-jsr310-2.8.11.jar;%APP_LIB_DIR%\org.scala-sbt.ipcsocket.ipcsocket-1.0.0.jar;%APP_LIB_DIR%\net.java.dev.jna.jna-platform-4.5.0.jar"
|
|
84
84
|
set "APP_MAIN_CLASS=com.icodici.farcallscala.Main"
|
|
85
85
|
set "SCRIPT_CONF_FILE=%APP_HOME%\conf\application.ini"
|
|
86
86
|
|
|
Binary file
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
module Universa
|
|
2
|
+
|
|
3
|
+
# Adapter for Universa Binder class which behaves like a ruby hash.
|
|
4
|
+
class Binder < RemoteAdapter
|
|
5
|
+
remote_class "net.sergeych.tools.Binder"
|
|
6
|
+
|
|
7
|
+
# Set object for a key
|
|
8
|
+
#
|
|
9
|
+
# @param [Object] key key.to_s will be used (so use Symbols or Strings freely)
|
|
10
|
+
# @param [Object] value
|
|
11
|
+
def []=(key, value)
|
|
12
|
+
__getobj__.set(key.to_s, value)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Get object by key.
|
|
16
|
+
# @param [Object] key key.to_s will be used (so use Symbols or Strings freely)
|
|
17
|
+
# @return [Object] or nil
|
|
18
|
+
def [](key)
|
|
19
|
+
__getobj__.get(key.to_s)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Create hew Binder from any hash. Keys will be converted to strings.
|
|
23
|
+
def self.of hash
|
|
24
|
+
invoke_static "of", hash.transform_keys(&:to_s)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Retrieve binder keys
|
|
28
|
+
def keys
|
|
29
|
+
__getobj__.keySet()
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# # Internal use only. Allow processing remote commands as local calls
|
|
33
|
+
def respond_to_missing?(method_name, include_private = false)
|
|
34
|
+
l = method_name[-1]
|
|
35
|
+
LOCAL_METHODS.include?(method_name) || l == '!' || l == '?'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Internal use only. Call remote method as needed. This is where all the magick comes from: it call
|
|
39
|
+
# remote get/set method
|
|
40
|
+
def method_missing(method_name, *args, &block)
|
|
41
|
+
if respond_to_missing?(method_name, true)
|
|
42
|
+
super
|
|
43
|
+
else
|
|
44
|
+
if method_name[-1] == '_'
|
|
45
|
+
__getobj__.set(method_name[0..-1], args[0])
|
|
46
|
+
args[0]
|
|
47
|
+
else
|
|
48
|
+
__getobj__.get(method_name)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
LOCAL_METHODS = Set.new(%i[to_hash to_ary [] []= keys values each each_key each_with_index size map to_s])
|
|
54
|
+
|
|
55
|
+
def to_s
|
|
56
|
+
to_h.to_s
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Converts binder to the array of [key, value] pairs, like with regular ruby hashes
|
|
60
|
+
def to_a
|
|
61
|
+
map {|x| x}
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Enumerates all binder entries with a required block
|
|
65
|
+
# @yield [key,value] pairs
|
|
66
|
+
def each &block
|
|
67
|
+
keys.each {|k| block.call [k, __getobj__.get(k)]}
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# @return an array of values returned by the block
|
|
71
|
+
# @yiekd [key,value] pairs.
|
|
72
|
+
def map &block
|
|
73
|
+
keys.map {|k| block.call [k, __getobj__.get(k)]}
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# @return [Array(Array(String,Object))] array of [key,value] pairs.
|
|
77
|
+
def to_a
|
|
78
|
+
map {|x| x}
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# converts to a regular ruby hash
|
|
82
|
+
def to_h
|
|
83
|
+
to_a.to_h
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
class Hash
|
|
90
|
+
def to_binder
|
|
91
|
+
Binder.of self
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
data/lib/universa/client.rb
CHANGED
|
@@ -10,6 +10,9 @@ module Universa
|
|
|
10
10
|
# and also implement newtor-wide procedures.
|
|
11
11
|
class Client
|
|
12
12
|
using Universa::Parallel
|
|
13
|
+
include Universa
|
|
14
|
+
|
|
15
|
+
attr :connection_key
|
|
13
16
|
|
|
14
17
|
# Create client
|
|
15
18
|
# @param [PrivateKey] private_key to connect with. Generates new one if omitted.
|
|
@@ -46,18 +49,20 @@ module Universa
|
|
|
46
49
|
# @return [ContractState] of some final node check It does not aggregates (yet)
|
|
47
50
|
def get_state obj
|
|
48
51
|
result = Concurrent::IVar.new
|
|
49
|
-
negative_votes = Concurrent::AtomicFixnum.new(@nodes.size *
|
|
52
|
+
negative_votes = Concurrent::AtomicFixnum.new(@nodes.size * 11 / 100)
|
|
50
53
|
positive_votes = Concurrent::AtomicFixnum.new(@nodes.size * 30 / 100)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
retry_with_timeout(20, 3) {
|
|
55
|
+
random_connections(@nodes.size).par.each {|conn|
|
|
56
|
+
if result.incomplete?
|
|
57
|
+
if (state = conn.get_state(obj)).approved?
|
|
58
|
+
result.try_set(state) if positive_votes.decrement < 0
|
|
59
|
+
else
|
|
60
|
+
result.try_set(state) if negative_votes.decrement < 0
|
|
61
|
+
end
|
|
57
62
|
end
|
|
58
|
-
|
|
63
|
+
}
|
|
64
|
+
result.value
|
|
59
65
|
}
|
|
60
|
-
result.value
|
|
61
66
|
end
|
|
62
67
|
|
|
63
68
|
# @return [Array(Connection)] array of count randomly selected connections
|
|
@@ -144,6 +149,8 @@ module Universa
|
|
|
144
149
|
# Access to the single node using universa client protocol.
|
|
145
150
|
#
|
|
146
151
|
class Connection
|
|
152
|
+
include Universa
|
|
153
|
+
|
|
147
154
|
# create connection for a given clietn. Don't call it direcly, use
|
|
148
155
|
# {Client.random_connection} or {Client.random_connections} instead. The client implements
|
|
149
156
|
# lazy initialization so time-consuming actual connection will be postponed until
|
|
@@ -168,12 +175,14 @@ module Universa
|
|
|
168
175
|
# @param [Contract] contract, muts be sealed ({Contract#seal})
|
|
169
176
|
# @return [ContractState] of the result. Could contain errors.
|
|
170
177
|
def register_single contract
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
178
|
+
retry_with_timeout(15, 3) {
|
|
179
|
+
result = ContractState.new(execute "approve", packedItem: contract.packed)
|
|
180
|
+
while result.is_pending
|
|
181
|
+
sleep(0.1)
|
|
182
|
+
result = get_state contract
|
|
183
|
+
end
|
|
184
|
+
result
|
|
185
|
+
}
|
|
177
186
|
end
|
|
178
187
|
|
|
179
188
|
# Get contract or hashId state from this single node
|
data/lib/universa/contract.rb
CHANGED
|
@@ -19,29 +19,6 @@ module Universa
|
|
|
19
19
|
remote_class "com.icodici.universa.contract.roles.Role"
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
# Adapter for Universa Binder class. Provides some ruby-style helpers
|
|
23
|
-
class Binder < RemoteAdapter
|
|
24
|
-
remote_class "net.sergeych.tools.Binder"
|
|
25
|
-
|
|
26
|
-
# Set object for a key
|
|
27
|
-
#
|
|
28
|
-
# @param [Object] key key.to_s will be used (so use Symbols or Strings freely)
|
|
29
|
-
# @param [Object] value
|
|
30
|
-
def []=(key, value)
|
|
31
|
-
set(key.to_s, value)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# Get object by key.
|
|
35
|
-
# @param [Object] key key.to_s will be used (so use Symbols or Strings freely)
|
|
36
|
-
# @return [Object] or nil
|
|
37
|
-
def [](key)
|
|
38
|
-
get(key.to_s)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def self.of hash
|
|
42
|
-
invoke_static "of", hash.transform_keys(&:to_s)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
22
|
|
|
46
23
|
# Adapter for Universa +HashId+ class, helps to avoid confusion when using different
|
|
47
24
|
# representations of the ID.
|
|
@@ -147,6 +124,10 @@ module Universa
|
|
|
147
124
|
get_owner
|
|
148
125
|
end
|
|
149
126
|
|
|
127
|
+
def owner= key
|
|
128
|
+
set_owner_key key
|
|
129
|
+
end
|
|
130
|
+
|
|
150
131
|
# Shortcut for is_ok
|
|
151
132
|
def ok?
|
|
152
133
|
is_ok
|
|
@@ -172,13 +153,33 @@ module Universa
|
|
|
172
153
|
end
|
|
173
154
|
|
|
174
155
|
def state
|
|
175
|
-
@state ||=
|
|
156
|
+
@state ||= getStateData()
|
|
176
157
|
end
|
|
177
158
|
|
|
159
|
+
# Get +transactional.data+ section creating it if need
|
|
160
|
+
# @return [Binder] instance
|
|
161
|
+
def transactional
|
|
162
|
+
@transactional ||= getTransactionalData()
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# def transactional?
|
|
166
|
+
# !!getTransactional()
|
|
167
|
+
# end
|
|
168
|
+
|
|
169
|
+
# Helper for many token-like contracts containing state.data.amount
|
|
170
|
+
# @return [BigDecimal] amount or nil
|
|
178
171
|
def amount
|
|
179
172
|
v = state[:amount] and BigDecimal(v.to_s)
|
|
180
173
|
end
|
|
181
174
|
|
|
175
|
+
# Write helper for many token-like contracts containing state.data.amount. Saves value
|
|
176
|
+
# in state.data.anomount and properly encodes it so it will be preserved on packing.
|
|
177
|
+
#
|
|
178
|
+
# @param [Object] value, should be some representation of a number (also string)
|
|
179
|
+
def amount= (value)
|
|
180
|
+
state[:amount] = value.to_s.force_encoding('utf-8')
|
|
181
|
+
end
|
|
182
|
+
|
|
182
183
|
# Get packed transaction containing the serialized signed contract and all its counterparts.
|
|
183
184
|
# Be sure to cal {#seal} somewhere before.
|
|
184
185
|
#
|
|
@@ -195,10 +196,29 @@ module Universa
|
|
|
195
196
|
}
|
|
196
197
|
end
|
|
197
198
|
|
|
198
|
-
#
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
199
|
+
# Call it after check to get summaru of errors found.
|
|
200
|
+
#
|
|
201
|
+
# @return [String] possibly empty ''
|
|
202
|
+
def errors_string
|
|
203
|
+
getErrors.map {|e| "(#{e.object || ''}): #{e.error}"}.join(', ').strip
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def can_perform_role name, *keys
|
|
207
|
+
getRole(name.to_s).isAllowedForKeys(Set.new keys.map {|x|
|
|
208
|
+
x.is_a?(PrivateKey) ? x.public_key : x
|
|
209
|
+
})
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
# Create a contract that revokes this one if register with the Universa network. BE CAREFUL!
|
|
213
|
+
# REVOCATION IS IRREVERSIBLE! period.
|
|
214
|
+
#
|
|
215
|
+
# @param [PrivateKey] keys enough to allow this contract revocation
|
|
216
|
+
# @return [Contract] revocation contract. Register it with the Universa network to perform revocation.
|
|
217
|
+
def create_revocation(*keys)
|
|
218
|
+
revoke = Service.umi.invoke_static 'ContractsService', 'createRevocation', *keys
|
|
219
|
+
revoke.seal
|
|
220
|
+
revoke
|
|
221
|
+
end
|
|
202
222
|
|
|
203
223
|
end
|
|
204
224
|
|
data/lib/universa/umi.rb
CHANGED
|
@@ -239,8 +239,15 @@ module Universa
|
|
|
239
239
|
x._as_umi_arg(self)
|
|
240
240
|
else
|
|
241
241
|
case x
|
|
242
|
+
when Set
|
|
243
|
+
# Make a Java Set
|
|
244
|
+
r = call("instantiate","Set", x.to_a.map{|i| i._as_umi_arg(self)})
|
|
245
|
+
# Ref will garbage collect it
|
|
246
|
+
Ref.new(self, r)
|
|
247
|
+
# but we need a ref struct only:
|
|
248
|
+
r
|
|
242
249
|
when Time
|
|
243
|
-
{
|
|
250
|
+
{__type: 'unixtime', seconds: x.to_i}
|
|
244
251
|
when String
|
|
245
252
|
x.encoding == Encoding::BINARY ? {__type: 'binary', base64: Base64.encode64(x)} : x
|
|
246
253
|
else
|
data/lib/universa/version.rb
CHANGED
data/lib/universa.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: universa
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- sergeych
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-11-
|
|
11
|
+
date: 2018-11-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: farcall
|
|
@@ -137,7 +137,7 @@ files:
|
|
|
137
137
|
- bin/umi/lib/com.icodici.common_tools-3.8.7.jar
|
|
138
138
|
- bin/umi/lib/com.icodici.crypto-3.8.7.jar
|
|
139
139
|
- bin/umi/lib/com.icodici.nanohttpd-2.1.0.jar
|
|
140
|
-
- bin/umi/lib/com.icodici.umi-0.8.
|
|
140
|
+
- bin/umi/lib/com.icodici.umi-0.8.17.jar
|
|
141
141
|
- bin/umi/lib/com.icodici.universa_core-3.8.7.jar
|
|
142
142
|
- bin/umi/lib/com.madgag.spongycastle.core-1.58.0.0.jar
|
|
143
143
|
- bin/umi/lib/com.squareup.jnagmp.jnagmp-2.0.0.jar
|
|
@@ -153,6 +153,7 @@ files:
|
|
|
153
153
|
- bin/umi/lib/org.yaml.snakeyaml-1.18.jar
|
|
154
154
|
- exe/universa
|
|
155
155
|
- lib/universa.rb
|
|
156
|
+
- lib/universa/binder.rb
|
|
156
157
|
- lib/universa/client.rb
|
|
157
158
|
- lib/universa/contract.rb
|
|
158
159
|
- lib/universa/errors.rb
|