elchapo 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ef89a15a572c27a49e4066309407551be248f52
4
- data.tar.gz: b0ecc19e544d7c0b78f11de540b9bc6b32be2e5c
3
+ metadata.gz: 90ac66b620839de68e1517a40fc4f40029544b24
4
+ data.tar.gz: 092f29394d553bd50980962042ffaaec144c06f0
5
5
  SHA512:
6
- metadata.gz: 0c00f2979a40759c7b43af5bfcbf742f7a650013a959051ee7ff63796fd49fa2835a09d6fcade15c1a694b9d6fe6dedf0877450e1a4c03837657eb02a19957f1
7
- data.tar.gz: 73191d5eaa4a42a75583ed9aac9621e310a137108da7212f72cd12c7e3a1c3b73de995d9e8ce4628bc0b6dec0c21041a624abbe9c4802c3c2396442e752639cc
6
+ metadata.gz: ed3bd8f6b617a4d3cab2c149f6dc195ad07e7f085acd1b4f5b4e36db9a141810d080704311ad5ff380df3d53373a9b85e30f77f71dbcea2366ccb457509fb504
7
+ data.tar.gz: d10f5fdbb29e24f8f58bccec09b156f8e8b1aea28bb593cbb1720bbf2bc9d48d798d3fb70a725da8d3982a4f767126f4395bfe5fe1a1af7d480dc0e329af9ad7
data/README.md CHANGED
@@ -1,29 +1,63 @@
1
1
  # Elchapo
2
2
 
