indium 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/indium.rb +27 -10
  3. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d206eca8e28130435ae97f8aa24919f803dbe7478893c6055e6aa9703f1b8ba
4
- data.tar.gz: 7327e437901999fd189bd8b6b7a533172583edf5beff8de0018a150c03a41cb8
3
+ metadata.gz: be2e0812d952ca29102fdd6a7330505392d48c279766d8b51ca0aad4c0f83057
4
+ data.tar.gz: 9d91ad6a6091e6453387c605142baa1523d7c0226df5af4fd8982096b6248ef7
5
5
  SHA512:
6
- metadata.gz: b5249e74030ae9f7adb5d14a00d0df5663e3e9d1fc668f9470f769637e75463380faea971e7634697394d3a3e8d4b934bbeefc3430ff28c9c669a2f52288693e
7
- data.tar.gz: 972bc6df1dd5cb3ca0a1d1229841f9fa2e2db895645d671b332cfa66bf25fd036dde90205cbbfe50a917fddffc8a25543a462033cca35a5357a2488265fa894d
6
+ metadata.gz: defb7020b77a0090b0cb119d2e07137f5d69aeed3294411f31f37fde5631fefb7d36ef502016c9ca874d6e0b84a497c0e005a822ed476ef482c9a424b5efe77b
7
+ data.tar.gz: dc4989038646a0a98206f35ec7808a5736d674217458c4c5f2bed111115c564bd382326e45f0dcd7132755faa0d7214108e820add38334f35d78040e7325994d
data/lib/indium.rb CHANGED
@@ -1,44 +1,61 @@
1
1
  require 'ethereum.rb'
2
2
  require 'eth'
3
+ require 'httpclient'
3
4
 
4
5
  class Indium
5
6
  attr_reader :client
6
7
 
7
8
  def initialize(node_url, chain_id)
9
+ @node_url = node_url
10
+ @chain_id = chain_id
8
11
  Eth.configure do |config|
9
12
  config.chain_id = chain_id # nil by default, meaning valid on any chain
10
13
  end
11
- @client = Ethereum::HttpClient.new(node_url)
14
+ @client = Ethereum::HttpClient.new(node_url, proxy = nil, log = true) # log to /tmp/ethereum_ruby_http.log
12
15
  end
13
16
 
14
17
  def balance(pubkey)
15
18
  @client.get_balance(pubkey)
16
19
  end
17
20
 
18
- def transfer(sender_privkey, receiver_pubkey, amount, hex_data, gas_limit = 21_000, gas_price = 3_141_592)
19
- @client.gas_price = gas_price
20
- @client.gas_limit = gas_limit
21
- @client.transfer(sender_privkey, receiver_pubkey, amount) # transfer_and_wait ?
21
+ def get_receipt(tx_hash)
22
+ @client.eth_get_transaction_receipt(tx_hash)
22
23
  end
23
24
 
24
- def create_indium_account
25
+ def transfer(signtxn_url, sender_privkey, receiver_pubkey, amount, hex_data = "", gas_limit = 21_000, gas_price = 3_141_592)
26
+ http = HTTPClient.new
27
+ params = {
28
+ "rpc" => @node_url,
29
+ "receiver" => receiver_pubkey,
30
+ "sender" => Eth::Key.new(priv: sender_privkey).address,
31
+ "privkey" => sender_privkey,
32
+ "amount" => amount,
33
+ "gaslimit" => gas_limit,
34
+ "gasprice" => gas_price,
35
+ "chain" => @chain_id,
36
+ "data" => hex_data
37
+ }
38
+ return http.post(signtxn_url, params)
39
+ end
40
+
41
+ def create_keypair
25
42
  kp = Eth::Key.new
26
43
  return kp.address, kp.private_hex
27
44
  end
28
45
 
29
- def self.local(chain_id = 17622)
46
+ def self.local(chain_id = 246)
30
47
  self.new('http://localhost:8545',chain_id)
31
48
  end
32
49
 
33
- def self.test(chain_id = 17622)
50
+ def self.test(chain_id = 246)
34
51
  self.new('http://testrpcnode.indium.network:8545',chain_id)
35
52
  end
36
53
 
37
- def self.prod(chain_id = 17622)
54
+ def self.prod(chain_id = 246)
38
55
  self.new('http://rpcnode.indium.network:8545',chain_id)
39
56
  end
40
57
 
41
- def self.custom(url, chain_id = 17622)
58
+ def self.custom(url, chain_id = 246)
42
59
  self.new(url, chain_id)
43
60
  end
44
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nilesh Trivedi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-04 00:00:00.000000000 Z
11
+ date: 2018-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eth
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httpclient
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.8'
41
55
  description: Library for querying/posting transactions from the Indium network
42
56
  email: github@nileshtrivedi.com
43
57
  executables: []