2021-09-10 22:30:39 +02:00
|
|
|
package lbcutil_test
|
2015-07-20 18:00:32 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math"
|
|
|
|
|
2021-09-10 22:30:39 +02:00
|
|
|
"github.com/lbryio/lbcutil"
|
2015-07-20 18:00:32 +02:00
|
|
|
)
|
|
|
|
|
2015-07-21 14:49:31 +02:00
|
|
|
func ExampleAmount() {
|
|
|
|
|
2021-09-10 22:30:39 +02:00
|
|
|
a := lbcutil.Amount(0)
|
2015-07-21 14:49:31 +02:00
|
|
|
fmt.Println("Zero Satoshi:", a)
|
|
|
|
|
2021-09-10 22:30:39 +02:00
|
|
|
a = lbcutil.Amount(1e8)
|
2015-07-21 14:49:31 +02:00
|
|
|
fmt.Println("100,000,000 Satoshis:", a)
|
|
|
|
|
2021-09-10 22:30:39 +02:00
|
|
|
a = lbcutil.Amount(1e5)
|
2015-07-21 14:49:31 +02:00
|
|
|
fmt.Println("100,000 Satoshis:", a)
|
|
|
|
// Output:
|
2021-12-14 18:52:58 +01:00
|
|
|
// Zero Satoshi: 0 LBC
|
|
|
|
// 100,000,000 Satoshis: 1 LBC
|
|
|
|
// 100,000 Satoshis: 0.001 LBC
|
2015-07-21 14:49:31 +02:00
|
|
|
}
|
|
|
|
|
2015-07-20 18:00:32 +02:00
|
|
|
func ExampleNewAmount() {
|
2021-09-10 22:30:39 +02:00
|
|
|
amountOne, err := lbcutil.NewAmount(1)
|
2015-07-20 18:00:32 +02:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Println(amountOne) //Output 1
|
|
|
|
|
2021-09-10 22:30:39 +02:00
|
|
|
amountFraction, err := lbcutil.NewAmount(0.01234567)
|
2015-07-20 18:00:32 +02:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Println(amountFraction) //Output 2
|
|
|
|
|
2021-09-10 22:30:39 +02:00
|
|
|
amountZero, err := lbcutil.NewAmount(0)
|
2015-07-20 18:00:32 +02:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Println(amountZero) //Output 3
|
|
|
|
|
2021-09-10 22:30:39 +02:00
|
|
|
amountNaN, err := lbcutil.NewAmount(math.NaN())
|
2015-07-20 18:00:32 +02:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Println(amountNaN) //Output 4
|
|
|
|
|
2021-12-14 18:52:58 +01:00
|
|
|
// Output: 1 LBC
|
|
|
|
// 0.01234567 LBC
|
|
|
|
// 0 LBC
|
|
|
|
// invalid coin amount
|
2015-07-20 18:00:32 +02:00
|
|
|
}
|
2015-07-21 14:49:31 +02:00
|
|
|
|
|
|
|
func ExampleAmount_unitConversions() {
|
2021-09-10 22:30:39 +02:00
|
|
|
amount := lbcutil.Amount(44433322211100)
|
2015-07-21 14:49:31 +02:00
|
|
|
|
2021-12-14 18:52:58 +01:00
|
|
|
fmt.Println("Satoshi to kLBC:", amount.Format(lbcutil.AmountKiloBTC))
|
|
|
|
fmt.Println("Satoshi to LBC:", amount)
|
|
|
|
fmt.Println("Satoshi to MilliLBC:", amount.Format(lbcutil.AmountMilliBTC))
|
|
|
|
fmt.Println("Satoshi to MicroLBC:", amount.Format(lbcutil.AmountMicroBTC))
|
2021-09-10 22:30:39 +02:00
|
|
|
fmt.Println("Satoshi to Satoshi:", amount.Format(lbcutil.AmountSatoshi))
|
2015-07-21 14:49:31 +02:00
|
|
|
|
|
|
|
// Output:
|
2021-12-14 18:52:58 +01:00
|
|
|
// Satoshi to kLBC: 444.333222111 kLBC
|
|
|
|
// Satoshi to LBC: 444333.222111 LBC
|
|
|
|
// Satoshi to MilliLBC: 444333222.111 mLBC
|
|
|
|
// Satoshi to MicroLBC: 444333222111 μLBC
|
2015-07-21 14:49:31 +02:00
|
|
|
// Satoshi to Satoshi: 44433322211100 Satoshi
|
|
|
|
}
|