Commit 5776a5c9 authored by mergify[bot]'s avatar mergify[bot] Committed by GitHub

Merge branch 'develop' into feat/remove-hive

parents 5c05a20d 99a78268
......@@ -880,7 +880,7 @@ jobs:
patterns: indexer
- run:
name: Lint
command: golangci-lint run -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 2m -e "errors.As" -e "errors.Is" ./...
command: golangci-lint run -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 4m -e "errors.As" -e "errors.Is" ./...
working_directory: indexer
- run:
name: install geth
......
package jsonutil
import (
"encoding/json"
"fmt"
"sort"
)
// LazySortedJsonMap provides sorted encoding order for JSON maps.
// The sorting is lazy: in-memory it's just a map, until it sorts just-in-time when the map is encoded to JSON.
// Warning: the just-in-time sorting requires a full allocation of the map structure and keys slice during encoding.
// Sorting order is not enforced when decoding from JSON.
type LazySortedJsonMap[K comparable, V any] map[K]V
func (m LazySortedJsonMap[K, V]) MarshalJSON() ([]byte, error) {
keys := make([]string, 0, len(m))
values := make(map[string]V)
for k, v := range m {
s := fmt.Sprintf("%q", any(k)) // format as quoted string
keys = append(keys, s)
values[s] = v
}
sort.Strings(keys)
var out []byte
out = append(out, '{')
for i, k := range keys {
out = append(out, k...) // quotes are already included
out = append(out, ':')
v, err := json.Marshal(values[k])
if err != nil {
return nil, fmt.Errorf("failed to encode value of %s: %w", k, err)
}
out = append(out, v...)
if i != len(keys)-1 {
out = append(out, ',')
}
}
out = append(out, '}')
return out, nil
}
func (m *LazySortedJsonMap[K, V]) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, (*map[K]V)(m))
}
package jsonutil
import (
"encoding/json"
"fmt"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
type LazySortedJsonMapTestCase[K comparable, V any] struct {
Object LazySortedJsonMap[K, V]
Json string
}
func (tc *LazySortedJsonMapTestCase[K, V]) Run(t *testing.T) {
t.Run("Marshal", func(t *testing.T) {
got, err := json.Marshal(tc.Object)
require.NoError(t, err)
require.Equal(t, tc.Json, string(got), "json output must match")
})
t.Run("Unmarshal", func(t *testing.T) {
var dest LazySortedJsonMap[K, V]
err := json.Unmarshal([]byte(tc.Json), &dest)
require.NoError(t, err)
require.Equal(t, len(tc.Object), len(dest), "lengths match")
for k, v := range tc.Object {
require.Equal(t, v, dest[k], "values of %q match", k)
}
})
}
func TestLazySortedJsonMap(t *testing.T) {
testCases := []interface{ Run(t *testing.T) }{
&LazySortedJsonMapTestCase[string, int]{Object: LazySortedJsonMap[string, int]{}, Json: `{}`},
&LazySortedJsonMapTestCase[string, int]{Object: LazySortedJsonMap[string, int]{"a": 1, "c": 2, "b": 3}, Json: `{"a":1,"b":3,"c":2}`},
&LazySortedJsonMapTestCase[common.Address, int]{Object: LazySortedJsonMap[common.Address, int]{
common.HexToAddress("0x4100000000000000000000000000000000000000"): 123,
common.HexToAddress("0x4200000000000000000000000000000000000000"): 100,
common.HexToAddress("0x4200000000000000000000000000000000000001"): 100,
},
Json: `{"0x4100000000000000000000000000000000000000":123,` +
`"0x4200000000000000000000000000000000000000":100,` +
`"0x4200000000000000000000000000000000000001":100}`},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("case %d", i), tc.Run)
}
}
......@@ -88,8 +88,8 @@ importers:
specifier: ^42.0.0
version: 42.0.0(eslint@8.47.0)
husky:
specifier: ^6.0.0
version: 6.0.0
specifier: ^8.0.3
version: 8.0.3
lerna:
specifier: ^7.1.5
version: 7.1.5
......@@ -9861,8 +9861,9 @@ packages:
dependencies:
ms: 2.1.3
/husky@6.0.0:
resolution: {integrity: sha512-SQS2gDTB7tBN486QSoKPKQItZw97BMOd+Kdb6ghfpBc0yXyzrddI0oDV5MkDAbuB4X2mO3/nj60TRMcYxwzZeQ==}
/husky@8.0.3:
resolution: {integrity: sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==}
engines: {node: '>=14'}
hasBin: true
dev: true
......@@ -16585,7 +16586,7 @@ packages:
web3-utils: 4.0.4
web3-validator: 2.0.0
optionalDependencies:
web3-providers-ipc: 4.0.4
web3-providers-ipc: 4.0.5
transitivePeerDependencies:
- bufferutil
- encoding
......@@ -16599,6 +16600,15 @@ packages:
web3-types: 1.1.0
dev: false
/web3-errors@1.1.1:
resolution: {integrity: sha512-9IEhcympCJEK3Nmkz2oE/daKnOh+3CxHceuVWWRkHWKUfuIiJQgXAv9wRkPGk63JJTP/R9jtGmP+IbkScKoTBA==}
engines: {node: '>=14', npm: '>=6.12.0'}
requiresBuild: true
dependencies:
web3-types: 1.1.1
dev: false
optional: true
/web3-eth-abi@4.1.0:
resolution: {integrity: sha512-qd+zCGKi2YsL2KkbM5M8Qztles/WPOvFpw6Lg3a904DRIVxkIvWdQfoK0JbA6Vbt8DSVKCc4rpZ15D6I/wfBKQ==}
engines: {node: '>=14', npm: '>=6.12.0'}
......@@ -16766,14 +16776,14 @@ packages:
- encoding
dev: false
/web3-providers-ipc@4.0.4:
resolution: {integrity: sha512-mKzyPggFAw9t+SG0fwsMKoH2npfCzpeUeKfhqaTC/HLIquoI7djOyfV+MPe2p8w9QmstB+OGdRzirVWp2op11A==}
/web3-providers-ipc@4.0.5:
resolution: {integrity: sha512-1mJWqBnKbQ6UGHVxuXDJRpw4NwkpJ7NabyF2XBmzctzFHKvzE0X1dAocy3tih49J38d0vKrmubTOqxxkMpq49Q==}
engines: {node: '>=14', npm: '>=6.12.0'}
requiresBuild: true
dependencies:
web3-errors: 1.1.0
web3-types: 1.1.0
web3-utils: 4.0.4
web3-errors: 1.1.1
web3-types: 1.1.1
web3-utils: 4.0.5
dev: false
optional: true
......@@ -16810,6 +16820,13 @@ packages:
engines: {node: '>=14', npm: '>=6.12.0'}
dev: false
/web3-types@1.1.1:
resolution: {integrity: sha512-bXmIPJi/NPed43JBcya71gT+euZSMvfQx6NYv8G97PSNxR1HWwANYBKbamTZvzBbq10QCwQLh0hZw3tyOXuPFA==}
engines: {node: '>=14', npm: '>=6.12.0'}
requiresBuild: true
dev: false
optional: true
/web3-utils@1.10.1:
resolution: {integrity: sha512-r6iUUw/uMnNcWXjhRv33Nyrhxq3VGOPBXeSzxhOXIci4SvC/LPTpROY0uTrMX7ztKyODYrHp8WhTkEf+ZnHssw==}
engines: {node: '>=8.0.0'}
......@@ -16833,6 +16850,18 @@ packages:
web3-validator: 2.0.0
dev: false
/web3-utils@4.0.5:
resolution: {integrity: sha512-43xIM7rr3htYNzliVQLpWLQmEf4XX8IXgjvqLcEuC/xje14O5UQM4kamRCtz8v3JZN3X6QTfsV6Zgby67mVmCg==}
engines: {node: '>=14', npm: '>=6.12.0'}
requiresBuild: true
dependencies:
ethereum-cryptography: 2.1.2
web3-errors: 1.1.1
web3-types: 1.1.1
web3-validator: 2.0.1
dev: false
optional: true
/web3-validator@1.0.2:
resolution: {integrity: sha512-orx1CQAEnwJUnl/8iF2II2zSA4wiooNJvFmVE0Dbmt/kE370SugIDViQP76snhxtouG2AXzz4GyKbPCMlLGh/A==}
engines: {node: '>=14', npm: '>=6.12.0'}
......@@ -16855,6 +16884,19 @@ packages:
zod: 3.22.1
dev: false
/web3-validator@2.0.1:
resolution: {integrity: sha512-RIdZCNhceBEOQpmzcEk6K3qqLHRfDIMkg2PJe7yllpuEc0fa0cmUZgGUl1FEnioc5Rx9GBEE8eTllaneIAiiQQ==}
engines: {node: '>=14', npm: '>=6.12.0'}
requiresBuild: true
dependencies:
ethereum-cryptography: 2.1.2
util: 0.12.5
web3-errors: 1.1.1
web3-types: 1.1.1
zod: 3.22.1
dev: false
optional: true
/web3@4.0.3:
resolution: {integrity: sha512-rUMxui5f52yPWjiMRQV6xqIrTQSovYM2CNhl57y+xj/fGXNLbI1D5FsLPnUMZjMaFHJBTteaBxq/sTEaw/1jNA==}
engines: {node: '>=14.0.0', npm: '>=6.12.0'}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment