Skip to content

Commit 97b0ad2

Browse files
authored
Merge pull request #17 from AlgoNode/sync-with-upstream
Sync with upstream
2 parents 90bf029 + c241596 commit 97b0ad2

File tree

23 files changed

+748
-398
lines changed

23 files changed

+748
-398
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ Below is a snippet of the output from `algorand-indexer api-config`:
110110
optional:
111111
- currency-greater-than: disabled
112112
- currency-less-than: disabled
113+
- online-only: disabled
113114
/v2/assets/{asset-id}/transactions:
114115
optional:
115116
- note-prefix: disabled

accounting/rewind.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,21 @@ func AccountAtRound(ctx context.Context, account models.Account, round uint64, d
165165
return
166166
}
167167
}
168+
168169
acct.Round = round
170+
169171
// Due to accounts being closed and re-opened, we cannot always rewind Rewards. So clear it out.
170172
acct.Rewards = 0
173+
171174
// Computing pending rewards is not supported.
172175
acct.PendingRewards = 0
173176
acct.Amount = acct.AmountWithoutPendingRewards
177+
174178
// MinBalance is not supported.
175179
acct.MinBalance = 0
180+
176181
// TODO: Clear out the closed-at field as well. Like Rewards we cannot know this value for all accounts.
177182
//acct.ClosedAt = 0
183+
178184
return
179185
}

accounting/rewind_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package accounting
2+
3+
import (
4+
"context"
5+
"errors"
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/mock"
10+
11+
models "github.com/algorand/indexer/v3/api/generated/v2"
12+
"github.com/algorand/indexer/v3/idb"
13+
"github.com/algorand/indexer/v3/idb/mocks"
14+
"github.com/algorand/indexer/v3/types"
15+
16+
sdk "github.com/algorand/go-algorand-sdk/v2/types"
17+
)
18+
19+
func TestBasic(t *testing.T) {
20+
var a sdk.Address
21+
a[0] = 'a'
22+
23+
account := models.Account{
24+
Address: a.String(),
25+
Amount: 100,
26+
AmountWithoutPendingRewards: 100,
27+
Round: 8,
28+
}
29+
30+
txnRow := idb.TxnRow{
31+
Round: 7,
32+
Txn: &sdk.SignedTxnWithAD{
33+
SignedTxn: sdk.SignedTxn{
34+
Txn: sdk.Transaction{
35+
Type: sdk.PaymentTx,
36+
PaymentTxnFields: sdk.PaymentTxnFields{
37+
Receiver: a,
38+
Amount: sdk.MicroAlgos(2),
39+
},
40+
},
41+
},
42+
},
43+
}
44+
45+
ch := make(chan idb.TxnRow, 1)
46+
ch <- txnRow
47+
close(ch)
48+
var outCh <-chan idb.TxnRow = ch
49+
50+
db := &mocks.IndexerDb{}
51+
db.On("GetSpecialAccounts", mock.Anything).Return(types.SpecialAddresses{}, nil)
52+
db.On("Transactions", mock.Anything, mock.Anything).Return(outCh, uint64(8))
53+
54+
account, err := AccountAtRound(context.Background(), account, 6, db)
55+
assert.NoError(t, err)
56+
57+
assert.Equal(t, uint64(98), account.Amount)
58+
}
59+
60+
// Test that when idb.Transactions() returns stale data the first time, we return an error.
61+
func TestStaleTransactions1(t *testing.T) {
62+
var a sdk.Address
63+
a[0] = 'a'
64+
65+
account := models.Account{
66+
Address: a.String(),
67+
Round: 8,
68+
}
69+
70+
ch := make(chan idb.TxnRow)
71+
var outCh <-chan idb.TxnRow = ch
72+
close(ch)
73+
74+
db := &mocks.IndexerDb{}
75+
db.On("GetSpecialAccounts", mock.Anything).Return(types.SpecialAddresses{}, nil)
76+
db.On("Transactions", mock.Anything, mock.Anything).Return(outCh, uint64(7)).Once()
77+
78+
account, err := AccountAtRound(context.Background(), account, 6, db)
79+
assert.True(t, errors.As(err, &ConsistencyError{}), "err: %v", err)
80+
}

api/disabled_parameters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func GetDefaultDisabledMapConfigForPostgres() *DisabledMapConfig {
317317
rval.addEntry(restPath, http.MethodGet, parameterNames)
318318
}
319319

320-
get("/v2/accounts", []string{"currency-greater-than", "currency-less-than"})
320+
get("/v2/accounts", []string{"currency-greater-than", "currency-less-than", "online-only"})
321321
get("/v2/accounts/{account-id}/transactions", []string{"note-prefix", "tx-type", "sig-type", "asset-id", "before-time", "after-time", "rekey-to"})
322322
get("/v2/assets", []string{"name", "unit"})
323323
get("/v2/assets/{asset-id}/balances", []string{"currency-greater-than", "currency-less-than"})

api/error_messages.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const (
3939
ErrMultipleBoxes = "multiple application boxes found for this app id and box name, please contact us, this shouldn't happen"
4040
ErrFailedLookingUpBoxes = "failed while looking up application boxes"
4141
errMultiAcctRewind = "multiple accounts rewind is not supported by this server"
42+
errOnlineOnlyRewind = "simultaneously rewinding and searching for online accounts is not supported"
43+
errOnlineOnlyDeleted = "simultaneously searching for online and deleted accounts is not supported"
4244
errRewindingAccount = "error while rewinding account"
4345
errLookingUpBlockForRound = "error while looking up block for round"
4446
errBlockHeaderSearch = "error while searching for block headers"

api/generated/common/routes.go

Lines changed: 172 additions & 171 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/generated/common/types.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)