A Symbol is what identifies a currency, and is made of a precision
and a
SymbolCode. For example, the symbol 1,EOS
is a symbol with
precision 1, and a symbol code of EOS
.
The precision number determines how many decimal digits can be used. In the example above, someone can have 0.1 EOS, but not 0.01 EOS.
precision : Symbol -> Basics.Int
Get the precision of a Symbol.
fromPrecisionAndCodeString 1 "EOS"
|> Result.map precision
--> Ok 1
code : Symbol -> Eos.SymbolCode.SymbolCode
Get the SymbolCode of a Symbol
import Eos.SymbolCode
fromPrecisionAndCodeString 1 "EOS"
|> Result.map (code >> Eos.SymbolCode.toString)
--> Ok "EOS"
String
s and Int
sfromPrecisionAndCodeString : Basics.Int -> String -> Result Error Symbol
Create a Symbol from a precision and a String
that represents a
SymbolCode. If you already have a SymbolCode,
use fromPrecisionAndCode instead.
import Eos.SymbolCode
fromPrecisionAndCodeString 1 "EOS"
|> Result.map
(\symbol ->
{ precision = precision symbol
, codeString = Eos.SymbolCode.toString (code symbol)
}
)
--> Ok { precision = 1, codeString = "EOS" }
fromPrecisionAndCodeString -1 "EOS"
--> Err (PrecisionError NegativePrecision)
fromPrecisionAndCodeString 1 "eos"
--> Err (SymbolCodeError (Eos.SymbolCode.InvalidCharacters ( 'e', [ 'o', 's' ] )))
fromPrecisionAndCode : Basics.Int -> Eos.SymbolCode.SymbolCode -> Result PrecisionError Symbol
Create a Symbol from a precision and a SymbolCode.
When creating a Symbol, there are two things we validate: the precision and the symbol code. This type represents that.
Precisions must be >= 0. This type represents the error that can happen when trying to create a Symbol with a negative precision.
errorToString : Error -> String
You can use this function to convert an Error to a human-readable
String
.
encode : Symbol -> Json.Encode.Value
Encode a Symbol into a JSON value.
decoder : Json.Decode.Decoder Symbol
Decode a Symbol from a JSON value.