From 146dd525e7f8816819508cdcc2709fc6de3cdbf8 Mon Sep 17 00:00:00 2001 From: Simon Chow Date: Mon, 4 Nov 2024 12:53:04 -0500 Subject: [PATCH] Address comments --- exp/xdrill/ledgers/ledgers.go | 14 ++++++++------ exp/xdrill/transform_ledger.go | 24 ++++++++++++------------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/exp/xdrill/ledgers/ledgers.go b/exp/xdrill/ledgers/ledgers.go index 4bb2005a38..130f52e19f 100644 --- a/exp/xdrill/ledgers/ledgers.go +++ b/exp/xdrill/ledgers/ledgers.go @@ -61,7 +61,7 @@ func (l Ledgers) LedgerVersion() uint32 { return uint32(l.LedgerHeaderHistoryEntry().Header.LedgerVersion) } -func (l Ledgers) GetSorobanFeeWrite1Kb() (int64, bool) { +func (l Ledgers) SorobanFeeWrite1Kb() (int64, bool) { lcmV1, ok := l.GetV1() if ok { extV1, ok := lcmV1.Ext.GetV1() @@ -73,7 +73,7 @@ func (l Ledgers) GetSorobanFeeWrite1Kb() (int64, bool) { return 0, false } -func (l Ledgers) GetTotalByteSizeOfBucketList() (uint64, bool) { +func (l Ledgers) TotalByteSizeOfBucketList() (uint64, bool) { lcmV1, ok := l.GetV1() if ok { return uint64(lcmV1.TotalByteSizeOfBucketList), true @@ -82,7 +82,7 @@ func (l Ledgers) GetTotalByteSizeOfBucketList() (uint64, bool) { return 0, false } -func (l Ledgers) GetNodeID() (string, bool) { +func (l Ledgers) NodeID() (string, bool) { LedgerCloseValueSignature, ok := l.LedgerHeaderHistoryEntry().Header.ScpValue.Ext.GetLcValueSignature() if ok { nodeID, ok := utils.GetAddress(LedgerCloseValueSignature.NodeId) @@ -94,7 +94,7 @@ func (l Ledgers) GetNodeID() (string, bool) { return "", false } -func (l Ledgers) GetSignature() (string, bool) { +func (l Ledgers) Signature() (string, bool) { LedgerCloseValueSignature, ok := l.LedgerHeaderHistoryEntry().Header.ScpValue.Ext.GetLcValueSignature() if ok { return base64.StdEncoding.EncodeToString(LedgerCloseValueSignature.Signature), true @@ -103,7 +103,8 @@ func (l Ledgers) GetSignature() (string, bool) { return "", false } -func (l Ledgers) GetTransactionCounts() (successTxCount, failedTxCount int32, ok bool) { +// Add docstring to larger, more complicated functions +func (l Ledgers) TransactionCounts() (successTxCount, failedTxCount int32, ok bool) { transactions := getTransactionSet(l) results := l.V0.TxProcessing txCount := len(transactions) @@ -122,7 +123,8 @@ func (l Ledgers) GetTransactionCounts() (successTxCount, failedTxCount int32, ok return successTxCount, failedTxCount, true } -func (l Ledgers) GetOperationCounts() (operationCount, txSetOperationCount int32, ok bool) { +// Add docstring to larger, more complicated functions +func (l Ledgers) OperationCounts() (operationCount, txSetOperationCount int32, ok bool) { transactions := getTransactionSet(l) results := l.V0.TxProcessing txCount := len(transactions) diff --git a/exp/xdrill/transform_ledger.go b/exp/xdrill/transform_ledger.go index fb857f9dc7..295e786b57 100644 --- a/exp/xdrill/transform_ledger.go +++ b/exp/xdrill/transform_ledger.go @@ -8,7 +8,7 @@ import ( "github.com/stellar/go/xdr" ) -type LedgerOutput struct { +type LedgerClosedOutput struct { Sequence uint32 `json:"sequence"` // sequence number of the ledger LedgerHash string `json:"ledger_hash"` PreviousLedgerHash string `json:"previous_ledger_hash"` @@ -32,51 +32,51 @@ type LedgerOutput struct { TotalByteSizeOfBucketList uint64 `json:"total_byte_size_of_bucket_list"` } -func TransformLedger(lcm xdr.LedgerCloseMeta) (LedgerOutput, error) { +func TransformLedger(lcm xdr.LedgerCloseMeta) (LedgerClosedOutput, error) { ledger := ledgers.Ledgers{ LedgerCloseMeta: lcm, } outputLedgerHeader, err := xdr.MarshalBase64(ledger.LedgerHeaderHistoryEntry().Header) if err != nil { - return LedgerOutput{}, err + return LedgerClosedOutput{}, err } - outputSuccessfulTransactionCount, outputFailedTransactionCount, ok := ledger.GetTransactionCounts() + outputSuccessfulTransactionCount, outputFailedTransactionCount, ok := ledger.TransactionCounts() if !ok { - return LedgerOutput{}, fmt.Errorf("could not get transaction counts") + return LedgerClosedOutput{}, fmt.Errorf("could not get transaction counts") } - outputOperationCount, outputTxSetOperationCount, ok := ledger.GetOperationCounts() + outputOperationCount, outputTxSetOperationCount, ok := ledger.OperationCounts() if !ok { - return LedgerOutput{}, fmt.Errorf("could not get operation counts") + return LedgerClosedOutput{}, fmt.Errorf("could not get operation counts") } var outputSorobanFeeWrite1Kb int64 - sorobanFeeWrite1Kb, ok := ledger.GetSorobanFeeWrite1Kb() + sorobanFeeWrite1Kb, ok := ledger.SorobanFeeWrite1Kb() if ok { outputSorobanFeeWrite1Kb = sorobanFeeWrite1Kb } var outputTotalByteSizeOfBucketList uint64 - totalByteSizeOfBucketList, ok := ledger.GetTotalByteSizeOfBucketList() + totalByteSizeOfBucketList, ok := ledger.TotalByteSizeOfBucketList() if ok { outputTotalByteSizeOfBucketList = totalByteSizeOfBucketList } var outputNodeID string - nodeID, ok := ledger.GetNodeID() + nodeID, ok := ledger.NodeID() if ok { outputNodeID = nodeID } var outputSigature string - signature, ok := ledger.GetSignature() + signature, ok := ledger.Signature() if ok { outputSigature = signature } - ledgerOutput := LedgerOutput{ + ledgerOutput := LedgerClosedOutput{ Sequence: ledger.LedgerSequence(), LedgerHash: ledger.Hash(), PreviousLedgerHash: ledger.Hash(),