Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-ogrady committed Dec 2, 2020
1 parent 64a8c7e commit 1caffcf
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions storage/modules/block_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ func getBlockIndexKey(index int64) []byte {
return []byte(fmt.Sprintf("%s/%d", blockIndexNamespace, index))
}

func getTransactionHashKey(
transactionIdentifier *types.TransactionIdentifier,
func getTransactionKey(
blockIdentifier *types.BlockIdentifier,
transactionIdentifier *types.TransactionIdentifier,
) (string, []byte) {
return transactionNamespace, []byte(
fmt.Sprintf(
Expand All @@ -92,7 +92,9 @@ func getTransactionHashKey(
)
}

func getTransactionHashPrefix(transactionIdentifier *types.TransactionIdentifier) []byte {
func getTransactionPrefix(
transactionIdentifier *types.TransactionIdentifier,
) []byte {
return []byte(
fmt.Sprintf(
"%s/%s/",
Expand Down Expand Up @@ -885,7 +887,7 @@ func (b *BlockStorage) storeTransaction(
blockIdentifier *types.BlockIdentifier,
tx *types.Transaction,
) error {
namespace, hashKey := getTransactionHashKey(tx.TransactionIdentifier, blockIdentifier)
namespace, hashKey := getTransactionKey(blockIdentifier, tx.TransactionIdentifier)
bt := &blockTransaction{
Transaction: tx,
BlockIndex: blockIdentifier.Index,
Expand All @@ -905,7 +907,7 @@ func (b *BlockStorage) pruneTransaction(
blockIdentifier *types.BlockIdentifier,
txIdentifier *types.TransactionIdentifier,
) error {
namespace, hashKey := getTransactionHashKey(txIdentifier, blockIdentifier)
namespace, hashKey := getTransactionKey(blockIdentifier, txIdentifier)
bt := &blockTransaction{
BlockIndex: blockIdentifier.Index,
}
Expand All @@ -924,7 +926,7 @@ func (b *BlockStorage) removeTransaction(
blockIdentifier *types.BlockIdentifier,
transactionIdentifier *types.TransactionIdentifier,
) error {
_, hashKey := getTransactionHashKey(transactionIdentifier, blockIdentifier)
_, hashKey := getTransactionKey(blockIdentifier, transactionIdentifier)

return transaction.Delete(ctx, hashKey)
}
Expand All @@ -937,8 +939,8 @@ func (b *BlockStorage) getAllTransactionsByIdentifier(
blockTransactions := []*types.BlockTransaction{}
_, err := txn.Scan(
ctx,
getTransactionHashPrefix(transactionIdentifier),
getTransactionHashPrefix(transactionIdentifier),
getTransactionPrefix(transactionIdentifier),
getTransactionPrefix(transactionIdentifier),
func(k []byte, v []byte) error {
// Decode blockTransaction
var bt blockTransaction
Expand Down Expand Up @@ -1017,7 +1019,7 @@ func (b *BlockStorage) findBlockTransaction(
return nil, storageErrs.ErrCannotAccessPrunedData
}

namespace, key := getTransactionHashKey(transactionIdentifier, blockIdentifier)
namespace, key := getTransactionKey(blockIdentifier, transactionIdentifier)
txExists, tx, err := txn.Get(ctx, key)
if err != nil {
return nil, fmt.Errorf("%w: %v", storageErrs.ErrTransactionDBQueryFailed, err)
Expand Down

0 comments on commit 1caffcf

Please sign in to comment.