Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Below is a snippet of the output from `algorand-indexer api-config`:
optional:
- currency-greater-than: disabled
- currency-less-than: disabled
- online-only: disabled
/v2/assets/{asset-id}/transactions:
optional:
- note-prefix: disabled
Expand Down
6 changes: 6 additions & 0 deletions accounting/rewind.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,21 @@ func AccountAtRound(ctx context.Context, account models.Account, round uint64, d
return
}
}

acct.Round = round

// Due to accounts being closed and re-opened, we cannot always rewind Rewards. So clear it out.
acct.Rewards = 0

// Computing pending rewards is not supported.
acct.PendingRewards = 0
acct.Amount = acct.AmountWithoutPendingRewards

// MinBalance is not supported.
acct.MinBalance = 0

// TODO: Clear out the closed-at field as well. Like Rewards we cannot know this value for all accounts.
//acct.ClosedAt = 0

return
}
80 changes: 80 additions & 0 deletions accounting/rewind_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package accounting

import (
"context"
"errors"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

models "github.com/algorand/indexer/v3/api/generated/v2"
"github.com/algorand/indexer/v3/idb"
"github.com/algorand/indexer/v3/idb/mocks"
"github.com/algorand/indexer/v3/types"

sdk "github.com/algorand/go-algorand-sdk/v2/types"
)

func TestBasic(t *testing.T) {
var a sdk.Address
a[0] = 'a'

account := models.Account{
Address: a.String(),
Amount: 100,
AmountWithoutPendingRewards: 100,
Round: 8,
}

txnRow := idb.TxnRow{
Round: 7,
Txn: &sdk.SignedTxnWithAD{
SignedTxn: sdk.SignedTxn{
Txn: sdk.Transaction{
Type: sdk.PaymentTx,
PaymentTxnFields: sdk.PaymentTxnFields{
Receiver: a,
Amount: sdk.MicroAlgos(2),
},
},
},
},
}

ch := make(chan idb.TxnRow, 1)
ch <- txnRow
close(ch)
var outCh <-chan idb.TxnRow = ch

db := &mocks.IndexerDb{}
db.On("GetSpecialAccounts", mock.Anything).Return(types.SpecialAddresses{}, nil)
db.On("Transactions", mock.Anything, mock.Anything).Return(outCh, uint64(8))

account, err := AccountAtRound(context.Background(), account, 6, db)
assert.NoError(t, err)

assert.Equal(t, uint64(98), account.Amount)
}

// Test that when idb.Transactions() returns stale data the first time, we return an error.
func TestStaleTransactions1(t *testing.T) {
var a sdk.Address
a[0] = 'a'

account := models.Account{
Address: a.String(),
Round: 8,
}

ch := make(chan idb.TxnRow)
var outCh <-chan idb.TxnRow = ch
close(ch)

db := &mocks.IndexerDb{}
db.On("GetSpecialAccounts", mock.Anything).Return(types.SpecialAddresses{}, nil)
db.On("Transactions", mock.Anything, mock.Anything).Return(outCh, uint64(7)).Once()

account, err := AccountAtRound(context.Background(), account, 6, db)
assert.True(t, errors.As(err, &ConsistencyError{}), "err: %v", err)
}
2 changes: 1 addition & 1 deletion api/disabled_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func GetDefaultDisabledMapConfigForPostgres() *DisabledMapConfig {
rval.addEntry(restPath, http.MethodGet, parameterNames)
}

get("/v2/accounts", []string{"currency-greater-than", "currency-less-than"})
get("/v2/accounts", []string{"currency-greater-than", "currency-less-than", "online-only"})
get("/v2/accounts/{account-id}/transactions", []string{"note-prefix", "tx-type", "sig-type", "asset-id", "before-time", "after-time", "rekey-to"})
get("/v2/assets", []string{"name", "unit"})
get("/v2/assets/{asset-id}/balances", []string{"currency-greater-than", "currency-less-than"})
Expand Down
2 changes: 2 additions & 0 deletions api/error_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const (
ErrMultipleBoxes = "multiple application boxes found for this app id and box name, please contact us, this shouldn't happen"
ErrFailedLookingUpBoxes = "failed while looking up application boxes"
errMultiAcctRewind = "multiple accounts rewind is not supported by this server"
errOnlineOnlyRewind = "simultaneously rewinding and searching for online accounts is not supported"
errOnlineOnlyDeleted = "simultaneously searching for online and deleted accounts is not supported"
errRewindingAccount = "error while rewinding account"
errLookingUpBlockForRound = "error while looking up block for round"
errBlockHeaderSearch = "error while searching for block headers"
Expand Down
343 changes: 172 additions & 171 deletions api/generated/common/routes.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions api/generated/common/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading