Skip to content

Commit

Permalink
Renames AssetType to PostAssetType
Browse files Browse the repository at this point in the history
  • Loading branch information
tjayrush committed Feb 23, 2025
1 parent 218c9b9 commit adce310
Show file tree
Hide file tree
Showing 96 changed files with 3,542 additions and 16,360 deletions.
10 changes: 5 additions & 5 deletions docs/content/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3293,6 +3293,11 @@ components:
type: string
format: int256
description: "the on-chain balance of the asset (see notes about intra-block reconciliations)"
postAssetType:
type: object
items:
$ref: "#/components/schemas/trialBalType"
description: "one of eth, eth-trace, token, or token-721"
reconciled:
type: boolean
format: boolean
Expand Down Expand Up @@ -3385,11 +3390,6 @@ components:
type: string
format: string
description: "the reason for the correcting entries, if any"
assetType:
type: object
items:
$ref: "#/components/schemas/trialBalType"
description: "one of eth, eth-trace, token, or token-721"
rollingBalance:
type: string
format: int256
Expand Down
2 changes: 1 addition & 1 deletion docs/content/data-model/accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Statements consist of the following fields:
| endBalDiff | endBal - endBalCalc, if non-zero, the reconciliation failed (calculated) | int256 |
| endBalCalc | begBal + amountNet (calculated) | int256 |
| correctingReason | the reason for the correcting entries, if any | string |
| assetType | one of eth, eth-trace, token, or token-721 | TrialBalType |
| postAssetType | one of eth, eth-trace, token, or token-721 | TrialBalType |
| rollingBalance | a rolling balance used to help debug intra-block reconciliations | int256 |

## AppearanceTable
Expand Down
2 changes: 1 addition & 1 deletion sdk
5 changes: 4 additions & 1 deletion src/apps/chifra/pkg/ledger/stmnt_from_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ledger

