class StraightServer::GatewayOnConfig

Uses a config file to load attributes and a special _last_keychain_id file to store last_keychain_id

Attributes

active[RW]

This affects whether it is possible to create a new order with the gateway. If it's set to false, then it won't be possible to create a new order, but it will keep checking on the existing ones.

callback_url[RW]

A url to which the gateway will send an HTTP request with the status of the order data (in JSON) when the status of the order is changed. The response should always be 200, otherwise the gateway will awesome something went wrong and will keep trying to send requests to this url according to a specific shedule.

check_signature[RW]

If set to false, doesn't require an unique id of the order along with the signed md5 hash of that id + secret to be passed into the create_order method.

exchange_rate_adapter_names[RW]
id[RW]

This will be assigned the number that is the order in which this gateway follows in the config file.

last_keychain_id[RW]

This is used to generate the next address to accept payments

orders_expiration_period[RW]
secret[RW]

This is the key that allows users (those, who use the gateway, online stores, for instance) to connect and create orders. It is not used directly, but is mixed with all the params being sent and a MD5 hash is calculted. Then the gateway checks whether the MD5 hash is correct.

test_last_keychain_id[RW]

This is used to generate the next address to accept payments

Public Class Methods

find_by_hashed_id(s) click to toggle source
# File lib/straight-server/gateway.rb, line 516
def self.find_by_hashed_id(s)
  self.find_by_id(s)
end
find_by_id(id) click to toggle source

This method is a replacement for the Sequel's model one used in DB version of the gateway and it finds gateways using the index of @@gateways Array.

# File lib/straight-server/gateway.rb, line 572
def self.find_by_id(id)
  @@gateways[id.to_i-1]
end
new() click to toggle source
# File lib/straight-server/gateway.rb, line 520
def initialize
  initialize_callbacks
  initialize_exchange_rate_adapters
  initialize_blockchain_adapters
  initialize_status_check_schedule
  initialize_network
end

Public Instance Methods

address_provider() click to toggle source
# File lib/straight-server/gateway.rb, line 566
def address_provider
  Kernel.const_get("Straight::AddressProvider::#{address_provider_type}").new(self)
end
address_provider_type() click to toggle source
# File lib/straight-server/gateway.rb, line 562
def address_provider_type
  @address_provider ? @address_provider.to_sym : :Bip32
end
build_keychain_path() click to toggle source
# File lib/straight-server/gateway.rb, line 557
def build_keychain_path
  filename = self.test_mode ? "/#{name}_test_last_keychain_id" : "/#{name}_last_keychain_id"
  StraightServer::Initializer::ConfigDir.path + filename
end
load_last_keychain_id!() click to toggle source

Loads last_keychain_id from a file in the .straight dir. If the file doesn't exist, we create it. Later, whenever an attribute is updated, we save it to the file.

# File lib/straight-server/gateway.rb, line 542
def load_last_keychain_id!
  @last_keychain_id_file ||= build_keychain_path
  if File.exists?(@last_keychain_id_file)
    self.last_keychain_id = File.read(@last_keychain_id_file).to_i
  else
    self.last_keychain_id = 0
    save
  end
end
save() click to toggle source

Because this is a config based gateway, we only save last_keychain_id and nothing more.

# File lib/straight-server/gateway.rb, line 535
def save
  save_last_keychain_id!
end
save_last_keychain_id!() click to toggle source
# File lib/straight-server/gateway.rb, line 552
def save_last_keychain_id!
  @last_keychain_id_file ||= build_keychain_path
  File.open(@last_keychain_id_file, 'w') {|f| f.write(last_keychain_id) }
end
validate_config() click to toggle source
# File lib/straight-server/gateway.rb, line 528
def validate_config
  raise NoPubkey if pubkey_missing?
  raise NoTestPubkey if test_pubkey_missing?
end