class XRBP::NodeStore::STAmount
Serialized Amount Representation.
From rippled docs:
Internal form: 1: If amount is zero, then value is zero and offset is -100 2: Otherwise: legal offset range is -96 to +80 inclusive value range is 10^15 to (10^16 - 1) inclusive amount = value * [10 ^ offset] Wire form: High 8 bits are (offset+142), legal range is, 80 to 22 inclusive Low 56 bits are value, legal range is 10^15 to (10^16 - 1) inclusive
Constants
- MAX_NATIVE
- MAX_OFFSET
- MAX_VAL
- MIN_OFFSET
DEFINES FROM STAmount.h
- MIN_VAL
- NOT_NATIVE
- POS_NATIVE
Attributes
exponent[R]
issue[RW]
mantissa[R]
neg[R]
offset[R]
value[R]
Public Class Methods
from_quality(rate)
click to toggle source
# File lib/xrbp/nodestore/sle/st_amount.rb, line 46 def self.from_quality(rate) return STAmount.new(:issue => NodeStore.no_issue) if rate == 0 mantissa = rate & ~(255 << (64 - 8)) exponent = (rate >> (64 - 8)).to_int32 - 100 return STAmount.new(:issue => NodeStore.no_issue, :mantissa => mantissa, :exponent => exponent) end
new(args={})
click to toggle source
# File lib/xrbp/nodestore/sle/st_amount.rb, line 58 def initialize(args={}) @issue = args[:issue] @mantissa = args[:mantissa] || 0 @exponent = args[:exponent] || 0 @neg = !!args[:neg] canonicalize end
zero(args={})
click to toggle source
# File lib/xrbp/nodestore/sle/st_amount.rb, line 42 def self.zero(args={}) STAmount.new args.merge({:mantissa => 0}) end
Public Instance Methods
inspect()
click to toggle source
# File lib/xrbp/nodestore/sle/st_amount.rb, line 77 def inspect return "0" if zero? i = issue.inspect i = i == '' ? '' : "(#{i})" (native? ? xrp_amount : iou_amount.to_f).to_s + (native? ? "" : i) end
native?()
click to toggle source
# File lib/xrbp/nodestore/sle/st_amount.rb, line 69 def native? @issue && @issue.xrp? end
to_s()
click to toggle source
# File lib/xrbp/nodestore/sle/st_amount.rb, line 86 def to_s inspect end
zero?()
click to toggle source
# File lib/xrbp/nodestore/sle/st_amount.rb, line 73 def zero? @mantissa == 0 end