Current stage: beta. 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 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.

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
contract.seal()

# 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 ise og 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 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.