/
arcs.go
66 lines (55 loc) · 1.48 KB
/
arcs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package aegirdungeons
import (
"context"
"encoding/json"
"errors"
"github.com/algorand/go-algorand-sdk/client/v2/indexer"
"github.com/algorand/go-algorand-sdk/types"
)
// ErrMetadataNotFound ...
var ErrMetadataNotFound = errors.New("metadata: no metadata found in transaction history")
// Arc69 ...
type Arc69 struct {
Standard string `json:"standard"`
Description string `json:"description"`
ExternalURL string `json:"external_url"`
MimeType string `json:"mime_type"`
Properties Properties `json:"properties"`
}
// Properties ...
type Properties struct {
Level string `json:"Level"`
Rarity string `json:"Rarity"`
}
func FetchArc69Metadata(ctx context.Context, ai *indexer.Client, asaID uint64, senderAddr string) (uint64, Arc69, error) {
nextToken := ""
var tempNote Arc69
var note Arc69
var highestRound uint64
for {
txnResp, err := ai.LookupAssetTransactions(asaID).TxType(string(types.AssetConfigTx)).NextToken(nextToken).Do(ctx)
if err != nil {
return highestRound, note, err
}
for _, txn := range txnResp.Transactions {
if err := json.Unmarshal(txn.Note, &tempNote); err != nil {
continue
}
if tempNote.Standard != "arc69" {
continue
}
if highestRound < txn.ConfirmedRound {
highestRound = txn.ConfirmedRound
note = tempNote
}
}
nextToken = txnResp.NextToken
if nextToken == "" {
break
}
}
if highestRound == 0 {
return highestRound, note, ErrMetadataNotFound
}
return highestRound, note, nil
}