Giter Site home page Giter Site logo

ripple-lib-rpc-ruby's Introduction

ripple-lib-rpc-ruby

Ripple Client Ruby Gem

Installation

Add this line to your application's Gemfile:

gem 'ripple_lib_rpc_ruby', :git => '[email protected]:kevinejohn/ripple-lib-rpc-ruby.git'

And then execute:

$ bundle

Usage

# WARNING!
# The client does not do local signing of transactions at this point. You must use a trusted endpoint!
# WARNING!

require 'ripple'

ripple = Ripple.client(
  endpoint: "http://s1.ripple.com:51234/",
  client_account: "r4LADqzmqQUMhgSyBLTtPMG4pAzrMDx7Yj",
  client_secret: "ssm5HPoeEZYJWvkJvQW9ro6e6hW9m"
  )

# Send XRP
tx_hash = ripple.send_basic_transaction({destination: "rfGKu3tSxwMFZ5mQ6bUcxWrxahACxABqKc",currency: "XRP",amount: "1"})

# Send IOU
tx_hash = ripple.send_basic_transaction({destination: "rfGKu3tSxwMFZ5mQ6bUcxWrxahACxABqKc",currency: "USD",amount: "0.00001"})

# XRP Balance
balance = ripple.xrp_balance

# Verify tx_hash
begin
  if ripple.transaction_suceeded?("84062717735DD0E6255F3A64750F543020D7DA05AA344012EFF1FEFB8213F735")
    puts "Transaction complete"
  else
    puts "Transaction Pending"
  end
rescue Ripple::InvalidTxHash
  puts "Invalid transaction"
end


# Send and confirm with error checking
success = false
failed = false
begin
  puts "Sending transaction"
  tx_hash = ripple.send_basic_transaction({destination: "rfGKu3tSxwMFZ5mQ6bUcxWrxahACxABqKc",currency: "USD",amount: "0.00001"})
  success = true
rescue Ripple::SubmitFailed => e
  puts "Transaction failed: " + e.message
  failed = true
rescue Ripple::ServerUnavailable
  puts "Server Unavailable"
rescue Ripple::Timedout
  puts "Request timed out"
end while not success and not failed
if success
  # Verify transaction
  complete = false
  begin
    puts "Checking transaction status"
    complete = ripple.transaction_suceeded?(tx_hash)
    if not complete
      # Sleep for small amount of time before checking again
      sleep 1
    end
  rescue Ripple::InvalidTxHash
    puts "Invalid Tx Hash"
  rescue Ripple::ServerUnavailable
    puts "Server Unavailable"
  rescue Ripple::Timedout
    puts "Request timed out"
  end while not complete
  puts "Transaction complete"
end



# Send and confirm complex send with error checking
# 1. Find path
success = false
begin
  puts "Finding Path"
  path = ripple.new_path(
    source_currency: 'USD',
    destination_account: "r44SfjdwtQMpzyAML3vJkssHBiQspdMBw9",
    destination_amount: ripple.new_amount(
      value: '1',
      currency: 'XRP',
      #issuer: 'r44SfjdwtQMpzyAML3vJkssHBiQspdMBw9'
      )
    )
  transaction = ripple.find_transaction_path(path)
  success = true
rescue Ripple::ServerUnavailable
  puts "Server Unavailable"
rescue Ripple::Timedout
  puts "Request timed out"
end while not success
# 2. Sign transaction
if success
  success = false
  failed = false
  begin
    puts "Signing transaction"
    #transaction.print_path_info
    transaction = ripple.sign_transaction(transaction)
    success = true
  rescue Ripple::SubmitFailed => e
    puts "Signing failed: " + e.message
    failed = true
  rescue Ripple::ServerUnavailable
    puts "Server Unavailable"
  rescue Ripple::Timedout
    puts "Request timed out"
  end while not success and not failed
end
# 3. Submit transaction
if success
  success = false
  failed = false
  begin
    puts "Submitting transaction"
    transaction.print_path_info
    tx_hash = ripple.submit_transaction(transaction)
    success = true
  rescue Ripple::SubmitFailed => e
    puts "Transaction failed: " + e.message
    failed = true
  rescue Ripple::ServerUnavailable
    puts "Server Unavailable"
  rescue Ripple::Timedout
    puts "Request timed out"
  end while not success and not failed
end
# 4. Verify transaction
if success
  complete = false
  begin
    puts "Checking transaction status"
    complete = ripple.transaction_suceeded?(tx_hash)
    if not complete
      # Sleep for small amount of time before checking again
      sleep 1
    end
  rescue Ripple::InvalidTxHash
    puts "Invalid Tx Hash"
  rescue Ripple::ServerUnavailable
    puts "Server Unavailable"
  rescue Ripple::Timedout
    puts "Request timed out"
  end while not complete
  puts "Transaction complete"
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

ripple-lib-rpc-ruby's People

Contributors

kevinejohn avatar nixoid avatar

Watchers

 avatar  avatar

Forkers

holytransaction

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.