Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

Commit

Permalink
add lovelace data type
Browse files Browse the repository at this point in the history
Signed-off-by: Marko Kungla <marko.kungla@gmail.com>
  • Loading branch information
mkungla committed Feb 5, 2022
1 parent 082b6aa commit faf93e0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ go install github.com/howijd/koios-rest-go-client/cmd/koios-rest@latest
- [Usage](#usage)
- [Basic usage](#basic-usage)
- [Concurrency using goroutines](#concurrency-using-goroutines)
- [Lovelace and math on assets and tokens.](#lovelace-and-math-on-assets-and-tokens)
- [Implemented Endpoints](#implemented-endpoints)


Expand Down Expand Up @@ -142,6 +143,22 @@ func main() {
}
```

## Lovelace and math on assets and tokens.

Liprary uses for most cases to represent lovelace using [`Lovelace`](https://pkg.go.dev/github.com/howijd/koios-rest-go-client#Lovelace) data type.

This library uses forked snapshot of [github.com/shopspring/decimal] package to provide
JSON and XML serialization/deserialization and make it ease to work with calculations
and deciimal precisions of ADA lovelace and native assets.


**For decimal package API see**

[![](https://pkg.go.dev/badge/github.com/shopspring/decimal)](https://pkg.go.dev/github.com/shopspring/decimal)

FORK: https://github.com/howijd/decimal
issues and bug reports are welcome to: https://github.com/howijd/decimal/issues.

## Implemented Endpoints

> WORK IN PROGRESS
Expand All @@ -165,3 +182,4 @@ func main() {
-->
<!-- LINKS -->
[Koios API]: https://koios.rest "Koios API"
[github.com/shopspring/decimal]: https://github.com/shopspring/decimal
12 changes: 5 additions & 7 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"encoding/json"
"fmt"
"net/url"

"github.com/shopspring/decimal"
)

type (
Expand Down Expand Up @@ -112,23 +110,23 @@ type (
Totals []struct {

// Circulating UTxOs for given epoch (in lovelaces).
Circulation decimal.Decimal `json:"circulation"`
Circulation Lovelace `json:"circulation"`

// Epoch number.
EpochNo EpochNo `json:"epoch_no"`

// Total Reserves yet to be unlocked on chain.
Reserves decimal.Decimal `json:"reserves"`
Reserves Lovelace `json:"reserves"`

// Rewards accumulated as of given epoch (in lovelaces).
Reward decimal.Decimal `json:"reward"`
Reward Lovelace `json:"reward"`

// Total Active Supply (sum of treasury funds, rewards,
// UTxOs, deposits and fees) for given epoch (in lovelaces).
Supply decimal.Decimal `json:"supply"`
Supply Lovelace `json:"supply"`

// Funds in treasury for given epoch (in lovelaces).
Treasury decimal.Decimal `json:"treasury"`
Treasury Lovelace `json:"treasury"`
}

// TotalsResponse represents response from `/totals` enpoint.
Expand Down
8 changes: 7 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@ type (
// of github.com/shopspring/decimal package to provide. JSON and XML
// serialization/deserialization and make it ease to work with calculations
// and deciimal precisions of ADA lovelace and native assets.
//
// For API of decimal package see
// https://pkg.go.dev/github.com/shopspring/decimal
//
// SEE: https://github.com/howijd/decimal
// issues and bug reports are welcome to:
// https://github.com/howijd/decimal/issues.
Lovelace decimal.Decimal
Lovelace struct {
decimal.Decimal
}
)

0 comments on commit faf93e0

Please sign in to comment.