Skip to content

Commit f31c0f5

Browse files
committed
Add v1Only flag to enforce fallback to V1 logic for NFD lookups and update dependencies
1 parent 93950a2 commit f31c0f5

3 files changed

Lines changed: 81 additions & 62 deletions

File tree

nfd-display/go.mod

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
module nfd-display
22

3-
go 1.21
4-
5-
toolchain go1.22.6
3+
go 1.25
64

75
require (
8-
github.com/algorand/go-algorand-sdk/v2 v2.6.0
9-
github.com/mailgun/holster/v4 v4.12.4
6+
github.com/algorand/go-algorand-sdk/v2 v2.9.0
7+
github.com/mailgun/holster/v4 v4.21.0
108
)
119

1210
require (
13-
github.com/algorand/go-codec/codec v1.1.10 // indirect
14-
github.com/google/go-querystring v1.0.0 // indirect
15-
golang.org/x/crypto v0.27.0 // indirect
11+
github.com/algorand/go-codec/codec v1.1.10 // indirect; indirects
12+
github.com/google/go-querystring v1.1.0 // indirect
13+
golang.org/x/crypto v0.38.0 // indirect
1614
)

nfd-display/go.sum

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
github.com/ahmetb/go-linq v3.0.0+incompatible h1:qQkjjOXKrKOTy83X8OpRmnKflXKQIL/mC/gMVVDMhOA=
22
github.com/ahmetb/go-linq v3.0.0+incompatible/go.mod h1:PFffvbdbtw+QTB0WKRP0cNht7vnCfnGlEpak/DVg5cY=
3-
github.com/algorand/go-algorand-sdk/v2 v2.6.0 h1:pfL8lloEi26l6PwAFicmPUguWgKpy1eZZTMlQcci5h0=
4-
github.com/algorand/go-algorand-sdk/v2 v2.6.0/go.mod h1:4ayerzjoWChm3kuVhbgFgURTbaYTtlj0c41eP3av5lw=
3+
github.com/algorand/go-algorand-sdk/v2 v2.9.0 h1:LBrhty+l1+QK+rbRU5j5ZFDUlZqGj72VhxupnLv00y8=
4+
github.com/algorand/go-algorand-sdk/v2 v2.9.0/go.mod h1:HyHp1eXomxHy4Kh1pDwTvFo5SQGsxVbYHDAekwD5/uI=
55
github.com/algorand/go-codec/codec v1.1.10 h1:zmWYU1cp64jQVTOG8Tw8wa+k0VfwgXIPbnDfiVa+5QA=
66
github.com/algorand/go-codec/codec v1.1.10/go.mod h1:YkEx5nmr/zuCeaDYOIhlDg92Lxju8tj2d2NrYqP7g7k=
77
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
88
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9-
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
10-
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
11-
github.com/mailgun/holster/v4 v4.12.4 h1:U9wHgacx+s1/mPhl9ELMhdnMofg2HZHBmeMWnur3HJ0=
12-
github.com/mailgun/holster/v4 v4.12.4/go.mod h1:s2H6HX3iMCub1K1Y7qjf0RgpzS2+mRxyj+i3vlb4FK0=
9+
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
10+
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
11+
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
12+
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
13+
github.com/mailgun/holster/v4 v4.21.0 h1:EH3fwKEGv56WA5gUwxjOTqZbeILY+oJ/VWEo1xku7t8=
14+
github.com/mailgun/holster/v4 v4.21.0/go.mod h1:G06Q741dj+zsH1WFrmoFvih3LtaocvBIoNtxITdWEtg=
1315
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
1416
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
1517
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1618
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
17-
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
18-
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
19-
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
20-
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
19+
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
20+
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
21+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
22+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
2123
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
2224
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
2325
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
24-
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
25-
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
26+
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
27+
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
2628
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
2729
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
2830
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
@@ -34,8 +36,8 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
3436
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3537
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3638
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
37-
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
38-
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
39+
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
40+
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
3941
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
4042
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
4143
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
@@ -46,6 +48,7 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
4648
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
4749
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
4850
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
51+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
4952
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
5053
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
5154
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

