Skip to content

Commit de2a37d

Browse files
committed
Make BlockOperation with BlockTransaction.Index
- For building blockoperation's indexes, tx.Index is needed.
1 parent cafe1e6 commit de2a37d

File tree

6 files changed

+10
-8
lines changed

6 files changed

+10
-8
lines changed

lib/block/operation.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ type BlockOperation struct {
3333

3434
// transaction will be used only for `Save` time.
3535
transaction transaction.Transaction
36+
txIndex uint64
3637
isSaved bool
3738
}
3839

3940
func NewBlockOperationKey(opHash, txHash string) string {
4041
return fmt.Sprintf("%s-%s", opHash, txHash)
4142
}
4243

43-
func NewBlockOperationFromOperation(op operation.Operation, tx transaction.Transaction, blockHeight, index uint64) (BlockOperation, error) {
44+
func NewBlockOperationFromOperation(op operation.Operation, tx transaction.Transaction, blockHeight, txIndex, index uint64) (BlockOperation, error) {
4445
body, err := op.B.Serialize()
4546
if err != nil {
4647
return BlockOperation{}, err
@@ -62,6 +63,7 @@ func NewBlockOperationFromOperation(op operation.Operation, tx transaction.Trans
6263
Index: index,
6364

6465
transaction: tx,
66+
txIndex: index,
6567
}, nil
6668
}
6769

lib/block/operation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestNewBlockOperationFromOperation(t *testing.T) {
1616
_, tx := transaction.TestMakeTransaction(conf.NetworkID, 1)
1717

1818
op := tx.B.Operations[0]
19-
bo, err := NewBlockOperationFromOperation(op, tx, 0, 0)
19+
bo, err := NewBlockOperationFromOperation(op, tx, 0, 1, 0)
2020
require.NoError(t, err)
2121

2222
require.Equal(t, bo.Type, op.H.Type)

lib/block/test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func TestMakeNewBlockOperation(networkID []byte, n int) (bos []BlockOperation) {
128128
_, tx := transaction.TestMakeTransaction(networkID, n)
129129

130130
for i, op := range tx.B.Operations {
131-
bo, err := NewBlockOperationFromOperation(op, tx, 0, uint64(i))
131+
bo, err := NewBlockOperationFromOperation(op, tx, 0, 1, uint64(i))
132132
if err != nil {
133133
panic(err)
134134
}

lib/block/transaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (bt *BlockTransaction) SaveBlockOperation(st *storage.LevelDBBackend, op op
212212
}
213213

214214
var bo BlockOperation
215-
bo, err = NewBlockOperationFromOperation(op, bt.Transaction(), bt.blockHeight, index)
215+
bo, err = NewBlockOperationFromOperation(op, bt.Transaction(), bt.blockHeight, bt.Index, index)
216216
if err != nil {
217217
return
218218
}

lib/node/runner/api/base_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ func prepareOpsWithoutSave(count int, st *storage.LevelDBBackend) (*keypair.Full
6464
}
6565

6666
theBlock := block.TestMakeNewBlockWithPrevBlock(block.GetLatestBlock(st), txHashes)
67-
for _, tx := range txs {
68-
for i, op := range tx.B.Operations {
69-
bo, err := block.NewBlockOperationFromOperation(op, tx, theBlock.Height, uint64(i))
67+
for i, tx := range txs {
68+
for j, op := range tx.B.Operations {
69+
bo, err := block.NewBlockOperationFromOperation(op, tx, theBlock.Height, uint64(i), uint64(j))
7070
if err != nil {
7171
panic(err)
7272
}

lib/node/runner/api/tx_operations_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestGetOperationsByTxHashHandlerStream(t *testing.T) {
7777

7878
boMap := make(map[string]block.BlockOperation)
7979
for i, op := range tx.B.Operations {
80-
bo, err := block.NewBlockOperationFromOperation(op, tx, 0, uint64(i))
80+
bo, err := block.NewBlockOperationFromOperation(op, tx, 0, 1, uint64(i))
8181
require.NoError(t, err)
8282
boMap[bo.Hash] = bo
8383
}

0 commit comments

Comments
 (0)