Skip to content

Commit e8c44c1

Browse files
committed
Getting better
1 parent 81479ce commit e8c44c1

File tree

1 file changed

+74
-43
lines changed

1 file changed

+74
-43
lines changed

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

Lines changed: 74 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,14 @@ func (r *Reconciler1) GetStatements1(pos *types.AppPosition, trans *types.Transa
7575

7676
if r.opts.UseTraces || !reconciled {
7777
results = make([]types.Statement, 0, 20) /* reset this */
78-
if s, err := r.getStatementFromTraces(pos, trans, &s); err != nil {
78+
if stmt, err := r.getStatementFromTraces(pos, trans, &s); err != nil {
7979
logger.Warn(colors.Yellow+"Statement at ", fmt.Sprintf("%d.%d", trans.BlockNumber, trans.TransactionIndex), " does not reconcile."+colors.Off)
8080
} else {
81-
_, _ = r.trialBalance(pos, trans, s)
82-
results = append(results, *s)
81+
if _, err = r.trialBalance(pos, trans, stmt); err != nil {
82+
return nil, err
83+
} else {
84+
results = append(results, *stmt)
85+
}
8386
}
8487
}
8588
}
@@ -109,31 +112,59 @@ func (r *Reconciler1) GetStatements1(pos *types.AppPosition, trans *types.Transa
109112
results = append(results, receiptStatements...)
110113
}
111114
}
112-
113115
return results, nil
114116
}
115117

