Class: Zold::Patch
- Inherits:
-
Object
- Object
- Zold::Patch
- Defined in:
- lib/zold/patch.rb
Overview
A patch
Instance Method Summary collapse
- #join(wallet) ⇒ Object
-
#save(file, overwrite: false) ⇒ Object
Returns TRUE if the file was actually modified.
- #start(wallet) ⇒ Object
Instance Method Details
#join(wallet) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/zold/patch.rb', line 39 def join(wallet) 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 == txn } next if 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, wallet.id, txn) @txns << txn end end |
#save(file, overwrite: false) ⇒ Object
Returns TRUE if the file was actually modified
55 56 57 58 59 60 61 62 63 |
# File 'lib/zold/patch.rb', line 55 def save(file, overwrite: false) before = '' before = File.read(file) if File.exist?(file) wallet = Wallet.new(file) wallet.init(@id, @key, overwrite: overwrite, network: @network) @txns.each { |t| wallet.add(t) } after = File.read(file) before != after end |
#start(wallet) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/zold/patch.rb', line 32 def start(wallet) @id = wallet.id @key = wallet.key @txns = wallet.txns @network = wallet.network end |