universa 3.13.2.2 → 3.14.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -6
- data/bin/refresh_umi +1 -1
- data/bin/umi/bin/umi +3 -3
- data/bin/umi/bin/umi.bat +1 -1
- data/bin/umi/lib/com.icodici.common_tools-3.14.4.jar +0 -0
- data/bin/umi/lib/com.icodici.crypto-3.14.4.jar +0 -0
- data/bin/umi/lib/{com.icodici.nanohttpd-2.1.0.jar → com.icodici.nanohttpd-2.1.0-20201129b.jar} +0 -0
- data/bin/umi/lib/com.icodici.umi-0.8.77.jar +0 -0
- data/bin/umi/lib/com.icodici.universa_core-3.14.4.jar +0 -0
- data/lib/universa/binder.rb +5 -5
- data/lib/universa/client.rb +1 -1
- data/lib/universa/contract.rb +29 -3
- data/lib/universa/dump.rb +40 -0
- data/lib/universa/keytool/keytool.rb +39 -20
- data/lib/universa/service.rb +6 -5
- data/lib/universa/text_objects.rb +22 -0
- data/lib/universa/umi.rb +1 -1
- data/lib/universa/version.rb +1 -1
- data/lib/universa.rb +1 -0
- data/samples/load_contract.rb +10 -0
- data/samples/safe58_sample.rb +45 -0
- data/universa.gemspec +2 -2
- metadata +20 -26
- data/bin/umi/lib/com.fasterxml.jackson.core.jackson-annotations-2.8.11.jar +0 -0
- data/bin/umi/lib/com.fasterxml.jackson.core.jackson-core-2.8.11.jar +0 -0
- data/bin/umi/lib/com.fasterxml.jackson.core.jackson-databind-2.8.11.1.jar +0 -0
- data/bin/umi/lib/com.fasterxml.jackson.datatype.jackson-datatype-jdk8-2.8.11.jar +0 -0
- data/bin/umi/lib/com.fasterxml.jackson.datatype.jackson-datatype-jsr310-2.8.11.jar +0 -0
- data/bin/umi/lib/com.icodici.common_tools-3.13.2.jar +0 -0
- data/bin/umi/lib/com.icodici.crypto-3.13.2.jar +0 -0
- data/bin/umi/lib/com.icodici.umi-0.8.67.jar +0 -0
- data/bin/umi/lib/com.icodici.universa_core-3.13.2.jar +0 -0
- data/bin/umi/lib/com.typesafe.play.play-functional_2.12-2.6.10.jar +0 -0
- data/bin/umi/lib/com.typesafe.play.play-json_2.12-2.6.10.jar +0 -0
- data/bin/umi/lib/joda-time.joda-time-2.9.9.jar +0 -0
- data/bin/umi/lib/org.scala-lang.scala-reflect-2.12.7.jar +0 -0
- data/bin/umi/lib/org.typelevel.macro-compat_2.12-1.1.1.jar +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8001c7a06a597283b164fde6c41537c16d2020d3d863c3a33530aa81740149c
|
4
|
+
data.tar.gz: 564bb025eddda58e6b567439a6c1020b32220d1974b612043fa5a12056d1fb95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84b096a5d6afc4ff68750e33b43e11d63d08d8dcc3b11b451c00c9efe5ffa37c9d873964fec368af0a9a14db57448de5821b1e7c88c4042c3d43a09ebf20e338
|
7
|
+
data.tar.gz: 9cc6e447a99fdcd91ea865e5cc70c653cf82765beeea765170b8e5feda49a27a238d46b00fc9626e5fdff0e4bc83d051694d43dc21aabce95bed8be2dd9eefaf
|
data/README.md
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
# Universa
|
2
2
|
|
3
|
-
> beta state: direct full access to Java API ready for test, started adapter of remote objects - syntax sugar
|
4
|
-
for direct access to remote objects.
|
5
|
-
|
6
|
-
__attention__ since this release version numbers match the Universa Core library version included.
|
7
|
-
|
8
3
|
This is an under-construction official gem from [Universa][universa] to facilitate access to the
|
9
|
-
Java library using Universa
|
4
|
+
Java library using Universa UMI protocol and Universa client services.
|
10
5
|
|
11
6
|
## News
|
12
7
|
|
8
|
+
- upgraded to new UMI (universa core is updated)
|
9
|
+
- unikeys cli tool now show information about public keys too
|
10
|
+
- unikeys extracts public keys and export as files or unversa text objects
|
11
|
+
them as both univera binaries or universa text objects
|
12
|
+
- support to pack universa text objects, see [kb on universa text objects](https://kb.universablockchain.com/text_format_for_universa_objects/311).
|
13
|
+
|
14
|
+
## Old News :)
|
15
|
+
|
16
|
+
- production-tested in various universa projects
|
13
17
|
- rewritten Client and Connection to use new consensus-based, dns-free Universa network topology discovery protocol
|
14
18
|
- added syntax sugar for TransactionPack
|
15
19
|
- alfa version of the local FS-based contract store.
|
@@ -46,6 +50,26 @@ Or install it yourself as:
|
|
46
50
|
|
47
51
|
## Usage
|
48
52
|
|
53
|
+
### Direct access to Universa objects:
|
54
|
+
|
55
|
+
~~~ruby
|
56
|
+
include Universa
|
57
|
+
|
58
|
+
@private_key = PrivateKey.new 2048
|
59
|
+
c = Contract.create @private_key
|
60
|
+
c.get_creator.get_all_addresses.should == [@private_key.long_address.to_s]
|
61
|
+
c.seal()
|
62
|
+
c.check() and c.trace_errors()
|
63
|
+
c.should be_ok
|
64
|
+
|
65
|
+
c1 = Contract.from_packed(c.packed)
|
66
|
+
c1.hash_id.should == c.hash_id
|
67
|
+
c1.should == c
|
68
|
+
c1.expires_at.should > (Time.now + 120)
|
69
|
+
~~~
|
70
|
+
|
71
|
+
see smaples in specs (spec/contract_spec, spec/compound_spec, etc.)
|
72
|
+
|
49
73
|
### Direct access to UMI
|
50
74
|
|
51
75
|
So far, you can only get direct access the the Java API functions. To get it:
|
data/bin/refresh_umi
CHANGED
data/bin/umi/bin/umi
CHANGED
@@ -281,10 +281,10 @@ java_version_check() {
|
|
281
281
|
if [[ "$major" -eq "1" ]]; then
|
282
282
|
local major=$(echo "$java_version" | cut -d'.' -f2)
|
283
283
|
fi
|
284
|
-
if [[ "$major" -lt "
|
284
|
+
if [[ "$major" -lt "8" ]]; then
|
285
285
|
echo
|
286
286
|
echo The java installation you have is not up to date
|
287
|
-
echo $app_name requires at least version 1.
|
287
|
+
echo $app_name requires at least version 1.8+, you have
|
288
288
|
echo version $java_version
|
289
289
|
echo
|
290
290
|
echo Please go to http://www.java.com/getjava/ and download
|
@@ -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.77.jar:$lib_dir/org.scala-lang.scala-library-2.12.7.jar:$lib_dir/com.icodici.universa_core-3.14.4.jar:$lib_dir/org.scala-sbt.ipcsocket.ipcsocket-1.0.0.jar:$lib_dir/net.sf.jopt-simple.jopt-simple-4.9.jar:$lib_dir/org.yaml.snakeyaml-1.18.jar:$lib_dir/com.icodici.nanohttpd-2.1.0-20201129b.jar:$lib_dir/com.icodici.common_tools-3.14.4.jar:$lib_dir/com.icodici.crypto-3.14.4.jar:$lib_dir/net.java.dev.jna.jna-4.5.1.jar:$lib_dir/net.java.dev.jna.jna-platform-4.5.0.jar:$lib_dir/com.eclipsesource.minimal-json.minimal-json-0.9.4.jar:$lib_dir/org.checkerframework.checker-qual-2.3.2.jar:$lib_dir/org.bouncycastle.bcprov-jdk15on-1.62.jar:$lib_dir/com.squareup.jnagmp.jnagmp-2.0.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.77.jar;%APP_LIB_DIR%\org.scala-lang.scala-library-2.12.7.jar;%APP_LIB_DIR%\com.icodici.universa_core-3.14.4.jar;%APP_LIB_DIR%\org.scala-sbt.ipcsocket.ipcsocket-1.0.0.jar;%APP_LIB_DIR%\net.sf.jopt-simple.jopt-simple-4.9.jar;%APP_LIB_DIR%\org.yaml.snakeyaml-1.18.jar;%APP_LIB_DIR%\com.icodici.nanohttpd-2.1.0-20201129b.jar;%APP_LIB_DIR%\com.icodici.common_tools-3.14.4.jar;%APP_LIB_DIR%\com.icodici.crypto-3.14.4.jar;%APP_LIB_DIR%\net.java.dev.jna.jna-4.5.1.jar;%APP_LIB_DIR%\net.java.dev.jna.jna-platform-4.5.0.jar;%APP_LIB_DIR%\com.eclipsesource.minimal-json.minimal-json-0.9.4.jar;%APP_LIB_DIR%\org.checkerframework.checker-qual-2.3.2.jar;%APP_LIB_DIR%\org.bouncycastle.bcprov-jdk15on-1.62.jar;%APP_LIB_DIR%\com.squareup.jnagmp.jnagmp-2.0.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
|
Binary file
|
data/bin/umi/lib/{com.icodici.nanohttpd-2.1.0.jar → com.icodici.nanohttpd-2.1.0-20201129b.jar}
RENAMED
Binary file
|
Binary file
|
Binary file
|
data/lib/universa/binder.rb
CHANGED
@@ -29,6 +29,10 @@ module Universa
|
|
29
29
|
__getobj__.keySet()
|
30
30
|
end
|
31
31
|
|
32
|
+
def binary(key)
|
33
|
+
__getobj__.getBinary(key)
|
34
|
+
end
|
35
|
+
|
32
36
|
# # Internal use only. Allow processing remote commands as local calls
|
33
37
|
def respond_to_missing?(method_name, include_private = false)
|
34
38
|
l = method_name[-1]
|
@@ -57,6 +61,7 @@ module Universa
|
|
57
61
|
end
|
58
62
|
|
59
63
|
# Converts binder to the array of [key, value] pairs, like with regular ruby hashes
|
64
|
+
# @return [Array(Array(String,Object))] array of [key,value] pairs.
|
60
65
|
def to_a
|
61
66
|
map {|x| x}
|
62
67
|
end
|
@@ -73,11 +78,6 @@ module Universa
|
|
73
78
|
keys.map {|k| block.call [k, __getobj__.get(k)]}
|
74
79
|
end
|
75
80
|
|
76
|
-
# @return [Array(Array(String,Object))] array of [key,value] pairs.
|
77
|
-
def to_a
|
78
|
-
map {|x| x}
|
79
|
-
end
|
80
|
-
|
81
81
|
# converts to a regular ruby hash
|
82
82
|
def to_h
|
83
83
|
to_a.to_h
|
data/lib/universa/client.rb
CHANGED
@@ -216,7 +216,7 @@ module Universa
|
|
216
216
|
|
217
217
|
end
|
218
218
|
|
219
|
-
# The state of some contract reported by
|
219
|
+
# The state of some contract reported by the network. It is a convenience wrapper around Universa
|
220
220
|
# ItemState structure.
|
221
221
|
class ContractState
|
222
222
|
def initialize(universa_contract_state)
|
data/lib/universa/contract.rb
CHANGED
@@ -35,6 +35,15 @@ module Universa
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
# Safe58 allows human-friendly binary-to-characters codec. It automatically corrects recognition
|
39
|
+
# errors like 0 instead of 0 and 1 instead of I. The code does not use characters that look alike and
|
40
|
+
# uses only encglish letters and digits that also simplify select-copy-paste routine.
|
41
|
+
#
|
42
|
+
# important! arguments MUST be binary strings, so use
|
43
|
+
#
|
44
|
+
# str.force_encoding('binary')
|
45
|
+
#
|
46
|
+
# as need, otherwise it will not work as expected.
|
38
47
|
class Safe58 < RemoteAdapter
|
39
48
|
remote_class "net.sergeych.utils.Safe58"
|
40
49
|
|
@@ -58,6 +67,11 @@ module Universa
|
|
58
67
|
remote_class "com.icodici.universa.contract.permissions.ChangeOwnerPermission"
|
59
68
|
end
|
60
69
|
|
70
|
+
# Adapter for Universa ChangeRolePermission
|
71
|
+
class ChangeRolePermission < RemoteAdapter
|
72
|
+
remote_class "com.icodici.universa.contract.permissions.ChangeRolePermission"
|
73
|
+
end
|
74
|
+
|
61
75
|
# Adapter for Universa RevokePermission
|
62
76
|
class RevokePermission < RemoteAdapter
|
63
77
|
remote_class "com.icodici.universa.contract.permissions.RevokePermission"
|
@@ -91,6 +105,10 @@ module Universa
|
|
91
105
|
# adapter for a role that is a list of roles
|
92
106
|
class ListRole < RemoteAdapter
|
93
107
|
remote_class "com.icodici.universa.contract.roles.ListRole"
|
108
|
+
|
109
|
+
class Mode
|
110
|
+
ANY = 'ANY'
|
111
|
+
end
|
94
112
|
end
|
95
113
|
|
96
114
|
# Adapter for permission to modify data
|
@@ -98,6 +116,10 @@ module Universa
|
|
98
116
|
remote_class "com.icodici.universa.contract.permissions.ModifyDataPermission"
|
99
117
|
end
|
100
118
|
|
119
|
+
# Adapter for Universa QuorumVoteRole
|
120
|
+
class QuorumVoteRole < RemoteAdapter
|
121
|
+
remote_class "com.icodici.universa.contract.roles.QuorumVoteRole"
|
122
|
+
end
|
101
123
|
|
102
124
|
# Wrapper for Java API Reference class
|
103
125
|
|
@@ -240,7 +262,7 @@ module Universa
|
|
240
262
|
# @return [Contract] simple contact, not sealed
|
241
263
|
def self.create issuer_key, expires_at: (Time.now + 90 * 24 * 60 * 60), use_short_address: false
|
242
264
|
contract = Contract.new
|
243
|
-
contract.set_expires_at expires_at
|
265
|
+
contract.set_expires_at expires_at.utc
|
244
266
|
contract.set_issuer_keys(use_short_address ? issuer_key.short_address : issuer_key.long_address)
|
245
267
|
contract.register_role(contract.issuer.link_as("owner"))
|
246
268
|
contract.register_role(contract.issuer.link_as("creator"))
|
@@ -320,7 +342,7 @@ module Universa
|
|
320
342
|
# set +expires_at+ field
|
321
343
|
# @param [Time] time when this contract will be expired, if yet +APPROVED+.
|
322
344
|
def expires_at=(time)
|
323
|
-
set_expires_at time
|
345
|
+
set_expires_at time.utc
|
324
346
|
end
|
325
347
|
|
326
348
|
# @return definition data
|
@@ -408,4 +430,8 @@ module Universa
|
|
408
430
|
end
|
409
431
|
end
|
410
432
|
|
411
|
-
|
433
|
+
class ExtendedSignature < RemoteAdapter
|
434
|
+
remote_class "com.icodici.universa.contract.ExtendedSignature"
|
435
|
+
end
|
436
|
+
|
437
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Universa
|
2
|
+
|
3
|
+
# Convert binary data to a human-readable dump string, like
|
4
|
+
#
|
5
|
+
# <code>
|
6
|
+
# 000000 27 23 64 61 74 61 c4 2d 0f |'#data.-.|
|
7
|
+
# 000008 0f 1f 43 63 6f 6e 74 72 61 |..Ccontra|
|
8
|
+
# </code>
|
9
|
+
#
|
10
|
+
# @param data[String] data to dump
|
11
|
+
# @param line_bytes[Number] how many bytes to show in each line
|
12
|
+
# @return [String] dump as a string
|
13
|
+
def dump_bytes data, line_bytes=16
|
14
|
+
data.force_encoding Encoding::BINARY
|
15
|
+
offset = 0
|
16
|
+
res = []
|
17
|
+
|
18
|
+
while( offset < data.length )
|
19
|
+
|
20
|
+
left = "%06x" % offset
|
21
|
+
portion = data[offset..(offset+line_bytes)].bytes
|
22
|
+
|
23
|
+
bytes = portion.map { |x| "%02x" % x }.join(' ')
|
24
|
+
chars = portion.map { |c| x = c.ord; x >= 32 && x <= 'z'.ord ? x.chr : '.' }.join('')
|
25
|
+
|
26
|
+
if chars.length < line_bytes
|
27
|
+
pad = line_bytes - chars.length + 1
|
28
|
+
chars += ' ' * pad
|
29
|
+
bytes += ' ' * pad
|
30
|
+
end
|
31
|
+
|
32
|
+
res << "#{left} #{bytes} |#{chars}|"
|
33
|
+
|
34
|
+
offset += line_bytes
|
35
|
+
end
|
36
|
+
res.join("\n")
|
37
|
+
end
|
38
|
+
|
39
|
+
module_function :dump_bytes
|
40
|
+
end
|
@@ -6,8 +6,7 @@ require 'universa/tools'
|
|
6
6
|
|
7
7
|
include Universa
|
8
8
|
|
9
|
-
class MessageException < Exception;
|
10
|
-
end
|
9
|
+
class MessageException < Exception; end
|
11
10
|
|
12
11
|
def error message
|
13
12
|
raise MessageException, message
|
@@ -55,20 +54,20 @@ class KeyTool
|
|
55
54
|
def session_password
|
56
55
|
@require_password or return nil
|
57
56
|
@session_password ||= begin
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
57
|
+
if @autogenerate_password
|
58
|
+
psw = 29.random_alnums
|
59
|
+
puts "Autogenerated password: #{ANSI.bold { psw }}"
|
60
|
+
psw
|
61
|
+
else
|
62
|
+
puts "\nPlease enter password for key to be generated"
|
63
|
+
psw1 = STDIN.noecho(&:gets).chomp
|
64
|
+
puts "Please re-enter the password"
|
65
|
+
psw2 = STDIN.noecho(&:gets).chomp
|
66
|
+
psw1 == psw2 or error "passwords do not match"
|
67
|
+
psw1.length < 8 and error "password is too short"
|
68
|
+
psw1
|
69
|
+
end
|
70
|
+
end
|
72
71
|
end
|
73
72
|
|
74
73
|
def output_file(extension = nil, overwrite_existing_name = nil)
|
@@ -80,7 +79,7 @@ class KeyTool
|
|
80
79
|
extension && !name.end_with?(extension) ? "#{name}#{extension}" : name
|
81
80
|
end
|
82
81
|
|
83
|
-
def load_key(name)
|
82
|
+
def load_key(name, allow_public = false)
|
84
83
|
packed = open(name, 'rb') { |f| f.read } rescue error("can't read file: #{name}")
|
85
84
|
begin
|
86
85
|
PrivateKey.from_packed(packed)
|
@@ -94,8 +93,14 @@ class KeyTool
|
|
94
93
|
key = PrivateKey.from_packed(packed, password: password) rescue nil
|
95
94
|
key and break key
|
96
95
|
end
|
96
|
+
elsif allow_public
|
97
|
+
begin
|
98
|
+
PublicKey.from_packed(packed)
|
99
|
+
rescue
|
100
|
+
error "can't load the private/public key (file corrupt?)"
|
101
|
+
end
|
97
102
|
else
|
98
|
-
error "can't load the key (file corrupt?)"
|
103
|
+
error "can't load the private key (file corrupt?)"
|
99
104
|
end
|
100
105
|
end
|
101
106
|
end
|
@@ -178,11 +183,25 @@ class KeyTool
|
|
178
183
|
@rounds < 100000 and error "To few rounds, use at least 100000"
|
179
184
|
}
|
180
185
|
|
186
|
+
opts.on("-p FILE", "--public FILE", "extract public key. If output file is not specified,",
|
187
|
+
"prints as universa text object to the standard output") { |name|
|
188
|
+
task {
|
189
|
+
key = load_key(name, true)
|
190
|
+
if @output_file
|
191
|
+
open(output_file(".public.unikey"), 'wb') { |f| f << key.pack() }
|
192
|
+
else
|
193
|
+
puts format_text_object(key.pack(), "public key", fileName: name)
|
194
|
+
# puts "not yet implemented #{key.long_address.to_s}"
|
195
|
+
end
|
196
|
+
}
|
197
|
+
}
|
198
|
+
|
181
199
|
opts.on("-s FILE", "--show FILE", "show key information") { |name|
|
182
200
|
task {
|
183
|
-
key = load_key(name)
|
201
|
+
key = load_key(name, true)
|
202
|
+
is_private = key.is_a? PrivateKey
|
184
203
|
puts "\r----------------------------------------------------------------------------------------"
|
185
|
-
puts "Private key, #{key.info.getKeyLength() * 8} bits\n"
|
204
|
+
puts "#{is_private ? 'Private' : 'Public'} key, #{key.info.getKeyLength() * 8} bits\n"
|
186
205
|
puts "Short address : #{ANSI.bold { key.short_address.to_s }}"
|
187
206
|
puts "Long address : #{ANSI.bold { key.long_address.to_s }}"
|
188
207
|
}
|
data/lib/universa/service.rb
CHANGED
@@ -2,7 +2,7 @@ require 'singleton'
|
|
2
2
|
|
3
3
|
module Universa
|
4
4
|
|
5
|
-
# The service is a singleton to provide
|
5
|
+
# The service is a singleton to provide process-wide objects and methods. For example,
|
6
6
|
# the {UMI} interface and reference class factory are unique per-process for Universa
|
7
7
|
# library. It uses exactly one lazy created {UMI} connection which is shared among all threads.
|
8
8
|
# As UMI server is multithreaded by nature, is will not block ruby threads waiting for remote
|
@@ -26,7 +26,8 @@ module Universa
|
|
26
26
|
@known_proxies = {}
|
27
27
|
[Contract, PrivateKey, PublicKey, KeyAddress, HashId, Binder,
|
28
28
|
Role, SimpleRole, RoleLink, ListRole, Parcel, UnsContract,
|
29
|
-
ChangeOwnerPermission,
|
29
|
+
ChangeOwnerPermission, ChangeRolePermission, RevokePermission,
|
30
|
+
ModifyDataPermission, SplitJoinPermission, QuorumVoteRole,
|
30
31
|
UmiClient, Duration, Compound, KeyInfo, PBKDF2].each {|klass| register_proxy klass}
|
31
32
|
end
|
32
33
|
|
@@ -128,7 +129,7 @@ module Universa
|
|
128
129
|
|
129
130
|
# Updating proxied object is not allowed. Raises error.
|
130
131
|
def __setobj__
|
131
|
-
raise "
|
132
|
+
raise "ObjectProxy does not support changing referenced object"
|
132
133
|
end
|
133
134
|
|
134
135
|
# Returns remote class name. There is no need to override it, when inheriting it use +remote_class+ helper:
|
@@ -139,11 +140,11 @@ module Universa
|
|
139
140
|
# #...
|
140
141
|
# end
|
141
142
|
#
|
142
|
-
# Notice: remote_class will do
|
143
|
+
# Notice: remote_class will do all necessary work for you.
|
143
144
|
#
|
144
145
|
# @return [String] remote class name
|
145
146
|
def self.remote_class_name
|
146
|
-
@remote_class_name or raise Error, "
|
147
|
+
@remote_class_name or raise Error, "provide remote class name"
|
147
148
|
end
|
148
149
|
|
149
150
|
# Registers remote class name to be used with this adapted. Call it early in descendant class
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
3
|
+
# Generate universa text object representation from arbitrary data, see
|
4
|
+
# https://kb.universablockchain.com/text_format_for_universa_objects/311
|
5
|
+
# for details.
|
6
|
+
#
|
7
|
+
# @param [Object] data binary string to pack as universa text object
|
8
|
+
# @param [Object] type object type, see link above
|
9
|
+
# @param [Hash] kwargs any additional fields
|
10
|
+
# @return [String] string with properly framed universa object
|
11
|
+
def format_text_object(data, type, **kwargs)
|
12
|
+
source = ["type: #{type}"]
|
13
|
+
kwargs.each { |k, v|
|
14
|
+
source << "#{k}: #{v}"
|
15
|
+
}
|
16
|
+
source << ""
|
17
|
+
source << Base64.encode64(data)
|
18
|
+
hash = Digest::SHA2.base64digest(source.join(''))
|
19
|
+
"==== Begin Universa Object: #{hash} ====\n" +
|
20
|
+
source.join("\n") +
|
21
|
+
"\n===== End Universa Object: #{hash} =====\n"
|
22
|
+
end
|
data/lib/universa/umi.rb
CHANGED
@@ -372,7 +372,7 @@ module Universa
|
|
372
372
|
# Java classes, whose references are created on-the-fly automatically (and will be reclaimed by GC on both
|
373
373
|
# ends soon).
|
374
374
|
#
|
375
|
-
# == Instances are
|
375
|
+
# == Instances are unique
|
376
376
|
#
|
377
377
|
# What means, if some calls will return the same Java object instance, it will be returned as the same {Ref}
|
378
378
|
# instance.
|
data/lib/universa/version.rb
CHANGED
data/lib/universa.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
# example:
|
2
|
+
#
|
3
|
+
# rationale:
|
4
|
+
# We want to pass order code to user which is potentially long integer (sam, above 9 characters in decimal
|
5
|
+
# notation), but the bank insist oreder code in the payment purpose should be 5-8 characters.
|
6
|
+
#
|
7
|
+
# solution:
|
8
|
+
#
|
9
|
+
# pack long id (we assume it will fit 5 bytes that give us >60 billions which is usually more
|
10
|
+
# than enough) to short and easy to human-retype code using SAFE58 encoding by Universa.
|
11
|
+
#
|
12
|
+
# It will nirmally give us 6 letter-code which is well protected against recognition mistakes,
|
13
|
+
# for example 0 instead of o or 1 instead of I or i. It autocorrects it and does not use like characters.
|
14
|
+
#
|
15
|
+
require 'universa'
|
16
|
+
|
17
|
+
# sample long to encode, 12 billions+ (12`884`901`887)
|
18
|
+
id = 0x2FFFFffff
|
19
|
+
|
20
|
+
def int_to_safe58(value)
|
21
|
+
# pack to BE 8-byte long
|
22
|
+
packed = [value].pack("Q>")
|
23
|
+
|
24
|
+
# important: safe58 needs binary encoded string, but pack already gives us binary string,
|
25
|
+
# so we strip 3 first bytes which are are zeroes and encode the rest to safe 58:
|
26
|
+
Universa::Safe58.encode(packed[3..])
|
27
|
+
end
|
28
|
+
|
29
|
+
def safe58_to_int(encoded)
|
30
|
+
# decode 5 bytes
|
31
|
+
bytes = Universa::Safe58.decode(encoded)
|
32
|
+
# pad left with 3 zero bytes to get back 64 bit integer and unpack it:
|
33
|
+
"\x0\x0\x0#{bytes}".unpack("Q>")[0]
|
34
|
+
end
|
35
|
+
|
36
|
+
puts "Encoded: #{id} -> #{int_to_safe58 id}"
|
37
|
+
|
38
|
+
id2 = safe58_to_int(int_to_safe58(id))
|
39
|
+
puts "Decoded: #{int_to_safe58 id} -> #{id2}"
|
40
|
+
|
41
|
+
id == id2 or raise "test failed"
|
42
|
+
|
43
|
+
puts "ALL OK"
|
44
|
+
|
45
|
+
|
data/universa.gemspec
CHANGED
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.add_dependency "concurrent-ruby-ext"
|
37
37
|
spec.add_dependency "ansi"
|
38
38
|
|
39
|
-
spec.add_development_dependency "bundler", "~>
|
40
|
-
spec.add_development_dependency "rake", "~>
|
39
|
+
spec.add_development_dependency "bundler", "~> 2"
|
40
|
+
spec.add_development_dependency "rake", "~> 12.3.3"
|
41
41
|
spec.add_development_dependency "rspec", "~> 3.8"
|
42
42
|
end
|
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: 3.
|
4
|
+
version: 3.14.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sergeych
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: farcall
|
@@ -86,28 +86,28 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '2'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '2'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rake
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 12.3.3
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 12.3.3
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rspec
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,29 +144,19 @@ files:
|
|
144
144
|
- bin/umi/bin/umi
|
145
145
|
- bin/umi/bin/umi.bat
|
146
146
|
- bin/umi/lib/com.eclipsesource.minimal-json.minimal-json-0.9.4.jar
|
147
|
-
- bin/umi/lib/com.
|
148
|
-
- bin/umi/lib/com.
|
149
|
-
- bin/umi/lib/com.
|
150
|
-
- bin/umi/lib/com.
|
151
|
-
- bin/umi/lib/com.
|
152
|
-
- bin/umi/lib/com.icodici.common_tools-3.13.2.jar
|
153
|
-
- bin/umi/lib/com.icodici.crypto-3.13.2.jar
|
154
|
-
- bin/umi/lib/com.icodici.nanohttpd-2.1.0.jar
|
155
|
-
- bin/umi/lib/com.icodici.umi-0.8.67.jar
|
156
|
-
- bin/umi/lib/com.icodici.universa_core-3.13.2.jar
|
147
|
+
- bin/umi/lib/com.icodici.common_tools-3.14.4.jar
|
148
|
+
- bin/umi/lib/com.icodici.crypto-3.14.4.jar
|
149
|
+
- bin/umi/lib/com.icodici.nanohttpd-2.1.0-20201129b.jar
|
150
|
+
- bin/umi/lib/com.icodici.umi-0.8.77.jar
|
151
|
+
- bin/umi/lib/com.icodici.universa_core-3.14.4.jar
|
157
152
|
- bin/umi/lib/com.squareup.jnagmp.jnagmp-2.0.0.jar
|
158
|
-
- bin/umi/lib/com.typesafe.play.play-functional_2.12-2.6.10.jar
|
159
|
-
- bin/umi/lib/com.typesafe.play.play-json_2.12-2.6.10.jar
|
160
|
-
- bin/umi/lib/joda-time.joda-time-2.9.9.jar
|
161
153
|
- bin/umi/lib/net.java.dev.jna.jna-4.5.1.jar
|
162
154
|
- bin/umi/lib/net.java.dev.jna.jna-platform-4.5.0.jar
|
163
155
|
- bin/umi/lib/net.sf.jopt-simple.jopt-simple-4.9.jar
|
164
156
|
- bin/umi/lib/org.bouncycastle.bcprov-jdk15on-1.62.jar
|
165
157
|
- bin/umi/lib/org.checkerframework.checker-qual-2.3.2.jar
|
166
158
|
- bin/umi/lib/org.scala-lang.scala-library-2.12.7.jar
|
167
|
-
- bin/umi/lib/org.scala-lang.scala-reflect-2.12.7.jar
|
168
159
|
- bin/umi/lib/org.scala-sbt.ipcsocket.ipcsocket-1.0.0.jar
|
169
|
-
- bin/umi/lib/org.typelevel.macro-compat_2.12-1.1.1.jar
|
170
160
|
- bin/umi/lib/org.yaml.snakeyaml-1.18.jar
|
171
161
|
- exe/unikeys
|
172
162
|
- lib/universa.rb
|
@@ -174,6 +164,7 @@ files:
|
|
174
164
|
- lib/universa/chain_store.rb
|
175
165
|
- lib/universa/client.rb
|
176
166
|
- lib/universa/contract.rb
|
167
|
+
- lib/universa/dump.rb
|
177
168
|
- lib/universa/errors.rb
|
178
169
|
- lib/universa/fs_store/entry.rb
|
179
170
|
- lib/universa/fs_store/file_store.rb
|
@@ -183,6 +174,7 @@ files:
|
|
183
174
|
- lib/universa/service.rb
|
184
175
|
- lib/universa/stored_contract.rb
|
185
176
|
- lib/universa/string_utils.rb
|
177
|
+
- lib/universa/text_objects.rb
|
186
178
|
- lib/universa/tools.rb
|
187
179
|
- lib/universa/u_settings.rb
|
188
180
|
- lib/universa/ubox.rb
|
@@ -191,12 +183,14 @@ files:
|
|
191
183
|
- lib/universa/version.rb
|
192
184
|
- lib/universa/weak_reference.rb
|
193
185
|
- sample_ping.rb
|
186
|
+
- samples/load_contract.rb
|
187
|
+
- samples/safe58_sample.rb
|
194
188
|
- universa.gemspec
|
195
|
-
homepage:
|
189
|
+
homepage:
|
196
190
|
licenses:
|
197
191
|
- MIT
|
198
192
|
metadata: {}
|
199
|
-
post_install_message:
|
193
|
+
post_install_message:
|
200
194
|
rdoc_options: []
|
201
195
|
require_paths:
|
202
196
|
- lib
|
@@ -211,8 +205,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
205
|
- !ruby/object:Gem::Version
|
212
206
|
version: '0'
|
213
207
|
requirements: []
|
214
|
-
rubygems_version: 3.
|
215
|
-
signing_key:
|
208
|
+
rubygems_version: 3.2.22
|
209
|
+
signing_key:
|
216
210
|
specification_version: 4
|
217
211
|
summary: Expose Universa Java API to ruby
|
218
212
|
test_files: []
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|