lib/zold/patch.rb
def save(file, overwrite: false, allow_negative_balance: false)
      raise 'You have to join at least one wallet in' if empty?
      before = ''
      wallet = Wallet.new(file)
      before = wallet.digest if wallet.exists?
      Tempfile.open([@id, Wallet::EXT]) do |f|
        temp = Wallet.new(f.path)
        temp.init(@id, @key, overwrite: overwrite, network: @network)
        File.open(f.path, 'a') do |t|
          @txns.each do |txn|
            next if Id::BANNED.include?(txn.bnf.to_s)
            t.print "#{txn}\n"
          end
        end
        temp.refurbish
        if temp.balance.negative? && !temp.id.root? && !allow_negative_balance
          if wallet.exists?
            @log.info("The balance is negative, won't merge #{temp.mnemo} on top of #{wallet.mnemo}")
          else
            @log.info("The balance is negative, won't save #{temp.mnemo}")
          end
        else
          FileUtils.mkdir_p(File.dirname(file))
          IO.write(file, IO.read(f.path))
        end
      end
      before != wallet.digest
    end
def save(file, overwrite: false, allow_negative_balance: false)
      raise 'You have to join at least one wallet in' if empty?
      before = ''
      wallet = Wallet.new(file)
      before = wallet.digest if wallet.exists?
      Tempfile.open([@id, Wallet::EXT]) do |f|
        temp = Wallet.new(f.path)
        temp.init(@id, @key, overwrite: overwrite, network: @network)
        File.open(f.path, 'a') do |t|
          @txns.each do |txn|
            next if Id::BANNED.include?(txn.bnf.to_s)
            t.print "#{txn}\n"
          end
        end
        temp.refurbish
        if temp.balance.negative? && !temp.id.root? && !allow_negative_balance
          if wallet.exists?
            @log.info("The balance is negative, won't merge #{temp.mnemo} on top of #{wallet.mnemo}")
          else
            @log.info("The balance is negative, won't save #{temp.mnemo}")
          end
        else
          FileUtils.mkdir_p(File.dirname(file))
          IO.write(file, IO.read(f.path))
        end
      end
      before != wallet.digest
    end
def save ( file , overwrite : false , allow_negative_balance : false ) raise 'You have to join at least one wallet in' if empty? before = '' wallet = Wallet . new ( file ) before = wallet . digest if wallet . exists? Tempfile . open ( [ @id , Wallet :: EXT ] ) do | f | temp = Wallet . new ( f . path ) temp . init ( @id , @key , overwrite : overwrite , network : @network ) File . open ( f . path , 'a' ) do | t | @txns . each do | txn | next if Id :: BANNED . include? ( txn . bnf . to_s ) t . print "#{txn}\n" end end temp . refurbish if temp . balance . negative? && ! temp . id . root? && ! allow_negative_balance if wallet . exists? @log . info ( "The balance is negative, won't merge #{temp.mnemo} on top of #{wallet.mnemo}" ) else @log . info ( "The balance is negative, won't save #{temp.mnemo}" ) end else FileUtils . mkdir_p ( File . dirname ( file ) ) IO . write ( file , IO . read ( f . path ) ) end end before != wallet . digest end
Returns TRUE if the file was actually modified
Returns TRUE if the file was actually modified