Universa Ruby gem

Current stage: production for more than 1 year.

Direct access for Java API from Ruby ready for tests. Adapters, Contracts, Binders, HashIds, network access utilities and full access to the Java API using UMI. (v0.1.9).

See our gem in GitHub at  sergeych/universa, 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.

It has also many syntax sugar for Ruby-way usage. For example:

@access_key = PrivateKey.from_packed open(File.expand_path "~/.universa/test_access.private.unikey", 'rb').read, password: 'something notthatsupid'

# create contract
contract = Contract.create @test_access_key
contract.definition.name = "just a test"
contract.expires_at = Time.now + 900 # 900 seconds from now

# It is not registered: should be undefined
state = @client.get_state contract
state.state.should == 'UNDEFINED'
state.is_pending.should == false
state.is_approved.should == false

# register it using whitelist more (private networks for example)
state = @client.register_single contract
state.should be_approved
state.errors.should be_nil
@client.get_state(contract).should be_approved

# Now revoke it
rev = contract.createRevocation(@test_access_key)
state = @client.register_single(rev)
state.should be_approved

# It should be revoked
state = @client.get_state(contract)
state.should_not be_approved
state.state.should == 'REVOKED'

Older samples

It allows unlimited direct usage of Universa JAVA API. 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 how we use the remote object as an argument to the remote call, and how we chain Java API calls with direct call sequence.

The gem ensures all references to the same Java objects are the same on the Ruby side, and Ruby equality operators work as supposed, calling remote equality methods when needed.

Adapter objects

Even simpler than with direct access, no boilerplate 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 where just select any node to connect with. This is the preferred way, rather than always using the same node.

See client documentation for more.

Submitting bugs

Create new issue in GitHub. Provide logs: use log facility -

@uml.with_trace {
    // code that produces error

or log creation parameter of the UMI class.