class Counterparty::Connection
This class connects to the Counterparty
api. Mostly it’s not intended for use by library consumers, but there are some helper methods in here for those that prefer the Connection.get_burns syntax instead of the Counterparty::Burn.find
syntax
Constants
- DEFAULT_TIMEOUT
The default connection timeout, nil is “no timeout”
Attributes
host[RW]
password[RW]
port[RW]
timeout[W]
A response timeout threshold By default, this initializes to -1, which means the library will wait indefinitely before timing out
username[RW]
Public Class Methods
new(port=4000, username='counterparty', password='1234', host='xcp-dev.vennd.io')
click to toggle source
# File lib/counterparty/connection.rb, line 16 def initialize(port=4000, username='counterparty', password='1234', host='xcp-dev.vennd.io') @host,@port,@username,@password=host.to_s,port.to_i,username.to_s,password.to_s @timeout = DEFAULT_TIMEOUT end
Public Instance Methods
api_url()
click to toggle source
The url being connected to for the purpose of an api call
# File lib/counterparty/connection.rb, line 22 def api_url 'http://%s:%s@%s:%s/api/' % [@username,@password,@host,@port.to_s] end
request(method, params)
click to toggle source
Issue a request to the counterpartyd server for the given method, with the given params.
# File lib/counterparty/connection.rb, line 33 def request(method, params) client = RestClient::Resource.new api_url, :timeout => @timeout request = { method: method, params: params, jsonrpc: '2.0', id: '0' }.to_json response = JSON.parse client.post(request, user: @username, password: @password, accept: 'json', content_type: 'json' ) raise JsonResponseError.new response if response.has_key? 'code' raise ResponseError.new response['error'] if response.has_key? 'error' response['result'] end
sign_tx(raw_tx, private_key)
click to toggle source
Returns a signed raw transaction, given a private key
# File lib/counterparty/connection.rb, line 27 def sign_tx(raw_tx, private_key) request 'sign_tx', unsigned_tx_hex: raw_tx, privkey: private_key end