Skip to content

Commit

Permalink
Signed-off-by: Marko Kungla <[email protected]>
Browse files Browse the repository at this point in the history
fix: update other Time related fields + api change

- AssetInfo MintingTxMetadata is now slice of TxInfoMetadata
- AssetTxsResponse is now returning slice of []TX
- EpochParams coins_per_utxo_word is now coins_per_utxo_size
- update testdata assets

BREAKING CHANGE: there are some breaking changes in struct field types
and names however this are released not as new major semver, since
these changes were caused by changes in  KOIOS API v0.
  • Loading branch information
mkungla committed Aug 22, 2022
1 parent bc4b8fe commit 5d016d7
Show file tree
Hide file tree
Showing 57 changed files with 33 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/misspell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: spellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- name: misspell
uses: reviewdog/action-misspell@v1
with:
Expand Down
37 changes: 6 additions & 31 deletions asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type (
Fingerprint string `json:"fingerprint"`

// MintingTxMetadata minting Tx JSON payload if it can be decoded as JSON
MintingTxMetadata *TxInfoMetadata `json:"minting_tx_metadata"`
MintingTxMetadata []TxInfoMetadata `json:"minting_tx_metadata"`

// Asset metadata registered on the Cardano Token Registry
TokenRegistryMetadata *TokenRegistryMetadata `json:"token_registry_metadata"`
Expand All @@ -103,18 +103,6 @@ type (
MintingTxHash TxHash `json:"minting_tx_hash"`
}

// AssetTxs Txs info for the given asset (latest first).
AssetTxs struct {
// AssetName (hex)
AssetName AssetName `json:"asset_name"`

// PoliciID Asset Policy ID (hex)
PolicyID PolicyID `json:"policy_id"`

// TxHashes List of Tx hashes
TxHashes []TxHash `json:"tx_hashes"`
}

// AssetListItem used to represent response from /asset_list`.
AssetListItem struct {
PolicyID PolicyID `json:"policy_id"`
Expand Down Expand Up @@ -157,19 +145,13 @@ type (
// AssetTxsResponse represents response from `/asset_txs` endpoint.
AssetTxsResponse struct {
Response
Data *AssetTxs `json:"response"`
}

// AssetPolicyInfo is response body for `/asset_policy_info` endpoint.
AssetPolicyInfo struct {
PolicyID PolicyID `json:"policy_id"`
Assets []AssetInfo `json:"assets"`
Data []TX `json:"response"`
}

// AssetPolicyInfoResponse represents response from `/asset_policy_info` endpoint.
AssetPolicyInfoResponse struct {
Response
Data *AssetPolicyInfo `json:"response"`
Data []AssetInfo `json:"response"`
}

// AssetMintTX holds specific mint tx hash and amount.
Expand Down Expand Up @@ -308,12 +290,9 @@ func (c *Client) GetAssetTxs(
if err != nil {
return
}
atxs := []AssetTxs{}
err = ReadAndUnmarshalResponse(rsp, &res.Response, &atxs)

if len(atxs) == 1 {
res.Data = &atxs[0]
}
err = ReadAndUnmarshalResponse(rsp, &res.Response, &res.Data)

return
}

Expand All @@ -334,12 +313,8 @@ func (c *Client) GetAssetPolicyInfo(
if err != nil {
return
}
info := []AssetPolicyInfo{}
err = ReadAndUnmarshalResponse(rsp, &res.Response, &info)
err = ReadAndUnmarshalResponse(rsp, &res.Response, &res.Data)

if len(info) == 1 {
res.Data = &info[0]
}
return
}

Expand Down
13 changes: 5 additions & 8 deletions asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ func (s *assetTestSuite) TestGetAssetPolicyInfoEndpoint() {
nil,
)
if s.NoError(err) {
s.NotEmpty(res.Data.PolicyID)
s.NotEmpty(res.Data.Assets[0].Name)
s.NotEmpty(res.Data.Assets[0].NameASCII)
s.False(res.Data.Assets[0].CreationTime.IsZero())
s.True(res.Data.Assets[0].TotalSupply.IsPositive())
s.NotEmpty(res.Data[0].Name)
s.NotEmpty(res.Data[0].NameASCII)
s.False(res.Data[0].CreationTime.IsZero())
s.True(res.Data[0].TotalSupply.IsPositive())
}
}
}
Expand Down Expand Up @@ -139,9 +138,7 @@ func (s *assetTestSuite) TestGetAssetTxsEndpoint() {
nil,
)
if s.NoError(err) {
s.Equal(res.Data.PolicyID, koios.PolicyID(spec.Request.Query.Get("_asset_policy")))
s.Equal(res.Data.AssetName, koios.AssetName(spec.Request.Query.Get("_asset_name")))
s.Greater(len(res.Data.TxHashes), 0)
s.Greater(len(res.Data), 0)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type (
BlockHash BlockHash `json:"block_hash"`

// The cost per UTxO word
CoinsPerUtxoWord Lovelace `json:"coins_per_utxo_word"`
CoinsPerUtxoSize Lovelace `json:"coins_per_utxo_size"`

// The percentage of the tx fee which must be provided as collateral
// when including non-native scripts
Expand Down
2 changes: 1 addition & 1 deletion epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (s *epochTestSuite) TestEpochParamsEndpoint() {
s.Greater(res.Data[0].MaxValSize, float32(0))
s.Greater(res.Data[0].CollateralPercent, int64(0))
s.Greater(res.Data[0].MaxCollateralInputs, 0)
s.True(res.Data[0].CoinsPerUtxoWord.IsPositive())
s.True(res.Data[0].CoinsPerUtxoSize.IsPositive(), res.Data[0].CoinsPerUtxoSize)
}
}
}
4 changes: 2 additions & 2 deletions internal/testdatagen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module github.com/cardano-community/koios-go-client/internal/testdatagen

go 1.16

replace github.com/cardano-community/koios-go-client v1.1.0 => ../../
replace github.com/cardano-community/koios-go-client v1.3.0 => ../../

require (
github.com/cardano-community/koios-go-client v1.1.0
github.com/cardano-community/koios-go-client v1.3.0
github.com/urfave/cli/v2 v2.3.0
)
16 changes: 9 additions & 7 deletions koios.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,13 @@ type (
// Call to New without options is same as call with default options.
// e.g.
// api, err := koios.New(
// koios.Host(koios.MainnetHost),
// koios.APIVersion(koios.DefaultAPIVersion),
// koios.Port(koios.DefaultPort),
// koios.Schema(koios.DefaultSchema),
// koios.HttpClient(koios.DefaultHttpClient),
//
// koios.Host(koios.MainnetHost),
// koios.APIVersion(koios.DefaultAPIVersion),
// koios.Port(koios.DefaultPort),
// koios.Schema(koios.DefaultSchema),
// koios.HttpClient(koios.DefaultHttpClient),
//
// ).
func New(opts ...Option) (*Client, error) {
c := &Client{
Expand Down Expand Up @@ -356,8 +358,8 @@ func (v StakeAddress) String() string {

func (t *Time) UnmarshalJSON(b []byte) error {
str := string(b)
if ts, err := strconv.Atoi(str); err == nil {
t.Time = time.Unix(int64(ts), 0)
if ts, err := strconv.ParseInt(str, 10, 0); err == nil {
t.Time = time.Unix(ts, 0)
return nil
}
p, err := time.Parse("\""+time.RFC3339+"\"", str)
Expand Down
5 changes: 2 additions & 3 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package koios
import (
"context"
"encoding/json"
"time"

"github.com/shopspring/decimal"
)
Expand All @@ -34,7 +33,7 @@ type (
BlockNo int `json:"block_no"`

// Timestamp for when the block was created
BlockTime string `json:"block_time"`
BlockTime Time `json:"block_time"`

// EpochNo number
EpochNo int `json:"epoch_no"`
Expand Down Expand Up @@ -94,7 +93,7 @@ type (
Slotsperkesperiod decimal.Decimal `json:"slotsperkesperiod"`

// Timestamp for first block (genesis) on chain.
Systemstart time.Time `json:"systemstart"`
Systemstart Time `json:"systemstart"`

// Number of BFT members that need to approve
// (via vote) a Protocol Update Proposal.
Expand Down
4 changes: 2 additions & 2 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ type (
TxHash TxHash `json:"tx_hash"`

// Time time of the block.
BlockTime string `json:"block_time"`
BlockTime Time `json:"block_time"`

// ID (bech32 format)
ID PoolID `json:"pool_id_bech32"`
Expand Down Expand Up @@ -231,7 +231,7 @@ type (
PoolDelegator struct {
StakeAddress StakeAddress `json:"stake_address"`
Amount Lovelace `json:"amount"`
Epoch EpochNo `json:"epoch_no"`
Epoch EpochNo `json:"active_epoch_no"`
}

// PoolRelays list item.
Expand Down
4 changes: 2 additions & 2 deletions pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ func (s *poolTestSuite) TestGetPoolBlocksEndpoint() {
func (s *poolTestSuite) TestGetPoolDelegatorsEndpoint() {
spec := s.GetSpec("endpoint_pool_delegators")
if s.NotNil(spec) {
epochNo, err := strconv.ParseUint(spec.Request.Query.Get("_epoch_no"), 10, 64)
_, err := strconv.ParseUint(spec.Request.Query.Get("_epoch_no"), 10, 64)
s.NoError(err)
epoch := koios.EpochNo(epochNo)
epoch := koios.EpochNo(236)

res, err := s.api.GetPoolDelegators(
context.Background(),
Expand Down
Binary file modified testdata/endpoint_account_addresses.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_account_assets.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_account_history.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_account_info.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_account_list.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_account_rewards.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_account_updates.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_address_assets.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_address_info.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_address_txs.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_asset_address_list.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_asset_history.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_asset_info.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_asset_list.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_asset_policy_info.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_asset_summary.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_asset_txs.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_block_info.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_block_txs.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_blocks.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_credential_txs.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_epoch_info.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_epoch_params.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_native_script_list.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_network_genesis.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_network_tip.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_network_totals.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_plutus_script_list.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_pool_blocks.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_pool_delegators.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_pool_history.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_pool_info.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_pool_list.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_pool_metadata.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_pool_relays.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_pool_updates.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_script_redeemers.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_tx_info.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_tx_metadata.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_tx_metalabels.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_tx_status.json.gz
Binary file not shown.
Binary file modified testdata/endpoint_tx_utxos.json.gz
Binary file not shown.
Binary file modified testdata/horizontal_filtering.json.gz
Binary file not shown.
Binary file modified testdata/pagination-page-1.json.gz
Binary file not shown.
Binary file modified testdata/pagination-page-2.json.gz
Binary file not shown.
Binary file modified testdata/vertical_filtering.json.gz
Binary file not shown.
3 changes: 2 additions & 1 deletion transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ type (
// BlockHeight is block number on chain where transaction was included.
BlockHeight int `json:"block_height"`
// BlockTime is time of the block.
BlockTime Time `json:"block_time"`
BlockTime Time `json:"block_time"`
Epoch EpochNo `json:"epoch_no,omitempty"`
}

// UTxO model holds inputs and outputs for given UTxO.
Expand Down

0 comments on commit 5d016d7

Please sign in to comment.