Skip to content

Commit

Permalink
Potential fix for panic on call to block w/ group resource sharing.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmalouf committed Dec 31, 2023
1 parent 9ef21ad commit d1008ac
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions api/converter_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,20 +518,16 @@ func signedTxnWithAdToTransaction(stxn *sdk.SignedTxnWithAD, extra rowData) (gen
}
if len(stxn.ApplyData.EvalDelta.LocalDeltas) > 0 {
keys := make([]tuple, 0)

for k := range stxn.ApplyData.EvalDelta.LocalDeltas {
if k == 0 {
keys = append(keys, tuple{
key: 0,
address: stxn.Txn.Sender,
})
} else {
addr := sdk.Address{}
copy(addr[:], stxn.Txn.Accounts[k-1][:])
keys = append(keys, tuple{
key: k,
address: addr,
})
addr, err := edIndexToAddress(k, stxn.Txn, stxn.ApplyData.EvalDelta.SharedAccounts)

Check failure on line 523 in api/converter_utils.go

View workflow job for this annotation

GitHub Actions / reviewdog-warnings

[Lint Warnings] reported by reviewdog 🐶 stxn.ApplyData.EvalDelta.SharedAccounts undefined (type "github.com/algorand/go-algorand-sdk/v2/types".EvalDelta has no field or method SharedAccounts)) (typecheck) Raw Output: api/converter_utils.go:523:72: stxn.ApplyData.EvalDelta.SharedAccounts undefined (type "github.com/algorand/go-algorand-sdk/v2/types".EvalDelta has no field or method SharedAccounts)) (typecheck) "github.com/algorand/indexer/v3/api" ^

Check failure on line 523 in api/converter_utils.go

View workflow job for this annotation

GitHub Actions / reviewdog-warnings

[Lint Warnings] reported by reviewdog 🐶 stxn.ApplyData.EvalDelta.SharedAccounts undefined (type "github.com/algorand/go-algorand-sdk/v2/types".EvalDelta has no field or method SharedAccounts)) (typecheck) Raw Output: api/converter_utils.go:523:72: stxn.ApplyData.EvalDelta.SharedAccounts undefined (type "github.com/algorand/go-algorand-sdk/v2/types".EvalDelta has no field or method SharedAccounts)) (typecheck) "github.com/algorand/indexer/v3/api" ^
if err != nil {
return generated.Transaction{}, err
}
keys = append(keys, tuple{
key: k,
address: addr,
})
}
sort.Slice(keys, func(i, j int) bool { return keys[i].key < keys[j].key })
d := make([]generated.AccountStateDelta, 0)
Expand Down Expand Up @@ -629,6 +625,20 @@ func signedTxnWithAdToTransaction(stxn *sdk.SignedTxnWithAD, extra rowData) (gen
return txn, nil
}

func edIndexToAddress(index uint64, txn sdk.Transaction, shared []sdk.Address) (sdk.Address, error) {
// index into [Sender, txn.Accounts[0], txn.Accounts[1], ..., shared[0], shared[1], ...]
switch {
case index == 0:
return txn.Sender, nil
case int(index-1) < len(txn.Accounts):
return txn.Accounts[index-1], nil
case int(index-1)-len(txn.Accounts) < len(shared):
return shared[int(index-1)-len(txn.Accounts)], nil
default:
return sdk.Address{}, fmt.Errorf("invalid Account Index %d in LocalDelta", index)
}
}

func (si *ServerImplementation) assetParamsToAssetQuery(params generated.SearchForAssetsParams) (idb.AssetsQuery, error) {
creator, errorArr := decodeAddress(params.Creator, "creator", make([]string, 0))
if len(errorArr) != 0 {
Expand Down

0 comments on commit d1008ac

Please sign in to comment.