From 40977acb690008e5e6f7b0ef02659bc5b553fbf7 Mon Sep 17 00:00:00 2001 From: Sean Date: Mon, 29 Aug 2022 11:35:20 +0200 Subject: [PATCH 1/3] add .DS_Store to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index aa97694..7d07633 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,5 @@ # Editor Files .vscode/ + +.DS_Store \ No newline at end of file From 3facff9beeed28f1371965585a887e36788f7d13 Mon Sep 17 00:00:00 2001 From: Sean Date: Mon, 29 Aug 2022 12:05:39 +0200 Subject: [PATCH 2/3] fixed AssetAddresses resource url, added query params to AssetAddresses, added new AssetAddressesAll function similar to AccountAssociatedAssetsAll --- api_assets.go | 59 +++++++++++++++++++++++++++++++++++++++++++--- api_assets_test.go | 2 +- client.go | 3 ++- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/api_assets.go b/api_assets.go index 1350cdd..177b1e8 100644 --- a/api_assets.go +++ b/api_assets.go @@ -103,6 +103,11 @@ type AssetResult struct { Err error } +type AssetAddressesAll struct { + Res []AssetAddress + Err error +} + // Assets returns a paginated list of assets. func (c *apiClient) Assets(ctx context.Context, query APIQueryParams) (a []Asset, err error) { requestUrl, err := url.Parse(fmt.Sprintf("%s/%s", c.server, resourceAssets)) @@ -240,17 +245,21 @@ func (c *apiClient) AssetTransactions(ctx context.Context, asset string) (trs [] return trs, nil } -// AssetAddresses returns list of a addresses containing a specific asset. -func (c *apiClient) AssetAddresses(ctx context.Context, asset string) (addrs []AssetAddress, err error) { - requestUrl, err := url.Parse(fmt.Sprintf("%s/%s/%s/%s", c.server, resourceAssets, asset, resourceAssetHistory)) +func (c *apiClient) AssetAddresses(ctx context.Context, asset string, query APIQueryParams) (addrs []AssetAddress, err error) { + requestUrl, err := url.Parse(fmt.Sprintf("%s/%s/%s/%s", c.server, resourceAssets, asset, resourceAddresses)) if err != nil { return } + req, err := http.NewRequestWithContext(ctx, http.MethodGet, requestUrl.String(), nil) if err != nil { return } + v := req.URL.Query() + v = formatParams(v, query) + req.URL.RawQuery = v.Encode() + res, err := c.handleRequest(req) if err != nil { return @@ -263,6 +272,50 @@ func (c *apiClient) AssetAddresses(ctx context.Context, asset string) (addrs []A return addrs, nil } +// AssetAddresses returns list of a addresses containing a specific asset. +func (c *apiClient) AssetAddressesAll(ctx context.Context, asset string) <-chan AssetAddressesAll { + ch := make(chan AssetAddressesAll, c.routines) + jobs := make(chan methodOptions, c.routines) + quit := make(chan bool, 1) + + wg := sync.WaitGroup{} + + for i := 0; i < c.routines; i++ { + wg.Add(1) + go func(jobs chan methodOptions, ch chan AssetAddressesAll, wg *sync.WaitGroup) { + defer wg.Done() + for j := range jobs { + ad, err := c.AssetAddresses(j.ctx, asset, j.query) + if len(ad) != j.query.Count || err != nil { + select { + case quit <- true: + default: + } + } + res := AssetAddressesAll{Res: ad, Err: err} + ch <- res + } + + }(jobs, ch, &wg) + } + go func() { + defer close(ch) + fetchScripts := true + for i := 1; fetchScripts; i++ { + select { + case <-quit: + fetchScripts = false + default: + jobs <- methodOptions{ctx: ctx, query: APIQueryParams{Count: 100, Page: i}} + } + } + + close(jobs) + wg.Wait() + }() + return ch +} + // AssetsByPolicy returns list of assets minted under a specific policy. func (c *apiClient) AssetsByPolicy(ctx context.Context, policyId string) (a []Asset, err error) { requestUrl, err := url.Parse(fmt.Sprintf("%s/%s/%s", c.server, resourcePolicyAssets, policyId)) diff --git a/api_assets_test.go b/api_assets_test.go index d1f5e27..f993d87 100644 --- a/api_assets_test.go +++ b/api_assets_test.go @@ -93,7 +93,7 @@ func TestResourceAssetddressesIntegration(t *testing.T) { asset := "3a9241cd79895e3a8d65261b40077d4437ce71e9d7c8c6c00e3f658e4669727374636f696e" api := blockfrost.NewAPIClient(blockfrost.APIClientOptions{}) - got, err := api.AssetAddresses(context.TODO(), asset) + got, err := api.AssetAddresses(context.TODO(), asset, blockfrost.APIQueryParams{}) if err != nil { t.Fatal(err) } diff --git a/client.go b/client.go index e7fc12c..32b9a6e 100644 --- a/client.go +++ b/client.go @@ -126,7 +126,8 @@ type APIClient interface { AssetsAll(ctx context.Context) <-chan AssetResult AssetHistory(ctx context.Context, asset string) ([]AssetHistory, error) AssetTransactions(ctx context.Context, asset string) ([]AssetTransaction, error) - AssetAddresses(ctx context.Context, asset string) ([]AssetAddress, error) + AssetAddresses(ctx context.Context, asset string, query APIQueryParams) ([]AssetAddress, error) + AssetAddressesAll(ctx context.Context, asset string) <-chan AssetAddressesAll AssetsByPolicy(ctx context.Context, policyId string) ([]Asset, error) Genesis(ctx context.Context) (GenesisBlock, error) MetadataTxLabels(ctx context.Context, query APIQueryParams) ([]MetadataTxLabel, error) From 399f58f3b284de6dda97b74df91d16b7aa11b118 Mon Sep 17 00:00:00 2001 From: Sean Date: Wed, 7 Sep 2022 12:30:47 +0200 Subject: [PATCH 3/3] added preprod and preview urls --- types.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types.go b/types.go index d197d49..ab37ff1 100644 --- a/types.go +++ b/types.go @@ -5,6 +5,8 @@ import "fmt" const ( CardanoMainNet = "https://cardano-mainnet.blockfrost.io/api/v0" CardanoTestNet = "https://cardano-testnet.blockfrost.io/api/v0" + CardanoPreProd = "https://cardano-preprod.blockfrost.io/api/v0" + CardanoPreview = "https://cardano-preview.blockfrost.io/api/v0" IPFSNet = "https://ipfs.blockfrost.io/api/v0" )