crea-ruby
Crea-ruby the Ruby API for Crea blockchain.
Full documentation: http://www.rubydoc.info/gems/crea-ruby
Note: This library depends on AppBase methods that are a work in progress.
Getting Started
The crea-ruby gem is compatible with Ruby 2.2.5 or later.
Install the gem for your project
(Assuming that Ruby is installed on your computer, as well as RubyGems)
To install the gem on your computer, run in shell:
gem install crea-ruby... then add in your code:
require 'crea'To add the gem as a dependency to your project with Bundler, you can add this line in your Gemfile:
gem 'crea-ruby', require: 'crea'Examples
Broadcast Vote
params = {
voter: voter,
author: author,
permlink: permlink,
weight: weight
}
Crea::Broadcast.vote(wif: wif, params: params) do |result|
puts result
endSee: Broadcast
Streaming
The value passed to the block is an object, with the keys: :type and :value.
stream = Crea::Stream.new
stream.operations do |op|
puts "#{op.type}: #{op.value}"
endTo start a stream from a specific block number, pass it as an argument:
stream = Crea::Stream.new
stream.operations(at_block_num: 9001) do |op|
puts "#{op.type}: #{op.value}"
endYou can also grab the related transaction id and block number for each operation:
stream = Crea::Stream.new
stream.operations do |op, trx_id, block_num|
puts "#{block_num} :: #{trx_id}"
puts "#{op.type}: #{op.value}"
endTo stream only certain operations:
stream = Crea::Stream.new
stream.operations(types: :vote_operation) do |op|
puts "#{op.type}: #{op.value}"
endOr pass an array of certain operations:
stream = Crea::Stream.new
stream.operations(types: [:comment_operation, :vote_operation]) do |op|
puts "#{op.type}: #{op.value}"
endOr (optionally) just pass the operation(s) you want as the only arguments. This is semantic sugar for when you want specific types and take all of the defaults.
stream = Crea::Stream.new
stream.operations(:vote_operation) do |op|
puts "#{op.type}: #{op.value}"
endTo also include virtual operations:
stream = Crea::Stream.new
stream.operations(include_virtual: true) do |op|
puts "#{op.type}: #{op.value}"
endMultisig
You can use multisignature to broadcast an operation.
params = {
voter: voter,
author: author,
permlink: permlink,
weight: weight
}
Crea::Broadcast.vote(wif: [wif1, wif2], params: params) do |result|
puts result
endIn addition to signing with multiple wif private keys, it is possible to also export a partially signed transaction to have signing completed by someone else.
builder = Crea::TransactionBuilder.new(wif: wif1)
builder.put(vote: {
voter: voter,
author: author,
permlink: permlink,
weight: weight
})
trx = builder.sign.to_json
File.open('trx.json', 'w') do |f|
f.write(trx)
endThen send the contents of trx.json to the other signing party so they can privately sign and broadcast the transaction.
trx = open('trx.json').read
builder = Crea::TransactionBuilder.new(wif: wif2, trx: trx)
api = Crea::CondenserApi.new
trx = builder.transaction
api.broadcast_transaction_synchronous(trx)Get Accounts
api = Crea::DatabaseApi.new
api.find_accounts(accounts: ['creary', 'alice']) do |result|
puts result.accounts
endSee: Api
Reputation Formatter
rep = Crea::Formatter.reputation(account.reputation)
puts repTests
- Clone the client repository into a directory of your choice:
git clone https://github.com/creary/crea-ruby.git
- Navigate into the new folder
cd crea-ruby
- All tests can be invoked as follows:
bundle exec rake test
- To run
statictests:bundle exec rake test:static
- To run
broadcasttests (broadcast is simulated, onlyverifyis actually used):bundle exec rake test:broadcast
- To run
threadstests (which quickly verifies thread safety):bundle exec rake test:threads
- To run
testnettests (which does actual broadcasts)TEST_NODE=https://testnet.crearydev.com bundle exec rake test:testnet
You can also run other tests that are not part of the above test execution:
- To run
block_range, which streams blocks (usingjson-rpc-batch)bundle exec rake stream:block_range
If you want to point to any node for tests, instead of letting the test suite pick the default, set the environment variable to TEST_NODE, e.g.:
$ TEST_NODE=https://api.crearydev.com bundle exec rake testContributions
Patches are welcome! Contributors are listed in the crea-ruby.gemspec file. Please run the tests (rake test) before opening a pull request and make sure that you are passing all of them. If you would like to contribute, but don't know what to work on, check the issues list.
Issues
When you find issues, please report them!
License
MIT