Skip to content

Commit

Permalink
Add absent parameter to GET /v2/blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
agodnic committed Oct 18, 2024
1 parent 56adbcd commit 92b57ad
Show file tree
Hide file tree
Showing 11 changed files with 494 additions and 415 deletions.
9 changes: 9 additions & 0 deletions api/converter_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,15 @@ func (si *ServerImplementation) blockParamsToBlockFilter(params generated.Search
filter.ExpiredParticipationAccounts[addr] = struct{}{}
}
}

filter.AbsentParticipationAccounts = make(map[sdk.Address]struct{}, 0)
if params.Absent != nil {
for _, s := range *params.Absent {
var addr sdk.Address
addr, errorArr = decodeSdkAddress(s, "absent", errorArr)
filter.AbsentParticipationAccounts[addr] = struct{}{}
}
}
}

// If there were any errorArr while setting up the BlockFilter, return now.
Expand Down
368 changes: 184 additions & 184 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.

463 changes: 235 additions & 228 deletions api/generated/v2/routes.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions api/generated/v2/types.go

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

14 changes: 14 additions & 0 deletions api/indexer.oas2.json
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,9 @@
},
{
"$ref": "#/parameters/expired"
},
{
"$ref": "#/parameters/absent"
}
],
"responses": {
Expand Down Expand Up @@ -2732,6 +2735,17 @@
}
},
"parameters": {
"absent": {
"type": "array",
"items": {
"type": "string",
"x-algorand-format": "Address"
},
"description": "Absent participation accounts. Comma separated list of addresses.",
"name": "absent",
"in": "query",
"required": false
},
"expired": {
"type": "array",
"items": {
Expand Down
28 changes: 28 additions & 0 deletions api/indexer.oas3.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
{
"components": {
"parameters": {
"absent": {
"description": "Absent participation accounts. Comma separated list of addresses.",
"explode": false,
"in": "query",
"name": "absent",
"schema": {
"items": {
"type": "string",
"x-algorand-format": "Address"
},
"type": "array"
},
"style": "form"
},
"account-id": {
"description": "account string",
"in": "path",
Expand Down Expand Up @@ -4917,6 +4931,20 @@
"type": "array"
},
"style": "form"
},
{
"description": "Absent participation accounts. Comma separated list of addresses.",
"explode": false,
"in": "query",
"name": "absent",
"schema": {
"items": {
"type": "string",
"x-algorand-format": "Address"
},
"type": "array"
},
"style": "form"
}
],
"responses": {
Expand Down
1 change: 1 addition & 0 deletions idb/idb.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ type BlockFilter struct {
BeforeTime time.Time
Proposers map[sdk.Address]struct{}
ExpiredParticipationAccounts map[sdk.Address]struct{}
AbsentParticipationAccounts map[sdk.Address]struct{}
}

// TransactionFilter is a parameter object with all the transaction filter options.
Expand Down
3 changes: 2 additions & 1 deletion idb/postgres/internal/schema/setup_postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ CREATE TABLE public.block_header (
CONSTRAINT block_header_pkey PRIMARY KEY (round ASC),
INDEX block_header_time (realtime ASC),
INDEX block_header_idx_proposer (((header->'prp')::TEXT), round) WHERE (header->'prp') IS NOT NULL,
INVERTED INDEX block_header_expired ((header->'partupdrmv')) WHERE (header->'partupdrmv' IS NOT NULL)
INVERTED INDEX block_header_expired ((header->'partupdrmv')) WHERE (header->'partupdrmv' IS NOT NULL),
INVERTED INDEX block_header_absent ((header->'partupdabs')) WHERE (header->'partupdabs' IS NOT NULL)
);

CREATE TABLE public.txn (
Expand Down
4 changes: 2 additions & 2 deletions idb/postgres/internal/schema/setup_postgres_sql.go

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

10 changes: 10 additions & 0 deletions idb/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,16 @@ func buildBlockQuery(bf idb.BlockFilter) (query string, whereArgs []interface{},
fmt.Sprintf("( (header->'partupdrmv') IS NOT NULL AND (header->'partupdrmv') ?| array[%s] )", strings.Join(expiredStr, ",")),
)
}
if len(bf.AbsentParticipationAccounts) > 0 {
var absentStr []string
for addr := range bf.AbsentParticipationAccounts {
absentStr = append(absentStr, `'`+addr.String()+`'`)
}
whereParts = append(
whereParts,
fmt.Sprintf("( (header->'partupdabs') IS NOT NULL AND (header->'partupdabs') ?| array[%s] )", strings.Join(absentStr, ",")),
)
}
}

// SELECT, FROM
Expand Down

0 comments on commit 92b57ad

Please sign in to comment.