118+
func (r *Reconciler1) NewStatement(trans *types.Transaction) *types.Statement {
119+
sym := "WEI"
120+
if r.opts.AsEther {
121+
sym = "ETH"
122+
}
123+
to := trans.To
124+
if trans.To.IsZero() && trans.Receipt != nil && !trans.Receipt.ContractAddress.IsZero() {
125+
to = trans.Receipt.ContractAddress
126+
}
127+
128+
return &types.Statement{
129+
AccountedFor: r.opts.AccountFor,
130+
Sender: trans.From,
131+
Recipient: to,
132+
BlockNumber: trans.BlockNumber,
133+
TransactionIndex: trans.TransactionIndex,
134+
TransactionHash: trans.Hash,
135+
Timestamp: trans.Timestamp,
136+
Asset: base.FAKE_ETH_ADDRESS,
137+
Symbol: sym,
138+
Decimals: 18,
139+
PriceSource: "not-priced",
140+
}
141+
}
142+
143+
func (r *Reconciler1) getStatementFromTransaction(trans *types.Transaction) *types.Statement {
144+
return nil
145+
}
146+
116147
func (r *Reconciler1) getStatementFromTraces(pos *types.AppPosition, trans *types.Transaction, s *types.Statement) (*types.Statement, error) {
117148

118-
ret := *s
149+
stmt := *s
119150
// clear all the internal accounting values. Keeps AmountIn, AmountOut and GasOut because
120151
// those are at the top level (both the transaction itself and trace '0' have them). We
121152
// skip trace '0' because it's the same as the transaction.
122-
// ret.AmountIn.SetUint64(0)
123-
ret.InternalIn.SetUint64(0)
124-
ret.MinerBaseRewardIn.SetUint64(0)
125-
ret.MinerNephewRewardIn.SetUint64(0)
126-
ret.MinerTxFeeIn.SetUint64(0)
127-
ret.MinerUncleRewardIn.SetUint64(0)
128-
ret.CorrectingIn.SetUint64(0)
129-
ret.PrefundIn.SetUint64(0)
130-
ret.SelfDestructIn.SetUint64(0)
153+
// stmt.AmountIn.SetUint64(0)
154+
stmt.InternalIn.SetUint64(0)
155+
stmt.MinerBaseRewardIn.SetUint64(0)
156+
stmt.MinerNephewRewardIn.SetUint64(0)
157+
stmt.MinerTxFeeIn.SetUint64(0)
158+
stmt.MinerUncleRewardIn.SetUint64(0)
159+
stmt.CorrectingIn.SetUint64(0)
160+
stmt.PrefundIn.SetUint64(0)
161+
stmt.SelfDestructIn.SetUint64(0)
131162

132-
// ret.AmountOut.SetUint64(0)
133-
// ret.GasOut.SetUint64(0)
134-
ret.InternalOut.SetUint64(0)
135-
ret.CorrectingOut.SetUint64(0)
136-
ret.SelfDestructOut.SetUint64(0)
163+
// stmt.AmountOut.SetUint64(0)
164+
// stmt.GasOut.SetUint64(0)
165+
stmt.InternalOut.SetUint64(0)
166+
stmt.CorrectingOut.SetUint64(0)
167+
stmt.SelfDestructOut.SetUint64(0)
137168

138169
if traces, err := r.opts.Connection.GetTracesByTransactionHash(trans.Hash.Hex(), trans); err != nil {
139170
return nil, err
@@ -157,59 +188,59 @@ func (r *Reconciler1) getStatementFromTraces(pos *types.AppPosition, trans *type
157188

158189
// Do not collapse, more than one of these can be true at the same time
159190
if trace.Action.From == s.AccountedFor {
160-
ret.InternalOut = plusEq(&ret.InternalOut, &trace.Action.Value)
161-
ret.Sender = trace.Action.From
191+
stmt.InternalOut = plusEq(&stmt.InternalOut, &trace.Action.Value)
192+
stmt.Sender = trace.Action.From
162193
if trace.Action.To.IsZero() {
163194
if trace.Result != nil {
164-
ret.Recipient = trace.Result.Address
195+
stmt.Recipient = trace.Result.Address
165196
}
166197
} else {
167-
ret.Recipient = trace.Action.To
198+
stmt.Recipient = trace.Action.To
168199
}
169200
}
170201

171202
if trace.Action.To == s.AccountedFor {
172-
ret.InternalIn = plusEq(&ret.InternalIn, &trace.Action.Value)
173-
ret.Sender = trace.Action.From
174-
ret.Recipient = trace.Action.To
203+
stmt.InternalIn = plusEq(&stmt.InternalIn, &trace.Action.Value)
204+
stmt.Sender = trace.Action.From
205+
stmt.Recipient = trace.Action.To
175206
}
176207

177208
if trace.Action.SelfDestructed == s.AccountedFor {
178-
ret.SelfDestructOut = plusEq(&ret.SelfDestructOut, &trace.Action.Balance)
179-
ret.Sender = trace.Action.SelfDestructed
180-
if ret.Sender.IsZero() {
181-
ret.Sender = trace.Action.Address
209+
stmt.SelfDestructOut = plusEq(&stmt.SelfDestructOut, &trace.Action.Balance)
210+
stmt.Sender = trace.Action.SelfDestructed
211+
if stmt.Sender.IsZero() {
212+
stmt.Sender = trace.Action.Address
182213
}
183-
ret.Recipient = trace.Action.RefundAddress
214+
stmt.Recipient = trace.Action.RefundAddress
184215
}
185216

186217
if trace.Action.RefundAddress == s.AccountedFor {
187-
ret.SelfDestructIn = plusEq(&ret.SelfDestructIn, &trace.Action.Balance)
188-
ret.Sender = trace.Action.SelfDestructed
189-
if ret.Sender.IsZero() {
190-
ret.Sender = trace.Action.Address
218+
stmt.SelfDestructIn = plusEq(&stmt.SelfDestructIn, &trace.Action.Balance)
219+
stmt.Sender = trace.Action.SelfDestructed
220+
if stmt.Sender.IsZero() {
221+
stmt.Sender = trace.Action.Address
191222
}
192-
ret.Recipient = trace.Action.RefundAddress
223+
stmt.Recipient = trace.Action.RefundAddress
193224
}
194225

195226
if trace.Action.Address == s.AccountedFor && !trace.Action.RefundAddress.IsZero() {
196-
ret.SelfDestructOut = plusEq(&ret.SelfDestructOut, &trace.Action.Balance)
227+
stmt.SelfDestructOut = plusEq(&stmt.SelfDestructOut, &trace.Action.Balance)
197228
// self destructed send
198-
ret.Sender = trace.Action.Address
199-
ret.Recipient = trace.Action.RefundAddress
229+
stmt.Sender = trace.Action.Address
230+
stmt.Recipient = trace.Action.RefundAddress
200231
}
201232

202233
if trace.Result != nil {
203234
if trace.Result.Address == s.AccountedFor {
204-
ret.InternalIn = plusEq(&ret.InternalIn, &trace.Action.Value)
205-
ret.Sender = trace.Action.From
206-
ret.Recipient = trace.Result.Address
235+
stmt.InternalIn = plusEq(&stmt.InternalIn, &trace.Action.Value)
236+
stmt.Sender = trace.Action.From
237+
stmt.Recipient = trace.Result.Address
207238
}
208239
}
209240
}
210241
}
211242

212-
return &ret, nil
243+
return &stmt, nil
213244
}
214245

215246
func (r *Reconciler1) getStatementsFromLogs(logs []types.Log) ([]types.Statement, error) {

0 commit comments

Comments
 (0)