Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unlimited assets: backwards-compatible JSON encodings for account data #896

Merged
merged 4 commits into from
Feb 24, 2022
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
26 changes: 11 additions & 15 deletions idb/postgres/internal/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,15 +681,14 @@ func TrimLcAccountData(ad ledgercore.AccountData) ledgercore.AccountData {

func convertTrimmedLcAccountData(ad ledgercore.AccountData) baseAccountData {
return baseAccountData{
Status: ad.Status,
AuthAddr: crypto.Digest(ad.AuthAddr),
TotalAppSchemaNumUint: ad.TotalAppSchema.NumUint,
TotalAppSchemaNumByteSlice: ad.TotalAppSchema.NumByteSlice,
TotalExtraAppPages: ad.TotalExtraAppPages,
TotalAssetParams: ad.TotalAssetParams,
TotalAssets: ad.TotalAssets,
TotalAppParams: ad.TotalAppParams,
TotalAppLocalStates: ad.TotalAppLocalStates,
Status: ad.Status,
AuthAddr: crypto.Digest(ad.AuthAddr),
TotalAppSchema: ad.TotalAppSchema,
TotalExtraAppPages: ad.TotalExtraAppPages,
TotalAssetParams: ad.TotalAssetParams,
TotalAssets: ad.TotalAssets,
TotalAppParams: ad.TotalAppParams,
TotalAppLocalStates: ad.TotalAppLocalStates,
baseOnlineAccountData: baseOnlineAccountData{
VoteID: ad.VoteID,
SelectionID: ad.SelectionID,
Expand All @@ -704,12 +703,9 @@ func convertTrimmedLcAccountData(ad ledgercore.AccountData) baseAccountData {
func unconvertTrimmedLcAccountData(ba baseAccountData) ledgercore.AccountData {
return ledgercore.AccountData{
AccountBaseData: ledgercore.AccountBaseData{
Status: ba.Status,
AuthAddr: basics.Address(ba.AuthAddr),
TotalAppSchema: basics.StateSchema{
NumUint: ba.TotalAppSchemaNumUint,
NumByteSlice: ba.TotalAppSchemaNumByteSlice,
},
Status: ba.Status,
AuthAddr: basics.Address(ba.AuthAddr),
TotalAppSchema: ba.TotalAppSchema,
TotalExtraAppPages: ba.TotalExtraAppPages,
TotalAppParams: ba.TotalAppParams,
TotalAppLocalStates: ba.TotalAppLocalStates,
Expand Down
2 changes: 1 addition & 1 deletion idb/postgres/internal/encoding/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ func TestLcAccountDataEncoding(t *testing.T) {
}
buf := EncodeTrimmedLcAccountData(ad)

expectedString := `{"A":"DgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","B":"DwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","C":"EwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==","D":16,"E":17,"F":18,"a":1,"b":"BgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","c":7,"d":8,"e":9,"f":12,"g":13,"h":10,"i":11}`
expectedString := `{"onl":1,"sel":"DwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","spend":"BgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","stprf":"EwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==","tapl":11,"tapp":10,"tas":13,"tasp":12,"teap":9,"tsch":{"nbs":8,"nui":7},"vote":"DgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","voteFst":16,"voteKD":18,"voteLst":17}`
assert.Equal(t, expectedString, string(buf))

decodedAd, err := DecodeTrimmedLcAccountData(buf)
Expand Down
29 changes: 14 additions & 15 deletions idb/postgres/internal/encoding/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,26 +111,25 @@ type specialAddresses struct {
type baseOnlineAccountData struct {
_struct struct{} `codec:",omitempty,omitemptyarray"`

VoteID crypto.OneTimeSignatureVerifier `codec:"A"`
SelectionID crypto.VRFVerifier `codec:"B"`
StateProofID merklesignature.Verifier `codec:"C"`
VoteFirstValid basics.Round `codec:"D"`
VoteLastValid basics.Round `codec:"E"`
VoteKeyDilution uint64 `codec:"F"`
VoteID crypto.OneTimeSignatureVerifier `codec:"vote"`
SelectionID crypto.VRFVerifier `codec:"sel"`
StateProofID merklesignature.Verifier `codec:"stprf"`
VoteFirstValid basics.Round `codec:"voteFst"`
VoteLastValid basics.Round `codec:"voteLst"`
VoteKeyDilution uint64 `codec:"voteKD"`
}

type baseAccountData struct {
_struct struct{} `codec:",omitempty,omitemptyarray"`

Status basics.Status `codec:"a"`
AuthAddr crypto.Digest `codec:"b"`
TotalAppSchemaNumUint uint64 `codec:"c"`
TotalAppSchemaNumByteSlice uint64 `codec:"d"`
TotalExtraAppPages uint32 `codec:"e"`
TotalAssetParams uint64 `codec:"f"`
TotalAssets uint64 `codec:"g"`
TotalAppParams uint64 `codec:"h"`
TotalAppLocalStates uint64 `codec:"i"`
Status basics.Status `codec:"onl"`
AuthAddr crypto.Digest `codec:"spend"`
TotalAppSchema basics.StateSchema `codec:"tsch"`
TotalExtraAppPages uint32 `codec:"teap"`
TotalAssetParams uint64 `codec:"tasp"`
TotalAssets uint64 `codec:"tas"`
TotalAppParams uint64 `codec:"tapp"`
TotalAppLocalStates uint64 `codec:"tapl"`

baseOnlineAccountData
}
2 changes: 1 addition & 1 deletion idb/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -1774,7 +1774,7 @@ func (db *IndexerDb) buildAccountQuery(opts idb.AccountQueryOptions) (query stri
whereParts = append(whereParts, "coalesce(a.deleted, false) = false")
}
if len(opts.EqualToAuthAddr) > 0 {
whereParts = append(whereParts, fmt.Sprintf("a.account_data ->> 'b' = $%d", partNumber))
whereParts = append(whereParts, fmt.Sprintf("a.account_data ->> 'spend' = $%d", partNumber))
whereArgs = append(whereArgs, encoding.Base64(opts.EqualToAuthAddr))
partNumber++
}
Expand Down