Skip to content

Commit 4c4993c

Browse files
committed
Getting better
1 parent e8c44c1 commit 4c4993c

File tree

1 file changed

+34
-52
lines changed

1 file changed

+34
-52
lines changed

src/apps/chifra/pkg/ledger1/get_statements.go

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,65 +17,22 @@ import (
1717
func (r *Reconciler1) GetStatements1(pos *types.AppPosition, trans *types.Transaction) ([]types.Statement, error) {
1818
results := make([]types.Statement, 0, 20)
1919
if ledger10.AssetOfInterest(r.opts.AssetFilters, base.FAKE_ETH_ADDRESS) {
20-
s := types.Statement{
21-
AccountedFor: r.opts.AccountFor,
22-
Sender: trans.From,
23-
Recipient: trans.To,
24-
BlockNumber: trans.BlockNumber,
25-
TransactionIndex: trans.TransactionIndex,
26-
TransactionHash: trans.Hash,
27-
LogIndex: 0,
28-
Timestamp: trans.Timestamp,
29-
Asset: base.FAKE_ETH_ADDRESS,
30-
Symbol: "WEI",
31-
Decimals: 18,
32-
SpotPrice: 0.0,
33-
PriceSource: "not-priced",
34-
}
35-
if r.opts.AsEther {
36-
s.Symbol = "ETH"
37-
}
38-
if trans.To.IsZero() && trans.Receipt != nil && !trans.Receipt.ContractAddress.IsZero() {
39-
s.Recipient = trans.Receipt.ContractAddress
40-
}
41-
20+
var err error
4221
reconciled := false
22+
stmt := r.getStatementFromTransaction(trans)
4323
if !r.opts.UseTraces {
44-
if s.Sender == r.opts.AccountFor {
45-
gasUsed := new(base.Wei)
46-
if trans.Receipt != nil {
47-
gasUsed.SetUint64(uint64(trans.Receipt.GasUsed))
48-
}
49-
gasPrice := new(base.Wei).SetUint64(uint64(trans.GasPrice))
50-
gasOut := new(base.Wei).Mul(gasUsed, gasPrice)
51-
s.AmountOut = trans.Value
52-
s.GasOut = *gasOut
53-
}
54-
55-
if s.Recipient == r.opts.AccountFor {
56-
if s.BlockNumber == 0 {
57-
s.PrefundIn = trans.Value
58-
} else {
59-
if trans.Rewards != nil {
60-
s.MinerBaseRewardIn = trans.Rewards.Block
61-
s.MinerNephewRewardIn = trans.Rewards.Nephew
62-
s.MinerTxFeeIn = trans.Rewards.TxFee
63-
s.MinerUncleRewardIn = trans.Rewards.Uncle
64-
} else {
65-
s.AmountIn = trans.Value
66-
}
24+
if reconciled, err = r.trialBalance(pos, trans, stmt); err != nil {
25+
return nil, err
26+
} else {
27+
if reconciled && stmt.IsMaterial() {
28+
results = append(results, *stmt)
6729
}
6830
}
69-
70-
reconciled, _ = r.trialBalance(pos, trans, &s)
71-
if reconciled && s.IsMaterial() {
72-
results = append(results, s)
73-
}
7431
}
7532

7633
if r.opts.UseTraces || !reconciled {
7734
results = make([]types.Statement, 0, 20) /* reset this */
78-
if stmt, err := r.getStatementFromTraces(pos, trans, &s); err != nil {
35+
if stmt, err := r.getStatementFromTraces(pos, trans, stmt); err != nil {
7936
logger.Warn(colors.Yellow+"Statement at ", fmt.Sprintf("%d.%d", trans.BlockNumber, trans.TransactionIndex), " does not reconcile."+colors.Off)
8037
} else {
8138
if _, err = r.trialBalance(pos, trans, stmt); err != nil {
@@ -141,7 +98,32 @@ func (r *Reconciler1) NewStatement(trans *types.Transaction) *types.Statement {
14198
}
14299

143100
func (r *Reconciler1) getStatementFromTransaction(trans *types.Transaction) *types.Statement {
144-
return nil
101+
stmt := r.NewStatement(trans)
102+
if stmt.Sender == r.opts.AccountFor {
103+
gasUsed := new(base.Wei)
104+
if trans.Receipt != nil {
105+
gasUsed.SetUint64(uint64(trans.Receipt.GasUsed))
106+
}
107+
gasPrice := new(base.Wei).SetUint64(uint64(trans.GasPrice))
108+
gasOut := new(base.Wei).Mul(gasUsed, gasPrice)
109+
stmt.AmountOut = trans.Value
110+
stmt.GasOut = *gasOut
111+
}
112+
if stmt.Recipient == r.opts.AccountFor {
113+
if stmt.BlockNumber == 0 {
114+
stmt.PrefundIn = trans.Value
115+
} else {
116+
if trans.Rewards != nil {
117+
stmt.MinerBaseRewardIn = trans.Rewards.Block
118+
stmt.MinerNephewRewardIn = trans.Rewards.Nephew
119+
stmt.MinerTxFeeIn = trans.Rewards.TxFee
120+
stmt.MinerUncleRewardIn = trans.Rewards.Uncle
121+
} else {
122+
stmt.AmountIn = trans.Value
123+
}
124+
}
125+
}
126+
return stmt
145127
}
146128

147129
func (r *Reconciler1) getStatementFromTraces(pos *types.AppPosition, trans *types.Transaction, s *types.Statement) (*types.Statement, error) {

0 commit comments

Comments
 (0)