lib/zold/patch.rb in zold-0.2 vs lib/zold/patch.rb in zold-0.3

- old
+ new

@@ -16,11 +16,11 @@ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -require_relative 'wallet.rb' +require_relative 'wallet' # Patch. # # Author:: Yegor Bugayenko (yegor256@gmail.com) # Copyright:: Copyright (c) 2018 Yegor Bugayenko @@ -33,18 +33,18 @@ @key = wallet.key @txns = wallet.txns end def join(wallet) - negative = @txns.select { |t| t[:amount].negative? } - max = negative.empty? ? 0 : negative.max_by { |t| t[:id] }[:id] + negative = @txns.select { |t| t.amount.negative? } + max = negative.empty? ? 0 : negative.max_by(&:id).id wallet.txns.each do |txn| - next if @txns.find { |t| t[:id] == txn[:id] && t[:bnf] == txn[:bnf] } + next if @txns.find { |t| t == txn } next if - txn[:amount].negative? && !@txns.empty? && - (txn[:id] <= max || - @txns.find { |t| t[:id] == txn[:id] } || - @txns.map { |t| t[:amount] }.inject(&:+) < txn[:amount]) + txn.amount.negative? && !@txns.empty? && + (txn.id <= max || + @txns.find { |t| t.id == txn.id } || + @txns.map(&:amount).inject(&:+) < txn.amount) next unless Signature.new.valid?(@key, txn) @txns << txn end end