nfd-display/main.go

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ type NFDProperties struct {
4141
Verified map[string]string `json:"verified"`
4242
}
4343

44+
var v1Only = flag.Bool("v1Only", false, "Only do v1 check")
45+
4446
func main() {
4547
var (
4648
ctx = context.Background()
@@ -174,18 +176,20 @@ func GetApplicationBoxes(ctx context.Context, appID uint64) (map[string][]byte,
174176
}
175177

176178
func FindNFDAppIDByName(ctx context.Context, nfdName string) (uint64, error) {
177-
// First try to resolve via V2
178-
boxValue, err := algoClient.GetApplicationBoxByName(registryAppID, GetRegistryBoxNameForNFD(nfdName)).Do(ctx)
179-
if err == nil {
180-
// The box data is stored as
181-
// {ASA ID}{APP ID} - packed 64-bit ints
182-
if len(boxValue.Value) != 16 {
183-
return 0, fmt.Errorf("box data is invalid - length:%d but should be 16 for nfd name:%s", len(boxValue.Value), nfdName)
179+
if !*v1Only {
180+
// First try to resolve via V2
181+
boxValue, err := algoClient.GetApplicationBoxByName(registryAppID, GetRegistryBoxNameForNFD(nfdName)).Do(ctx)
182+
if err == nil {
183+
// The box data is stored as
184+
// {ASA ID}{APP ID} - packed 64-bit ints
185+
if len(boxValue.Value) != 16 {
186+
return 0, fmt.Errorf("box data is invalid - length:%d but should be 16 for nfd name:%s", len(boxValue.Value), nfdName)
187+
}
188+
asaID := binary.BigEndian.Uint64(boxValue.Value[0:8])
189+
appID := binary.BigEndian.Uint64(boxValue.Value[8:])
190+
fmt.Printf("Found as V2 name, ASA ID:%d, APP ID:%d\n", asaID, appID)
191+
return appID, nil
184192
}
185-
asaID := binary.BigEndian.Uint64(boxValue.Value[0:8])
186-
appID := binary.BigEndian.Uint64(boxValue.Value[8:])
187-
fmt.Printf("Found as V2 name, ASA ID:%d, APP ID:%d\n", asaID, appID)
188-
return appID, nil
189193
}
190194
// fall back to V1 approach
191195
nameLSIG, err := GetNFDSigNameLSIG(nfdName, registryAppID)
@@ -223,6 +227,15 @@ func FindNfdsOwnedByAddress(ctx context.Context, lookupAddress string) ([]uint64
223227
if err != nil {
224228
return nil, err
225229
}
230+
// prefixToFind := GetAccountOwnsNfdBoxName(lookupAddr)
231+
// prefixToFindBase64 := base64.URLEncoding.EncodeToString(prefixToFind)
232+
// boxes, err := algoClient.GetApplicationBoxes(registryAppID).
233+
// Prefix(fmt.Sprintf("b64:%s", prefixToFindBase64)).
234+
// Values(true).
235+
// Do(ctx)
236+
// if err != nil {
237+
// return nil, fmt.Errorf("failed to get boxes for registry: %w", err)
238+
// }
226239
prefixToFind := GetAccountOwnsNfdBoxName(lookupAddr, 0)[:33] // grab first 33 bytes only
227240
for _, box := range boxes.Boxes {
228241
if bytes.HasPrefix(box.Name, prefixToFind) {
@@ -241,40 +254,45 @@ func FindNFDAppIDsByAddress(ctx context.Context, lookupAddress string) ([]uint64
241254
return nil, err
242255
}
243256

244-
// First try to resolve via V2
245-
boxValue, err := algoClient.GetApplicationBoxByName(registryAppID, GetRegistryBoxNameForAddress(algoAddress)).Do(ctx)
246-
if err == nil {
247-
// Get the set of nfd app ids referenced by this address - we just grab the first for now
248-
nfdAppIDs, err = FetchUInt64sFromPackedValue(boxValue.Value)
249-
if err != nil {
250-
return nil, fmt.Errorf("box address lookup data is invalid, error: %w", err)
251-
}
252-
fmt.Printf("Found %d NFDs linked as V2 address\n", len(nfdAppIDs))
253-
} else {
254-
// error should be 404 not found and checked, but this is simple example, so... assume it's just not found
255-
// fall back to V1 approach
256-
revAddressLSIG, err := GetNFDSigRevAddressLSIG(algoAddress, registryAppID)
257-
if err != nil {
258-
return nil, fmt.Errorf("failed to get nfd sig name lsig: %w", err)
257+
if !*v1Only {
258+
// First try to resolve via V2
259+
boxValue, err := algoClient.GetApplicationBoxByName(registryAppID, GetRegistryBoxNameForAddress(algoAddress)).Do(ctx)
260+
if err == nil {
261+
// Get the set of nfd app ids referenced by this address - we just grab the first for now
262+
nfdAppIDs, err = FetchUInt64sFromPackedValue(boxValue.Value)
263+
if err != nil {
264+
return nil, fmt.Errorf("box address lookup data is invalid, error: %w", err)
265+
}
266+
fmt.Printf("Found %d NFDs linked as V2 address\n", len(nfdAppIDs))
259267
}
260-
// Read the local state for our registry SC from this specific account
261-
address, _ := revAddressLSIG.Address()
262-
fmt.Printf("V1 LSIG Rev-Address used:%s\n", address.String())
263-
account, err := algoClient.AccountApplicationInformation(address.String(), registryAppID).Do(ctx)
264-
if err != nil {
265-
return nil, nil
268+
if len(nfdAppIDs) == 0 {
269+
return nil, fmt.Errorf("no NFDs found for this address")
266270
}
271+
return nfdAppIDs, nil
272+
}
273+
// error should be 404 not found and checked, but this is simple example, so... assume it's just not found
274+
// fall back to V1 approach
275+
revAddressLSIG, err := GetNFDSigRevAddressLSIG(algoAddress, registryAppID)
276+
if err != nil {
277+
return nil, fmt.Errorf("failed to get nfd sig name lsig: %w", err)
278+
}
279+
// Read the local state for our registry SC from this specific account
280+
address, _ := revAddressLSIG.Address()
281+
fmt.Printf("V1 LSIG Rev-Address used:%s\n", address.String())
282+
account, err := algoClient.AccountApplicationInformation(address.String(), registryAppID).Do(ctx)
283+
if err != nil {
284+
return nil, nil
285+
}
267286

268-
// We found our registry contract in the local state of the account
269-
for idx := 0; idx < 16; idx++ {
270-
thisKeyIDs, _ := FetchUint64sFromState(account.AppLocalState.KeyValue, fmt.Sprintf("i.apps%d", idx))
271-
if thisKeyIDs == nil {
272-
break
273-
}
274-
nfdAppIDs = append(nfdAppIDs, thisKeyIDs...)
287+
// We found our registry contract in the local state of the account
288+
for idx := 0; idx < 16; idx++ {
289+
thisKeyIDs, _ := FetchUint64sFromState(account.AppLocalState.KeyValue, fmt.Sprintf("i.apps%d", idx))
290+
if thisKeyIDs == nil {
291+
break
275292
}
276-
fmt.Printf("Found %d NFDs linked as V1 address\n", len(nfdAppIDs))
293+
nfdAppIDs = append(nfdAppIDs, thisKeyIDs...)
277294
}
295+
fmt.Printf("Found %d NFDs linked as V1 address\n", len(nfdAppIDs))
278296
if len(nfdAppIDs) == 0 {
279297
return nil, fmt.Errorf("no NFDs found for this address")
280298
}

0 commit comments

Comments
 (0)