diff --git a/VERSION b/VERSION index ff3b2cd990..398d0dac7e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.5.10 +2.5.11 diff --git a/docs/content/api/openapi.yaml b/docs/content/api/openapi.yaml index 3f36dd98a7..2db44992e8 100644 --- a/docs/content/api/openapi.yaml +++ b/docs/content/api/openapi.yaml @@ -7,7 +7,7 @@ info: license: name: GPL 3.0 url: http://www.gnu.org/licenses/ - version: 2.5.10-release + version: 2.5.11-release description: > A REST layer over the TrueBlocks chifra command line. With `chifra daemon`, you can run this on your own machine, and make calls to `localhost`. @@ -3487,7 +3487,7 @@ components: compressedTx: type: string format: string - description: "truncated, more readable version of the articulation" + description: "truncated, more readable version of the articulation (calculated)" withdrawal: description: "withdrawal record for post-Shanghai withdrawals from the consensus layer" type: object @@ -3510,7 +3510,7 @@ components: description: "the number of this block" index: type: number - format: numeral + format: index description: "a monotonically increasing zero-based index that increments by 1 per withdrawal to uniquely identify each withdrawal" timestamp: type: number @@ -3522,7 +3522,7 @@ components: description: "the timestamp as a date (calculated)" validatorIndex: type: number - format: numeral + format: index description: "the validator_index of the validator on the consensus layer the withdrawal corresponds to" receipt: description: "receipt data as returned from the RPC (with slight enhancements)" @@ -3613,7 +3613,7 @@ components: compressedLog: type: string format: string - description: "a truncated, more readable version of the articulation" + description: "a truncated, more readable version of the articulation (calculated)" logFilter: description: "used by the fast path log queries for various commands" type: object @@ -3699,7 +3699,7 @@ components: compressedTrace: type: string format: string - description: "a compressed string version of the articulated trace" + description: "a compressed string version of the articulated trace (calculated)" traceAction: description: "trace action data as returned from the RPC (with slight enhancements)" type: object @@ -4626,7 +4626,7 @@ components: ether: type: string format: ether - description: "if --ether is specified, the value in ether" + description: "if --ether is specified, the value in ether (calculated)" gas: type: number format: gas @@ -4651,7 +4651,7 @@ components: compressedTx: type: string format: string - description: "truncated, more readable version of the articulation" + description: "truncated, more readable version of the articulation (calculated)" isError: type: boolean format: boolean diff --git a/docs/content/data-model/chaindata.md b/docs/content/data-model/chaindata.md index 698dca97aa..f02e27f866 100644 --- a/docs/content/data-model/chaindata.md +++ b/docs/content/data-model/chaindata.md @@ -82,7 +82,7 @@ Transactions consist of the following fields: | articulatedTx | | [Function](/data-model/other/#function) | | hasToken | `true` if the transaction is token related, `false` otherwise | bool | | isError | `true` if the transaction ended in error, `false` otherwise | bool | -| compressedTx | truncated, more readable version of the articulation | string | +| compressedTx | truncated, more readable version of the articulation (calculated) | string | ## Withdrawal @@ -101,10 +101,10 @@ Withdrawals consist of the following fields: | amount | a nonzero amount of ether given in gwei (1e9 wei) | wei | | ether | if --ether is specified, the amount in ether (calculated) | ether | | blockNumber | the number of this block | blknum | -| index | a monotonically increasing zero-based index that increments by 1 per withdrawal to uniquely identify each withdrawal | numeral | +| index | a monotonically increasing zero-based index that increments by 1 per withdrawal to uniquely identify each withdrawal | index | | timestamp | the timestamp for this block | timestamp | | date | the timestamp as a date (calculated) | datetime | -| validatorIndex | the validator_index of the validator on the consensus layer the withdrawal corresponds to | numeral | +| validatorIndex | the validator_index of the validator on the consensus layer the withdrawal corresponds to | index | ## Receipt @@ -163,7 +163,7 @@ Logs consist of the following fields: | transactionHash | the hash of the transction | hash | | blockHash | the hash of the block | hash | | articulatedLog | a human-readable version of the topic and data fields | [Function](/data-model/other/#function) | -| compressedLog | a truncated, more readable version of the articulation | string | +| compressedLog | a truncated, more readable version of the articulation (calculated) | string | ## LogFilter @@ -203,21 +203,21 @@ The following commands produce and manage Traces: Traces consist of the following fields: -| Field | Description | Type | -| ---------------- | --------------------------------------------------------- | ------------------------------------------------- | -| blockHash | the hash of the block containing this trace | hash | -| blockNumber | the number of the block | blknum | -| timestamp | the timestamp of the block | timestamp | -| date | the timestamp as a date (calculated) | datetime | -| transactionHash | the transaction's hash containing this trace | hash | -| transactionIndex | the zero-indexed position of the transaction in the block | txnum | -| traceAddress | a particular trace's address in the trace tree | uint64[] | -| subtraces | the number of children traces that the trace hash | uint64 | -| type | the type of the trace | string | -| action | the trace action for this trace | [TraceAction](/data-model/chaindata/#traceaction) | -| result | the trace result of this trace | [TraceResult](/data-model/chaindata/#traceresult) | -| articulatedTrace | human readable version of the trace action input data | [Function](/data-model/other/#function) | -| compressedTrace | a compressed string version of the articulated trace | string | +| Field | Description | Type | +| ---------------- | ----------------------------------------------------------------- | ------------------------------------------------- | +| blockHash | the hash of the block containing this trace | hash | +| blockNumber | the number of the block | blknum | +| timestamp | the timestamp of the block | timestamp | +| date | the timestamp as a date (calculated) | datetime | +| transactionHash | the transaction's hash containing this trace | hash | +| transactionIndex | the zero-indexed position of the transaction in the block | txnum | +| traceAddress | a particular trace's address in the trace tree | uint64[] | +| subtraces | the number of children traces that the trace hash | uint64 | +| type | the type of the trace | string | +| action | the trace action for this trace | [TraceAction](/data-model/chaindata/#traceaction) | +| result | the trace result of this trace | [TraceResult](/data-model/chaindata/#traceresult) | +| articulatedTrace | human readable version of the trace action input data | [Function](/data-model/other/#function) | +| compressedTrace | a compressed string version of the articulated trace (calculated) | string | ### Notes @@ -412,10 +412,10 @@ This documentation mentions the following basic data types. | ether | a big number float | as a string | | gas | a 64-bit unsigned integer | | | hash | an '0x'-prefixed 32-byte hex string | lowercase | +| index | an alias for a uint64 | | | int64 | a 64-bit signed integer | | | lognum | an alias for a uint64 | | | nonce | a 64-bit unsigned integer | | -| numeral | an alias for a uint64 | | | string | a normal character string | | | timestamp | a 64-bit unsigned integer | Unix timestamp | | topic | an '0x'-prefixed 32-byte hex string | lowercase | diff --git a/docs/content/data-model/other.md b/docs/content/data-model/other.md index 41880b2899..c4b8f8e92c 100644 --- a/docs/content/data-model/other.md +++ b/docs/content/data-model/other.md @@ -136,13 +136,13 @@ Slurps consist of the following fields: | from | address from which the transaction was sent | address | | to | address to which the transaction was sent | address | | value | the amount of wei sent with this transactions | wei | -| ether | if --ether is specified, the value in ether | ether | +| ether | if --ether is specified, the value in ether (calculated) | ether | | gas | the maximum number of gas allowed for this transaction | gas | | gasPrice | the number of wei per unit of gas the sender is willing to spend | gas | | input | byte data either containing a message or funcational data for a smart contracts. See the --articulate | bytes | | hasToken | `true` if the transaction is token related, `false` otherwise | bool | | articulatedTx | if present, the function that was called in the transaction | [Function](/data-model/other/#function) | -| compressedTx | truncated, more readable version of the articulation | string | +| compressedTx | truncated, more readable version of the articulation (calculated) | string | | isError | `true` if the transaction ended in error, `false` otherwise | bool | ## SlurpCount @@ -198,9 +198,9 @@ This documentation mentions the following basic data types. | ether | a big number float | as a string | | gas | a 64-bit unsigned integer | | | hash | an '0x'-prefixed 32-byte hex string | lowercase | +| index | an alias for a uint64 | | | int64 | a 64-bit signed integer | | | nonce | a 64-bit unsigned integer | | -| numeral | an alias for a uint64 | | | string | a normal character string | | | timestamp | a 64-bit unsigned integer | Unix timestamp | | txnum | an alias for a uint64 | | diff --git a/examples/balanceChart/main.go b/examples/balanceChart/main.go index 94bb6127b4..1fd2a960d5 100644 --- a/examples/balanceChart/main.go +++ b/examples/balanceChart/main.go @@ -75,12 +75,15 @@ func getBalances(names []types.Name, chain string, start, end gostradamus.DateTi Chain: chain, }, } + clamps, _, _ := clamp.When() - if start.UnixTimestamp() < clamps[0].Timestamp { - start = gostradamus.FromUnixTimestamp(clamps[0].Timestamp) + sTs := base.Timestamp(start.UnixTimestamp()) + eTs := base.Timestamp(end.UnixTimestamp()) + if sTs < clamps[0].Timestamp { + start = gostradamus.FromUnixTimestamp(int64(clamps[0].Timestamp)) } - if end.UnixTimestamp() > clamps[1].Timestamp { - end = gostradamus.FromUnixTimestamp(clamps[1].Timestamp - 1) + if eTs > clamps[1].Timestamp { + end = gostradamus.FromUnixTimestamp(int64(clamps[1].Timestamp - 1)) } whenOpts := sdk.WhenOptions{ diff --git a/src/apps/chifra/internal/chunks/output.go b/src/apps/chifra/internal/chunks/output.go index 8890ab46f0..92d3962ee0 100644 --- a/src/apps/chifra/internal/chunks/output.go +++ b/src/apps/chifra/internal/chunks/output.go @@ -22,7 +22,6 @@ import ( outputHelpers "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output/helpers" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/tslib" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/spf13/cobra" ) @@ -155,7 +154,7 @@ func GetChunkStats(chain, path string) (s types.ChunkStats, err error) { ts, _ := tslib.FromBnToTs(chain, chunk.Range.Last) s = types.ChunkStats{ Range: chunk.Range.String(), - RangeEnd: utils.FormattedDate(ts), + RangeEnd: base.FormattedDate(ts), NBlocks: uint64(chunk.Range.Last - chunk.Range.First + 1), NAddrs: uint64(chunk.Index.Header.AddressCount), NApps: uint64(chunk.Index.Header.AppearanceCount), diff --git a/src/apps/chifra/internal/explore/validate.go b/src/apps/chifra/internal/explore/validate.go index c221fbf67c..24467bee4b 100644 --- a/src/apps/chifra/internal/explore/validate.go +++ b/src/apps/chifra/internal/explore/validate.go @@ -153,11 +153,11 @@ func (opts *ExploreOptions) idToTxHash(arg string, isBlockHash func(arg string) } if isBlockHash(parts[0]) { - return opts.Conn.GetTransactionHashByHashAndID(parts[0], base.MustParseNumeral(parts[1])) + return opts.Conn.GetTransactionHashByHashAndID(parts[0], base.MustParseIndex(parts[1])) } blockNum := base.MustParseBlknum(parts[0]) - txId := base.MustParseNumeral(parts[1]) + txId := base.MustParseIndex(parts[1]) hash, err := opts.Conn.GetTransactionHashByNumberAndID(blockNum, base.Txnum(txId)) return hash.Hex(), err } diff --git a/src/apps/chifra/internal/export/handle_traces.go b/src/apps/chifra/internal/export/handle_traces.go index 7d981459ae..edebe8b62e 100644 --- a/src/apps/chifra/internal/export/handle_traces.go +++ b/src/apps/chifra/internal/export/handle_traces.go @@ -94,7 +94,7 @@ func (opts *ExportOptions) HandleTraces(monitorArray []monitor.Monitor) error { items := make([]*types.Trace, 0, len(thisMap)) for _, tx := range thisMap { for index, trace := range tx.Traces { - trace.TraceIndex = base.TraceId(index) + trace.TraceIndex = base.Tracenum(index) isCreate := trace.Action.CallType == "creation" || trace.TraceType == "create" if !opts.Factory || isCreate { if opts.Articulate { diff --git a/src/apps/chifra/internal/scrape/scrape_consolidate.go b/src/apps/chifra/internal/scrape/scrape_consolidate.go index 669d0fcbce..6db88838d1 100644 --- a/src/apps/chifra/internal/scrape/scrape_consolidate.go +++ b/src/apps/chifra/internal/scrape/scrape_consolidate.go @@ -191,7 +191,7 @@ func (bm *BlazeManager) AsciiFileToAppearanceMap(fn string) (map[string][]types. if len(parts) == 3 { // shouldn't be needed, but just in case... addr := strings.ToLower(parts[0]) bn := base.MustParseBlknum(strings.TrimLeft(parts[1], "0")) - txid := base.MustParseNumeral(strings.TrimLeft(parts[2], "0")) + txid := base.MustParseIndex(strings.TrimLeft(parts[2], "0")) // See #3252 if addr == base.SentinalAddr.Hex() && txid == types.MisconfigReward { continue diff --git a/src/apps/chifra/internal/traces/handle_filter.go b/src/apps/chifra/internal/traces/handle_filter.go index 852145ff7c..d0502856b6 100644 --- a/src/apps/chifra/internal/traces/handle_filter.go +++ b/src/apps/chifra/internal/traces/handle_filter.go @@ -84,7 +84,7 @@ func (opts *TracesOptions) HandleFilter() error { errorChan <- err // continue even with an error } } - traces[index].TraceIndex = base.TraceId(index) + traces[index].TraceIndex = base.Tracenum(index) tr = append(tr, traces[index]) } value.Traces = append(value.Traces, tr...) diff --git a/src/apps/chifra/internal/when/handle_ts_show.go b/src/apps/chifra/internal/when/handle_ts_show.go index 739d5480be..df821ebd81 100644 --- a/src/apps/chifra/internal/when/handle_ts_show.go +++ b/src/apps/chifra/internal/when/handle_ts_show.go @@ -40,7 +40,7 @@ func (opts *WhenOptions) HandleTimestampsShow() error { s := types.Timestamp{ BlockNumber: base.Blknum(ts.Bn), Timestamp: base.Timestamp(ts.Ts), - Diff: base.Timestamp(ts.Ts) - prev, + Diff: int64(base.Timestamp(ts.Ts) - prev), } if bn == 0 { s.Diff = 0 diff --git a/src/apps/chifra/pkg/base/hash.go b/src/apps/chifra/pkg/base/hash.go index a9bebd4cf1..1b20706a95 100644 --- a/src/apps/chifra/pkg/base/hash.go +++ b/src/apps/chifra/pkg/base/hash.go @@ -39,7 +39,7 @@ func (h Hash) MarshalText() ([]byte, error) { } func (h *Hash) UnmarshalJSON(data []byte) error { - if string(data) == "\"0x0\"" { + if string(data) == "\"0x0\"" || string(data) == "\"\"" { return nil } return h.Hash.UnmarshalJSON(data) diff --git a/src/apps/chifra/pkg/base/types.go b/src/apps/chifra/pkg/base/types.go index 6d6b1717a7..326d777203 100644 --- a/src/apps/chifra/pkg/base/types.go +++ b/src/apps/chifra/pkg/base/types.go @@ -2,6 +2,8 @@ package base import ( "strconv" + + "github.com/bykof/gostradamus" ) // make -j 12 && time make test-all shows: @@ -11,29 +13,34 @@ import ( // and more useful because it supports Json parsing and future needs type Numeral uint64 - -func (g *Numeral) UnmarshalJSON(data []byte) error { - result, _ := strconv.ParseUint(string(data), 0, 64) - *g = Numeral(result) - return nil -} - type Blknum = Numeral type Txnum = Numeral -type TraceId = Numeral +type Tracenum = Numeral type Lognum = Numeral type Gas = Numeral type Nonce = Numeral +type Index = Numeral type Topic = string -type Timestamp = int64 +type Timestamp int64 const NOPOS = uint64(^uint64(0)) -const NOPOSI = int64(0xdeadbeef) +const NOPOSI = Timestamp(0xdeadbeef) const NOPOSN = Numeral(^uint64(0)) -func MustParseNumeral(input string) Numeral { - ret, _ := strconv.ParseUint(input, 0, 64) - return Numeral(ret) +func (g *Numeral) UnmarshalJSON(data []byte) error { + result, _ := strconv.ParseUint(string(data), 0, 64) + *g = Numeral(result) + return nil +} + +func (t *Timestamp) UnmarshalJSON(data []byte) error { + result, _ := strconv.ParseUint(string(data), 0, 64) + *t = Timestamp(result) + return nil +} + +func (t *Timestamp) Int64() int64 { + return int64(*t) } // TODO: This is here to avoid circular imports @@ -42,6 +49,26 @@ func MustParseBlknum(input string) Blknum { return Blknum(ret) } +func MustParseIndex(input string) Txnum { + ret, _ := strconv.ParseUint(input, 0, 64) + return Txnum(ret) +} + +func MustParseTimestamp(input string) Timestamp { + ret, _ := strconv.ParseInt(input, 0, 64) + return Timestamp(ret) +} + +func MustParseWei(input string) Wei { + i := MustParseUint(input) + return *NewWei(0).SetUint64(i) +} + +func MustParseGas(input string) Gas { + ret, _ := strconv.ParseUint(input, 0, 64) + return Gas(ret) +} + func MustParseInt(input string) int64 { ret, _ := strconv.ParseInt(input, 0, 64) return ret @@ -52,16 +79,15 @@ func MustParseUint(input string) uint64 { return ret } -func MustParseWei(input string) Wei { - i := MustParseUint(input) - return *NewWei(0).SetUint64(i) -} - func MustParseFloat(val string) float64 { f, _ := strconv.ParseFloat(val, 64) return f } +func FormattedDate(ts Timestamp) string { + return gostradamus.FromUnixTimestamp(int64(ts)).Format("2006-01-02 15:04:05 UTC") +} + func IsFinal(latestTs, blockTs Timestamp) bool { // TODO: This is not consistent with they way we determine unripe in the scraper, for example. var min = Timestamp(5) diff --git a/src/apps/chifra/pkg/base/types_ether.go b/src/apps/chifra/pkg/base/types_ether.go index dfaf08229c..6bc4038ad4 100644 --- a/src/apps/chifra/pkg/base/types_ether.go +++ b/src/apps/chifra/pkg/base/types_ether.go @@ -66,6 +66,9 @@ func (e *Ether) Quo(a, b *Ether) *Ether { func (e *Ether) UnmarshalJSON(data []byte) error { str := strings.Trim(strings.TrimSpace(string(data)), "\"") // strip quotes and whitespace if any + if len(str) == 0 { + return nil + } return (*big.Float)(e).UnmarshalText([]byte(str)) } diff --git a/src/apps/chifra/pkg/base/types_wei.go b/src/apps/chifra/pkg/base/types_wei.go index b67763d3fe..8f57e0b5ed 100644 --- a/src/apps/chifra/pkg/base/types_wei.go +++ b/src/apps/chifra/pkg/base/types_wei.go @@ -97,6 +97,14 @@ func (w *Wei) MarshalText() (text []byte, err error) { return (*big.Int)(w).MarshalText() } +func (e *Wei) UnmarshalJSON(data []byte) error { + str := strings.Trim(strings.TrimSpace(string(data)), "\"") // strip quotes and whitespace if any + if len(str) == 0 { + return nil + } + return (*big.Int)(e).UnmarshalText([]byte(str)) +} + func (w *Wei) UnmarshalCache(version uint64, reader io.Reader) error { var v big.Int if err := cache.ReadValue(reader, &v, version); err != nil { diff --git a/src/apps/chifra/pkg/identifiers/resolve.go b/src/apps/chifra/pkg/identifiers/resolve.go index 55f614e152..8c8b278e60 100644 --- a/src/apps/chifra/pkg/identifiers/resolve.go +++ b/src/apps/chifra/pkg/identifiers/resolve.go @@ -109,13 +109,14 @@ func snapBnToPeriod(bn base.Blknum, chain, period string) (base.Blknum, error) { dt = dt.FloorYear() } - firstDate := gostradamus.FromUnixTimestamp(conn.GetBlockTimestamp(0)) + zeroTs := conn.GetBlockTimestamp(0) + firstDate := gostradamus.FromUnixTimestamp(zeroTs.Int64()) if dt.Time().Before(firstDate.Time()) { dt = firstDate } ts := dt.UnixTimestamp() - return tslib.FromTsToBn(chain, ts) + return tslib.FromTsToBn(chain, base.Timestamp(ts)) } func (id *Identifier) nextBlock(chain string, current base.Blknum) (base.Blknum, error) { @@ -161,7 +162,7 @@ func (id *Identifier) nextBlock(chain string, current base.Blknum) (base.Blknum, } ts := dt.UnixTimestamp() - bn, err = tslib.FromTsToBn(chain, ts) + bn, err = tslib.FromTsToBn(chain, base.Timestamp(ts)) if err != nil { return bn, err } diff --git a/src/apps/chifra/pkg/rpc/client_integration_test.go b/src/apps/chifra/pkg/rpc/client_integration_test.go index fd0514ecae..ba6ac98f77 100644 --- a/src/apps/chifra/pkg/rpc/client_integration_test.go +++ b/src/apps/chifra/pkg/rpc/client_integration_test.go @@ -10,6 +10,7 @@ package rpc import ( "testing" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) @@ -22,7 +23,7 @@ func Test_Client(t *testing.T) { } ts := conn.GetBlockTimestamp(1) - blockOneTimestamp := int64(1438269988) + blockOneTimestamp := base.Timestamp(1438269988) if ts != blockOneTimestamp { t.Error("timestamp for block 1 is not correct") } diff --git a/src/apps/chifra/pkg/rpc/get_block.go b/src/apps/chifra/pkg/rpc/get_block.go index 81c6ffee4c..7879c985e7 100644 --- a/src/apps/chifra/pkg/rpc/get_block.go +++ b/src/apps/chifra/pkg/rpc/get_block.go @@ -8,7 +8,6 @@ import ( "context" "errors" "fmt" - "strconv" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" @@ -49,7 +48,7 @@ func (conn *Connection) GetBlockBodyByNumber(bn base.Blknum) (types.Block[types. return block, err } - ts, _ := strconv.ParseInt(rawBlock.Timestamp, 0, 64) + ts := base.MustParseTimestamp(rawBlock.Timestamp) block.Transactions = make([]types.Transaction, 0, len(rawBlock.Transactions)) _, receiptMap, _ := conn.GetReceiptsByNumber(bn, ts) for _, rawTx := range rawBlock.Transactions { @@ -62,7 +61,7 @@ func (conn *Connection) GetBlockBodyByNumber(bn base.Blknum) (types.Block[types. raw := types.NewRawTransactionFromMap(rawData) // Get the receipt - idx := base.MustParseNumeral(raw.TransactionIndex) + idx := base.MustParseIndex(raw.TransactionIndex) var receipt types.Receipt if receiptMap[idx] == nil { receipt, err = conn.GetReceipt(bn, idx, ts) @@ -206,8 +205,8 @@ func loadBlock[Tx string | types.Transaction](conn *Connection, bn base.Blknum, Timestamp: base.Timestamp(base.MustParseInt(rawBlock.Timestamp)), // note that we turn Ethereum's timestamps into types. Timestamp upon read. Hash: base.HexToHash(rawBlock.Hash), ParentHash: base.HexToHash(rawBlock.ParentHash), - GasLimit: base.MustParseNumeral(rawBlock.GasLimit), - GasUsed: base.MustParseNumeral(rawBlock.GasUsed), + GasLimit: base.MustParseGas(rawBlock.GasLimit), + GasUsed: base.MustParseGas(rawBlock.GasUsed), Miner: base.HexToAddress(rawBlock.Miner), Difficulty: base.MustParseUint(rawBlock.Difficulty), Uncles: uncleHashes, @@ -223,8 +222,8 @@ func loadBlock[Tx string | types.Transaction](conn *Connection, bn base.Blknum, Amount: *amt, BlockNumber: block.BlockNumber, Timestamp: block.Timestamp, - Index: base.MustParseNumeral(withdrawal.Index), - ValidatorIndex: base.MustParseNumeral(withdrawal.ValidatorIndex), + Index: base.MustParseIndex(withdrawal.Index), + ValidatorIndex: base.MustParseIndex(withdrawal.ValidatorIndex), } block.Withdrawals = append(block.Withdrawals, s) } diff --git a/src/apps/chifra/pkg/rpc/get_traces.go b/src/apps/chifra/pkg/rpc/get_traces.go index 31738bf672..b18b7274d6 100644 --- a/src/apps/chifra/pkg/rpc/get_traces.go +++ b/src/apps/chifra/pkg/rpc/get_traces.go @@ -37,7 +37,7 @@ func (conn *Connection) GetTracesByBlockNumber(bn base.Blknum) ([]types.Trace, e } else { curApp := types.Appearance{BlockNumber: uint32(^uint32(0))} curTs := conn.GetBlockTimestamp(bn) - var traceIndex base.TraceId + var traceIndex base.Tracenum // TODO: This could be loadTrace in the same way load Blocks works var ret []types.Trace @@ -48,7 +48,7 @@ func (conn *Connection) GetTracesByBlockNumber(bn base.Blknum) ([]types.Trace, e Balance: base.MustParseWei(rawTrace.Action.Balance), CallType: rawTrace.Action.CallType, From: base.HexToAddress(rawTrace.Action.From), - Gas: base.MustParseNumeral(rawTrace.Action.Gas), + Gas: base.MustParseGas(rawTrace.Action.Gas), Init: rawTrace.Action.Init, Input: rawTrace.Action.Input, RefundAddress: base.HexToAddress(rawTrace.Action.RefundAddress), @@ -61,7 +61,7 @@ func (conn *Connection) GetTracesByBlockNumber(bn base.Blknum) ([]types.Trace, e if rawTrace.Result != nil { traceResult.Address = base.HexToAddress(rawTrace.Result.Address) traceResult.Code = rawTrace.Result.Code - traceResult.GasUsed = base.MustParseNumeral(rawTrace.Result.GasUsed) + traceResult.GasUsed = base.MustParseGas(rawTrace.Result.GasUsed) traceResult.Output = rawTrace.Result.Output } trace := types.Trace{ @@ -147,7 +147,7 @@ func (conn *Connection) GetTracesByTransactionHash(txHash string, transaction *t } else { curApp := types.Appearance{BlockNumber: uint32(^uint32(0))} - var traceIndex base.TraceId + var traceIndex base.Tracenum for _, rawTrace := range *rawTraces { value := base.NewWei(0) @@ -158,7 +158,7 @@ func (conn *Connection) GetTracesByTransactionHash(txHash string, transaction *t action := types.TraceAction{ CallType: rawTrace.Action.CallType, From: base.HexToAddress(rawTrace.Action.From), - Gas: base.MustParseNumeral(rawTrace.Action.Gas), + Gas: base.MustParseGas(rawTrace.Action.Gas), Input: rawTrace.Action.Input, To: base.HexToAddress(rawTrace.Action.To), Value: *value, @@ -173,7 +173,7 @@ func (conn *Connection) GetTracesByTransactionHash(txHash string, transaction *t var result *types.TraceResult if rawTrace.Result != nil { result = &types.TraceResult{ - GasUsed: base.MustParseNumeral(rawTrace.Result.GasUsed), + GasUsed: base.MustParseGas(rawTrace.Result.GasUsed), Output: rawTrace.Result.Output, Code: rawTrace.Result.Code, } @@ -246,7 +246,7 @@ func (conn *Connection) GetTracesByFilter(filter string) ([]types.Trace, error) } else { curApp := types.Appearance{BlockNumber: uint32(^uint32(0))} curTs := conn.GetBlockTimestamp(f.FromBlock) - var traceIndex base.TraceId + var traceIndex base.Tracenum // TODO: This could be loadTrace in the same way load Blocks works for _, rawTrace := range *rawTraces { @@ -258,7 +258,7 @@ func (conn *Connection) GetTracesByFilter(filter string) ([]types.Trace, error) action := types.TraceAction{ CallType: rawTrace.Action.CallType, From: base.HexToAddress(rawTrace.Action.From), - Gas: base.MustParseNumeral(rawTrace.Action.Gas), + Gas: base.MustParseGas(rawTrace.Action.Gas), Input: rawTrace.Action.Input, To: base.HexToAddress(rawTrace.Action.To), Value: *value, @@ -273,7 +273,7 @@ func (conn *Connection) GetTracesByFilter(filter string) ([]types.Trace, error) var result *types.TraceResult if rawTrace.Result != nil { result = &types.TraceResult{ - GasUsed: base.MustParseNumeral(rawTrace.Result.GasUsed), + GasUsed: base.MustParseGas(rawTrace.Result.GasUsed), Output: rawTrace.Result.Output, Code: rawTrace.Result.Code, } diff --git a/src/apps/chifra/pkg/rpc/get_transaction.go b/src/apps/chifra/pkg/rpc/get_transaction.go index 72c90d4d30..841eecf614 100644 --- a/src/apps/chifra/pkg/rpc/get_transaction.go +++ b/src/apps/chifra/pkg/rpc/get_transaction.go @@ -205,7 +205,7 @@ func (conn *Connection) GetTransactionPrefundByApp(raw *types.RawAppearance) (tx return nil, err } else { var blockHash base.Hash - var ts int64 + var ts base.Timestamp if block, err := conn.GetBlockHeaderByNumber(0); err != nil { return nil, err } else { diff --git a/src/apps/chifra/pkg/rpc/get_uncle.go b/src/apps/chifra/pkg/rpc/get_uncle.go index 1fb256f4cd..fc7c7f2e01 100644 --- a/src/apps/chifra/pkg/rpc/get_uncle.go +++ b/src/apps/chifra/pkg/rpc/get_uncle.go @@ -39,7 +39,7 @@ func (conn *Connection) GetUncleBodiesByNumber(bn base.Blknum) ([]types.Block[ty Hash: base.HexToHash(rawUncle.Hash), Miner: base.HexToAddress(rawUncle.Miner), ParentHash: base.HexToHash(rawUncle.ParentHash), - Timestamp: base.MustParseInt(rawUncle.Timestamp), + Timestamp: base.MustParseTimestamp(rawUncle.Timestamp), // Transactions: rawUncle.Transactions, // BaseFeePerGas: rawUncle.BaseFeePerGas, // Difficulty: rawUncle.Difficulty, diff --git a/src/apps/chifra/pkg/rpc/provider/covalent.go b/src/apps/chifra/pkg/rpc/provider/covalent.go index 2fef80e9fc..ee7c46a046 100644 --- a/src/apps/chifra/pkg/rpc/provider/covalent.go +++ b/src/apps/chifra/pkg/rpc/provider/covalent.go @@ -144,7 +144,7 @@ func (c *covalentTransaction) Slurp() (s types.Slurp) { From: base.HexToAddress(*c.From), Gas: base.Gas(*c.GasSpent), IsError: !(*c.Successful), - Timestamp: c.BlockSignedAt.Unix(), + Timestamp: base.Timestamp(c.BlockSignedAt.Unix()), To: base.HexToAddress(*c.To), TransactionIndex: base.Txnum(*c.TxOffset), Value: *c.Value, diff --git a/src/apps/chifra/pkg/rpc/provider/etherscan.go b/src/apps/chifra/pkg/rpc/provider/etherscan.go index af41421e7b..2c987fb3f9 100644 --- a/src/apps/chifra/pkg/rpc/provider/etherscan.go +++ b/src/apps/chifra/pkg/rpc/provider/etherscan.go @@ -205,13 +205,13 @@ func (p *EtherscanProvider) defaultConvertSlurpType(address string, requestType Hash: base.HexToHash(rawTx.Hash), BlockHash: base.HexToHash(rawTx.BlockHash), BlockNumber: base.MustParseBlknum(rawTx.BlockNumber), - TransactionIndex: base.MustParseNumeral(rawTx.TransactionIndex), - Timestamp: base.MustParseInt(rawTx.Timestamp), + TransactionIndex: base.MustParseIndex(rawTx.TransactionIndex), + Timestamp: base.MustParseTimestamp(rawTx.Timestamp), From: base.HexToAddress(rawTx.From), To: base.HexToAddress(rawTx.To), - Gas: base.MustParseNumeral(rawTx.Gas), - GasPrice: base.MustParseNumeral(rawTx.GasPrice), - GasUsed: base.MustParseNumeral(rawTx.GasUsed), + Gas: base.MustParseGas(rawTx.Gas), + GasPrice: base.MustParseGas(rawTx.GasPrice), + GasUsed: base.MustParseGas(rawTx.GasUsed), Input: rawTx.Input, } @@ -243,8 +243,8 @@ func (p *EtherscanProvider) defaultConvertSlurpType(address string, requestType s.BlockHash = base.HexToHash("0xdeadbeef") s.TransactionIndex = types.WithdrawalAmt s.From = base.WithdrawalSender - s.ValidatorIndex = base.MustParseNumeral(rawTx.ValidatorIndex) - s.WithdrawalIndex = base.MustParseNumeral(rawTx.WithdrawalIndex) + s.ValidatorIndex = base.MustParseIndex(rawTx.ValidatorIndex) + s.WithdrawalIndex = base.MustParseIndex(rawTx.WithdrawalIndex) s.Value.SetString(rawTx.Amount, 0) s.To = base.HexToAddress(address) if s.To != base.HexToAddress(rawTx.Address) { diff --git a/src/apps/chifra/pkg/rpc/provider/etherscan_test.go b/src/apps/chifra/pkg/rpc/provider/etherscan_test.go index 8f8f6b6673..d755f28e38 100644 --- a/src/apps/chifra/pkg/rpc/provider/etherscan_test.go +++ b/src/apps/chifra/pkg/rpc/provider/etherscan_test.go @@ -114,7 +114,7 @@ func mockConvertSlurpType(t *testing.T) func(address string, requestType string, return func(address string, requestType string, rawTx *types.RawSlurp) (types.Slurp, error) { return types.Slurp{ BlockNumber: base.MustParseBlknum(rawTx.BlockNumber), - TransactionIndex: base.MustParseNumeral(rawTx.TransactionIndex), + TransactionIndex: base.MustParseIndex(rawTx.TransactionIndex), }, nil } } diff --git a/src/apps/chifra/pkg/rpc/provider/key.go b/src/apps/chifra/pkg/rpc/provider/key.go index b3207f8ca3..f8db8bbfd5 100644 --- a/src/apps/chifra/pkg/rpc/provider/key.go +++ b/src/apps/chifra/pkg/rpc/provider/key.go @@ -105,9 +105,8 @@ func (p *KeyProvider) TransactionsByAddress(ctx context.Context, query *Query, e func transactionToSlurp(tx *types.Transaction) *types.Slurp { return &types.Slurp{ // ArticulatedTx: tx.ArticulatedTx, - BlockHash: tx.BlockHash, - BlockNumber: tx.BlockNumber, - CompressedTx: tx.CompressedTx, + BlockHash: tx.BlockHash, + BlockNumber: tx.BlockNumber, // ContractAddress: tx.ContractAddress, // CumulativeGasUsed: tx.CumulativeGasUsed, // Ether: tx.Ether, diff --git a/src/apps/chifra/pkg/rpc/state.go b/src/apps/chifra/pkg/rpc/state.go index 8b27e9becf..ab5add8653 100644 --- a/src/apps/chifra/pkg/rpc/state.go +++ b/src/apps/chifra/pkg/rpc/state.go @@ -99,7 +99,7 @@ func (conn *Connection) GetState(fieldBits StatePart, address base.Address, bloc } if value, ok := queryResults["nonce"]; ok && (fieldBits&Nonce) != 0 { - state.Nonce = base.MustParseNumeral(*value) + state.Nonce = base.MustParseIndex(*value) } if value, ok := queryResults["code"]; ok && (fieldBits&Code) != 0 { diff --git a/src/apps/chifra/pkg/tslib/list.go b/src/apps/chifra/pkg/tslib/list.go index 19851faf52..6092ec40a7 100644 --- a/src/apps/chifra/pkg/tslib/list.go +++ b/src/apps/chifra/pkg/tslib/list.go @@ -92,7 +92,7 @@ func readSpecials(path string, nFields int) (specials []types.NamedBlock, err er } s := types.NamedBlock{ BlockNumber: base.MustParseBlknum(record[locs["bn"]]), - Timestamp: base.MustParseInt(record[locs["ts"]]), + Timestamp: base.MustParseTimestamp(record[locs["ts"]]), Name: record[locs["name"]], } // is this the header? diff --git a/src/apps/chifra/pkg/tslib/todate.go b/src/apps/chifra/pkg/tslib/todate.go index e8cc71e87b..518c29774a 100644 --- a/src/apps/chifra/pkg/tslib/todate.go +++ b/src/apps/chifra/pkg/tslib/todate.go @@ -43,5 +43,5 @@ func FromNameToDate(chain, name string) (gostradamus.DateTime, error) { // FromTsToDate returns a date given a Linux timestamp (not chain-specific) func FromTsToDate(ts base.Timestamp) (gostradamus.DateTime, error) { - return gostradamus.FromUnixTimestamp(ts), nil + return gostradamus.FromUnixTimestamp(ts.Int64()), nil } diff --git a/src/apps/chifra/pkg/types/types_appearance.go b/src/apps/chifra/pkg/types/types_appearance.go index 2f19b7fa50..aefb02d66e 100644 --- a/src/apps/chifra/pkg/types/types_appearance.go +++ b/src/apps/chifra/pkg/types/types_appearance.go @@ -15,7 +15,6 @@ import ( "sort" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) const ( @@ -170,7 +169,7 @@ func (s *Appearance) Model(chain, format string, verbose bool, extraOptions map[ } func (s *Appearance) Date() string { - return utils.FormattedDate(s.Timestamp) + return base.FormattedDate(s.Timestamp) } // FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen diff --git a/src/apps/chifra/pkg/types/types_block.go b/src/apps/chifra/pkg/types/types_block.go index 67ae3a013f..70e8537503 100644 --- a/src/apps/chifra/pkg/types/types_block.go +++ b/src/apps/chifra/pkg/types/types_block.go @@ -18,7 +18,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/cache" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/version" ) @@ -209,7 +208,7 @@ func (s *Block[Tx]) Model(chain, format string, verbose bool, extraOptions map[s } func (s *Block[Tx]) Date() string { - return utils.FormattedDate(s.Timestamp) + return base.FormattedDate(s.Timestamp) } func (s *Block[Tx]) CacheName() string { diff --git a/src/apps/chifra/pkg/types/types_blockcount.go b/src/apps/chifra/pkg/types/types_blockcount.go index 5607d41f65..eebdaf4f38 100644 --- a/src/apps/chifra/pkg/types/types_blockcount.go +++ b/src/apps/chifra/pkg/types/types_blockcount.go @@ -13,7 +13,6 @@ import ( "encoding/json" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) // EXISTING_CODE @@ -134,7 +133,7 @@ func (s *BlockCount) Model(chain, format string, verbose bool, extraOptions map[ } func (s *BlockCount) Date() string { - return utils.FormattedDate(s.Timestamp) + return base.FormattedDate(s.Timestamp) } // FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen diff --git a/src/apps/chifra/pkg/types/types_bounds.go b/src/apps/chifra/pkg/types/types_bounds.go index 53abce8706..89bba55954 100644 --- a/src/apps/chifra/pkg/types/types_bounds.go +++ b/src/apps/chifra/pkg/types/types_bounds.go @@ -14,7 +14,6 @@ import ( "fmt" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) // EXISTING_CODE @@ -64,10 +63,10 @@ func (s *Bounds) Model(chain, format string, verbose bool, extraOptions map[stri "count": s.Count, "firstApp": s.FirstApp.Model(chain, format, verbose, extraOptions).Data, //fmt.Sprintf("%d.%d", s.FirstApp.BlockNumber, s.FirstApp.TransactionIndex), "firstTs": s.FirstTs, - "firstDate": utils.FormattedDate(s.FirstTs), + "firstDate": base.FormattedDate(s.FirstTs), "latestApp": s.LatestApp.Model(chain, format, verbose, extraOptions).Data, //fmt.Sprintf("%d.%d", s.LatestApp.BlockNumber, s.LatestApp.TransactionIndex), "latestTs": s.LatestTs, - "latestDate": utils.FormattedDate(s.LatestTs), + "latestDate": base.FormattedDate(s.LatestTs), "blockSpan": (s.LatestApp.BlockNumber - s.FirstApp.BlockNumber), "blockFreq": uint64(s.LatestApp.BlockNumber-s.FirstApp.BlockNumber) / s.Count, } diff --git a/src/apps/chifra/pkg/types/types_log.go b/src/apps/chifra/pkg/types/types_log.go index 1ff6112330..fab8002745 100644 --- a/src/apps/chifra/pkg/types/types_log.go +++ b/src/apps/chifra/pkg/types/types_log.go @@ -19,7 +19,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/cache" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/version" ) // EXISTING_CODE @@ -42,7 +42,6 @@ type Log struct { ArticulatedLog *Function `json:"articulatedLog,omitempty"` BlockHash base.Hash `json:"blockHash"` BlockNumber base.Blknum `json:"blockNumber"` - CompressedLog string `json:"compressedLog,omitempty"` Data string `json:"data,omitempty"` LogIndex base.Lognum `json:"logIndex"` Timestamp base.Timestamp `json:"timestamp,omitempty"` @@ -157,7 +156,7 @@ func (s *Log) Model(chain, format string, verbose bool, extraOptions map[string] } func (s *Log) Date() string { - return utils.FormattedDate(s.Timestamp) + return base.FormattedDate(s.Timestamp) } type LogGroup struct { @@ -220,11 +219,6 @@ func (s *Log) MarshalCache(writer io.Writer) (err error) { return err } - // CompressedLog - if err = cache.WriteValue(writer, s.CompressedLog); err != nil { - return err - } - // Data if err = cache.WriteValue(writer, s.Data); err != nil { return err @@ -287,9 +281,13 @@ func (s *Log) UnmarshalCache(vers uint64, reader io.Reader) (err error) { return err } - // CompressedLog - if err = cache.ReadValue(reader, &s.CompressedLog, vers); err != nil { - return err + // Used to be CompressedLog, since removed + vCompressedLog := version.NewVersion("2.5.10") + if vers <= vCompressedLog.Uint64() { + var val string + if err = cache.ReadValue(reader, &val, vers); err != nil { + return err + } } // Data @@ -347,9 +345,9 @@ func (r *RawLog) RawTo(vals map[string]any) (Log, error) { Address: base.HexToAddress(r.Address), BlockNumber: base.MustParseBlknum(r.BlockNumber), BlockHash: base.HexToHash(r.BlockHash), - TransactionIndex: base.MustParseNumeral(r.TransactionIndex), + TransactionIndex: base.MustParseIndex(r.TransactionIndex), TransactionHash: hash, - LogIndex: base.MustParseNumeral(r.LogIndex), + LogIndex: base.MustParseIndex(r.LogIndex), Data: r.Data, raw: r, } diff --git a/src/apps/chifra/pkg/types/types_namedblock.go b/src/apps/chifra/pkg/types/types_namedblock.go index 99c240acab..8987b880aa 100644 --- a/src/apps/chifra/pkg/types/types_namedblock.go +++ b/src/apps/chifra/pkg/types/types_namedblock.go @@ -13,7 +13,6 @@ import ( "encoding/json" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) // EXISTING_CODE @@ -104,7 +103,7 @@ func (s *NamedBlock) Model(chain, format string, verbose bool, extraOptions map[ } func (s *NamedBlock) Date() string { - return utils.FormattedDate(s.Timestamp) + return base.FormattedDate(s.Timestamp) } // FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen diff --git a/src/apps/chifra/pkg/types/types_receipt.go b/src/apps/chifra/pkg/types/types_receipt.go index 1b842934c8..ba453e83ec 100644 --- a/src/apps/chifra/pkg/types/types_receipt.go +++ b/src/apps/chifra/pkg/types/types_receipt.go @@ -286,7 +286,7 @@ func (s *Receipt) UnmarshalCache(vers uint64, reader io.Reader) (err error) { if err = cache.ReadValue(reader, &val, vers); err != nil { return err } - s.CumulativeGasUsed = base.MustParseNumeral(val) + s.CumulativeGasUsed = base.MustParseGas(val) } else { // CumulativeGasUsed if err = cache.ReadValue(reader, &s.CumulativeGasUsed, vers); err != nil { @@ -389,12 +389,12 @@ func (r *RawReceipt) RawTo(vals map[string]any) (Receipt, error) { BlockNumber: base.MustParseBlknum(r.BlockNumber), ContractAddress: base.HexToAddress(r.ContractAddress), CumulativeGasUsed: base.Gas(cumulativeGasUsed), - EffectiveGasPrice: base.MustParseNumeral(r.EffectiveGasPrice), - GasUsed: base.MustParseNumeral(r.GasUsed), + EffectiveGasPrice: base.MustParseGas(r.EffectiveGasPrice), + GasUsed: base.MustParseGas(r.GasUsed), Status: base.MustParseUint(r.Status), IsError: base.MustParseUint(r.Status) == 0, TransactionHash: base.HexToHash(r.TransactionHash), - TransactionIndex: base.MustParseNumeral(r.TransactionIndex), + TransactionIndex: base.MustParseIndex(r.TransactionIndex), Logs: logs, raw: r, } diff --git a/src/apps/chifra/pkg/types/types_result.go b/src/apps/chifra/pkg/types/types_result.go index a88a2998b8..d6f1051ca9 100644 --- a/src/apps/chifra/pkg/types/types_result.go +++ b/src/apps/chifra/pkg/types/types_result.go @@ -18,7 +18,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/cache" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) // EXISTING_CODE @@ -137,7 +136,7 @@ func (s *Result) Model(chain, format string, verbose bool, extraOptions map[stri } func (s *Result) Date() string { - return utils.FormattedDate(s.Timestamp) + return base.FormattedDate(s.Timestamp) } func (s *Result) CacheName() string { diff --git a/src/apps/chifra/pkg/types/types_slurp.go b/src/apps/chifra/pkg/types/types_slurp.go index 0f398a15ff..7b60d8aaeb 100644 --- a/src/apps/chifra/pkg/types/types_slurp.go +++ b/src/apps/chifra/pkg/types/types_slurp.go @@ -18,7 +18,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/cache" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" "github.com/ethereum/go-ethereum/common/hexutil" ) @@ -29,13 +28,11 @@ type RawSlurp struct { BlockNumber string `json:"blockNumber"` ContractAddress string `json:"contractAddress"` CumulativeGasUsed string `json:"cumulativeGasUsed"` - Ether string `json:"ether"` From string `json:"from"` FunctionName string `json:"functionName"` Gas string `json:"gas"` GasPrice string `json:"gasPrice"` GasUsed string `json:"gasUsed"` - HasToken string `json:"hasToken"` Hash string `json:"hash"` Input string `json:"input"` MethodId string `json:"methodId"` @@ -57,10 +54,8 @@ type Slurp struct { ArticulatedTx *Function `json:"articulatedTx"` BlockHash base.Hash `json:"blockHash"` BlockNumber base.Blknum `json:"blockNumber"` - CompressedTx string `json:"compressedTx"` ContractAddress base.Address `json:"contractAddress"` CumulativeGasUsed string `json:"cumulativeGasUsed"` - Ether base.Ether `json:"ether"` From base.Address `json:"from"` FunctionName string `json:"functionName"` Gas base.Gas `json:"gas"` @@ -76,9 +71,9 @@ type Slurp struct { To base.Address `json:"to"` TransactionIndex base.Txnum `json:"transactionIndex"` TxReceiptStatus string `json:"txReceiptStatus"` - ValidatorIndex base.Numeral `json:"validatorIndex"` + ValidatorIndex base.Index `json:"validatorIndex"` Value base.Wei `json:"value"` - WithdrawalIndex base.Numeral `json:"withdrawalIndex"` + WithdrawalIndex base.Index `json:"withdrawalIndex"` raw *RawSlurp `json:"-"` // EXISTING_CODE // EXISTING_CODE @@ -265,7 +260,7 @@ func (s *Slurp) Model(chain, format string, verbose bool, extraOptions map[strin } func (s *Slurp) Date() string { - return utils.FormattedDate(s.Timestamp) + return base.FormattedDate(s.Timestamp) } type SlurpGroup struct { @@ -324,11 +319,6 @@ func (s *Slurp) MarshalCache(writer io.Writer) (err error) { return err } - // CompressedTx - if err = cache.WriteValue(writer, s.CompressedTx); err != nil { - return err - } - // ContractAddress if err = cache.WriteValue(writer, s.ContractAddress); err != nil { return err @@ -339,11 +329,6 @@ func (s *Slurp) MarshalCache(writer io.Writer) (err error) { return err } - // Ether - if err = cache.WriteValue(writer, s.Ether); err != nil { - return err - } - // From if err = cache.WriteValue(writer, s.From); err != nil { return err @@ -461,11 +446,6 @@ func (s *Slurp) UnmarshalCache(vers uint64, reader io.Reader) (err error) { return err } - // CompressedTx - if err = cache.ReadValue(reader, &s.CompressedTx, vers); err != nil { - return err - } - // ContractAddress if err = cache.ReadValue(reader, &s.ContractAddress, vers); err != nil { return err @@ -476,11 +456,6 @@ func (s *Slurp) UnmarshalCache(vers uint64, reader io.Reader) (err error) { return err } - // Ether - if err = cache.ReadValue(reader, &s.Ether, vers); err != nil { - return err - } - // From if err = cache.ReadValue(reader, &s.From, vers); err != nil { return err diff --git a/src/apps/chifra/pkg/types/types_state.go b/src/apps/chifra/pkg/types/types_state.go index 0049b450fa..07198dda81 100644 --- a/src/apps/chifra/pkg/types/types_state.go +++ b/src/apps/chifra/pkg/types/types_state.go @@ -125,7 +125,7 @@ func (s *State) Model(chain, format string, verbose bool, extraOptions map[strin } func (s *State) Date() string { - return utils.FormattedDate(s.Timestamp) + return base.FormattedDate(s.Timestamp) } func (s *State) CacheName() string { diff --git a/src/apps/chifra/pkg/types/types_statement.go b/src/apps/chifra/pkg/types/types_statement.go index 97418234ea..257148ff50 100644 --- a/src/apps/chifra/pkg/types/types_statement.go +++ b/src/apps/chifra/pkg/types/types_statement.go @@ -19,7 +19,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/cache" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) // EXISTING_CODE @@ -187,7 +186,7 @@ func (s *Statement) Model(chain, format string, verbose bool, extraOptions map[s } func (s *Statement) Date() string { - return utils.FormattedDate(s.Timestamp) + return base.FormattedDate(s.Timestamp) } type StatementGroup struct { diff --git a/src/apps/chifra/pkg/types/types_timestamp.go b/src/apps/chifra/pkg/types/types_timestamp.go index 34131ef0f9..555a14b930 100644 --- a/src/apps/chifra/pkg/types/types_timestamp.go +++ b/src/apps/chifra/pkg/types/types_timestamp.go @@ -13,7 +13,6 @@ import ( "encoding/json" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) // EXISTING_CODE @@ -72,7 +71,7 @@ func (s *Timestamp) Model(chain, format string, verbose bool, extraOptions map[s } func (s *Timestamp) Date() string { - return utils.FormattedDate(s.Timestamp) + return base.FormattedDate(s.Timestamp) } // FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen diff --git a/src/apps/chifra/pkg/types/types_token.go b/src/apps/chifra/pkg/types/types_token.go index 21c7bfbc47..fa324ed4c9 100644 --- a/src/apps/chifra/pkg/types/types_token.go +++ b/src/apps/chifra/pkg/types/types_token.go @@ -14,7 +14,6 @@ import ( "math/big" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) // EXISTING_CODE @@ -155,7 +154,7 @@ func (s *Token) Model(chain, format string, verbose bool, extraOptions map[strin } func (s *Token) Date() string { - return utils.FormattedDate(s.Timestamp) + return base.FormattedDate(s.Timestamp) } // FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen diff --git a/src/apps/chifra/pkg/types/types_trace.go b/src/apps/chifra/pkg/types/types_trace.go index 9ff4f02c54..fcff823879 100644 --- a/src/apps/chifra/pkg/types/types_trace.go +++ b/src/apps/chifra/pkg/types/types_trace.go @@ -18,7 +18,7 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/cache" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/version" "github.com/ethereum/go-ethereum/common/hexutil" ) @@ -44,7 +44,6 @@ type Trace struct { ArticulatedTrace *Function `json:"articulatedTrace,omitempty"` BlockHash base.Hash `json:"blockHash"` BlockNumber base.Blknum `json:"blockNumber"` - CompressedTrace string `json:"compressedTrace,omitempty"` Error string `json:"error,omitempty"` Result *TraceResult `json:"result"` Subtraces uint64 `json:"subtraces"` @@ -55,8 +54,8 @@ type Trace struct { TraceType string `json:"type,omitempty"` raw *RawTrace `json:"-"` // EXISTING_CODE - TraceIndex base.TraceId `json:"-"` - sortString string `json:"-"` + TraceIndex base.Tracenum `json:"-"` + sortString string `json:"-"` // EXISTING_CODE } @@ -199,7 +198,7 @@ func (s *Trace) Model(chain, format string, verbose bool, extraOptions map[strin } func (s *Trace) Date() string { - return utils.FormattedDate(s.Timestamp) + return base.FormattedDate(s.Timestamp) } type TraceGroup struct { @@ -265,11 +264,6 @@ func (s *Trace) MarshalCache(writer io.Writer) (err error) { return err } - // CompressedTrace - if err = cache.WriteValue(writer, s.CompressedTrace); err != nil { - return err - } - // Error if err = cache.WriteValue(writer, s.Error); err != nil { return err @@ -349,9 +343,13 @@ func (s *Trace) UnmarshalCache(vers uint64, reader io.Reader) (err error) { return err } - // CompressedTrace - if err = cache.ReadValue(reader, &s.CompressedTrace, vers); err != nil { - return err + // Used to be CompressedTrace, since removed + vCompressedTrace := version.NewVersion("2.5.10") + if vers <= vCompressedTrace.Uint64() { + var val string + if err = cache.ReadValue(reader, &val, vers); err != nil { + return err + } } // Error diff --git a/src/apps/chifra/pkg/types/types_tracecount.go b/src/apps/chifra/pkg/types/types_tracecount.go index eeed3b47ce..97b2276aeb 100644 --- a/src/apps/chifra/pkg/types/types_tracecount.go +++ b/src/apps/chifra/pkg/types/types_tracecount.go @@ -13,7 +13,6 @@ import ( "encoding/json" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) // EXISTING_CODE @@ -80,7 +79,7 @@ func (s *TraceCount) Model(chain, format string, verbose bool, extraOptions map[ } func (s *TraceCount) Date() string { - return utils.FormattedDate(s.Timestamp) + return base.FormattedDate(s.Timestamp) } // FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen diff --git a/src/apps/chifra/pkg/types/types_transaction.go b/src/apps/chifra/pkg/types/types_transaction.go index 6a5a412ca5..303c9c61bc 100644 --- a/src/apps/chifra/pkg/types/types_transaction.go +++ b/src/apps/chifra/pkg/types/types_transaction.go @@ -18,7 +18,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/cache" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) type StorageSlot struct { @@ -72,7 +71,6 @@ type Transaction struct { ArticulatedTx *Function `json:"articulatedTx"` BlockHash base.Hash `json:"blockHash"` BlockNumber base.Blknum `json:"blockNumber"` - CompressedTx string `json:"compressedTx"` From base.Address `json:"from"` Gas base.Gas `json:"gas"` GasPrice base.Gas `json:"gasPrice"` @@ -323,7 +321,7 @@ func (s *Transaction) Model(chain, format string, verbose bool, extraOptions map } func (s *Transaction) Date() string { - return utils.FormattedDate(s.Timestamp) + return base.FormattedDate(s.Timestamp) } func (s *Transaction) CacheName() string { @@ -623,16 +621,16 @@ func NewTransaction(raw *RawTransaction, receipt *Receipt, timestamp base.Timest s.Hash = base.HexToHash(raw.Hash) s.BlockHash = base.HexToHash(raw.BlockHash) s.BlockNumber = base.MustParseBlknum(raw.BlockNumber) - s.TransactionIndex = base.MustParseNumeral(raw.TransactionIndex) - s.Nonce = base.MustParseNumeral(raw.Nonce) + s.TransactionIndex = base.MustParseIndex(raw.TransactionIndex) + s.Nonce = base.MustParseIndex(raw.Nonce) s.Timestamp = timestamp s.From = base.HexToAddress(raw.From) s.To = base.HexToAddress(raw.To) s.Value.SetString(raw.Value, 0) - s.Gas = base.MustParseNumeral(raw.Gas) - s.GasPrice = base.MustParseNumeral(raw.GasPrice) - s.MaxFeePerGas = base.MustParseNumeral(raw.MaxFeePerGas) - s.MaxPriorityFeePerGas = base.MustParseNumeral(raw.MaxPriorityFeePerGas) + s.Gas = base.MustParseGas(raw.Gas) + s.GasPrice = base.MustParseGas(raw.GasPrice) + s.MaxFeePerGas = base.MustParseGas(raw.MaxFeePerGas) + s.MaxPriorityFeePerGas = base.MustParseGas(raw.MaxPriorityFeePerGas) s.Input = raw.Input s.TransactionType = raw.TransactionType diff --git a/src/apps/chifra/pkg/types/types_withdrawal.go b/src/apps/chifra/pkg/types/types_withdrawal.go index c5898b8f61..0ecf0a2e28 100644 --- a/src/apps/chifra/pkg/types/types_withdrawal.go +++ b/src/apps/chifra/pkg/types/types_withdrawal.go @@ -18,7 +18,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/cache" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils" ) // EXISTING_CODE @@ -38,9 +37,9 @@ type Withdrawal struct { Address base.Address `json:"address"` Amount base.Wei `json:"amount"` BlockNumber base.Blknum `json:"blockNumber"` - Index base.Numeral `json:"index"` + Index base.Index `json:"index"` Timestamp base.Timestamp `json:"timestamp"` - ValidatorIndex base.Numeral `json:"validatorIndex"` + ValidatorIndex base.Index `json:"validatorIndex"` raw *RawWithdrawal `json:"-"` // EXISTING_CODE // EXISTING_CODE @@ -99,7 +98,7 @@ func (s *Withdrawal) Model(chain, format string, verbose bool, extraOptions map[ } func (s *Withdrawal) Date() string { - return utils.FormattedDate(s.Timestamp) + return base.FormattedDate(s.Timestamp) } type WithdrawalGroup struct { diff --git a/src/apps/chifra/pkg/uniq/uniq_appearances_details.go b/src/apps/chifra/pkg/uniq/uniq_appearances_details.go index 8c7413645b..add592f7ce 100644 --- a/src/apps/chifra/pkg/uniq/uniq_appearances_details.go +++ b/src/apps/chifra/pkg/uniq/uniq_appearances_details.go @@ -89,7 +89,7 @@ func GetUniqAddressesInBlock(chain, flow string, conn *rpc.Connection, procFunc return nil } -func GetUniqAddressesInTransaction(chain string, procFunc UniqProcFunc, flow string, trans *types.Transaction, ts int64, addrMap AddressBooleanMap, conn *rpc.Connection) error { +func GetUniqAddressesInTransaction(chain string, procFunc UniqProcFunc, flow string, trans *types.Transaction, ts base.Timestamp, addrMap AddressBooleanMap, conn *rpc.Connection) error { bn := trans.BlockNumber txid := trans.TransactionIndex traceid := base.NOPOSN @@ -130,7 +130,7 @@ func GetUniqAddressesInTransaction(chain string, procFunc UniqProcFunc, flow str } // uniqFromLogsDetails extracts addresses from the logs -func uniqFromLogsDetails(chain string, procFunc UniqProcFunc, flow string, logs []types.Log, ts int64, addrMap AddressBooleanMap) (err error) { +func uniqFromLogsDetails(chain string, procFunc UniqProcFunc, flow string, logs []types.Log, ts base.Timestamp, addrMap AddressBooleanMap) (err error) { traceid := base.NOPOSN for l, log := range logs { generator := log.Address.Hex() @@ -160,7 +160,7 @@ func uniqFromLogsDetails(chain string, procFunc UniqProcFunc, flow string, logs return } -func traceReason(traceId base.TraceId, trace *types.Trace, r string) string { +func traceReason(traceId base.Tracenum, trace *types.Trace, r string) string { switch r { case "from": fallthrough @@ -197,7 +197,7 @@ func traceReason(traceId base.TraceId, trace *types.Trace, r string) string { } // uniqFromTracesDetails extracts addresses from traces -func uniqFromTracesDetails(chain string, procFunc UniqProcFunc, flow string, traces []types.Trace, ts int64, addrMap AddressBooleanMap, conn *rpc.Connection) (err error) { +func uniqFromTracesDetails(chain string, procFunc UniqProcFunc, flow string, traces []types.Trace, ts base.Timestamp, addrMap AddressBooleanMap, conn *rpc.Connection) (err error) { for _, trace := range traces { traceid := trace.TraceIndex bn := base.Blknum(trace.BlockNumber) @@ -326,7 +326,7 @@ var mapSync2 sync.Mutex // streamAppearance streams an appearance to the model channel if we've not seen this appearance before. We // keep track of appearances we've seen with `appsMap`. -func streamAppearance(procFunc UniqProcFunc, flow string, reason string, address string, bn base.Blknum, txid base.Txnum, traceid base.TraceId, ts int64, addrMap AddressBooleanMap) { +func streamAppearance(procFunc UniqProcFunc, flow string, reason string, address string, bn base.Blknum, txid base.Txnum, traceid base.Tracenum, ts base.Timestamp, addrMap AddressBooleanMap) { if base.IsPrecompile(address) { return } diff --git a/src/apps/chifra/pkg/utils/formatted.go b/src/apps/chifra/pkg/utils/formatted.go index 408de1180d..e836a8a33b 100644 --- a/src/apps/chifra/pkg/utils/formatted.go +++ b/src/apps/chifra/pkg/utils/formatted.go @@ -6,14 +6,8 @@ package utils import ( "strings" - - "github.com/bykof/gostradamus" ) -func FormattedDate(ts int64) string { - return gostradamus.FromUnixTimestamp(ts).Format("2006-01-02 15:04:05 UTC") -} - func FormattedCode(verbose bool, code string) string { codeLen := len(code) if verbose || codeLen <= 128 { diff --git a/src/apps/chifra/pkg/version/string.go b/src/apps/chifra/pkg/version/string.go index 1d32c0b797..1ec530ec91 100644 --- a/src/apps/chifra/pkg/version/string.go +++ b/src/apps/chifra/pkg/version/string.go @@ -7,4 +7,4 @@ package version -const LibraryVersion = "GHC-TrueBlocks//2.5.10-release" +const LibraryVersion = "GHC-TrueBlocks//2.5.11-release" diff --git a/src/dev_tools/goMaker/templates/base-types.csv b/src/dev_tools/goMaker/templates/base-types.csv index 0ec884128e..d70c9549f6 100644 --- a/src/dev_tools/goMaker/templates/base-types.csv +++ b/src/dev_tools/goMaker/templates/base-types.csv @@ -10,12 +10,12 @@ base ,ether ,a big number float ,as a stri base ,float64 ,a double precision float ,64 bits base ,gas ,a 64-bit unsigned integer , base ,hash ,an '0x'-prefixed 32-byte hex string ,lowercase +base ,index ,an alias for a uint64 , base ,int256 ,a signed big number ,as a string base ,int64 ,a 64-bit signed integer , base ,ipfshash ,a multi-hash produced by IPFS ,mixed-case base ,lognum ,an alias for a uint64 , base ,nonce ,a 64-bit unsigned integer , -base ,numeral ,an alias for a uint64 , base ,string ,a normal character string , base ,[]string ,an array of strings , base ,timestamp ,a 64-bit unsigned integer ,Unix timestamp diff --git a/src/dev_tools/goMaker/templates/classDefinitions/fields/log.csv b/src/dev_tools/goMaker/templates/classDefinitions/fields/log.csv index ec243154ae..c946a69fee 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/fields/log.csv +++ b/src/dev_tools/goMaker/templates/classDefinitions/fields/log.csv @@ -1,13 +1,13 @@ -name ,type ,strDefault ,attributes ,docOrder ,description -blockNumber ,blknum , , , 1 ,the number of the block -transactionIndex ,txnum , , , 2 ,the zero-indexed position of the transaction in the block -logIndex ,lognum , , , 3 ,the zero-indexed position of this log relative to the block -timestamp ,timestamp , ,omitempty|simponly , 4 ,the timestamp of the block this log appears in -date ,datetime , ,calc , 5 ,the timestamp as a date -address ,address , , , 6 ,the smart contract that emitted this log -topics ,[]topic , ,omitempty , 7 ,the first topic hashes event signature of the log, up to 3 additional index parameters may appear -data ,bytes , ,omitempty , 8 ,any remaining un-indexed parameters to the event -transactionHash ,hash , , , 9 ,the hash of the transction -blockHash ,hash , , , 10 ,the hash of the block -articulatedLog ,*Function , ,omitempty|simponly , 11 ,a human-readable version of the topic and data fields -compressedLog ,string , ,omitempty|simponly , 12 ,a truncated, more readable version of the articulation +name ,type ,strDefault ,attributes ,upgrades ,docOrder ,description +blockNumber ,blknum , , , , 1 ,the number of the block +transactionIndex ,txnum , , , , 2 ,the zero-indexed position of the transaction in the block +logIndex ,lognum , , , , 3 ,the zero-indexed position of this log relative to the block +timestamp ,timestamp , ,omitempty|simponly , , 4 ,the timestamp of the block this log appears in +date ,datetime , ,calc , , 5 ,the timestamp as a date +address ,address , , , , 6 ,the smart contract that emitted this log +topics ,[]topic , ,omitempty , , 7 ,the first topic hashes event signature of the log, up to 3 additional index parameters may appear +data ,bytes , ,omitempty , , 8 ,any remaining un-indexed parameters to the event +transactionHash ,hash , , , , 9 ,the hash of the transction +blockHash ,hash , , , , 10 ,the hash of the block +articulatedLog ,*Function , ,omitempty|simponly , , 11 ,a human-readable version of the topic and data fields +compressedLog ,string , ,calc ,2.5.10:string , 12 ,a truncated, more readable version of the articulation diff --git a/src/dev_tools/goMaker/templates/classDefinitions/fields/slurp.csv b/src/dev_tools/goMaker/templates/classDefinitions/fields/slurp.csv index dd3aa6e917..dbd8cd5ad3 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/fields/slurp.csv +++ b/src/dev_tools/goMaker/templates/classDefinitions/fields/slurp.csv @@ -1,27 +1,27 @@ -name ,type ,strDefault ,attributes ,docOrder ,description -hash ,hash , , , 1 ,the hash of the transaction -blockHash ,hash , , , 2 ,the hash of the block containing this transaction -blockNumber ,blknum , , , 3 ,the number of the block -transactionIndex ,txnum , , , 4 ,the zero-indexed position of the transaction in the block -nonce ,nonce , , , 5 ,sequence number of the transactions sent by the sender -timestamp ,timestamp , , , 6 ,the Unix timestamp of the object -date ,datetime , ,calc , 7 ,the timestamp as a date -from ,address , , , 8 ,address from which the transaction was sent -to ,address , , , 9 ,address to which the transaction was sent -value ,wei , , , 10 ,the amount of wei sent with this transactions -ether ,ether , , , 11 ,if --ether is specified, the value in ether -gas ,gas , , , 12 ,the maximum number of gas allowed for this transaction -gasPrice ,gas , , , 13 ,the number of wei per unit of gas the sender is willing to spend -input ,bytes , , , 14 ,byte data either containing a message or funcational data for a smart contracts. See the --articulate -hasToken ,bool , , , 15 ,`true` if the transaction is token related, `false` otherwise -articulatedTx ,*Function , ,simponly , 16 ,if present, the function that was called in the transaction -compressedTx ,string , ,simponly , 17 ,truncated, more readable version of the articulation -isError ,bool , ,simponly , 18 ,`true` if the transaction ended in error, `false` otherwise -functionName ,string , , , ,the name of the articulated function if any -methodId ,string , , , ,the fourbyte of the function -gasUsed ,gas , , , ,the amount of gas used by the transaction (from the receipt) -contractAddress ,address , , , ,if created, the address of the newly-created contract -cumulativeGasUsed ,string , , , ,a basically unused field showing all gas used -txReceiptStatus ,string , , , ,the status field from the receipt -withdrawalIndex ,numeral , , , ,for withdrawal transactions only, the index of the withdrawal since inception -validatorIndex ,numeral , , , ,for withdrawal transactions only, the index of the validator receiving the withdrawal +name ,type ,strDefault ,attributes ,docOrder ,description +hash ,hash , , , 1 ,the hash of the transaction +blockHash ,hash , , , 2 ,the hash of the block containing this transaction +blockNumber ,blknum , , , 3 ,the number of the block +transactionIndex ,txnum , , , 4 ,the zero-indexed position of the transaction in the block +nonce ,nonce , , , 5 ,sequence number of the transactions sent by the sender +timestamp ,timestamp , , , 6 ,the Unix timestamp of the object +date ,datetime , ,calc , 7 ,the timestamp as a date +from ,address , , , 8 ,address from which the transaction was sent +to ,address , , , 9 ,address to which the transaction was sent +value ,wei , , , 10 ,the amount of wei sent with this transactions +ether ,ether , ,calc , 11 ,if --ether is specified, the value in ether +gas ,gas , , , 12 ,the maximum number of gas allowed for this transaction +gasPrice ,gas , , , 13 ,the number of wei per unit of gas the sender is willing to spend +input ,bytes , , , 14 ,byte data either containing a message or funcational data for a smart contracts. See the --articulate +hasToken ,bool , ,simponly , 15 ,`true` if the transaction is token related, `false` otherwise +articulatedTx ,*Function , ,simponly , 16 ,if present, the function that was called in the transaction +compressedTx ,string , ,calc , 17 ,truncated, more readable version of the articulation +isError ,bool , ,simponly , 18 ,`true` if the transaction ended in error, `false` otherwise +functionName ,string , , , ,the name of the articulated function if any +methodId ,string , , , ,the fourbyte of the function +gasUsed ,gas , , , ,the amount of gas used by the transaction (from the receipt) +contractAddress ,address , , , ,if created, the address of the newly-created contract +cumulativeGasUsed ,string , , , ,a basically unused field showing all gas used +txReceiptStatus ,string , , , ,the status field from the receipt +withdrawalIndex ,index , , , ,for withdrawal transactions only, the index of the withdrawal since inception +validatorIndex ,index , , , ,for withdrawal transactions only, the index of the validator receiving the withdrawal diff --git a/src/dev_tools/goMaker/templates/classDefinitions/fields/trace.csv b/src/dev_tools/goMaker/templates/classDefinitions/fields/trace.csv index bcfef7dca3..276300a3bd 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/fields/trace.csv +++ b/src/dev_tools/goMaker/templates/classDefinitions/fields/trace.csv @@ -1,15 +1,15 @@ -name ,type ,strDefault ,attributes ,docOrder ,description -blockHash ,hash , , , 1 ,the hash of the block containing this trace -blockNumber ,blknum , , , 2 ,the number of the block -subtraces ,uint64 , , , 8 ,the number of children traces that the trace hash -traceAddress ,[]uint64 , , , 7 ,a particular trace's address in the trace tree -transactionHash ,hash , , , 5 ,the transaction's hash containing this trace -transactionIndex ,txnum , , , 6 ,the zero-indexed position of the transaction in the block -type ,string , ,omitempty , 9 ,the type of the trace -error ,string , ,omitempty , , -action ,*TraceAction , , , 10 ,the trace action for this trace -result ,*TraceResult , , , 11 ,the trace result of this trace -articulatedTrace ,*Function , ,omitempty|simponly , 12 ,human readable version of the trace action input data -compressedTrace ,string , ,omitempty|simponly , 13 ,a compressed string version of the articulated trace -timestamp ,timestamp , ,simponly , 3 ,the timestamp of the block -date ,datetime , ,omitempty|calc , 4 ,the timestamp as a date +name ,type ,strDefault ,attributes ,upgrades ,docOrder ,description +blockHash ,hash , , , , 1 ,the hash of the block containing this trace +blockNumber ,blknum , , , , 2 ,the number of the block +subtraces ,uint64 , , , , 8 ,the number of children traces that the trace hash +traceAddress ,[]uint64 , , , , 7 ,a particular trace's address in the trace tree +transactionHash ,hash , , , , 5 ,the transaction's hash containing this trace +transactionIndex ,txnum , , , , 6 ,the zero-indexed position of the transaction in the block +type ,string , ,omitempty , , 9 ,the type of the trace +error ,string , ,omitempty , , , +action ,*TraceAction , , , , 10 ,the trace action for this trace +result ,*TraceResult , , , , 11 ,the trace result of this trace +articulatedTrace ,*Function , ,omitempty|simponly , , 12 ,human readable version of the trace action input data +compressedTrace ,string , ,calc ,2.5.10:string , 13 ,a compressed string version of the articulated trace +timestamp ,timestamp , ,simponly , , 3 ,the timestamp of the block +date ,datetime , ,omitempty|calc , , 4 ,the timestamp as a date diff --git a/src/dev_tools/goMaker/templates/classDefinitions/fields/transaction.csv b/src/dev_tools/goMaker/templates/classDefinitions/fields/transaction.csv index 88d2e3a40d..afc8ef9c77 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/fields/transaction.csv +++ b/src/dev_tools/goMaker/templates/classDefinitions/fields/transaction.csv @@ -22,7 +22,7 @@ hasToken ,bool , ,simponly , 18 ,`true` receipt ,*Receipt , ,simponly , 15 , traces ,[]Trace , ,simponly , , articulatedTx ,*Function , ,simponly , 17 , -compressedTx ,string , ,simponly , 20 ,truncated, more readable version of the articulation +compressedTx ,string , ,calc , 20 ,truncated, more readable version of the articulation statements ,[]Statement , ,simponly|calc , 16 ,array of reconciliations gasUsed ,gas , ,simponly , , type ,string , , , , diff --git a/src/dev_tools/goMaker/templates/classDefinitions/fields/withdrawal.csv b/src/dev_tools/goMaker/templates/classDefinitions/fields/withdrawal.csv index fce9a3ab40..01bc968c04 100644 --- a/src/dev_tools/goMaker/templates/classDefinitions/fields/withdrawal.csv +++ b/src/dev_tools/goMaker/templates/classDefinitions/fields/withdrawal.csv @@ -3,7 +3,7 @@ address ,address , , , 1 ,the recipient for t amount ,wei , , , 2 ,a nonzero amount of ether given in gwei (1e9 wei) ether ,ether , ,calc , 3 ,if --ether is specified, the amount in ether blockNumber ,blknum , , , 4 ,the number of this block -index ,numeral , , , 5 ,a monotonically increasing zero-based index that increments by 1 per withdrawal to uniquely identify each withdrawal +index ,index , , , 5 ,a monotonically increasing zero-based index that increments by 1 per withdrawal to uniquely identify each withdrawal timestamp ,timestamp , , , 6 ,the timestamp for this block date ,datetime , ,calc , 7 ,the timestamp as a date -validatorIndex ,numeral , , , 8 ,the validator_index of the validator on the consensus layer the withdrawal corresponds to +validatorIndex ,index , , , 8 ,the validator_index of the validator on the consensus layer the withdrawal corresponds to diff --git a/src/dev_tools/goMaker/templates/src_apps_chifra_pkg_types_type.go.tmpl b/src/dev_tools/goMaker/templates/src_apps_chifra_pkg_types_type.go.tmpl index b09983b23b..826f8bc50a 100644 --- a/src/dev_tools/goMaker/templates/src_apps_chifra_pkg_types_type.go.tmpl +++ b/src/dev_tools/goMaker/templates/src_apps_chifra_pkg_types_type.go.tmpl @@ -52,7 +52,7 @@ func (s *{{.ModelName ""}}) Model(chain, format string, verbose bool, extraOptio {{if .HasTimestamp}} func (s *{{.ModelName ""}}) Date() string { - return utils.FormattedDate(s.Timestamp) + return base.FormattedDate(s.Timestamp) } {{end}} diff --git a/src/dev_tools/goMaker/types/types_codebase.go b/src/dev_tools/goMaker/types/types_codebase.go index 1dca0987de..046ff6c62e 100644 --- a/src/dev_tools/goMaker/types/types_codebase.go +++ b/src/dev_tools/goMaker/types/types_codebase.go @@ -121,7 +121,7 @@ var knownTypes = map[string]bool{ "ipfshash": true, "lognum": true, "nonce": true, - "numeral": true, + "index": true, "RawAppearance": true, "StorageSlot": true, "string": true, diff --git a/src/dev_tools/goMaker/types/types_member.go b/src/dev_tools/goMaker/types/types_member.go index 30c2446d19..d90bcb6741 100644 --- a/src/dev_tools/goMaker/types/types_member.go +++ b/src/dev_tools/goMaker/types/types_member.go @@ -238,8 +238,8 @@ func (m *Member) GoType() string { ret = "base.Txnum" case "lognum": ret = "base.Lognum" - case "numeral": - ret = "base.Numeral" + case "index": + ret = "base.Index" case "timestamp": ret = "base.Timestamp" case "topic": @@ -269,11 +269,11 @@ func (m *Member) NeedsPtr() bool { m.IsObject() } +// MarshalCode writes the writer code for caching this item func (m *Member) MarshalCode() string { if m.IsCalc() || m.IsRawOnly() || - (m.Container() == "Transaction" && - (m.GoName() == "CompressedTx" || m.GoName() == "Traces")) { + (m.Container() == "Transaction" && m.GoName() == "Traces") { return "" } @@ -345,11 +345,12 @@ func (m *Member) MarshalCode() string { return m.executeTemplate(tmplName, tmpl) } +// UnmarshalCode writes the reader code for caching this item func (m *Member) UnmarshalCode() string { - if m.IsCalc() || + wasRemoved := m.HasUpgrade() && m.IsCalc() + if (!wasRemoved && m.IsCalc()) || m.IsRawOnly() || - (m.Container() == "Transaction" && - (m.GoName() == "CompressedTx" || m.GoName() == "Traces")) { + (m.Container() == "Transaction" && m.GoName() == "Traces") { return "" } @@ -411,8 +412,21 @@ func (m *Member) UnmarshalCode() string { code := m.executeTemplate(tmplName, tmpl) if m.HasUpgrade() { - tmplName := "upgrage" - tmpl := ` // {{.GoName}} + if wasRemoved { + tmplName = "upgrageRemoved" + tmpl = ` // Used to be {{.GoName}}, since removed + v{{.GoName}} := version.NewVersion("++VERS++") + if vers <= v{{.GoName}}.Uint64() { + var val ++PRIOR_TYPE++ + if err = cache.ReadValue(reader, &val, vers); err != nil { + return err + } + } + +` + } else { + tmplName = "upgrage" + tmpl = ` // {{.GoName}} v{{.GoName}} := version.NewVersion("++VERS++") if vers <= v{{.GoName}}.Uint64() { var val ++PRIOR_TYPE++ @@ -425,6 +439,8 @@ func (m *Member) UnmarshalCode() string { } ` + } + cc := strings.Trim(code, "\n") parts := strings.Split(m.Upgrades, ":") if len(parts) != 2 { @@ -441,7 +457,7 @@ func (m *Member) UnmarshalCode() string { } // TODO: hack mm := map[string]string{ - "CumulativeGasUsed": "base.MustParseNumeral", + "CumulativeGasUsed": "base.MustParseGas", "Status": "uint64", "BaseFeePerGas": "weiToGas", } @@ -462,7 +478,7 @@ func (m *Member) YamlType() string { } if m.IsObject() { return "object" + o - } else if m.Type == "blknum" || m.Type == "txnum" || m.Type == "lognum" || m.Type == "numeral" || + } else if m.Type == "blknum" || m.Type == "txnum" || m.Type == "lognum" || m.Type == "index" || m.Type == "timestamp" || m.Type == "float64" || m.Type == "gas" || m.Type == "uint64" || m.Type == "int64" || m.Type == "uint32" || m.Type == "int" || m.Type == "nonce" { return "number" + f diff --git a/src/dev_tools/sdkFuzzer/abis.go b/src/dev_tools/sdkFuzzer/abis.go index e4ff0431bb..561bd2914e 100644 --- a/src/dev_tools/sdkFuzzer/abis.go +++ b/src/dev_tools/sdkFuzzer/abis.go @@ -96,30 +96,30 @@ func TestAbis(which, f, fn string, opts *sdk.AbisOptions) { switch which { case "abis": if funcs, _, err := opts.Abis(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Function](fn, funcs); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "encode": if funcs, _, err := opts.AbisEncode(f); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Function](fn, funcs); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "find": if funcs, _, err := opts.AbisFind([]string{f}); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Function](fn, funcs); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } diff --git a/src/dev_tools/sdkFuzzer/blocks.go b/src/dev_tools/sdkFuzzer/blocks.go index 046138009c..cde45665ec 100644 --- a/src/dev_tools/sdkFuzzer/blocks.go +++ b/src/dev_tools/sdkFuzzer/blocks.go @@ -89,80 +89,80 @@ func TestBlocks(which, fn string, opts *sdk.BlocksOptions) { switch which { case "txs": if blocks, _, err := opts.Blocks(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Block[types.Transaction]](fn, blocks); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "hashes": if blocks, _, err := opts.BlocksHashes(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Block[string]](fn, blocks); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "uncles": if uncles, _, err := opts.BlocksUncles(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Block[string]](fn, uncles); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "traces": if traces, _, err := opts.BlocksTraces(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Trace](fn, traces); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "uniq": if apps, _, err := opts.BlocksUniq(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Appearance](fn, apps); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "logs": if logs, _, err := opts.BlocksLogs(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Log](fn, logs); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "withdrawals": if withdrawals, _, err := opts.BlocksWithdrawals(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Withdrawal](fn, withdrawals); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "count": if counts, _, err := opts.BlocksCount(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.BlockCount](fn, counts); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } diff --git a/src/dev_tools/sdkFuzzer/chunks.go b/src/dev_tools/sdkFuzzer/chunks.go index 6c90a04835..c62e46523f 100644 --- a/src/dev_tools/sdkFuzzer/chunks.go +++ b/src/dev_tools/sdkFuzzer/chunks.go @@ -2,16 +2,20 @@ package main import ( "github.com/TrueBlocks/trueblocks-core/sdk" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) // DoChunks tests the chunks sdk function func DoChunks() { + file.EstablishFolder("sdkFuzzer-output/chunks") opts := sdk.ChunksOptions{ - FirstBlock: 1000, - LastBlock: 2000, + FirstBlock: 0, + LastBlock: base.NOPOSN, + MaxAddrs: base.NOPOS, } - ShowHeader("ChunksManifest", &opts) // BlockIds []string `json:"blocks,omitempty"` // Check bool `json:"check,omitempty"` @@ -20,98 +24,105 @@ func DoChunks() { // Publisher base.Address `json:"publisher,omitempty"` // Remote bool `json:"remote,omitempty"` // Belongs []string `json:"belongs,omitempty"` - // FirstBlock base.Blknum `json:"firstBlock,omitempty"` - // LastBlock base.Blknum `json:"lastBlock,omitempty"` - // MaxAddrs uint64 `json:"maxAddrs,omitempty"` // Deep bool `json:"deep,omitempty"` // Rewrite bool `json:"rewrite,omitempty"` // List bool `json:"list,omitempty"` // Unpin bool `json:"unpin,omitempty"` // Count bool `json:"count,omitempty"` // Sleep float64 `json:"sleep,omitempty"` - // func (opts *ChunksOptions) ChunksManifest() ([]types.ChunkManifest, *types.MetaData, error) { - // func (opts *ChunksOptions) ChunksIndex() ([]types.ChunkIndex, *types.MetaData, error) { - // func (opts *ChunksOptions) ChunksBlooms() ([]types.ChunkBloom, *types.MetaData, error) { - // func (opts *ChunksOptions) ChunksPins() ([]types.ChunkPin, *types.MetaData, error) { - // func (opts *ChunksOptions) ChunksAddresses() ([]types.ChunkAddress, *types.MetaData, error) { - // func (opts *ChunksOptions) ChunksAppearances() ([]types.ChunkAppearance, *types.MetaData, error) { - // func (opts *ChunksOptions) ChunksStats() ([]types.ChunkStats, *types.MetaData, error) { + ShowHeader("ChunksManifest", &opts) + + baseFn := "chunks/chunks" + fn := getFilename(baseFn, &opts.Globals) + TestChunks("manifest", fn, &opts) + TestChunks("index", fn, &opts) + // TestChunks("blooms", fn, &opts) + // TestChunks("pins", fn, &opts) + // TestChunks("addresses", fn, &opts) + // TestChunks("appearances", fn, &opts) + TestChunks("stats", fn, &opts) + // func (opts *ChunksOptions) ChunksTruncate(val base.Blknum) ([]types.Message, *types.MetaData, error) { // func (opts *ChunksOptions) ChunksDiff() ([]types.Message, *types.MetaData, error) { // func (opts *ChunksOptions) ChunksTag(val string) ([]types.Message, *types.MetaData, error) { - // NoCHM ChunksMode = 0 - // CMManifest = 1 << iota - // CMIndex - // CMBlooms - // CMPins - // CMAddresses - // CMAppearances - // CMStats +} - if chunksManifest, _, err := opts.ChunksManifest(); err != nil { - logger.Error(err) - } else { - if err := SaveToFile("sdkFuzzer/chunksManifest.json", chunksManifest); err != nil { - logger.Error(err) +func TestChunks(which, fn string, opts *sdk.ChunksOptions) { + fn += "-" + which + logger.Info("-------------", fn, "-------------") + switch which { + case "manifest": + if manifest, _, err := opts.ChunksManifest(); err != nil { + ReportError(fn, opts, err) + } else { + if err := SaveToFile[types.ChunkManifest](fn, manifest); err != nil { + ReportError2(fn, err) + } else { + ReportOkay(fn) + } } - } - - ShowHeader("ChunksIndex", &opts) - if chunksIndex, _, err := opts.ChunksIndex(); err != nil { - logger.Error(err) - } else { - if err := SaveToFile("sdkFuzzer/chunksIndex.json", chunksIndex); err != nil { - logger.Error(err) + case "index": + if index, _, err := opts.ChunksIndex(); err != nil { + ReportError(fn, opts, err) + } else { + if err := SaveToFile[types.ChunkIndex](fn, index); err != nil { + ReportError2(fn, err) + } else { + ReportOkay(fn) + } } - } - - ShowHeader("ChunksBlooms", &opts) - if chunksBlooms, _, err := opts.ChunksBlooms(); err != nil { - logger.Error(err) - } else { - if err := SaveToFile("sdkFuzzer/chunksBlooms.json", chunksBlooms); err != nil { - logger.Error(err) + case "blooms": + if blooms, _, err := opts.ChunksBlooms(); err != nil { + ReportError(fn, opts, err) + } else { + if err := SaveToFile[types.ChunkBloom](fn, blooms); err != nil { + ReportError2(fn, err) + } else { + ReportOkay(fn) + } } - } - - ShowHeader("ChunksPins", &opts) - opts.List = true - if chunksPins, _, err := opts.ChunksPins(); err != nil { - logger.Error(err) - } else { - if err := SaveToFile("sdkFuzzer/chunksPins.json", chunksPins); err != nil { - logger.Error(err) + case "pins": + // TODO: Not sure this is included in the SDK + opts.List = true + if pins, _, err := opts.ChunksPins(); err != nil { + ReportError(fn, opts, err) + } else { + if err := SaveToFile[types.ChunkPin](fn, pins); err != nil { + ReportError2(fn, err) + } else { + ReportOkay(fn) + } } - } - - ShowHeader("ChunksAddresses", &opts) - opts.List = false - // if chunksAddresses, _, err := opts.ChunksAddresses(); err != nil { - // logger.Error(err) - // } else { - // if err := SaveToFile("sdkFuzzer/chunksAddresses.json", chunksAddresses); err != nil { - // logger.Error(err) - // } - // } - - ShowHeader("ChunksAppearances", &opts) - // if chunksAppearances, _, err := opts.ChunksAppearances(); err != nil { - // logger.Error(err) - // } else { - // if err := SaveToFile("sdkFuzzer/chunksAppearances.json", chunksAppearances, &opts, func() error { - // _, _, err := opts.ChunksAppearances() - // return err - // }); err != nil { - // logger.Error(err) - // } - // } - - ShowHeader("ChunksStats", &opts) - if chunkStats, _, err := opts.ChunksStats(); err != nil { - logger.Error(err) - } else { - if err := SaveToFile("sdkFuzzer/chunkStats.json", chunkStats); err != nil { - logger.Error(err) + opts.List = false + case "addresses": + if addresses, _, err := opts.ChunksAddresses(); err != nil { + ReportError(fn, opts, err) + } else { + if err := SaveToFile[types.ChunkAddress](fn, addresses); err != nil { + ReportError2(fn, err) + } else { + ReportOkay(fn) + } + } + case "appearances": + if appearances, _, err := opts.ChunksAppearances(); err != nil { + ReportError(fn, opts, err) + } else { + if err := SaveToFile[types.ChunkAppearance](fn, appearances); err != nil { + ReportError2(fn, err) + } else { + ReportOkay(fn) + } + } + case "stats": + if stats, _, err := opts.ChunksStats(); err != nil { + ReportError(fn, opts, err) + } else { + if err := SaveToFile[types.ChunkStats](fn, stats); err != nil { + ReportError2(fn, err) + } else { + ReportOkay(fn) + } } } } diff --git a/src/dev_tools/sdkFuzzer/config.go b/src/dev_tools/sdkFuzzer/config.go index 67ea90f66a..8c34d3be9a 100644 --- a/src/dev_tools/sdkFuzzer/config.go +++ b/src/dev_tools/sdkFuzzer/config.go @@ -24,10 +24,10 @@ func TestConfig(which, fn string, opts *sdk.ConfigOptions) { switch which { case "paths": if paths, _, err := opts.ConfigPaths(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.CacheItem](fn, paths); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } diff --git a/src/dev_tools/sdkFuzzer/globals.go b/src/dev_tools/sdkFuzzer/globals.go index d16815c45a..49bdb4de2c 100644 --- a/src/dev_tools/sdkFuzzer/globals.go +++ b/src/dev_tools/sdkFuzzer/globals.go @@ -32,7 +32,12 @@ func getFilename(baseName string, g *sdk.Globals) string { var spaces = strings.Repeat(" ", 30) -func ReportError(fn string, err error) { +func ReportError(fn string, opts fmt.Stringer, err error) { + logger.Error(fmt.Errorf("NO %s (%s): %v%s", fn, opts.String(), err, spaces)) + logger.Error(fmt.Errorf("NO %s (%s): %v%s", fn, opts.String(), err, spaces)) +} + +func ReportError2(fn string, err error) { logger.Error(fmt.Errorf("NO %s: %v%s", fn, err, spaces)) } diff --git a/src/dev_tools/sdkFuzzer/list.go b/src/dev_tools/sdkFuzzer/list.go index c95c3fd3c1..eeead5ab0e 100644 --- a/src/dev_tools/sdkFuzzer/list.go +++ b/src/dev_tools/sdkFuzzer/list.go @@ -75,30 +75,30 @@ func TestList(which, fn string, opts *sdk.ListOptions) { switch which { case "list": if apps, _, err := opts.List(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Appearance](fn, apps); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "count": if counts, _, err := opts.ListCount(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.AppearanceCount](fn, counts); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "bounds": if bounds, _, err := opts.ListBounds(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Bounds](fn, bounds); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } diff --git a/src/dev_tools/sdkFuzzer/logs.go b/src/dev_tools/sdkFuzzer/logs.go index 7930ff53ee..e72a81aaea 100644 --- a/src/dev_tools/sdkFuzzer/logs.go +++ b/src/dev_tools/sdkFuzzer/logs.go @@ -47,10 +47,10 @@ func DoLogs() { func TestLogs(fn string, opts *sdk.LogsOptions) { if logs, _, err := opts.Logs(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Log](fn, logs); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } diff --git a/src/dev_tools/sdkFuzzer/main.go b/src/dev_tools/sdkFuzzer/main.go index 80110ee597..91a000f85b 100644 --- a/src/dev_tools/sdkFuzzer/main.go +++ b/src/dev_tools/sdkFuzzer/main.go @@ -5,23 +5,22 @@ import ( ) func main() { - DoReceipts() - DoLogs() - DoTraces() - DoState() - DoAbis() - DoBlocks() - DoWhen() - DoList() - DoNames() // does not test crud commands - DoConfig() - DoTransactions() - DoTokens() - // DoSlurp() - - // DoChunks() - // DoExport() - DoStatus() + // DoReceipts() + // DoLogs() + // DoTraces() + // DoState() + // DoAbis() + // DoBlocks() + // DoWhen() + // DoList() + // DoNames() // this does not test crud commands + // DoChunks() // this needs a lot of work + // DoConfig() + // DoTransactions() + // DoTokens() + // DoStatus() + DoSlurp() + //- DoExport() // DoInit() // DoMonitors() diff --git a/src/dev_tools/sdkFuzzer/names.go b/src/dev_tools/sdkFuzzer/names.go index 527a08f361..bd75644ade 100644 --- a/src/dev_tools/sdkFuzzer/names.go +++ b/src/dev_tools/sdkFuzzer/names.go @@ -99,30 +99,30 @@ func TestNames(which, fn string, opts *sdk.NamesOptions) { switch which { case "names": if names, _, err := opts.Names(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Name](fn, names); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "addrs": if names, _, err := opts.NamesAddr(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Name](fn, names); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "tags": if names, _, err := opts.NamesTags(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Name](fn, names); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } @@ -130,10 +130,10 @@ func TestNames(which, fn string, opts *sdk.NamesOptions) { case "autoname": addr := base.HexToAddress("0xde30da39c46104798bb5aa3fe8b9e0e1f348163f") if names, _, err := opts.NamesAutoname(addr); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Message](fn, names); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } diff --git a/src/dev_tools/sdkFuzzer/receipts.go b/src/dev_tools/sdkFuzzer/receipts.go index b3d58beca8..079e1891d0 100644 --- a/src/dev_tools/sdkFuzzer/receipts.go +++ b/src/dev_tools/sdkFuzzer/receipts.go @@ -37,10 +37,10 @@ func DoReceipts() { func TestReceipts(fn string, opts *sdk.ReceiptsOptions) { if receipts, _, err := opts.Receipts(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Receipt](fn, receipts); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } diff --git a/src/dev_tools/sdkFuzzer/slurp.go b/src/dev_tools/sdkFuzzer/slurp.go index 67fd26bd90..e4911f8c9d 100644 --- a/src/dev_tools/sdkFuzzer/slurp.go +++ b/src/dev_tools/sdkFuzzer/slurp.go @@ -2,78 +2,103 @@ package main import ( "github.com/TrueBlocks/trueblocks-core/sdk" - "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger" + "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file" "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" ) // DoSlurp tests the slurp sdk function func DoSlurp() { + file.EstablishFolder("sdkFuzzer-output/slurp") opts := sdk.SlurpOptions{ Addrs: []string{testAddrs[0]}, PerPage: 10, } ShowHeader("DoSlurp", &opts) - if slurp, _, err := opts.Slurp(); err != nil { - logger.Error(err) - } else { - if err := SaveAndClean[types.Slurp]("sdkFuzzer/slurp.json", slurp, &opts, func() error { - _, _, err := opts.Slurp() - return err - }); err != nil { - logger.Error(err) - } + // Page uint64 `json:"page,omitempty"` + // PageId string `json:"pageId,omitempty"` + // PerPage uint64 `json:"perPage,omitempty"` + + types1 := []sdk.SlurpTypes{ + sdk.NoST, + sdk.STExt, + sdk.STInt, + sdk.STToken, + sdk.STNfts, + sdk.ST1155, + sdk.STMiner, + sdk.STUncles, + sdk.STWithdrawals, + sdk.STSome, + sdk.STAll, } + sources := []sdk.SlurpSource{ + sdk.SSEtherscan, + sdk.SSKey, + sdk.SSCovalent, + sdk.SSAlchemy, + } + art := []bool{false, true} + globs := noCache(globals) - if appearances, _, err := opts.SlurpAppearances(); err != nil { - logger.Error(err) - } else { - if err := SaveAndClean[types.Appearance]("sdkFuzzer/slurpAppearances.json", appearances, &opts, func() error { - _, _, err := opts.SlurpAppearances() - return err - }); err != nil { - logger.Error(err) + for _, s := range sources { + for _, t := range types1 { + if sdk.NoST != t && sdk.SSEtherscan != s { + continue + } + for _, a := range art { + baseFn := "slurp/slurp" + "-" + t.String() + "-" + s.String() + if a { + baseFn += "-articulate" + } + opts.Source = s + opts.Types = t + opts.Articulate = a + for _, g := range globs { + opts.Globals = g + fn := getFilename(baseFn, &opts.Globals) + TestSlurp("slurp", fn, &opts) + fn = getFilename(baseFn+"-apps", &opts.Globals) + TestSlurp("appearances", fn, &opts) + fn = getFilename(baseFn+"-count", &opts.Globals) + TestSlurp("count", fn, &opts) + } + } } } +} - if counts, _, err := opts.SlurpCount(); err != nil { - logger.Error(err) - } else { - if err := SaveAndClean[types.SlurpCount]("sdkFuzzer/slurpCount.json", counts, &opts, func() error { - _, _, err := opts.SlurpCount() - return err - }); err != nil { - logger.Error(err) +func TestSlurp(which, fn string, opts *sdk.SlurpOptions) { + switch which { + case "slurp": + if slurp, _, err := opts.Slurp(); err != nil { + ReportError(fn, opts, err) + } else { + if err := SaveToFile[types.Slurp](fn, slurp); err != nil { + ReportError2(fn, err) + } else { + ReportOkay(fn) + } + } + case "appearances": + if appearances, _, err := opts.SlurpAppearances(); err != nil { + ReportError(fn, opts, err) + } else { + if err := SaveToFile[types.Appearance](fn, appearances); err != nil { + ReportError2(fn, err) + } else { + ReportOkay(fn) + } + } + case "count": + if count, _, err := opts.SlurpCount(); err != nil { + ReportError(fn, opts, err) + } else { + if err := SaveToFile[types.SlurpCount](fn, count); err != nil { + ReportError2(fn, err) + } else { + ReportOkay(fn) + } } } - } - -// Addrs []string `json:"addrs,omitempty"` -// BlockIds []string `json:"blocks,omitempty"` -// Types SlurpTypes `json:"types,omitempty"` -// Articulate bool `json:"articulate,omitempty"` -// Source SlurpSource `json:"source,omitempty"` -// Page uint64 `json:"page,omitempty"` -// PageId string `json:"pageId,omitempty"` -// PerPage uint64 `json:"perPage,omitempty"` -// Sleep float64 `json:"sleep,omitempty"` -// func (opts *SlurpOptions) Slurp() ([]types.Slurp, *types.MetaData, error) { -// func (opts *SlurpOptions) SlurpAppearances() ([]types.Appearance, *types.MetaData, error) { -// func (opts *SlurpOptions) SlurpCount() ([]types.SlurpCount, *types.MetaData, error) { -// NoST SlurpTypes = 0 -// STExt = 1 << iota -// STInt -// STToken -// STNfts -// ST1155 -// STMiner -// STUncles -// STWithdrawals -// STSome = STExt | STInt | STToken | STNfts -// STAll = STExt | STInt | STToken | STNfts | ST1155 | STMiner | STUncles | STWithdrawals -// NoSS SlurpSource = 0 -// SSEtherscan = 1 << iota -// SSKey -// SSCovalent -// SSAlchemy diff --git a/src/dev_tools/sdkFuzzer/state.go b/src/dev_tools/sdkFuzzer/state.go index 88101dd164..baae805f31 100644 --- a/src/dev_tools/sdkFuzzer/state.go +++ b/src/dev_tools/sdkFuzzer/state.go @@ -101,10 +101,10 @@ func DoState() { func TestState(fn string, opts *sdk.StateOptions) { if state, _, err := opts.State(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.State](fn, state); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } @@ -114,10 +114,10 @@ func TestState(fn string, opts *sdk.StateOptions) { func TestStateCall(call, fn string, opts *sdk.StateOptions) { fn = strings.ReplaceAll(fn, ".json", "-call.json") if stateResult, _, err := opts.StateCall(call); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Result](fn, stateResult); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } diff --git a/src/dev_tools/sdkFuzzer/status.go b/src/dev_tools/sdkFuzzer/status.go index 1ed7eebfb2..d4aa7188ee 100644 --- a/src/dev_tools/sdkFuzzer/status.go +++ b/src/dev_tools/sdkFuzzer/status.go @@ -109,16 +109,16 @@ func TestStatus(which, fn string, opts *sdk.StatusOptions) { case "all": f = opts.StatusAll default: - ReportError(fn, fmt.Errorf("unknown status type: %s", which)) + ReportError(fn, opts, fmt.Errorf("unknown status type: %s", which)) return } if status, _, err := f(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { fn = strings.Replace(fn, ".json", "-"+which+".json", 1) if err := SaveToFile[types.Status](fn, status); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } diff --git a/src/dev_tools/sdkFuzzer/tokens.go b/src/dev_tools/sdkFuzzer/tokens.go index b60d2b881e..038660bc26 100644 --- a/src/dev_tools/sdkFuzzer/tokens.go +++ b/src/dev_tools/sdkFuzzer/tokens.go @@ -67,10 +67,10 @@ func TestTokens(which, fn string, opts *sdk.TokensOptions) { switch which { case "tokens": if tokens, _, err := opts.Tokens(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Token](fn, tokens); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } diff --git a/src/dev_tools/sdkFuzzer/traces.go b/src/dev_tools/sdkFuzzer/traces.go index 7db530b396..287ec1f912 100644 --- a/src/dev_tools/sdkFuzzer/traces.go +++ b/src/dev_tools/sdkFuzzer/traces.go @@ -49,10 +49,10 @@ func DoTraces() { func TestTraces(fn string, opts *sdk.TracesOptions) { if traces, _, err := opts.Traces(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Trace](fn, traces); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } @@ -62,10 +62,10 @@ func TestTraces(fn string, opts *sdk.TracesOptions) { func TestTracesCount(fn string, opts *sdk.TracesOptions) { fn = strings.ReplaceAll(fn, ".json", "-count.json") if tracesCounts, _, err := opts.TracesCount(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.TraceCount](fn, tracesCounts); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } diff --git a/src/dev_tools/sdkFuzzer/transactions.go b/src/dev_tools/sdkFuzzer/transactions.go index e92d50d35a..ec9d763192 100644 --- a/src/dev_tools/sdkFuzzer/transactions.go +++ b/src/dev_tools/sdkFuzzer/transactions.go @@ -91,40 +91,40 @@ func TestTransactions(which, fn string, opts *sdk.TransactionsOptions) { switch which { case "txs": if txs, _, err := opts.Transactions(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Transaction](fn, txs); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "logs": if logs, _, err := opts.TransactionsLogs(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Log](fn, logs); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "traces": if traces, _, err := opts.TransactionsTraces(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Trace](fn, traces); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "uniq": if apps, _, err := opts.TransactionsUniq(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Appearance](fn, apps); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } diff --git a/src/dev_tools/sdkFuzzer/when.go b/src/dev_tools/sdkFuzzer/when.go index 1f2beb97f0..654776d6c9 100644 --- a/src/dev_tools/sdkFuzzer/when.go +++ b/src/dev_tools/sdkFuzzer/when.go @@ -38,40 +38,40 @@ func TestWhen(which, fn string, opts *sdk.WhenOptions) { switch which { case "when": if blocks, _, err := opts.When(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.NamedBlock](fn, blocks); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "list": if blocks, _, err := opts.WhenList(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.NamedBlock](fn, blocks); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "timestamps": if timestamps, _, err := opts.WhenTimestamps(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.Timestamp](fn, timestamps); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } } case "count": if counts, _, err := opts.WhenCount(); err != nil { - ReportError(fn, err) + ReportError(fn, opts, err) } else { if err := SaveToFile[types.TimestampCount](fn, counts); err != nil { - ReportError(fn, err) + ReportError2(fn, err) } else { ReportOkay(fn) } diff --git a/src/dev_tools/testRunner/main_test.go b/src/dev_tools/testRunner/main_test.go index 653db53bba..b1415e63f1 100644 --- a/src/dev_tools/testRunner/main_test.go +++ b/src/dev_tools/testRunner/main_test.go @@ -10,7 +10,7 @@ import ( func TestMainFunction(t *testing.T) { os.Setenv("TEST_MODE", "true") - os.Setenv("TB_TEST_FILTER", "init") + os.Setenv("TB_TEST_FILTER", "slurp") err := os.Chdir("../../../build/") if err != nil { logger.Fatal(fmt.Sprintf("Failed to change directory: %v", err)) diff --git a/tests b/tests index 5b59bb3768..58792687f9 160000 --- a/tests +++ b/tests @@ -1 +1 @@ -Subproject commit 5b59bb37683f52259627ef8c273130d88bed9854 +Subproject commit 58792687f9f8231a205e0c8813ac61ba2e8fa97e