Class: Zold::SafeEntrance
- Inherits:
-
Object
- Object
- Zold::SafeEntrance
- Defined in:
- lib/zold/node/safe_entrance.rb
Overview
The safe entrance
Instance Method Summary collapse
-
#initialize(entrance, network: 'test') ⇒ SafeEntrance
constructor
A new instance of SafeEntrance.
-
#push(id, body) ⇒ Object
Returns a list of modifed wallets (as Zold::Id).
- #start ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(entrance, network: 'test') ⇒ SafeEntrance
Returns a new instance of SafeEntrance.
41 42 43 44 45 46 |
# 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 |
Instance Method Details
#push(id, body) ⇒ Object
Returns a list of modifed wallets (as Zold::Id)
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# 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 ⇒ Object
48 49 50 51 |
# 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 ⇒ Object
53 54 55 |
# File 'lib/zold/node/safe_entrance.rb', line 53 def to_json @entrance.to_json end |