Class: Stellar::Account

Inherits:
Object
  • Object
show all
Includes:
Contracts
Defined in:
lib/stellar/account.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keypair) ⇒ Account

Returns a new instance of Account.



68
69
70
# File 'lib/stellar/account.rb', line 68

def initialize(keypair)
  @keypair = keypair
end

Instance Attribute Details

#keypairObject (readonly)

Returns the value of attribute keypair.



65
66
67
# File 'lib/stellar/account.rb', line 65

def keypair
  @keypair
end

Class Method Details

.from_address(address) ⇒ Object



22
23
24
25
# File 'lib/stellar/account.rb', line 22

def self.from_address(address)
  keypair = Stellar::KeyPair.from_address(address)
  new(keypair)
end

.from_seed(seed) ⇒ Object



17
18
19
20
# File 'lib/stellar/account.rb', line 17

def self.from_seed(seed)
  keypair = Stellar::KeyPair.from_seed(seed)
  new(keypair)
end

.lookup(federated_name) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/stellar/account.rb', line 27

def self.lookup(federated_name)
  _, domain = federated_name.split('*')
  if domain.nil?
    raise InvalidFederationAddress.new
  end

  domain_req = Faraday.new("https://#{domain}/.well-known/stellar.toml").get

  unless domain_req.status == 200
    raise InvalidStellarDomain.new('Domain does not contain stellar.toml file')
  end
  
  fed_server_url = TomlRB.parse(domain_req.body)["FEDERATION_SERVER"]
  if fed_server_url.nil?
    raise InvalidStellarTOML.new('Invalid Stellar TOML file')
  end

  unless fed_server_url =~ URI::regexp
    raise InvalidFederationURL.new('Invalid Federation Server URL')
  end

  lookup_req = Faraday.new(fed_server_url).get do |req|
    req.params[:q] = federated_name
    req.params[:type] = 'name'
  end

  unless lookup_req.status == 200
    raise AccountNotFound.new('Account not found')
  end

  JSON.parse(lookup_req.body)["account_id"]
end

.masterObject



60
61
62
63
# File 'lib/stellar/account.rb', line 60

def self.master
  keypair = Stellar::KeyPair.from_raw_seed("allmylifemyhearthasbeensearching")
  new(keypair)
end

.randomObject



12
13
14
15
# File 'lib/stellar/account.rb', line 12

def self.random
  keypair = Stellar::KeyPair.random
  new(keypair)
end