lib/zold/patch.rb in zold-0.31.5 vs lib/zold/patch.rb in zold-0.31.6
- old
+ new
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-# Copyright (c) 2018-2023 Zerocracy, Inc.
+# Copyright (c) 2018-2023 Zerocracy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -49,11 +49,11 @@
# legacy negative transactions to the patch before everything else. They
# are not supposed to be disputed, ever.
def legacy(wallet, hours: 24)
raise 'You can\'t add legacy to a non-empty patch' unless @id.nil?
wallet.txns.each do |txn|
- @txns << txn if txn.amount.negative? && txn.date < Time.now - hours * 60 * 60
+ @txns << txn if txn.amount.negative? && txn.date < Time.now - (hours * 60 * 60)
end
end
# Joins a new wallet on top of existing patch. An attempt is made to
# copy as many transactions from the newcoming wallet to the existing
@@ -168,22 +168,21 @@
end
@txns << txn
added += 1
next unless txn.amount.negative?
File.open(ledger, 'a') do |f|
- f.puts(
- [
- Time.now.utc.iso8601,
- txn.id,
- txn.date.utc.iso8601,
- wallet.id,
- txn.bnf,
- txn.amount.to_i * -1,
- txn.prefix,
- txn.details
- ].map(&:to_s).join(';') + "\n"
- )
+ msg = [
+ Time.now.utc.iso8601,
+ txn.id,
+ txn.date.utc.iso8601,
+ wallet.id,
+ txn.bnf,
+ txn.amount.to_i * -1,
+ txn.prefix,
+ txn.details
+ ].map(&:to_s).join(';')
+ f.puts("#{msg}\n")
end
end
end
def empty?
@@ -212,10 +211,10 @@
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))
+ File.write(file, File.read(f.path))
end
end
before != wallet.digest
end
end