@@ -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+
4446func main () {
4547 var (
4648 ctx = context .Background ()
@@ -174,18 +176,20 @@ func GetApplicationBoxes(ctx context.Context, appID uint64) (map[string][]byte,
174176}
175177
176178func 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