3
- Ruby API for Ethereum Blockchain network
3
+ Ruby API for Ethereum & Bitcoin Blockchain networks
4
+
5
+ ## Ethereum
6
+
7
+ ### IPC Connection
8
+
9
+ Have a look at this blog post for a detail description about [Connect to Ethereum node using IPC](http://dilumn.github.io/ethereum/2017/10/22/connect-to-ethereum-ipc-using-ruby/)
10
+
11
+ ## Installation
12
+ Once you've verified that Ruby is installed:
13
+
14
+ `gem install elchapo`
4
15
 
5
- ## IPC Connection
6
16
 
7
17
  ```ruby
8
18
  require 'elchapo'
9
19
 
10
- client = Ethereum::Connection.new("/root/.ethereum/rinkeby/geth.ipc")
20
+ ```
21
+
22
+ IPC Client for Ethereum
23
+
24
+ ```
25
+ eth_client = Ethereum::Connection.new("/root/.ethereum/rinkeby/geth.ipc")
26
+ ```
27
+
28
+ RPC Client for Ethereum
29
+
30
+ ```
31
+ eth_client = Ethereum::HttpConnection.new("http://0.0.0.0:8545")
32
+ ```
33
+
34
+ RPC Client for Bitcoin
11
35
 
36
+ ```
37
+ btc_client = Bitcoin::HttpConnection.new("http://127.0.0.1:18333", user: "foo", pass: "bar")
12
38
  ```
13
39
 
14
- After you create the connection client, you can use all these Ethereum `eth` commands & call those methods.
40
+ After you create the connection client, you can use all these Ethereum `eth` commands & Bitcoin RPC commands.
15
41
 
16
42
  [https://github.com/ethereum/wiki/wiki/JSON-RPC](https://github.com/ethereum/wiki/wiki/JSON-RPC)
17
43
 
18
44
  [https://github.com/ethereum/go-ethereum/wiki/Management-APIs](https://github.com/ethereum/go-ethereum/wiki/Management-APIs)
19
45
 
20
- `client.eth_accounts`
46
+ [https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list](https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list)
47
+
48
+ `eth_client.eth_accounts`
49
+
50
+ `btc_client.getinfo`
51
+
52
+ You can pass parameters as method arguments,
53
+
54
+ `btc_client.sendtoaddress("awl2llkjalwo209ao23rjaslkjv30", 0.1)`
21
55
 
22
56
  Make sure you are using underscore instead of capitals. Eg: `getBalance` => `get_balance`
23
57
 
24
58
  `client.get_balance("ACCOUNT NUMBER")`
25
59
 
26
- This gem is inspired & forked from [ethereum.rb](https://github.com/EthWorks/ethereum.rb)
60
+ This gem is inspired from [ethereum.rb](https://github.com/EthWorks/ethereum.rb)
27
61
 
28
62
  ## License
29
63
 
@@ -0,0 +1,42 @@
1
+ module Bitcoin
2
+ class Client
3
+
4
+ # https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list
5
+ RPC_COMMANDS = %w(addmultisigaddress addnode backupwallet createmultisig createrawtransaction decoderawtransaction dumpprivkey dumpwallet encryptwallet getaccount getaccountaddress getaddednodeinfo getaddressesbyaccount getbalance getbestblockhash getblock getblockcount getblockhash getblocknumber getblocktemplate getconnectioncount getdifficulty getgenerate gethashespersec getinfo getmemorypool getmininginfo getnewaddress getpeerinfo getrawchangeaddress getrawmempool getrawtransaction getreceivedbyaccount getreceivedbyaddress gettransaction gettxout gettxoutsetinfo getwork help importprivkey invalidateblock keypoolrefill listaccounts listaddressgroupings listreceivedbyaccount listreceivedbyaddress listsinceblock listtransactions listunspent listlockunspent lockunspent move sendfrom sendmany sendrawtransaction sendtoaddress setaccount setgenerate settxfee signmessage signrawtransaction stop submitblock validateaddress verifymessage walletlock walletpassphrase walletpassphrasechange)
6
+
7
+ attr_accessor :command, :id, :default_account
8
+
9
+ def initialize
10
+ @id = 0
11
+ end
12
+
13
+ def get_id
14
+ @id += 1
15
+ return @id
16
+ end
17
+
18
+ def reset_id
19
+ @id = 0
20
+ end
21
+
22
+ def send_command(command,args)
23
+ payload = {jsonrpc: "2.0", method: command, params: args, id: get_id}
24
+ @logger.info("Sending #{payload.to_json}") if @log
25
+
26
+ output = JSON.parse(send_single(payload.to_json))
27
+ @logger.info("Received #{output.to_json}") if @log
28
+ reset_id
29
+ raise IOError, output["error"]["message"] if output["error"]
30
+ return output["result"]
31
+ end
32
+
33
+ (RPC_COMMANDS).each do |rpc_command|
34
+ method_name = rpc_command.underscore
35
+ define_method method_name do |*args|
36
+ send_command(rpc_command, args)
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,39 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ module Bitcoin
4
+ class HttpConnection < Client
5
+ attr_accessor :host, :port, :uri, :ssl
6
+
7
+ def initialize(host, user:, pass:)
8
+ super()
9
+ uri = URI.parse(host)
10
+ raise ArgumentError unless ['http', 'https'].include? uri.scheme
11
+ @host = uri.host
12
+ @port = uri.port
13
+ @user = user
14
+ @pass = pass
15
+
16
+ @ssl = uri.scheme == 'https'
17
+ if ssl
18
+ @uri = URI("https://#{@host}:#{@port}")
19
+ else
20
+ @uri = URI("http://#{@host}:#{@port}")
21
+ end
22
+ end
23
+
24
+ def send_single(payload)
25
+ http = ::Net::HTTP.new(@host, @port)
26
+ if @ssl
27
+ http.use_ssl = true
28
+ end
29
+ header = {'Content-Type' => 'application/json'}
30
+ request = ::Net::HTTP::Post.new(uri, header)
31
+ request.basic_auth(@user, @pass)
32
+ request.body = payload
33
+ response = http.request(request)
34
+ return response.body
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -4,7 +4,7 @@ module Ethereum
4
4
  attr_accessor :ipcpath
5
5
 
6
6
  def initialize(ipcpath)
7
- super
7
+ super()
8
8
  @ipcpath = ipcpath
9
9
  end
10
10
 
@@ -4,8 +4,8 @@ module Ethereum
4
4
  class HttpConnection < Client
5
5
  attr_accessor :host, :port, :uri, :ssl
6
6
 
7
- def initialize(host, log = false)
8
- super(log)
7
+ def initialize(host)
8
+ super()
9
9
  uri = URI.parse(host)
10
10
  raise ArgumentError unless ['http', 'https'].include? uri.scheme
11
11
  @host = uri.host
@@ -1,3 +1,3 @@
1
1
  module Elchapo
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/elchapo.rb CHANGED
@@ -8,4 +8,7 @@ module Elchapo
8
8
  require 'elchapo/ethereum/client'
9
9
  require 'elchapo/ethereum/connection'
10
10
  require 'elchapo/ethereum/http_connection'
11
+
12
+ require 'elchapo/bitcoin/client'
13
+ require 'elchapo/bitcoin/http_connection'
11
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elchapo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - DilumN
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-22 00:00:00.000000000 Z
11
+ date: 2017-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -95,6 +95,8 @@ files:
95
95
  - bin/setup
96
96
  - elchapo.gemspec
97
97
  - lib/elchapo.rb
98
+ - lib/elchapo/bitcoin/client.rb
99
+ - lib/elchapo/bitcoin/http_connection.rb
98
100
  - lib/elchapo/ethereum/client.rb
99
101
  - lib/elchapo/ethereum/connection.rb
100
102
  - lib/elchapo/ethereum/http_connection.rb