Class: Stellar::Account

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keypair, id = nil) ⇒ Account

Returns a new instance of Account.

Parameters:



35
36
37
38
# File 'lib/stellar/account.rb', line 35

def initialize(keypair, id = nil)
  @keypair = keypair
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



31
32
33
# File 'lib/stellar/account.rb', line 31

def id
  @id
end

#keypairObject (readonly)

Returns the value of attribute keypair.



31
32
33
# File 'lib/stellar/account.rb', line 31

def keypair
  @keypair
end

Class Method Details

.from_address(address) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/stellar/account.rb', line 15

def self.from_address(address)
  muxed_xdr = Util::StrKey.(address)

  if muxed_xdr.ed25519
    new(KeyPair.from_public_key(muxed_xdr.ed25519))
  else
    muxed_xdr = muxed_xdr.med25519!
    new(KeyPair.from_public_key(muxed_xdr.ed25519), muxed_xdr.id)
  end
end

.from_seed(seed) ⇒ Object



10
11
12
13
# File 'lib/stellar/account.rb', line 10

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

.masterObject



26
27
28
29
# File 'lib/stellar/account.rb', line 26

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

.randomObject



5
6
7
8
# File 'lib/stellar/account.rb', line 5

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

Instance Method Details

#address(force_account_id: true) ⇒ Object



49
50
51
52
53
# File 'lib/stellar/account.rb', line 49

def address(force_account_id: true)
  return keypair.address if 

  Util::StrKey.check_encode(:muxed, keypair.raw_public_key + [id].pack("Q>"))
end

#base_accountObject



40
41
42
# File 'lib/stellar/account.rb', line 40

def 
  Stellar::MuxedAccount.ed25519(keypair.raw_public_key)
end

#muxed_accountObject



44
45
46
47
# File 'lib/stellar/account.rb', line 44

def 
  return  unless id
  Stellar::MuxedAccount.med25519(ed25519: keypair.raw_public_key, id: id)
end

#to_keypairObject



55
56
57
# File 'lib/stellar/account.rb', line 55

def to_keypair
  keypair
end