Skip to content

Commit 3cdc7c6

Browse files
Merge pull request #70 from blockfrost/chore/23-update
SDK update
2 parents dd587e8 + 89ad6f2 commit 3cdc7c6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1894
-346
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ name: Test
22

33
on:
44
push:
5-
branches:
5+
branches:
66
- master
77
- feat**
88
- test**
99
- docs**
1010
- ref**
1111
pull_request:
12-
branches: [ master ]
12+
branches: [master]
1313

1414
jobs:
1515
test:
@@ -18,12 +18,12 @@ jobs:
1818
BLOCKFROST_PROJECT_ID: ${{ secrets.BLOCKFROST_PROJECT_ID }}
1919
BLOCKFROST_IPFS_PROJECT_ID: ${{ secrets.BLOCKFROST_IPFS_PROJECT_ID }}
2020
steps:
21-
- uses: actions/checkout@v2
21+
- uses: actions/checkout@v4
2222

23-
- name: Set up Go
24-
uses: actions/setup-go@v2
25-
with:
26-
go-version: 1.17
23+
- name: Set up Go
24+
uses: actions/setup-go@v4
25+
with:
26+
go-version: 1.21.4
2727

28-
- name: Test
29-
run: go clean -testcache && go test -v
28+
- name: Test
29+
run: go clean -testcache && go test -v

