diff --git a/cmd/indexer/mappings/bigmapaction.json b/cmd/indexer/mappings/bigmapaction.json new file mode 100644 index 000000000..e48136977 --- /dev/null +++ b/cmd/indexer/mappings/bigmapaction.json @@ -0,0 +1,54 @@ +{ + "mappings": { + "properties": { + "indexed_time": { + "type": "long" + }, + "address": { + "type": "text", + "fields": { + "keyword": { + "ignore_above": 256.0, + "type": "keyword" + } + } + }, + "level": { + "type": "long" + }, + "action": { + "type": "text", + "fields": { + "keyword": { + "ignore_above": 256.0, + "type": "keyword" + } + } + }, + "operation_id": { + "type": "text", + "fields": { + "keyword": { + "ignore_above": 256.0, + "type": "keyword" + } + } + }, + "network": { + "type": "text", + "fields": { + "keyword": { + "ignore_above": 256.0, + "type": "keyword" + } + } + }, + "source_ptr": { + "type": "long" + }, + "timestamp": { + "type": "date" + } + } + } +} \ No newline at end of file diff --git a/cmd/indexer/mappings/operation.json b/cmd/indexer/mappings/operation.json index b03c36ea3..d643a9486 100644 --- a/cmd/indexer/mappings/operation.json +++ b/cmd/indexer/mappings/operation.json @@ -1 +1,300 @@ -{"mappings":{"properties":{"amount":{"type":"long"},"balance":{"type":"long"},"balance_updates":{"properties":{"change":{"type":"long"},"contract":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"kind":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}},"burned":{"type":"long"},"counter":{"type":"long"},"deffated_storage":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"delegate":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"delegate_alias":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"destination":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"destination_alias":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"entrypoint":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"errors":{"properties":{"amount":{"type":"long"},"balance":{"type":"long"},"descr":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"id":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"kind":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"location":{"type":"long"},"title":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"with":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}},"fee":{"type":"long"},"gas_limit":{"type":"long"},"hash":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"indexed_time":{"type":"long"},"internal":{"type":"boolean"},"nonce":{"type":"long"},"kind":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"level":{"type":"long"},"manager_pubkey":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"network":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"parameter_strings":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"parameters":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"protocol":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"result":{"properties":{"allocated_destination_contract":{"type":"boolean"},"consumed_gas":{"type":"long"},"paid_storage_size_diff":{"type":"long"},"storage_size":{"type":"long"}}},"source":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"source_alias":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"status":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"storage_limit":{"type":"long"},"storage_strings":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"timestamp":{"type":"date"}}}} \ No newline at end of file +{ + "mappings": { + "properties": { + "amount": { + "type": "long" + }, + "balance": { + "type": "long" + }, + "balance_updates": { + "properties": { + "change": { + "type": "long" + }, + "contract": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "kind": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + } + } + }, + "burned": { + "type": "long" + }, + "counter": { + "type": "long" + }, + "deffated_storage": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "delegate": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "delegate_alias": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "destination": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "destination_alias": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "entrypoint": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "errors": { + "properties": { + "amount": { + "type": "long" + }, + "balance": { + "type": "long" + }, + "descr": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "expected_form": { + "type": "text" + }, + "id": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "kind": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "location": { + "type": "long" + }, + "title": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "with": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "wrong_expression": { + "type": "text" + } + } + }, + "fee": { + "type": "long" + }, + "gas_limit": { + "type": "long" + }, + "hash": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "indexed_time": { + "type": "long" + }, + "internal": { + "type": "boolean" + }, + "nonce": { + "type": "long" + }, + "kind": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "level": { + "type": "long" + }, + "manager_pubkey": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "network": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "parameter_strings": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "parameters": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "protocol": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "result": { + "properties": { + "allocated_destination_contract": { + "type": "boolean" + }, + "consumed_gas": { + "type": "long" + }, + "paid_storage_size_diff": { + "type": "long" + }, + "storage_size": { + "type": "long" + } + } + }, + "source": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "source_alias": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "status": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "storage_limit": { + "type": "long" + }, + "storage_strings": { + "type": "text", + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }, + "timestamp": { + "type": "date" + } + } + } +} \ No newline at end of file diff --git a/cmd/indexer/mappings/transfer.json b/cmd/indexer/mappings/transfer.json new file mode 100644 index 000000000..f17b3b3f5 --- /dev/null +++ b/cmd/indexer/mappings/transfer.json @@ -0,0 +1,84 @@ +{ + "mappings": { + "properties": { + "amount": { + "type": "long" + }, + "indexed_time": { + "type": "long" + }, + "token_id": { + "type": "long" + }, + "level": { + "type": "long" + }, + "contract": { + "type": "text", + "fields": { + "keyword": { + "ignore_above": 256.0, + "type": "keyword" + } + } + }, + "alias": { + "type": "text", + "fields": { + "keyword": { + "ignore_above": 256.0, + "type": "keyword" + } + } + }, + "from": { + "type": "text", + "fields": { + "keyword": { + "ignore_above": 256.0, + "type": "keyword" + } + } + }, + "to": { + "type": "text", + "fields": { + "keyword": { + "ignore_above": 256.0, + "type": "keyword" + } + } + }, + "hash": { + "type": "text", + "fields": { + "keyword": { + "ignore_above": 256.0, + "type": "keyword" + } + } + }, + "network": { + "type": "text", + "fields": { + "keyword": { + "ignore_above": 256.0, + "type": "keyword" + } + } + }, + "status": { + "type": "text", + "fields": { + "keyword": { + "ignore_above": 256.0, + "type": "keyword" + } + } + }, + "timestamp": { + "type": "date" + } + } + } +} \ No newline at end of file diff --git a/internal/contractparser/cerrors/error.go b/internal/contractparser/cerrors/error.go index 593bd3e73..3a40e32f6 100644 --- a/internal/contractparser/cerrors/error.go +++ b/internal/contractparser/cerrors/error.go @@ -130,9 +130,65 @@ func getErrorObject(data gjson.Result) IError { var e IError if strings.Contains(id, consts.BalanceTooLowError) { e = &BalanceTooLowError{} + } else if strings.Contains(id, consts.InvalidSyntacticConstantError) { + e = &InvalidSyntacticConstantError{} } else { e = &DefaultError{} } e.Parse(data) return e } + +// InvalidSyntacticConstantError - +type InvalidSyntacticConstantError struct { + DefaultError + + WrongExpression string `json:"wrong_expression"` + ExpectedForm string `json:"expected_form"` +} + +// Parse - parse error from json +func (e *InvalidSyntacticConstantError) Parse(data gjson.Result) { + e.DefaultError = DefaultError{} + e.DefaultError.Parse(data) + + for _, key := range []string{"wrongExpression", "wrong_expression"} { + item := data.Get(key) + if item.Exists() { + e.WrongExpression = item.String() + break + } + } + + for _, key := range []string{"expectedForm", "expected_form"} { + item := data.Get(key) + if item.Exists() { + e.ExpectedForm = item.String() + break + } + } +} + +// String - +func (e *InvalidSyntacticConstantError) String() string { + return gjson.Parse(e.WrongExpression).Raw +} + +// Format - +func (e *InvalidSyntacticConstantError) Format() error { + if err := e.DefaultError.Format(); err != nil { + return err + } + wrongExpression, err := formatter.MichelineToMichelson(gjson.Parse(e.WrongExpression), false, formatter.DefLineSize) + if err != nil { + return err + } + e.WrongExpression = wrongExpression + + expectedForm, err := formatter.MichelineToMichelson(gjson.Parse(e.ExpectedForm), false, formatter.DefLineSize) + if err != nil { + return err + } + e.ExpectedForm = expectedForm + return nil +} diff --git a/internal/contractparser/cerrors/error_test.go b/internal/contractparser/cerrors/error_test.go index d50cb02a3..ea7d538fa 100644 --- a/internal/contractparser/cerrors/error_test.go +++ b/internal/contractparser/cerrors/error_test.go @@ -222,3 +222,40 @@ func TestDefaultError_Format(t *testing.T) { }) } } + +func TestInvalidSyntacticConstantError_Parse(t *testing.T) { + tests := []struct { + name string + args string + ret InvalidSyntacticConstantError + }{ + { + name: "Error 1", + args: `{ "kind": "permanent", "id": "proto.005-PsBabyM1.invalidSyntacticConstantError", "location": 0, "expectedForm":{"prim": "unit"}, "wrongExpression":{"int": "0"}}`, + ret: InvalidSyntacticConstantError{ + DefaultError: DefaultError{ + Kind: "permanent", + ID: "proto.005-PsBabyM1.invalidSyntacticConstantError", + Title: "Invalid constant (parse error)", + Description: "A compile-time constant was invalid for its expected form.", + }, + ExpectedForm: `{"prim": "unit"}`, + WrongExpression: `{"int": "0"}`, + }, + }, + } + + if err := LoadErrorDescriptions("errors.json"); err != nil { + panic(err) + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var e InvalidSyntacticConstantError + data := gjson.Parse(tt.args) + e.Parse(data) + if !reflect.DeepEqual(e, tt.ret) { + t.Errorf("Invalid parsed error: %v != %v", e, tt.ret) + } + }) + } +} diff --git a/internal/contractparser/consts/const.go b/internal/contractparser/consts/const.go index 813c9312a..ae5192052 100644 --- a/internal/contractparser/consts/const.go +++ b/internal/contractparser/consts/const.go @@ -23,10 +23,11 @@ const ( // Error IDs const ( - BadParameterError = "michelson_v1.bad_contract_parameter" - GasExhaustedError = "gas_exhausted.operation" - ScriptRejectedError = "michelson_v1.script_rejected" - BalanceTooLowError = "contract.balance_too_low" + BadParameterError = "michelson_v1.bad_contract_parameter" + GasExhaustedError = "gas_exhausted.operation" + ScriptRejectedError = "michelson_v1.script_rejected" + BalanceTooLowError = "contract.balance_too_low" + InvalidSyntacticConstantError = "invalidSyntacticConstantError" ) // Statuses diff --git a/internal/elastic/bulk.go b/internal/elastic/bulk.go index 70961184d..78eda7a94 100644 --- a/internal/elastic/bulk.go +++ b/internal/elastic/bulk.go @@ -40,8 +40,12 @@ func (e *Elastic) BulkInsert(items []Model) error { data = append(data, "\n"...) bulk.Grow(len(meta) + len(data)) - bulk.Write(meta) - bulk.Write(data) + if _, err := bulk.Write(meta); err != nil { + return err + } + if _, err := bulk.Write(data); err != nil { + return err + } if (i%1000 == 0 && i > 0) || i == len(items)-1 { if err := e.bulk(bulk); err != nil { diff --git a/internal/elastic/elastic.go b/internal/elastic/elastic.go index 15c2b3be4..039c48b4b 100644 --- a/internal/elastic/elastic.go +++ b/internal/elastic/elastic.go @@ -196,11 +196,13 @@ func (e *Elastic) CreateIndexes() error { for _, index := range []string{ DocContracts, DocMetadata, + DocBigMapActions, DocBigMapDiff, DocOperations, DocMigrations, DocProtocol, DocBlocks, + DocTransfers, } { if err := e.CreateIndexIfNotExists(index); err != nil { return err diff --git a/internal/metrics/operation.go b/internal/metrics/operation.go index 64b4728f0..ef70f0b62 100644 --- a/internal/metrics/operation.go +++ b/internal/metrics/operation.go @@ -85,7 +85,6 @@ func (h *Handler) SendSentryNotifications(operation models.Operation) error { initSentry(operation.Network, subscription.SentryDSN) hub := sentry.CurrentHub().Clone() - tags := map[string]string{ "hash": operation.Hash, "source": operation.Source, @@ -102,13 +101,17 @@ func (h *Handler) SendSentryNotifications(operation models.Operation) error { exceptions := make([]sentry.Exception, 0) var message string for i := range operation.Errors { + if err := operation.Errors[i].Format(); err != nil { + return err + } + if i == 0 { message = operation.Errors[i].GetTitle() } exceptions = append(exceptions, sentry.Exception{ - Value: operation.Errors[i].GetTitle(), - Type: operation.Errors[i].String(), + Value: operation.Errors[i].String(), + Type: operation.Errors[i].GetTitle(), }) }