Class: BTC::ScriptVersion
- Inherits:
-
Object
- Object
- BTC::ScriptVersion
- Defined in:
- lib/btcruby/script/script_version.rb
Constant Summary collapse
- VERSION_DEFAULT =
0- VERSION_P2SH =
1
Instance Attribute Summary collapse
-
#sighash_version ⇒ Object
readonly
Returns a matching signature hash version for the given script version.
-
#version ⇒ Object
readonly
binary string containing the version.
Instance Method Summary collapse
- #default? ⇒ Boolean
-
#initialize(version) ⇒ ScriptVersion
constructor
A new instance of ScriptVersion.
-
#known? ⇒ Boolean
Returns true if version is known.
- #name ⇒ Object
- #p2sh? ⇒ Boolean
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(version) ⇒ ScriptVersion
Returns a new instance of ScriptVersion.
9 10 11 |
# File 'lib/btcruby/script/script_version.rb', line 9 def initialize(version) @version = version end |
Instance Attribute Details
#sighash_version ⇒ Object (readonly)
Returns a matching signature hash version for the given script version. All currently known script versions use sighash version 1.
15 16 17 |
# File 'lib/btcruby/script/script_version.rb', line 15 def sighash_version @sighash_version end |
#version ⇒ Object (readonly)
binary string containing the version
6 7 8 |
# File 'lib/btcruby/script/script_version.rb', line 6 def version @version end |
Instance Method Details
#default? ⇒ Boolean
26 27 28 |
# File 'lib/btcruby/script/script_version.rb', line 26 def default? @version == VERSION_DEFAULT end |
#known? ⇒ Boolean
Returns true if version is known. Unknown versions are supported too, but scripts are not even parsed and interpreted as “anyone can spend”.
21 22 23 24 |
# File 'lib/btcruby/script/script_version.rb', line 21 def known? default? || p2sh? end |
#name ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/btcruby/script/script_version.rb', line 34 def name case version when VERSION_DEFAULT "Default script" when VERSION_P2SH "P2SH v1" else "Unknown script version" end end |
#p2sh? ⇒ Boolean
30 31 32 |
# File 'lib/btcruby/script/script_version.rb', line 30 def p2sh? @version == VERSION_P2SH end |
#to_i ⇒ Object
45 46 47 |
# File 'lib/btcruby/script/script_version.rb', line 45 def to_i @version end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/btcruby/script/script_version.rb', line 49 def to_s "v#{@version} (#{name})" end |