class Zold::SafeEntrance
The safe entrance
Public Class Methods
new(entrance, network: 'test')
click to toggle source
# File lib/zold/node/safe_entrance.rb, line 41 def initialize(entrance, network: 'test') raise 'Entrance can\'t be nil' if entrance.nil? @entrance = entrance raise 'Network can\'t be nil' if network.nil? @network = network end
Public Instance Methods
push(id, body)
click to toggle source
Returns a list of modifed wallets (as Zold::Id
)
# File lib/zold/node/safe_entrance.rb, line 58 def push(id, body) raise 'Id can\'t be nil' if id.nil? raise 'Id must be of type Id' unless id.is_a?(Id) raise 'Body can\'t be nil' if body.nil? Tempfile.open(['', Wallet::EXT]) do |f| IO.write(f, body) wallet = Wallet.new(f.path) wallet.refurbish unless wallet.protocol == Zold::PROTOCOL raise SoftError, "Protocol mismatch, #{wallet.id} is in '#{wallet.protocol}', we are in '#{Zold::PROTOCOL}'" end unless wallet.network == @network raise SoftError, "Network name mismatch, #{wallet.id} is in '#{wallet.network}', we are in '#{@network}'" end balance = wallet.balance if balance.negative? && !wallet.root? raise SoftError, "The balance #{balance} of #{wallet.id} is negative and it's not a root wallet" end tax = Tax.new(wallet) if tax.in_debt? raise SoftError, "Taxes are not paid, can't accept the wallet #{wallet.mnemo}; the debt is #{tax.debt} \ (#{tax.debt.to_i} zents); formula ingredients are #{tax.to_text}" end @entrance.push(id, body) end end
start() { |self| ... }
click to toggle source
# File lib/zold/node/safe_entrance.rb, line 48 def start raise 'Block must be given to start()' unless block_given? @entrance.start { yield(self) } end
to_json()
click to toggle source
# File lib/zold/node/safe_entrance.rb, line 53 def to_json @entrance.to_json end