Class: Stellar::Account
- Inherits:
-
Object
- Object
- Stellar::Account
- Defined in:
- lib/stellar/account.rb
Instance Attribute Summary collapse
-
#keypair ⇒ Object
readonly
Returns the value of attribute keypair.
Class Method Summary collapse
- .from_address(address) ⇒ Object
- .from_seed(seed) ⇒ Object
- .lookup(federated_name) ⇒ Object
- .master ⇒ Object
- .random ⇒ Object
Instance Method Summary collapse
-
#initialize(keypair) ⇒ Account
constructor
A new instance of Account.
- #to_keypair ⇒ Object
Constructor Details
#initialize(keypair) ⇒ Account
Returns a new instance of Account.
66 67 68 |
# File 'lib/stellar/account.rb', line 66 def initialize(keypair) @keypair = keypair end |
Instance Attribute Details
#keypair ⇒ Object (readonly)
Returns the value of attribute keypair.
63 64 65 |
# File 'lib/stellar/account.rb', line 63 def keypair @keypair end |
Class Method Details
.from_address(address) ⇒ Object
20 21 22 23 |
# File 'lib/stellar/account.rb', line 20 def self.from_address(address) keypair = Stellar::KeyPair.from_address(address) new(keypair) end |
.from_seed(seed) ⇒ Object
15 16 17 18 |
# File 'lib/stellar/account.rb', line 15 def self.from_seed(seed) keypair = Stellar::KeyPair.from_seed(seed) new(keypair) end |
.lookup(federated_name) ⇒ Object
25 26 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 |
# File 'lib/stellar/account.rb', line 25 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&.match?(URI::DEFAULT_PARSER.make_regexp) raise InvalidFederationURL.new("Invalid Federation Server URL") end lookup_req = Faraday.new(fed_server_url).get { |req| req.params[:q] = federated_name req.params[:type] = "name" } unless lookup_req.status == 200 raise AccountNotFound.new("Account not found") end JSON.parse(lookup_req.body)["account_id"] end |
.master ⇒ Object
58 59 60 61 |
# File 'lib/stellar/account.rb', line 58 def self.master keypair = Stellar::KeyPair.from_raw_seed("allmylifemyhearthasbeensearching") new(keypair) end |
.random ⇒ Object
10 11 12 13 |
# File 'lib/stellar/account.rb', line 10 def self.random keypair = Stellar::KeyPair.random new(keypair) end |
Instance Method Details
#to_keypair ⇒ Object
70 71 72 |
# File 'lib/stellar/account.rb', line 70 def to_keypair keypair end |