import (
"fmt"
"os"
"strings"

"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
Expand Down Expand Up @@ -109,7 +110,9 @@ func (l *Reconciler) getStatementsFromLog(pos *types.AppPosition, trans *types.T
logger.Progress(true, colors.Green+"Transaction", id, "reconciled "+colors.Off)
} else {
id := fmt.Sprintf(" %d.%d.%d", s.BlockNumber, s.TransactionIndex, s.LogIndex)
logger.Warn(colors.Yellow+"Log statement at ", id, " does not reconcile."+colors.Off)
if os.Getenv("TEST_MODE") != "true" {
logger.Warn("Log statement at ", id, " does not reconcile.")
}
}
return s, nil
}
Expand Down
6 changes: 2 additions & 4 deletions src/apps/chifra/pkg/ledger/stmnt_from_receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ func (l *Reconciler) getStatementsFromReceipt(pos *types.AppPosition, filter *fi
if s, err := l.getStatementsFromLog(pos, trans, &log); err != nil {
return statements, err
} else {
if s.Sender == l.accountFor || s.Recipient == l.accountFor {
if s.IsMaterial() {
statements = append(statements, s)
}
if (s.Sender == l.accountFor || s.Recipient == l.accountFor) && s.IsMaterial() {
statements = append(statements, s)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/pkg/ledger/trail_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (l *Reconciler) trialBalance(pos *types.AppPosition, reason types.TrialBalT
s.BlockNumberNext = pos.Next
s.PostFirst = pos.First
s.PostLast = pos.Last
s.AssetType = reason
s.PostAssetType = reason

var okay bool
if okay = s.Reconciled(); !okay {
Expand Down
12 changes: 6 additions & 6 deletions src/apps/chifra/pkg/ledger/trail_balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestCorrectForNullTransfer(t *testing.T) {

stmt := new(types.Statement)
stmt.AssetAddress = base.HexToAddress("0xCCC")
stmt.AssetType = types.TrialBalToken
stmt.PostAssetType = types.TrialBalToken
stmt.Sender = base.HexToAddress("0x0")
stmt.BegBal = *base.NewWei(100)
stmt.EndBal = *base.NewWei(100)
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestCorrectForNullTransfer(t *testing.T) {

stmt := new(types.Statement)
stmt.AssetAddress = base.HexToAddress("0xCCC")
stmt.AssetType = types.TrialBalToken
stmt.PostAssetType = types.TrialBalToken
stmt.Sender = base.HexToAddress("0xABC")
stmt.BegBal = *base.NewWei(100)
stmt.EndBal = *base.NewWei(100)
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestCorrectForNullTransfer(t *testing.T) {
// t.Run("ETH branch: per-block-balance correction", func(t *testing.T) {
// stmt := &types.Statement{
// AssetAddress: base.FAKE_ETH_ADDRESS, // so that IsEth() returns true
// AssetType: types.TrialBalTraceEth,
// PostAssetType: types.TrialBalTraceEth,
// BlockNumberPrev: 99,
// BlockNumber: 100,
// BlockNumberNext: 101,
Expand Down Expand Up @@ -191,7 +191,7 @@ func TestCorrectForNullTransfer(t *testing.T) {
// stmt := new(types.Statement)

// stmt.AssetAddress = base.HexToAddress("0x1111111111111111111111111111111111111111") // Not ETH.
// stmt.AssetType = types.TrialBalToken
// stmt.PostAssetType = types.TrialBalToken
// stmt.BlockNumber = 200

// stmt.PrevBal = *base.NewWei(90)
Expand Down Expand Up @@ -252,6 +252,6 @@ func TestCorrectForNullTransfer(t *testing.T) {
// if !result {
// t.Error("Expected trial Balance to return true for a reconciled statement")
// }
// if s.AssetType != string(types.TrialBalEth) {
// t.Errorf("Expected AssetType to be %s, got %s", types.TrialBalEth, s.AssetType)
// if s.PostAssetType != string(types.TrialBalEth) {
// t.Errorf("Expected PostAssetType to be %s, got %s", types.TrialBalEth, s.PostAssetType)
// }
124 changes: 121 additions & 3 deletions src/apps/chifra/pkg/ledger2/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func CorrectForNullTransfer(s *types.Statement, tx *types.Transaction) bool {
func (r *Reconciler2) queryBalances(at AssetTransfer) Posting {
ret := Posting(at)

if at.AssetType != types.TrialBalToken && at.AssetType != types.TrialBalNft {
if at.PostAssetType != types.TrialBalToken && at.PostAssetType != types.TrialBalNft {
prevBal, _ := r.connection.GetBalanceAt(r.LedgerBook.AccountedFor, at.BlockNumberPrev)
if at.BlockNumber == 0 {
prevBal = new(base.Wei)
Expand Down Expand Up @@ -245,7 +245,7 @@ func (r *Reconciler2) GetAssetTransfers(pos *types.AppPosition, filter *filter.A
LogIndex: 0,
Sender: trans.From,
Recipient: trans.To,
AssetType: types.TrialBalEth,
PostAssetType: types.TrialBalEth,
Decimals: 18,
PostFirst: pos.First,
PostLast: pos.Last,
Expand Down Expand Up @@ -388,7 +388,7 @@ func (r *Reconciler2) GetAssetTransfers(pos *types.AppPosition, filter *filter.A
LogIndex: lg.LogIndex,
Sender: fromAddr,
Recipient: toAddr,
AssetType: types.TrialBalToken,
PostAssetType: types.TrialBalToken,
PostFirst: pos.First,
PostLast: pos.Last,
}
Expand Down Expand Up @@ -436,3 +436,121 @@ func AssetOfInterest(filters []base.Address, needle base.Address) bool {

return false
}

// func (l *Reconciler2) getStatementsFromTraces(pos *types.AppPosition, trans *types.Transaction) ([]types.Statement, error) {
// _ = pos
// statements := make([]types.Statement, 0, 20) // a high estimate of the number of statements we'll need

// ret := types.Statement{} // *s
// // clear all the internal accounting values. Keeps AmountIn, AmountOut and GasOut because
// // those are at the top level (both the transaction itself and trace '0' have them). We
// // skip trace '0' because it's the same as the transaction.
// // ret.AmountIn.SetUint64(0)
// ret.InternalIn.SetUint64(0)
// ret.MinerBaseRewardIn.SetUint64(0)
// ret.MinerNephewRewardIn.SetUint64(0)
// ret.MinerTxFeeIn.SetUint64(0)
// ret.MinerUncleRewardIn.SetUint64(0)
// ret.CorrectingIn.SetUint64(0)
// ret.PrefundIn.SetUint64(0)
// ret.SelfDestructIn.SetUint64(0)

// // ret.AmountOut.SetUint64(0)
// // ret.GasOut.SetUint64(0)
// ret.InternalOut.SetUint64(0)
// ret.CorrectingOut.SetUint64(0)
// ret.SelfDestructOut.SetUint64(0)

// if traces, err := l.connection.GetTracesByTransactionHash(trans.Hash.Hex(), trans); err != nil {
// return statements, err

// } else {
// // These values accumulate...so we use += instead of =
// for i, trace := range traces {
// if i == 0 {
// // the first trace is identical to the transaction itself, so we can skip it
// continue
// }

// if trace.Action.CallType == "delegatecall" && trace.Action.To != l.LedgerBook.AccountedFor {
// // delegate calls are not included in the transaction's gas cost, so we skip them
// continue
// }

// plusEq := func(a1, a2 *base.Wei) base.Wei {
// return *a1.Add(a1, a2)
// }

// // Do not collapse, more than one of these can be true at the same time
// if trace.Action.From == l.LedgerBook.AccountedFor {
// ret.InternalOut = plusEq(&ret.InternalOut, &trace.Action.Value)
// ret.Sender = trace.Action.From
// if trace.Action.To.IsZero() {
// if trace.Result != nil {
// ret.Recipient = trace.Result.Address
// }
// } else {
// ret.Recipient = trace.Action.To
// }
// }

// if trace.Action.To == l.LedgerBook.AccountedFor {
// ret.InternalIn = plusEq(&ret.InternalIn, &trace.Action.Value)
// ret.Sender = trace.Action.From
// ret.Recipient = trace.Action.To
// }

// if trace.Action.SelfDestructed == l.LedgerBook.AccountedFor {
// ret.SelfDestructOut = plusEq(&ret.SelfDestructOut, &trace.Action.Balance)
// ret.Sender = trace.Action.SelfDestructed
// if ret.Sender.IsZero() {
// ret.Sender = trace.Action.Address
// }
// ret.Recipient = trace.Action.RefundAddress
// }

// if trace.Action.RefundAddress == l.LedgerBook.AccountedFor {
// ret.SelfDestructIn = plusEq(&ret.SelfDestructIn, &trace.Action.Balance)
// ret.Sender = trace.Action.SelfDestructed
// if ret.Sender.IsZero() {
// ret.Sender = trace.Action.Address
// }
// ret.Recipient = trace.Action.RefundAddress
// }

// if trace.Action.Address == l.LedgerBook.AccountedFor && !trace.Action.RefundAddress.IsZero() {
// ret.SelfDestructOut = plusEq(&ret.SelfDestructOut, &trace.Action.Balance)
// // self destructed send
// ret.Sender = trace.Action.Address
// ret.Recipient = trace.Action.RefundAddress
// }

// if trace.Result != nil {
// if trace.Result.Address == l.LedgerBook.AccountedFor {
// ret.InternalIn = plusEq(&ret.InternalIn, &trace.Action.Value)
// ret.Sender = trace.Action.From
// ret.Recipient = trace.Result.Address
// }
// }
// }
// }

// if utils.IsFuzzing() {
// statements = append(statements, ret)
// return statements, nil
// }

// // reconciled := l.trialBalance(pos, types.TrialBalTraceEth, trans, &ret)
// // if !reconciled {
// // statements = append(statements, ret)
// // return statements, nil
// // }

// if ret.IsMaterial() {
// statements = append(statements, ret)
// // } else {
// // logger.TestLog(true, "Tx reconciled with a zero value net amount. It's okay.")
// }

// return statements, nil
// }
32 changes: 16 additions & 16 deletions src/apps/chifra/pkg/types/types_statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type Statement struct {
AmountOut base.Wei `json:"amountOut,omitempty"`
AssetAddress base.Address `json:"assetAddress"`
AssetSymbol string `json:"assetSymbol"`
AssetType TrialBalType `json:"assetType,omitempty"`
BegBal base.Wei `json:"begBal"`
BlockNumber base.Blknum `json:"blockNumber"`
BlockNumberNext base.Blknum `json:"blockNumberNext"`
Expand All @@ -47,6 +46,7 @@ type Statement struct {
MinerNephewRewardIn base.Wei `json:"minerNephewRewardIn,omitempty"`
MinerTxFeeIn base.Wei `json:"minerTxFeeIn,omitempty"`
MinerUncleRewardIn base.Wei `json:"minerUncleRewardIn,omitempty"`
PostAssetType TrialBalType `json:"postAssetType,omitempty"`
PostFirst bool `json:"postFirst,omitempty"`
PostLast bool `json:"postLast,omitempty"`
PrefundIn base.Wei `json:"prefundIn,omitempty"`
Expand Down Expand Up @@ -83,7 +83,6 @@ func (s *Statement) Model(chain, format string, verbose bool, extraOpts map[stri
"timestamp": s.Timestamp,
"date": s.Date(),
"assetAddress": s.AssetAddress,
"assetType": s.AssetType.String(),
"assetSymbol": s.AssetSymbol,
"decimals": s.Decimals,
"spotPrice": s.SpotPrice,
Expand Down Expand Up @@ -120,14 +119,15 @@ func (s *Statement) Model(chain, format string, verbose bool, extraOpts map[stri
}

if extraOpts["testMode"] == true {
model["postAssetType"] = s.PostAssetType.String()
model["postType"] = s.getPostType()
model["postFirst"] = s.PostFirst
model["postLast"] = s.PostLast
}

order = []string{
"blockNumber", "transactionIndex", "logIndex", "transactionHash", "timestamp", "date",
"assetAddress", "assetType", "assetSymbol", "decimals", "spotPrice", "priceSource", "accountedFor",
"assetAddress", "assetSymbol", "decimals", "spotPrice", "priceSource", "accountedFor",
"sender", "recipient", "begBal", "amountNet", "endBal", "reconciled",
"totalIn", "amountIn", "internalIn", "selfDestructIn", "minerBaseRewardIn", "minerNephewRewardIn",
"minerTxFeeIn", "minerUncleRewardIn", "prefundIn", "totalOut", "amountOut", "internalOut",
Expand Down Expand Up @@ -233,11 +233,6 @@ func (s *Statement) MarshalCache(writer io.Writer) (err error) {
return err
}

// AssetType
if err = cache.WriteValue(writer, s.AssetType); err != nil {
return err
}

// BegBal
if err = cache.WriteValue(writer, &s.BegBal); err != nil {
return err
Expand Down Expand Up @@ -323,6 +318,11 @@ func (s *Statement) MarshalCache(writer io.Writer) (err error) {
return err
}

// PostAssetType
if err = cache.WriteValue(writer, s.PostAssetType); err != nil {
return err
}

// PostFirst
if err = cache.WriteValue(writer, s.PostFirst); err != nil {
return err
Expand Down Expand Up @@ -426,11 +426,6 @@ func (s *Statement) UnmarshalCache(fileVersion uint64, reader io.Reader) (err er
return err
}

// AssetType
if err = cache.ReadValue(reader, &s.AssetType, fileVersion); err != nil {
return err
}

// BegBal
if err = cache.ReadValue(reader, &s.BegBal, fileVersion); err != nil {
return err
Expand Down Expand Up @@ -516,6 +511,11 @@ func (s *Statement) UnmarshalCache(fileVersion uint64, reader io.Reader) (err er
return err
}

// PostAssetType
if err = cache.ReadValue(reader, &s.PostAssetType, fileVersion); err != nil {
return err
}

// PostFirst
if err = cache.ReadValue(reader, &s.PostFirst, fileVersion); err != nil {
return err
Expand Down Expand Up @@ -730,21 +730,21 @@ func (s *Statement) DebugStatement(pos *AppPosition) {
}

logger.TestLog(true, "===================================================")
logger.TestLog(true, fmt.Sprintf("====> %s", s.AssetType))
logger.TestLog(true, fmt.Sprintf("====> %s", s.PostAssetType))
logger.TestLog(true, "===================================================")
logger.TestLog(true, "Previous: ", pos.Prev)
logger.TestLog(true, "Current: ", s.BlockNumber)
logger.TestLog(true, "Next: ", pos.Next)
logger.TestLog(true, "postType: ", s.getPostType())
logger.TestLog(true, "postFirst: ", s.PostFirst)
logger.TestLog(true, "postLast: ", s.PostLast)
logger.TestLog(true, "assetType: ", s.AssetType)
logger.TestLog(true, "postAssetType: ", s.PostAssetType)
logger.TestLog(true, "accountedFor: ", s.AccountedFor)
logger.TestLog(true, "sender: ", s.Sender, " ==> ", s.Recipient)
logger.TestLog(true, "assetAddress: ", s.AssetAddress, "("+s.AssetSymbol+")", fmt.Sprintf("decimals: %d", s.Decimals))
logger.TestLog(true, "hash: ", s.TransactionHash)
logger.TestLog(true, "timestamp: ", s.Timestamp)
if s.AssetType != TrialBalToken && s.AssetType != TrialBalNft {
if s.PostAssetType != TrialBalToken && s.PostAssetType != TrialBalNft {
logger.TestLog(true, fmt.Sprintf("blockNumber: %d.%d", s.BlockNumber, s.TransactionIndex))
} else {
logger.TestLog(true, fmt.Sprintf("blockNumber: %d.%d.%d", s.BlockNumber, s.TransactionIndex, s.LogIndex))
Expand Down
Loading

0 comments on commit adce310

Please sign in to comment.