Class: Bitcoin::ValidationState

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoin/validation.rb

Constant Summary collapse

MODE =
{valid: 0, invlid: 1, error: 2}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeValidationState

Returns a new instance of ValidationState.



85
86
87
88
89
90
# File 'lib/bitcoin/validation.rb', line 85

def initialize
  @mode = MODE[:valid]
  @n_dos = 0
  @reject_code = 0
  @corruption_possible = false
end

Instance Attribute Details

#corruption_possibleObject

Returns the value of attribute corruption_possible.



82
83
84
# File 'lib/bitcoin/validation.rb', line 82

def corruption_possible
  @corruption_possible
end

#debug_messageObject

Returns the value of attribute debug_message.



83
84
85
# File 'lib/bitcoin/validation.rb', line 83

def debug_message
  @debug_message
end

#modeObject

Returns the value of attribute mode.



78
79
80
# File 'lib/bitcoin/validation.rb', line 78

def mode
  @mode
end

#n_dosObject

Returns the value of attribute n_dos.



79
80
81
# File 'lib/bitcoin/validation.rb', line 79

def n_dos
  @n_dos
end

#reject_codeObject

Returns the value of attribute reject_code.



81
82
83
# File 'lib/bitcoin/validation.rb', line 81

def reject_code
  @reject_code
end

#reject_reasonObject

Returns the value of attribute reject_reason.



80
81
82
# File 'lib/bitcoin/validation.rb', line 80

def reject_reason
  @reject_reason
end

Instance Method Details

#DoS(level, ret: false, reject_code: 0, reject_reason: '', corruption_in: false, debug_message: '') ⇒ Object



92
93
94
95
96
97
98
99
100
101
# File 'lib/bitcoin/validation.rb', line 92

def DoS(level, ret: false, reject_code: 0, reject_reason: '', corruption_in: false, debug_message: '')
  @reject_code = reject_code
  @reject_reason = reject_reason
  @corruption_possible = corruption_in
  @debug_message = debug_message
  return ret if mode == MODE[:error]
  @n_dos += level
  @mode = MODE[:invalid]
  ret
end

#error?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/bitcoin/validation.rb', line 111

def error?
  mode == MODE[:error]
end

#invalid?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/bitcoin/validation.rb', line 107

def invalid?
  mode == MODE[:invalid]
end

#valid?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/bitcoin/validation.rb', line 103

def valid?
  mode == MODE[:valid]
end