Skip to content

Commit

Permalink
feat: enhance AssetListResponse closes #38
Browse files Browse the repository at this point in the history
BREAKING CHANGE: AssetListResponse is now array of
{policy_id, asset_name, fingerprint}

Signed-off-by: Marko Kungla <marko.kungla@gmail.com>
  • Loading branch information
mkungla committed Nov 18, 2022
1 parent 27d4199 commit 751b4a9
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 51 deletions.
44 changes: 23 additions & 21 deletions .github/workflows/test-guild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ env:
KOIOS_NETWORK: guild

jobs:
transactions:
network:
runs-on: ubuntu-latest
needs:
# just to limit concurrent check groups to 3
- transactions
strategy:
matrix:
test:
- TxInfo
- TxUTxO
- TxMetadata
- TxMetaLabels
- TxStatus
- NetworkTip
- NetworkGenesis
- NetworkTotals
steps:
- uses: actions/setup-go@v3
with:
Expand All @@ -34,17 +35,15 @@ jobs:
name: "${{ env.KOIOS_NETWORK }}-${{ github.job }}-${{ matrix.test }}"
files: ./coverage.txt
env_vars: KOIOS_NETWORK
network:

epoch:
runs-on: ubuntu-latest
needs:
# just to limit concurrent check groups to 3
- transactions
strategy:
matrix:
test:
- NetworkTip
- NetworkGenesis
- NetworkTotals
- EpochInfo
- EpochParams
- EpochBlockProtocols
steps:
- uses: actions/setup-go@v3
with:
Expand All @@ -59,14 +58,14 @@ jobs:
files: ./coverage.txt
env_vars: KOIOS_NETWORK

epoch:
blocks:
runs-on: ubuntu-latest
strategy:
matrix:
test:
- EpochInfo
- EpochParams
- EpochBlockProtocols
- Blocks
- BlockInfo
- BlockTxs
steps:
- uses: actions/setup-go@v3
with:
Expand All @@ -81,14 +80,16 @@ jobs:
files: ./coverage.txt
env_vars: KOIOS_NETWORK

blocks:
transactions:
runs-on: ubuntu-latest
strategy:
matrix:
test:
- Blocks
- BlockInfo
- BlockTxs
- TxInfo
- TxUTxO
- TxMetadata
- TxMetaLabels
- TxStatus
steps:
- uses: actions/setup-go@v3
with:
Expand Down Expand Up @@ -128,6 +129,7 @@ jobs:
name: "${{ env.KOIOS_NETWORK }}-${{ github.job }}-${{ matrix.test }}"
files: ./coverage.txt
env_vars: KOIOS_NETWORK

account:
runs-on: ubuntu-latest
needs:
Expand Down
44 changes: 25 additions & 19 deletions asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,22 @@ import (
// introduces breaking change since v1.3.0

type (
// AssetName defines type for _asset_name.
AssetName string

// AssetFingerprint defines type for asset_fingerprint.
// The CIP14 fingerprint of the asset,
// This specification defines a user-facing asset fingerprint
// as a bech32-encoded blake2b-160 digest of the concatenation
// of the policy id and the asset name.
AssetFingerprint string

// Asset represents Cardano Asset.
Asset struct {
// Asset Name (hex).
AssetName AssetName `json:"asset_name,omitempty"`

Fingerprint string `json:"fingerprint,omitempty"`
Fingerprint AssetFingerprint `json:"fingerprint,omitempty"`

// Asset Policy ID (hex).
PolicyID PolicyID `json:"policy_id"`
Expand Down Expand Up @@ -84,7 +94,7 @@ type (
AssetNameASCII string `json:"asset_name_ascii"`

// The CIP14 fingerprint of the asset
Fingerprint string `json:"fingerprint"`
Fingerprint AssetFingerprint `json:"fingerprint"`

// MintingTxMetadata minting Tx JSON payload if it can be decoded as JSON
// MintingTxMetadata *TxInfoMetadata `json:"minting_tx_metadata"`
Expand Down Expand Up @@ -112,25 +122,11 @@ type (
MintingTxHash TxHash `json:"minting_tx_hash"`
}

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

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

// // TxHashes List of Tx hashes
// TxHash TxHash `json:"tx_hash"`
// }.

// AssetListItem used to represent response from /asset_list`.
AssetListItem struct {
PolicyID PolicyID `json:"policy_id"`
AssetNames struct {
HEX []string `json:"hex"`
ASCII []string `json:"ascii"`
} `json:"asset_names"`
PolicyID PolicyID `json:"policy_id"`
AssetName AssetName `json:"asset_name"`
Fingerprint AssetFingerprint `json:"fingerprint"`
}

// AssetListResponse represents response from `/asset_list` endpoint.
Expand Down Expand Up @@ -197,6 +193,16 @@ type (
}
)

// String returns AssetName as string.
func (v AssetName) String() string {
return string(v)
}

// String returns AssetFingerprint as string.
func (v AssetFingerprint) String() string {
return string(v)
}

// GetAssetList returns the list of all native assets (paginated).
func (c *Client) GetAssets(
ctx context.Context,
Expand Down
3 changes: 1 addition & 2 deletions assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ func assetsTest(t TestingT, client *koios.Client) {

for _, item := range res.Data {
assertNotEmpty(t, item.PolicyID, "policy_id")
assertGreater(t, len(item.AssetNames.ASCII), 0, item.PolicyID.String()+"asset_names.ascii")
assertGreater(t, len(item.AssetNames.HEX), 0, item.PolicyID.String()+"asset_names.hex")
assertGreater(t, len(item.Fingerprint), 0, item.PolicyID.String()+" fingerprint")
}
}

Expand Down
8 changes: 0 additions & 8 deletions koios.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ type (
// PaymentCredential type def.
PaymentCredential string

// AssetName defines type for _asset_name.
AssetName string

// BlockHash defines type for _block_hash.
BlockHash string

Expand Down Expand Up @@ -255,11 +252,6 @@ func (v PaymentCredential) String() string {
return string(v)
}

// String returns AssetName as string.
func (v AssetName) String() string {
return string(v)
}

// String returns BlockHash as string.
func (v BlockHash) String() string {
return string(v)
Expand Down
2 changes: 1 addition & 1 deletion koios_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func networkBlockHash() koios.BlockHash {
var hash koios.BlockHash
switch os.Getenv("KOIOS_NETWORK") {
case "guild":
hash = koios.BlockHash("af2f6f7dd4e4ea6765103a1e38e023da3edd2b3c7fea2aa367222564dbe01cfd")
hash = koios.BlockHash("bddbbc6df0ad09567a513349bafd56d8ec5c8fcd9ee9db12173624b896350d57")
case "testnet":
hash = koios.BlockHash("f75fea40852ed7d7f539d008e45255725daef8553ae7162750836f279570813a")
case "mainnet":
Expand Down

0 comments on commit 751b4a9

Please sign in to comment.