Module: XRBP::NodeStore::STAmount::Conversion

Included in:
XRBP::NodeStore::STAmount
Defined in:
lib/xrbp/nodestore/sle/st_amount_conversion.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#clearObject


174
175
176
177
178
179
180
181
182
# File 'lib/xrbp/nodestore/sle/st_amount_conversion.rb', line 174

def clear
  # From rippled docs:
  #   The -100 is used to allow 0 to sort less than a small positive values
  #   which have a negative exponent.
  @exponent = native? ? 0 : -100

  @neg = false
  @mantissa = 0
end

#iou_amountObject


197
198
199
# File 'lib/xrbp/nodestore/sle/st_amount_conversion.rb', line 197

def iou_amount
  (neg ? -1 : 1) * mantissa * 10 ** exponent
end

#negate!Object


109
110
111
112
# File 'lib/xrbp/nodestore/sle/st_amount_conversion.rb', line 109

def negate!
  return if zero?
  @neg = !@neg
end

#sn_valueObject


184
185
186
# File 'lib/xrbp/nodestore/sle/st_amount_conversion.rb', line 184

def sn_value
  neg ? (-mantissa) : mantissa
end

#to_hObject


102
103
104
105
106
107
# File 'lib/xrbp/nodestore/sle/st_amount_conversion.rb', line 102

def to_h
  {:mantissa => mantissa,
   :exponent => exponent,
   :neg      => neg,
   :issue    => issue.to_h}
end

#to_wireObject

Encode STAmount into binary format


91
92
93
94
95
96
97
98
# File 'lib/xrbp/nodestore/sle/st_amount_conversion.rb', line 91

def to_wire
  xrp_bit = ((native? ? 0 : 1) << 63)
  neg_bit = ((   neg  ? 0 : 1) << 62)
  value_bits = native? ? mantissa :
            (((exponent+97) << 54) + mantissa)

  xrp_bit + neg_bit + value_bits
end

#xrp_amountObject Also known as: drops

In drops!


191
192
193
# File 'lib/xrbp/nodestore/sle/st_amount_conversion.rb', line 191

def xrp_amount
  neg ? (-value) : value
end