Skip to content

Commit

Permalink
Add to_json Deprecation Warnings
Browse files Browse the repository at this point in the history
Closes #267

Add deprecation warnings on `Bitcoin::Protocol::Tx#to_json(_file)` as well as
to `Bitcoin::Protocol::Block#to_json(_file)`.

This causes the tests to display a lot of warnings and the tests and examples
using these methods must also be removed / revised once they are gone for good.
  • Loading branch information
etscrivner committed Sep 19, 2018
1 parent 48b8897 commit 6952eb5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/bitcoin/protocol/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@ def bip34_block_height(height = nil)
nil
end

# convert to json representation as seen in the block explorer.
# (see also #from_json)
# <b>DEPRECATED:</b> This method will removed in a future release.
def to_json(options = { space: '' }, *_)
warn "[DEPRECATION] Bitcoin::Protocol::Block#to_json is deprecated and will be removed in a future release."
JSON.pretty_generate(to_hash(options), options)
end

# write json representation to a file
# (see also #to_json)
# <b>DEPRECATED:</b> This method will removed in a future release.
def to_json_file(path)
warn "[DEPRECATION] Bitcoin::Protocol::Block#to_json_file is deprecated and will be removed in a future release."
File.open(path, 'wb') { |f| f.print to_json; }
end

Expand Down
7 changes: 4 additions & 3 deletions lib/bitcoin/protocol/tx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,15 @@ def to_hash(options = {})
h
end

# generates rawblock json as seen in the block explorer.
# <b>DEPRECATED:</b> This method will removed in a future release.
def to_json(options = { space: '' }, *_a)
warn "[DEPRECATION] Bitcoin::Protocol::Tx#to_json is deprecated and will be removed in a future release."
JSON.pretty_generate(to_hash(options), options)
end

# write json representation to a file
# (see also #to_json)
# <b>DEPRECATED:</b> This method will removed in a future release.
def to_json_file(path)
warn "[DEPRECATION] Bitcoin::Protocol::Tx#to_json_file is deprecated and will be removed in a future release."
File.open(path, 'wb') { |f| f.print to_json; }
end

Expand Down

0 comments on commit 6952eb5

Please sign in to comment.