api_account.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type Account struct {
3131
Active bool `json:"active"`
3232

3333
// Epoch of the most recent action - registration or deregistration
34-
ActiveEpoch int64 `json:"active_epoch"`
34+
ActiveEpoch *int64 `json:"active_epoch"`
3535

3636
// Balance of the account in Lovelaces
3737
ControlledAmount string `json:"controlled_amount"`
@@ -52,7 +52,7 @@ type Account struct {
5252
WithdrawableAmount string `json:"withdrawable_amount"`
5353

5454
// Bech32 pool ID that owns the account
55-
PoolID string `json:"pool_id"`
55+
PoolID *string `json:"pool_id"`
5656
}
5757

5858
// AccountRewardsHist return Account reward history
@@ -267,11 +267,11 @@ func (c *apiClient) AccountRewardsHistoryAll(ctx context.Context, stakeAddress s
267267
}
268268
go func() {
269269
defer close(ch)
270-
fetchScripts := true
271-
for i := 1; fetchScripts; i++ {
270+
fetchNextPage := true
271+
for i := 1; fetchNextPage; i++ {
272272
select {
273273
case <-quit:
274-
fetchScripts = false
274+
fetchNextPage = false
275275
default:
276276
jobs <- methodOptions{ctx: ctx, query: APIQueryParams{Count: 100, Page: i}}
277277
}
@@ -339,11 +339,11 @@ func (c *apiClient) AccountHistoryAll(ctx context.Context, address string) <-cha
339339
}
340340
go func() {
341341
defer close(ch)
342-
fetchScripts := true
343-
for i := 1; fetchScripts; i++ {
342+
fetchNextPage := true
343+
for i := 1; fetchNextPage; i++ {
344344
select {
345345
case <-quit:
346-
fetchScripts = false
346+
fetchNextPage = false
347347
default:
348348
jobs <- methodOptions{ctx: ctx, query: APIQueryParams{Count: 100, Page: i}}
349349
}
@@ -411,11 +411,11 @@ func (c *apiClient) AccountDelegationHistoryAll(ctx context.Context, stakeAddres
411411
}
412412
go func() {
413413
defer close(ch)
414-
fetchScripts := true
415-
for i := 1; fetchScripts; i++ {
414+
fetchNextPage := true
415+
for i := 1; fetchNextPage; i++ {
416416
select {
417417
case <-quit:
418-
fetchScripts = false
418+
fetchNextPage = false
419419
default:
420420
jobs <- methodOptions{ctx: ctx, query: APIQueryParams{Count: 100, Page: i}}
421421
}
@@ -483,11 +483,11 @@ func (c *apiClient) AccountRegistrationHistoryAll(ctx context.Context, stakeAddr
483483
}
484484
go func() {
485485
defer close(ch)
486-
fetchScripts := true
487-
for i := 1; fetchScripts; i++ {
486+
fetchNextPage := true
487+
for i := 1; fetchNextPage; i++ {
488488
select {
489489
case <-quit:
490-
fetchScripts = false
490+
fetchNextPage = false
491491
default:
492492
jobs <- methodOptions{ctx: ctx, query: APIQueryParams{Count: 100, Page: i}}
493493
}
@@ -555,11 +555,11 @@ func (c *apiClient) AccountWithdrawalHistoryAll(ctx context.Context, stakeAddres
555555
}
556556
go func() {
557557
defer close(ch)
558-
fetchScripts := true
559-
for i := 1; fetchScripts; i++ {
558+
fetchNextPage := true
559+
for i := 1; fetchNextPage; i++ {
560560
select {
561561
case <-quit:
562-
fetchScripts = false
562+
fetchNextPage = false
563563
default:
564564
jobs <- methodOptions{ctx: ctx, query: APIQueryParams{Count: 100, Page: i}}
565565
}
@@ -627,11 +627,11 @@ func (c *apiClient) AccountMIRHistoryAll(ctx context.Context, stakeAddress strin
627627
}
628628
go func() {
629629
defer close(ch)
630-
fetchScripts := true
631-
for i := 1; fetchScripts; i++ {
630+
fetchNextPage := true
631+
for i := 1; fetchNextPage; i++ {
632632
select {
633633
case <-quit:
634-
fetchScripts = false
634+
fetchNextPage = false
635635
default:
636636
jobs <- methodOptions{ctx: ctx, query: APIQueryParams{Count: 100, Page: i}}
637637
}
@@ -698,11 +698,11 @@ func (c *apiClient) AccountAssociatedAddressesAll(ctx context.Context, stakeAddr
698698
}
699699
go func() {
700700
defer close(ch)
701-
fetchScripts := true
702-
for i := 1; fetchScripts; i++ {
701+
fetchNextPage := true
702+
for i := 1; fetchNextPage; i++ {
703703
select {
704704
case <-quit:
705-
fetchScripts = false
705+
fetchNextPage = false
706706
default:
707707
jobs <- methodOptions{ctx: ctx, query: APIQueryParams{Count: 100, Page: i}}
708708
}
@@ -770,11 +770,11 @@ func (c *apiClient) AccountAssociatedAssetsAll(ctx context.Context, stakeAddress
770770
}
771771
go func() {
772772
defer close(ch)
773-
fetchScripts := true
774-
for i := 1; fetchScripts; i++ {
773+
fetchNextPage := true
774+
for i := 1; fetchNextPage; i++ {
775775
select {
776776
case <-quit:
777-
fetchScripts = false
777+
fetchNextPage = false
778778
default:
779779
jobs <- methodOptions{ctx: ctx, query: APIQueryParams{Count: 100, Page: i}}
780780
}

api_addresses.go

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type Address struct {
2727
Amount []AddressAmount `json:"amount"`
2828

2929
// Stake address that controls the key
30-
StakeAddress string `json:"stake_address"`
30+
StakeAddress *string `json:"stake_address"`
3131

3232
// Address era.
3333
// Enum: "byron" "shelley"
@@ -62,6 +62,7 @@ type AddressTransactions struct {
6262
}
6363

6464
type AddressUTXO struct {
65+
Address string `json:"address"`
6566
// Transaction hash of the UTXO
6667
TxHash string `json:"tx_hash"`
6768

@@ -73,7 +74,10 @@ type AddressUTXO struct {
7374
Block string `json:"block"`
7475

7576
// The hash of the transaction output datum
76-
DataHash string `json:"data_hash"`
77+
DataHash *string `json:"data_hash"`
78+
79+
InlineDatum *string `json:"inline_datum"`
80+
ReferenceScriptHash *string `json:"reference_script_hash"`
7781
}
7882

7983
type AddressTxResult struct {
@@ -162,11 +166,11 @@ func (c *apiClient) AddressTransactionsAll(ctx context.Context, address string)
162166
}
163167
go func() {
164168
defer close(ch)
165-
fetchScripts := true
166-
for i := 1; fetchScripts; i++ {
169+
fetchNextPage := true
170+
for i := 1; fetchNextPage; i++ {
167171
select {
168172
case <-quit:
169-
fetchScripts = false
173+
fetchNextPage = false
170174
default:
171175
jobs <- methodOptions{ctx: ctx, query: APIQueryParams{Count: 100, Page: i}}
172176
}
@@ -253,11 +257,81 @@ func (c *apiClient) AddressUTXOsAll(ctx context.Context, address string) <-chan
253257
}
254258
go func() {
255259
defer close(ch)
256-
fetchScripts := true
257-
for i := 1; fetchScripts; i++ {
260+
fetchNextPage := true
261+
for i := 1; fetchNextPage; i++ {
262+
select {
263+
case <-quit:
264+
fetchNextPage = false
265+
default:
266+
jobs <- methodOptions{ctx: ctx, query: APIQueryParams{Count: 100, Page: i}}
267+
}
268+
}
269+
270+
close(jobs)
271+
wg.Wait()
272+
}()
273+
return ch
274+
}
275+
276+
func (c *apiClient) AddressUTXOsAsset(ctx context.Context, address, asset string, query APIQueryParams) (utxos []AddressUTXO, err error) {
277+
requestUrl, err := url.Parse(fmt.Sprintf("%s/%s/%s/%s/%s", c.server, resourceAddresses, address, resourceUTXOs, asset))
278+
if err != nil {
279+
return
280+
}
281+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, requestUrl.String(), nil)
282+
if err != nil {
283+
return
284+
}
285+
v := req.URL.Query()
286+
query.From = ""
287+
query.To = ""
288+
v = formatParams(v, query)
289+
req.URL.RawQuery = v.Encode()
290+
291+
res, err := c.handleRequest(req)
292+
if err != nil {
293+
return
294+
}
295+
defer res.Body.Close()
296+
297+
if err = json.NewDecoder(res.Body).Decode(&utxos); err != nil {
298+
return
299+
}
300+
return utxos, nil
301+
}
302+
303+
func (c *apiClient) AddressUTXOsAssetAll(ctx context.Context, address, asset string) <-chan AddressUTXOResult {
304+
ch := make(chan AddressUTXOResult, c.routines)
305+
jobs := make(chan methodOptions, c.routines)
306+
quit := make(chan bool, 1)
307+
308+
wg := sync.WaitGroup{}
309+
310+
for i := 0; i < c.routines; i++ {
311+
wg.Add(1)
312+
go func(jobs chan methodOptions, ch chan AddressUTXOResult, wg *sync.WaitGroup) {
313+
defer wg.Done()
314+
for j := range jobs {
315+
autxo, err := c.AddressUTXOsAsset(j.ctx, address, asset, j.query)
316+
if len(autxo) != j.query.Count || err != nil {
317+
select {
318+
case quit <- true:
319+
default:
320+
}
321+
}
322+
res := AddressUTXOResult{Res: autxo, Err: err}
323+
ch <- res
324+
}
325+
326+
}(jobs, ch, &wg)
327+
}
328+
go func() {
329+
defer close(ch)
330+
fetchNextPage := true
331+
for i := 1; fetchNextPage; i++ {
258332
select {
259333
case <-quit:
260-
fetchScripts = false
334+
fetchNextPage = false
261335
default:
262336
jobs <- methodOptions{ctx: ctx, query: APIQueryParams{Count: 100, Page: i}}
263337
}

api_addresses_test.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ var (
2323
const testdata = "testdata"
2424

2525
func TestAddressUnMarshall(t *testing.T) {
26+
stakeAddress := "stake1ux3u6x5cs388djqz6awnyuvez2f6n8jzjhqq59s4yxhm8jskeh0t9"
27+
2628
want := blockfrost.Address{
2729
Address: "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz",
2830
Amount: []blockfrost.AddressAmount{{Unit: "lovelace", Quantity: "0"}},
29-
StakeAddress: "stake1ux3u6x5cs388djqz6awnyuvez2f6n8jzjhqq59s4yxhm8jskeh0t9",
31+
StakeAddress: &stakeAddress,
3032
Type: "shelley",
3133
Script: false,
3234
}
@@ -66,7 +68,7 @@ func WriteGoldenFile(t *testing.T, path string, bytes []byte) {
6668

6769
func ReadOrGenerateGoldenFile(t *testing.T, path string, v interface{}) []byte {
6870
t.Helper()
69-
b, err := ioutil.ReadFile(path)
71+
b, err := os.ReadFile(path)
7072
switch {
7173
case errors.Is(err, os.ErrNotExist):
7274
if *generate {
@@ -152,3 +154,24 @@ func TestAddressUTXOs(t *testing.T) {
152154
var want []blockfrost.AddressUTXO
153155
testIntUtil(t, fp, &got, &want)
154156
}
157+
158+
func TestAddressUTXOsAsset(t *testing.T) {
159+
addr := "addr1q8zsjx7vxkl4esfejafhxthyew8c54c9ch95gkv3nz37sxrc9ty742qncmffaesxqarvqjmxmy36d9aht2duhmhvekgq3jd3w2"
160+
asset := "d436d9f6b754582f798fe33f4bed12133d47493f78b944b9cc55fd1853756d6d69744c6f64676534393539"
161+
162+
api := blockfrost.NewAPIClient(blockfrost.APIClientOptions{})
163+
164+
got, err := api.AddressUTXOsAsset(
165+
context.TODO(),
166+
addr,
167+
asset,
168+
blockfrost.APIQueryParams{},
169+
)
170+
if err != nil {
171+
t.Fatal(err)
172+
}
173+
174+
fp := filepath.Join(testdata, strings.ToLower(strings.TrimLeft(t.Name(), "Test"))+".golden")
175+
var want []blockfrost.AddressUTXO
176+
testIntUtil(t, fp, &got, &want)
177+
}

0 commit comments

Comments
 (0)