v.12 by Sergey Chernov
2018-11-10 17:11

Universa Ruby gem


Current stage: direct access for Java API from Ruby ready for test. Adapters early preview (v0.1.4)

See our gem in the GitHub and online documentation for programming reference.

Getting started

As for now, the gem allows easy accessing all JAVA API functions from ruby with zero boilerplate code and taking care of remote objects lifespan. For example:

require 'universa'

umi = Universa::UMI.new

p umi.version                                         #=> "0.8.7"
key = umi.instantiate "PrivateKey", 2048
contract = umi.instantiate "Contract", key
sealed = contract.seal()
puts "Contract is ok: #{contract.check()}"            #=> contract is ok: true"
puts "Contract id: #{contract.getId.toBase64String}"  #=> contract id: x9Ey+q...

 # Get the address of the first signer key
address = contract.getKeysToSignWith()[0].getPublicKey().getShortAddress().toString()

Notice using remote object as an argument to the remote call and chainig Java API calls with direct call sequence.

The gem ensures all references to the same Java objects are same in the ruby side, and ruby equality operators work as supposed, calling remote equality methods as need.

Adapter objects

Even simpler than with direct access, no voilerplate code:

key = PrivateKey.new 2048
contract = Contract.new(key)
k1 = contract.signing_keys[0]
k1.should == key
k1.short_address.should == key.short_address
sealed = contract.seal()
contract.check().should be_truthy

Connect to the network

Connecting to the network in a reliable way is not that simple: one needs to connect several root nodes, read the network information from it, compare it and select trusted nodes configurations. Since v0.1.5 is is as simple as:

client = Client.new  # thats all folks ;)
# now execute any client command like this:
client.random_connection.execute("sping") #=> #<Farcall::SmartHash sping="spong">

random_connection ehre just select any node to connect with. This is preferred way - rather than usnig always the same node.

See client for more.

Submitting bugs

Create an issue in the github. Provide logs: use log facility -

@uml.with_trace {
    // code that produces error
}

or log creation parameter of the UMI class.