From 58b25832395848c0bcf44a1c389676ccf8ff9b3d Mon Sep 17 00:00:00 2001 From: Geoffrey Ragot Date: Mon, 13 Jun 2022 19:22:56 +0200 Subject: [PATCH] Unexpose some functions. --- pkg/ledger/ledger.go | 14 +++++++------- pkg/ledger/volume_agg.go | 16 ++++++++-------- pkg/ledger/volume_agg_test.go | 24 ++++++++++++------------ 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/pkg/ledger/ledger.go b/pkg/ledger/ledger.go index b0eec8279..04deb92eb 100644 --- a/pkg/ledger/ledger.go +++ b/pkg/ledger/ledger.go @@ -94,7 +94,7 @@ func (l *Ledger) processTx(ctx context.Context, ts []core.TransactionData) (*Com return nil, NewTransactionCommitError(i, NewValidationError("transaction has no postings")) } - txVolumeAggregator := volumeAggregator.NextTx() + txVolumeAggregator := volumeAggregator.nextTx() for _, p := range t.Postings { if p.Amount < 0 { @@ -109,13 +109,13 @@ func (l *Ledger) processTx(ctx context.Context, ts []core.TransactionData) (*Com if !core.AssetIsValid(p.Asset) { return nil, NewTransactionCommitError(i, NewValidationError("invalid asset")) } - err := txVolumeAggregator.Transfer(ctx, p.Source, p.Destination, p.Asset, uint64(p.Amount)) + err := txVolumeAggregator.transfer(ctx, p.Source, p.Destination, p.Asset, uint64(p.Amount)) if err != nil { return nil, NewTransactionCommitError(i, err) } } - for addr, volumes := range txVolumeAggregator.PostCommitVolumes() { + for addr, volumes := range txVolumeAggregator.postCommitVolumes() { for asset, volume := range volumes { if addr == "world" { continue @@ -152,8 +152,8 @@ func (l *Ledger) processTx(ctx context.Context, ts []core.TransactionData) (*Com TransactionData: t, ID: nextTxId, Timestamp: time.Now().UTC().Format(time.RFC3339), - PostCommitVolumes: txVolumeAggregator.PostCommitVolumes(), - PreCommitVolumes: txVolumeAggregator.PreCommitVolumes(), + PostCommitVolumes: txVolumeAggregator.postCommitVolumes(), + PreCommitVolumes: txVolumeAggregator.preCommitVolumes(), } generatedTxs = append(generatedTxs, tx) newLog := core.NewTransactionLog(lastLog, tx) @@ -163,8 +163,8 @@ func (l *Ledger) processTx(ctx context.Context, ts []core.TransactionData) (*Com } return &CommitResult{ - PreCommitVolumes: volumeAggregator.AggregatedPreCommitVolumes(), - PostCommitVolumes: volumeAggregator.AggregatedPostCommitVolumes(), + PreCommitVolumes: volumeAggregator.aggregatedPreCommitVolumes(), + PostCommitVolumes: volumeAggregator.aggregatedPostCommitVolumes(), GeneratedTransactions: generatedTxs, GeneratedLogs: generatedLogs, }, nil diff --git a/pkg/ledger/volume_agg.go b/pkg/ledger/volume_agg.go index b5b49053b..e1ef191bc 100644 --- a/pkg/ledger/volume_agg.go +++ b/pkg/ledger/volume_agg.go @@ -14,15 +14,15 @@ type transactionVolumeAggregator struct { previousTx *transactionVolumeAggregator } -func (tva *transactionVolumeAggregator) PostCommitVolumes() core.AggregatedVolumes { +func (tva *transactionVolumeAggregator) postCommitVolumes() core.AggregatedVolumes { return tva.postVolumes } -func (tva *transactionVolumeAggregator) PreCommitVolumes() core.AggregatedVolumes { +func (tva *transactionVolumeAggregator) preCommitVolumes() core.AggregatedVolumes { return tva.preVolumes } -func (tva *transactionVolumeAggregator) Transfer(ctx context.Context, from, to, asset string, amount uint64) error { +func (tva *transactionVolumeAggregator) transfer(ctx context.Context, from, to, asset string, amount uint64) error { if tva.preVolumes == nil { tva.preVolumes = core.AggregatedVolumes{} } @@ -75,7 +75,7 @@ type volumeAggregator struct { txs []*transactionVolumeAggregator } -func (agg *volumeAggregator) NextTx() *transactionVolumeAggregator { +func (agg *volumeAggregator) nextTx() *transactionVolumeAggregator { var previousTx *transactionVolumeAggregator if len(agg.txs) > 0 { previousTx = agg.txs[len(agg.txs)-1] @@ -88,11 +88,11 @@ func (agg *volumeAggregator) NextTx() *transactionVolumeAggregator { return tva } -func (agg *volumeAggregator) AggregatedPostCommitVolumes() core.AggregatedVolumes { +func (agg *volumeAggregator) aggregatedPostCommitVolumes() core.AggregatedVolumes { ret := core.AggregatedVolumes{} for i := len(agg.txs) - 1; i >= 0; i-- { tx := agg.txs[i] - postVolumes := tx.PostCommitVolumes() + postVolumes := tx.postCommitVolumes() for account, volumes := range postVolumes { for asset, volume := range volumes { if _, ok := ret[account]; !ok { @@ -107,11 +107,11 @@ func (agg *volumeAggregator) AggregatedPostCommitVolumes() core.AggregatedVolume return ret } -func (agg *volumeAggregator) AggregatedPreCommitVolumes() core.AggregatedVolumes { +func (agg *volumeAggregator) aggregatedPreCommitVolumes() core.AggregatedVolumes { ret := core.AggregatedVolumes{} for i := 0; i < len(agg.txs); i++ { tx := agg.txs[i] - preVolumes := tx.PreCommitVolumes() + preVolumes := tx.preCommitVolumes() for account, volumes := range preVolumes { for asset, volume := range volumes { if _, ok := ret[account]; !ok { diff --git a/pkg/ledger/volume_agg_test.go b/pkg/ledger/volume_agg_test.go index 5bd956f52..377124954 100644 --- a/pkg/ledger/volume_agg_test.go +++ b/pkg/ledger/volume_agg_test.go @@ -56,9 +56,9 @@ func TestVolumeAggregator(t *testing.T) { require.NoError(t, store.AppendLog(context.Background(), firstTxLog, secondTxLog)) volumeAggregator := newVolumeAggregator(store) - firstTx := volumeAggregator.NextTx() - require.NoError(t, firstTx.Transfer(context.Background(), "bob", "alice", "USD", 100)) - require.NoError(t, firstTx.Transfer(context.Background(), "bob", "zoro", "USD", 50)) + firstTx := volumeAggregator.nextTx() + require.NoError(t, firstTx.transfer(context.Background(), "bob", "alice", "USD", 100)) + require.NoError(t, firstTx.transfer(context.Background(), "bob", "zoro", "USD", 50)) require.Equal(t, core.AggregatedVolumes{ "bob": core.Volumes{ @@ -76,7 +76,7 @@ func TestVolumeAggregator(t *testing.T) { Input: 50, }, }, - }, firstTx.PostCommitVolumes()) + }, firstTx.postCommitVolumes()) require.Equal(t, core.AggregatedVolumes{ "bob": core.Volumes{ "USD": { @@ -93,11 +93,11 @@ func TestVolumeAggregator(t *testing.T) { Input: 0, }, }, - }, firstTx.PreCommitVolumes()) + }, firstTx.preCommitVolumes()) - secondTx := volumeAggregator.NextTx() - require.NoError(t, secondTx.Transfer(context.Background(), "alice", "fred", "USD", 50)) - require.NoError(t, secondTx.Transfer(context.Background(), "bob", "fred", "USD", 25)) + secondTx := volumeAggregator.nextTx() + require.NoError(t, secondTx.transfer(context.Background(), "alice", "fred", "USD", 50)) + require.NoError(t, secondTx.transfer(context.Background(), "bob", "fred", "USD", 25)) require.Equal(t, core.AggregatedVolumes{ "bob": core.Volumes{ "USD": { @@ -115,7 +115,7 @@ func TestVolumeAggregator(t *testing.T) { Input: 75, }, }, - }, secondTx.PostCommitVolumes()) + }, secondTx.postCommitVolumes()) require.Equal(t, core.AggregatedVolumes{ "bob": core.Volumes{ "USD": { @@ -130,9 +130,9 @@ func TestVolumeAggregator(t *testing.T) { "fred": core.Volumes{ "USD": {}, }, - }, secondTx.PreCommitVolumes()) + }, secondTx.preCommitVolumes()) - aggregatedPostVolumes := volumeAggregator.AggregatedPostCommitVolumes() + aggregatedPostVolumes := volumeAggregator.aggregatedPostCommitVolumes() require.Equal(t, core.AggregatedVolumes{ "bob": core.Volumes{ "USD": { @@ -158,7 +158,7 @@ func TestVolumeAggregator(t *testing.T) { }, }, aggregatedPostVolumes) - aggregatedPreVolumes := volumeAggregator.AggregatedPreCommitVolumes() + aggregatedPreVolumes := volumeAggregator.aggregatedPreCommitVolumes() require.Equal(t, core.AggregatedVolumes{ "bob": core.Volumes{ "USD": {