indium 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/indium.rb +64 -15
- metadata +39 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 879c7fd8a25a82458c27c6799589b91b7d27c517ad2bfc1be5894bddc3ff9db9
|
4
|
+
data.tar.gz: 95a0def23edda27521b15e5d036a4fbb43d5fdc6a98f0aa1c2fe802bf54d0c0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eddcbaa0e50bdb03600838f430d30f9c7af9defc2f2425e4c6cf3964bf292dd8004f39b25a1d7503bf1d138494519d3bada570b2e54ceced08a280ffd2a3ad2b
|
7
|
+
data.tar.gz: 9a29700f3e06596c99e5eb67aef0419ebb2dfb52d84131b5f4df7dd28f76384474c548bff2560ecde48d5177fc9acd608b2f4567e083c40d87958551f1dbbf1d
|
data/lib/indium.rb
CHANGED
@@ -1,27 +1,76 @@
|
|
1
|
-
require '
|
1
|
+
require 'stellar-sdk'
|
2
|
+
require 'httparty'
|
3
|
+
require 'json'
|
2
4
|
|
3
5
|
class Indium
|
4
|
-
attr_reader :
|
5
|
-
attr_reader :ipdb
|
6
|
+
attr_reader :mode
|
6
7
|
|
7
|
-
def initialize(
|
8
|
-
@
|
9
|
-
@
|
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
|
13
|
-
|
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
|
17
|
-
|
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
|
21
|
-
|
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
|
25
|
-
self.new(
|
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.
|
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:
|
11
|
+
date: 2018-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
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.
|
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.
|
27
|
-
|
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.
|
83
|
+
rubygems_version: 2.7.3
|
55
84
|
signing_key:
|
56
85
|
specification_version: 4
|
57
|
-
summary: Indium
|
86
|
+
summary: Indium
|
58
87
|
test_files: []
|