indium 0.0.8 → 0.0.9

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 +5 -5
  2. data/lib/indium.rb +64 -15
  3. metadata +39 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ec8d3d69b208a36c643f1924fbd3fa8e9df3ac63
4
- data.tar.gz: 9c56cac2d4082dd9547d4615abbbc9c415642dec
2
+ SHA256:
3
+ metadata.gz: 879c7fd8a25a82458c27c6799589b91b7d27c517ad2bfc1be5894bddc3ff9db9
4
+ data.tar.gz: 95a0def23edda27521b15e5d036a4fbb43d5fdc6a98f0aa1c2fe802bf54d0c0c
5
5
  SHA512:
6
- metadata.gz: fc95737dd7e93fedf6b689a2c0686279f9dd144ee88aae5338a7247867da172953d89564b1fb4df2c0de796f54416a904be336aa15f287c9b65236dc4213a0b2
7
- data.tar.gz: 22e51886cfd94c98939d5c777b74c129b4bb329581e4a101fa2d58cd6c7ee4c71082be36839bbad9f4d33699d9c76b65a5fb3abd2bd8a6417d9facbc6fb49a8d
6
+ metadata.gz: eddcbaa0e50bdb03600838f430d30f9c7af9defc2f2425e4c6cf3964bf292dd8004f39b25a1d7503bf1d138494519d3bada570b2e54ceced08a280ffd2a3ad2b
7
+ data.tar.gz: 9a29700f3e06596c99e5eb67aef0419ebb2dfb52d84131b5f4df7dd28f76384474c548bff2560ecde48d5177fc9acd608b2f4567e083c40d87958551f1dbbf1d
data/lib/indium.rb CHANGED
@@ -1,27 +1,76 @@
1
- require 'bigchaindb'
1
+ require 'stellar-sdk'
2
+ require 'httparty'
3
+ require 'json'
2
4
 
3
5
  class Indium
4
- attr_reader :asset_id
5
- attr_reader :ipdb
6
+ attr_reader :mode
6
7
 
7
- def initialize(asset_id, ipdb)
8
- @asset_id = asset_id
9
- @ipdb = ipdb
8
+ def initialize(mode)
9
+ @issuer_address = "GB6TBT62K4NG2MIHMGGRZPIW2GI62T56RCWHWHKCY2BIORDPQQ5LCPVR"
10
+ @issuer = Stellar::KeyPair.from_address(@issuer_address)
11
+ @asset = Stellar::Asset.alphanum12("INDIUM", @issuer)
12
+ @mode = mode # test or prod
13
+ if mode == 'test'
14
+ @client = Stellar::Client.default_testnet
15
+ @horizon = "https://horizon-testnet.stellar.org"
16
+ elsif mode == 'prod'
17
+ @client = Stellar::Client.default
18
+ @horizon = "https://horizon.stellar.org"
19
+ end
10
20
  end
11
21
 
12
- def balance(pubkey)
13
- Bdb.balance_asset(@ipdb, pubkey, @asset_id)
22
+ def balances(pubkey)
23
+ resp = HTTParty.get(@horizon + "/accounts/" + pubkey)
24
+ JSON.parse(resp.body)["balances"].inject({}) do |f,h|
25
+ f.merge({ (h["asset_code"] || h["asset_type"]) => h["balance"] })
26
+ end
14
27
  end
15
28
 
16
- def transfer(receiver_pubkeys_amounts, sender_pubkey, sender_privkey, data)
17
- Bdb.transfer_asset(@ipdb, receiver_pubkeys_amounts, sender_pubkey, sender_privkey, unspent_outputs = nil, @asset_id, data)
29
+ def balances_direct(pubkey)
30
+ account = Stellar::Account.from_address(pubkey)
31
+ @client.account_info(account).balances.inject({}) do |f,h|
32
+ f.merge({ (h["asset_code"] || h["asset_type"]) => h["balance"] })
33
+ end
18
34
  end
19
35
 
20
- def self.test(app_id = nil, app_key = nil)
21
- self.new("4bf41c7d08bef68181fd378308691cc2ce65661804d317e2db72b9c0d4f1d73f", {"url" => "https://test.ipdb.io/api/v1", "app_id" => app_id, "app_key" => app_key})
36
+ def transfer_native(amount, sender_privkey, receiver_pubkey)
37
+ sender = Stellar::Account.from_seed(sender_privkey)
38
+ recipient = Stellar::Account.from_address(receiver_pubkey)
39
+
40
+ @client.send_payment({
41
+ from: sender,
42
+ to: recipient,
43
+ amount: Stellar::Amount.new(amount)
44
+ })
45
+ end
46
+
47
+ def transfer(amount, sender_privkey, receiver_pubkey)
48
+ sender = Stellar::Account.from_seed(sender_privkey)
49
+ recipient = Stellar::Account.from_address(receiver_pubkey)
50
+
51
+ @client.send_payment({
52
+ from: sender,
53
+ to: recipient,
54
+ amount: Stellar::Amount.new(amount, @asset)
55
+ })
56
+ end
57
+
58
+ def create_indium_account(privkey)
59
+ account = Stellar::Account.random
60
+ transfer_native(4, privkey, account.address) # Activate the account
61
+
62
+ @client.trust({
63
+ account: account,
64
+ asset: @asset
65
+ }) # create a trustline for Indium token
66
+ return [account.address, account.keypair.seed]
67
+ end
68
+
69
+ def self.test
70
+ self.new('test')
22
71
  end
23
72
 
24
- def self.prod(app_id = nil, app_key = nil)
25
- self.new("c49b21534ee715ad844bc178a6a578d63a4971d1f52ad783e18a6a2f27710e68", {"url" => "https://test.ipdb.io/api/v1", "app_id" => app_id, "app_key" => app_key})
73
+ def self.prod
74
+ self.new('prod')
26
75
  end
27
- end
76
+ end
metadata CHANGED
@@ -1,30 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nilesh Trivedi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-27 00:00:00.000000000 Z
11
+ date: 2018-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bigchaindb
14
+ name: stellar-sdk
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.8
19
+ version: '0.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.8
27
- description: Library for querying/posting Indium transactions on IPDB
26
+ version: '0.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.15'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
55
+ description: Library for querying/posting Indium transactions from Stellar test/main
56
+ network
28
57
  email: github@nileshtrivedi.com
29
58
  executables: []
30
59
  extensions: []
@@ -51,8 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
80
  version: '0'
52
81
  requirements: []
53
82
  rubyforge_project:
54
- rubygems_version: 2.6.11
83
+ rubygems_version: 2.7.3
55
84
  signing_key:
56
85
  specification_version: 4
57
- summary: Indium - asset on IPDB
86
+ summary: Indium
58
87
  test_files: []