Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix/accounting 5 #3461

Merged
merged 14 commits into from
Jan 5, 2024
12 changes: 0 additions & 12 deletions docs/content/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1232,14 +1232,6 @@ paths:
items:
type: string
format: topic
- name: accountFor
description: reconcile the transaction as per the provided address
required: false
style: form
in: query
explode: true
schema:
type: string
- name: ether
description: export values in ether
required: false
Expand Down Expand Up @@ -2741,10 +2733,6 @@ components:
type: string
format: int256
description: "totalOut - gasOut (calculated)"
prevAppBlk:
type: number
format: blknum
description: "the block number of the previous appearance, or 0 if this is the first appearance"
prevBal:
type: string
format: int256
Expand Down
1 change: 0 additions & 1 deletion docs/content/data-model/accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ Statements consist of the following fields:
| selfDestructOut | the value of the self-destructed value out if the accountedFor address was self-destructed | int256 |
| gasOut | if the transaction's original sender is the accountedFor address, the amount of gas expended | int256 |
| totalOutLessGas | totalOut - gasOut (calculated) | int256 |
| prevAppBlk | the block number of the previous appearance, or 0 if this is the first appearance | blknum |
| prevBal | the account balance for the given asset for the previous reconciliation | int256 |
| begBalDiff | difference between expected beginning balance and balance at last reconciliation, if non-zero, the reconciliation failed (calculated) | int256 |
| endBalDiff | endBal - endBalCalc, if non-zero, the reconciliation failed (calculated) | int256 |
Expand Down
4 changes: 0 additions & 4 deletions docs/templates/api/components.txt
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,6 @@ components:
type: string
format: int256
description: "totalOut - gasOut (calculated)"
prevAppBlk:
type: number
format: blknum
description: "the block number of the previous appearance, or 0 if this is the first appearance"
prevBal:
type: string
format: int256
Expand Down
1 change: 0 additions & 1 deletion sdk/python/src/_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"logs": {"hotkey": "-l", "type": "switch"},
"emitter": {"hotkey": "-m", "type": "flag"},
"topic": {"hotkey": "-B", "type": "flag"},
"accountFor": {"hotkey": "-A", "type": "flag"},
"cacheTraces": {"hotkey": "", "type": "switch"},
"ether": {"hotkey": "-H", "type": "switch"},
"raw": {"hotkey": "-w", "type": "switch"},
Expand Down
1 change: 0 additions & 1 deletion sdk/typescript/src/paths/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export function getTransactions(
logs?: boolean,
emitter?: address[],
topic?: topic[],
accountFor?: address,
chain: string,
noHeader?: boolean,
fmt?: string,
Expand Down
1 change: 0 additions & 1 deletion sdk/typescript/src/types/statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export type Statement = {
selfDestructOut?: int256
gasOut?: int256
totalOutLessGas: int256
prevAppBlk?: blknum
prevBal?: int256
begBalDiff?: int256
endBalDiff?: int256
Expand Down
2 changes: 0 additions & 2 deletions src/apps/chifra/cmd/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ Notes:
- The transactions list may be one or more transaction hashes, blockNumber.transactionID pairs, or a blockHash.transactionID pairs.
- This tool checks for valid input syntax, but does not check that the transaction requested actually exists.
- If the queried node does not store historical state, the results for most older transactions are undefined.
- The --traces option, when used with --account_for, will descend into traces to complete reconciliations.
- The --decache option removes the all transaction(s) and all traces in those transactions from the cache.`

func init() {
Expand All @@ -72,7 +71,6 @@ One of [ from | to ]`)
transactionsCmd.Flags().BoolVarP(&transactionsPkg.GetOptions().Logs, "logs", "l", false, "display only the logs found in the transaction(s)")
transactionsCmd.Flags().StringSliceVarP(&transactionsPkg.GetOptions().Emitter, "emitter", "m", nil, "for the --logs option only, filter logs to show only those logs emitted by the given address(es)")
transactionsCmd.Flags().StringSliceVarP(&transactionsPkg.GetOptions().Topic, "topic", "B", nil, "for the --logs option only, filter logs to show only those with this topic(s)")
transactionsCmd.Flags().StringVarP(&transactionsPkg.GetOptions().AccountFor, "account_for", "A", "", "reconcile the transaction as per the provided address")
transactionsCmd.Flags().BoolVarP(&transactionsPkg.GetOptions().CacheTraces, "cache_traces", "", false, "force the transaction's traces into the cache (hidden)")
transactionsCmd.Flags().BoolVarP(&transactionsPkg.GetOptions().Source, "source", "s", false, "find the source of the funds sent to the receiver (hidden)")
if os.Getenv("TEST_MODE") != "true" {
Expand Down
97 changes: 0 additions & 97 deletions src/apps/chifra/internal/transactions/handle_accountfor.go

This file was deleted.

8 changes: 0 additions & 8 deletions src/apps/chifra/internal/transactions/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type TransactionsOptions struct {
Logs bool `json:"logs,omitempty"` // Display only the logs found in the transaction(s)
Emitter []string `json:"emitter,omitempty"` // For the --logs option only, filter logs to show only those logs emitted by the given address(es)
Topic []string `json:"topic,omitempty"` // For the --logs option only, filter logs to show only those with this topic(s)
AccountFor string `json:"accountFor,omitempty"` // Reconcile the transaction as per the provided address
CacheTraces bool `json:"cacheTraces,omitempty"` // Force the transaction's traces into the cache
Source bool `json:"source,omitempty"` // Find the source of the funds sent to the receiver
Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options
Expand All @@ -55,7 +54,6 @@ func (opts *TransactionsOptions) testLog() {
logger.TestLog(opts.Logs, "Logs: ", opts.Logs)
logger.TestLog(len(opts.Emitter) > 0, "Emitter: ", opts.Emitter)
logger.TestLog(len(opts.Topic) > 0, "Topic: ", opts.Topic)
logger.TestLog(len(opts.AccountFor) > 0, "AccountFor: ", opts.AccountFor)
logger.TestLog(opts.CacheTraces, "CacheTraces: ", opts.CacheTraces)
logger.TestLog(opts.Source, "Source: ", opts.Source)
opts.Conn.TestLog(opts.getCaches())
Expand Down Expand Up @@ -99,8 +97,6 @@ func transactionsFinishParseApi(w http.ResponseWriter, r *http.Request) *Transac
s := strings.Split(val, " ") // may contain space separated items
opts.Topic = append(opts.Topic, s...)
}
case "accountFor":
opts.AccountFor = value[0]
case "cacheTraces":
opts.CacheTraces = true
case "source":
Expand All @@ -112,8 +108,6 @@ func transactionsFinishParseApi(w http.ResponseWriter, r *http.Request) *Transac
}
}
opts.Conn = opts.Globals.FinishParseApi(w, r, opts.getCaches())
opts.AccountFor, _ = opts.Conn.GetEnsAddress(opts.AccountFor)
opts.AccountForAddr = base.HexToAddress(opts.AccountFor)

// EXISTING_CODE
// EXISTING_CODE
Expand All @@ -140,8 +134,6 @@ func transactionsFinishParse(args []string) *TransactionsOptions {
defFmt := "txt"
opts := GetOptions()
opts.Conn = opts.Globals.FinishParse(args, opts.getCaches())
opts.AccountFor, _ = opts.Conn.GetEnsAddress(opts.AccountFor)
opts.AccountForAddr = base.HexToAddress(opts.AccountFor)

// EXISTING_CODE
opts.Transactions = args
Expand Down
3 changes: 0 additions & 3 deletions src/apps/chifra/internal/transactions/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ func (opts *TransactionsOptions) TransactionsInternal() error {
} else if opts.Uniq {
err = opts.HandleUniq()

} else if len(opts.AccountFor) > 0 {
err = opts.HandleAccounting()

} else {
err = opts.HandleShow()
}
Expand Down
16 changes: 0 additions & 16 deletions src/apps/chifra/internal/transactions/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
package transactionsPkg

import (
"strings"

"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc"
Expand All @@ -26,11 +24,6 @@ func (opts *TransactionsOptions) validateTransactions() error {
return validate.Usage("chain {0} is not properly configured.", chain)
}

key := config.GetKey("trueblocks").License
if len(opts.AccountFor) > 0 && !strings.Contains(key, "+accounting") {
return validate.Usage("The {0} option requires a license key. Please contact us in our discord.", "--accounting")
}

if len(opts.Flow) > 0 {
if !opts.Uniq {
return validate.Usage("The {0} option is only available with the {1} option", "--flow", "--uniq")
Expand Down Expand Up @@ -66,15 +59,6 @@ func (opts *TransactionsOptions) validateTransactions() error {
return validate.Usage("Please supply one or more transaction identifiers.")
}

if len(opts.AccountFor) > 0 {
if opts.Uniq {
return validate.Usage("The {0} option is not available{1}.", "--uniq", " with the --account_for option")
}
if !base.IsValidAddress(opts.AccountFor) {
return validate.Usage("Invalid reconcilation address {0}.", opts.AccountFor)
}
}

if opts.Traces {
if !opts.Conn.IsNodeTracing() {
return validate.Usage("{0} requires tracing, err: {1}", "chifra transactions --traces", rpc.ErrTraceBlockMissing)
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/pkg/base/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func IsValidAddress(val string) bool {

func IsValidAddressE(val string) (bool, error) {
if strings.HasSuffix(val, ".eth") {
return true, nil
return strings.Replace(val, "\t\n\r", "", -1) == val, nil
}
return isValidHex("address", val, 20)
}
Expand Down
13 changes: 6 additions & 7 deletions src/apps/chifra/pkg/index/download_chunks.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,12 @@ func fetchFromIpfsGateway(ctx context.Context, gateway, hash string) (*fetchResu
return nil, fmt.Errorf("fetchFromIpfsGateway %s returned status code: %d", url, response.StatusCode)
}

if len(response.Header.Get("Content-Length")) == 0 {
return nil, fmt.Errorf("fetchFromIpfsGateway %s returned zero length header", url)
}

contentLen, err := strconv.ParseInt(response.Header.Get("Content-Length"), 10, 64)
if err != nil {
return nil, fmt.Errorf("response.Header.Get %s returned error: %w", url, err)
contentLen := int64(0)
if len(response.Header.Get("Content-Length")) != 0 {
contentLen, err = strconv.ParseInt(response.Header.Get("Content-Length"), 10, 64)
if err != nil {
return nil, fmt.Errorf("response.Header.Get %s returned error: %w", url, err)
}
}

body := response.Body
Expand Down
1 change: 0 additions & 1 deletion src/apps/chifra/pkg/ledger/stmnt_from_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func (l *Ledger) getStatementsFromLog(conn *rpc.Connection, logIn *types.SimpleL
// TODO: AND CACHE RESULTS IN MEMORY, BUT BE CAREFUL OF MULTIPLE LOGS PER BLOCK (OR TRANSACTION)
key := l.ctxKey(log.BlockNumber, log.TransactionIndex)
ctx := l.Contexts[key]
s.PrevAppBlk = ctx.PrevBlock

if ofInterest {
var err error
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/pkg/ledger/stmnt_from_receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (l *Ledger) getStatementsFromReceipt(conn *rpc.Connection, filter *filter.A
return statements, err
} else {
if statement.Sender == l.AccountFor || statement.Recipient == l.AccountFor {
add := !l.NoZero || statement.MoneyMoved()
add := !l.NoZero || statement.IsMaterial()
if add {
statements = append(statements, statement)
}
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/pkg/ledger/stmnt_from_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (l *Ledger) getStatementsFromTraces(conn *rpc.Connection, trans *types.Simp
}

if l.trialBalance("trace-eth", &ret) {
if ret.MoneyMoved() {
if ret.IsMaterial() {
statements = append(statements, ret)
} else {
logger.TestLog(true, "Tx reconciled with a zero value net amount. It's okay.")
Expand Down
3 changes: 1 addition & 2 deletions src/apps/chifra/pkg/ledger/stmnt_from_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func (l *Ledger) GetStatements(conn *rpc.Connection, filter *filter.AppearanceFi
Decimals: 18,
SpotPrice: 0.0,
PriceSource: "not-priced",
PrevAppBlk: ctx.PrevBlock,
PrevBal: *prevBal,
BegBal: *begBal,
EndBal: *endBal,
Expand Down Expand Up @@ -102,7 +101,7 @@ func (l *Ledger) GetStatements(conn *rpc.Connection, filter *filter.AppearanceFi
}

if !l.UseTraces && l.trialBalance("eth", &ret) {
if ret.MoneyMoved() {
if ret.IsMaterial() {
statements = append(statements, ret)
} else {
logger.TestLog(true, "Tx reconciled with a zero value net amount. It's okay.")
Expand Down
9 changes: 2 additions & 7 deletions src/apps/chifra/pkg/ledger/trail_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,13 @@ func (l *Ledger) trialBalance(reason string, s *types.SimpleStatement) bool {
var okay bool
if okay = s.Reconciled(); !okay {
if okay = s.CorrectForNullTransfer(l.theTx); !okay {
okay = s.CorrectForSomethingElse(l.theTx)
_ = s.CorrectForSomethingElse(l.theTx)
}
}

// TODO: BOGUS PERF
if okay && s.MoneyMoved() {
// var err error
if s.IsMaterial() {
s.SpotPrice, s.PriceSource, _ = pricing.PriceUsd(l.Conn, l.TestMode, s)
// if s.SpotPrice, s.PriceSource, err = pricing.PriceUsd(l.Conn, l.TestMode, s); err != nil {
// logger.Error("Failed to get price for", s.AssetSymbol, "at", s.BlockNumber, s.TransactionIndex)
// logger.Error("Error returned from PriceUsd:", err)
// }
}

if l.TestMode {
Expand Down
Loading
Loading