Sha256: 325bb5c738e3ce01100abb87103904dbceeb044b6c6804da2a5230a7fbdc2512

Contents?: true

Size: 1.62 KB

Versions: 18

Compression:

Stored size: 1.62 KB

Contents

module Stellar
  # Provides a container for well-known network passphrases, such as the main network and SDF test network
  module Networks

    PUBLIC  = "Public Global Stellar Network ; September 2015"
    TESTNET = "Test SDF Network ; September 2015"

  end

  # Configures the default stellar network passphrase for the current process.  Unless otherwise
  # specified in a method that needs the passphrase, this value will be used.
  #
  # NOTE:  This method is not thread-safe.  It's best to just call this at startup once and use the other
  #        methods of specifying a network if you need two threads in the same process to communicate with
  #        different networks
  #
  # @see Stellar.default_network
  # @see Stellar.on_network
  def self.default_network=(passphrase)
    @default_network = passphrase
  end

  # Returns the passphrase for the currently-configured network, as set by Stellar.default_network
  # or Stellar.on_network
  def self.current_network
    Thread.current["stellar_network_passphrase"] || 
    @default_network || 
    Stellar::Networks::TESTNET
  end

  # Returns the id for the currently configured network, suitable for use in generating
  # a signature base string or making the root account's keypair.
  def self.current_network_id
    Digest::SHA256.digest(self.current_network) 
  end

  # Executes the provided block in the context of the provided network.
  def self.on_network(passphrase, &block)
    old = Thread.current["stellar_network_passphrase"]
    Thread.current["stellar_network_passphrase"] = passphrase
    block.call
  ensure
    Thread.current["stellar_network_passphrase"] = old
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
stellar-base-0.22.0 lib/stellar/networks.rb
stellar-base-0.21.0 lib/stellar/networks.rb
stellar-base-0.20.0 lib/stellar/networks.rb
stellar-base-0.19.0 lib/stellar/networks.rb
stellar-base-0.18.0 lib/stellar/networks.rb
stellar-base-0.17.0 lib/stellar/networks.rb
stellar-base-0.16.0 lib/stellar/networks.rb
stellar-base-0.15.0 lib/stellar/networks.rb
stellar-base-0.14.0 lib/stellar/networks.rb
stellar-base-0.13.0 lib/stellar/networks.rb
stellar-base-0.12.0 lib/stellar/networks.rb
stellar-base-0.11.0 lib/stellar/networks.rb
auction-ruby-base-0.1.3 lib/stellar/networks.rb
auction-ruby-base-0.1.2 lib/stellar/networks.rb
auction-ruby-base-0.1.1 lib/stellar/networks.rb
stellar-base-0.10.0 lib/stellar/networks.rb
stellar-base-0.9.0 lib/stellar/networks.rb
stellar-base-0.8.0 lib/stellar/networks.rb