diff --git a/exp/lighthorizon/archive/main.go b/exp/lighthorizon/archive/main.go index e3d7063df5..00b3a57620 100644 --- a/exp/lighthorizon/archive/main.go +++ b/exp/lighthorizon/archive/main.go @@ -30,9 +30,39 @@ type LedgerTransactionReader interface { // Archive here only has the methods LightHorizon cares about, to make caching/wrapping easier type Archive interface { + + //GetLedger - retreive a ledger's meta data + // + //ctx - the caller's request context + //ledgerCloseMeta - the sequence number of ledger to fetch + // + //returns error or meta data for requested ledger GetLedger(ctx context.Context, sequence uint32) (xdr.LedgerCloseMeta, error) + + // Close - releases any resources used for this archive instance. Close() error + + // NewLedgerTransactionReaderFromLedgerCloseMeta - get a reader for ledger meta data + // + // networkPassphrase - the network passphrase + // ledgerCloseMeta - the meta data for a ledger + // + // returns error or LedgerTransactionReader NewLedgerTransactionReaderFromLedgerCloseMeta(networkPassphrase string, ledgerCloseMeta xdr.LedgerCloseMeta) (LedgerTransactionReader, error) + + // GetTransactionParticipants - get set of all participants(accounts) in a transaction + // + // transaction - the ledger transaction + // + // returns error or map with keys of participant account id's and value of empty struct GetTransactionParticipants(transaction LedgerTransaction) (map[string]struct{}, error) + + // GetOperationParticipants - get set of all participants(accounts) in a operation + // + // transaction - the ledger transaction + // operation - the operation within this transaction + // opIndex - the 0 based index of the operation within the transaction + // + // returns error or map with keys of participant account id's and value of empty struct GetOperationParticipants(transaction LedgerTransaction, operation xdr.Operation, opIndex int) (map[string]struct{}, error) } diff --git a/exp/lighthorizon/index/modules.go b/exp/lighthorizon/index/modules.go index ca4c4c6681..9250125ab9 100644 --- a/exp/lighthorizon/index/modules.go +++ b/exp/lighthorizon/index/modules.go @@ -109,6 +109,9 @@ func GetTransactionParticipants(transaction ingest.LedgerTransaction) ([]string, return participantsForOperations(transaction, false) } +// transaction - the ledger transaction +// operation - the operation within this transaction +// opIndex - the 0 based index of the operation within the transaction func GetOperationParticipants(transaction ingest.LedgerTransaction, operation xdr.Operation, opIndex int) ([]string, error) { return participantsForOperation(transaction, operation, opIndex, false) } @@ -130,6 +133,9 @@ func participantsForOperations(transaction ingest.LedgerTransaction, onlyPayment return participants, nil } +// transaction - the ledger transaction +// operation - the operation within this transaction +// opIndex - the 0 based index of the operation within the transaction func participantsForOperation(transaction ingest.LedgerTransaction, operation xdr.Operation, opIndex int, onlyPayments bool) ([]string, error) { participants := []string{} opSource := operation.SourceAccount diff --git a/exp/lighthorizon/services/main.go b/exp/lighthorizon/services/main.go index 3bd16f8c54..27baca1ef7 100644 --- a/exp/lighthorizon/services/main.go +++ b/exp/lighthorizon/services/main.go @@ -49,7 +49,7 @@ func (os *OperationsService) GetOperationsByAccount(ctx context.Context, cursor ops := []common.Operation{} opsCallback := func(tx archive.LedgerTransaction, ledgerHeader *xdr.LedgerHeader) (bool, error) { for operationOrder, op := range tx.Envelope.Operations() { - opParticipants, opParticipantErr := os.Config.Archive.GetOperationParticipants(tx, op, operationOrder+1) + opParticipants, opParticipantErr := os.Config.Archive.GetOperationParticipants(tx, op, operationOrder) if opParticipantErr != nil { return false, opParticipantErr } @@ -59,7 +59,7 @@ func (os *OperationsService) GetOperationsByAccount(ctx context.Context, cursor TransactionResult: &tx.Result.Result, LedgerHeader: ledgerHeader, TxIndex: int32(tx.Index), - OpIndex: int32(operationOrder + 1), + OpIndex: int32(operationOrder), }) if uint64(len(ops)) == limit { return true, nil @@ -146,12 +146,10 @@ func searchTxByAccount(ctx context.Context, cursor int64, accountId string, conf } } nextCursor := toid.New(int32(nextLedger), 1, 1).ToInt64() - nextLedger, err = getAccountNextLedgerCursor(accountId, nextCursor, config.IndexStore) - if err != nil { - if err == io.EOF { - return nil - } + if err == io.EOF { + return nil + } else if err != nil { return err } } diff --git a/exp/lighthorizon/services/main_test.go b/exp/lighthorizon/services/main_test.go index 882372d000..ae402bfcea 100644 --- a/exp/lighthorizon/services/main_test.go +++ b/exp/lighthorizon/services/main_test.go @@ -152,13 +152,13 @@ func mockArchiveAndIndex(ctx context.Context, passphrase string) (archive.Archiv mockArchive.On("GetTransactionParticipants", expectedLedger3Transaction1).Return(allParticipants, nil) mockArchive.On("GetTransactionParticipants", expectedLedger3Transaction2).Return(partialParticipants, nil) + mockArchive.On("GetOperationParticipants", expectedLedger1Transaction1, mock.Anything, int(0)).Return(partialParticipants, nil) mockArchive.On("GetOperationParticipants", expectedLedger1Transaction1, mock.Anything, int(1)).Return(partialParticipants, nil) - mockArchive.On("GetOperationParticipants", expectedLedger1Transaction1, mock.Anything, int(2)).Return(partialParticipants, nil) - mockArchive.On("GetOperationParticipants", expectedLedger1Transaction2, mock.Anything, int(1)).Return(partialParticipants, nil) - mockArchive.On("GetOperationParticipants", expectedLedger2Transaction1, mock.Anything, int(1)).Return(partialParticipants, nil) - mockArchive.On("GetOperationParticipants", expectedLedger2Transaction2, mock.Anything, int(1)).Return(allParticipants, nil) - mockArchive.On("GetOperationParticipants", expectedLedger3Transaction1, mock.Anything, int(1)).Return(allParticipants, nil) - mockArchive.On("GetOperationParticipants", expectedLedger3Transaction2, mock.Anything, int(1)).Return(partialParticipants, nil) + mockArchive.On("GetOperationParticipants", expectedLedger1Transaction2, mock.Anything, int(0)).Return(partialParticipants, nil) + mockArchive.On("GetOperationParticipants", expectedLedger2Transaction1, mock.Anything, int(0)).Return(partialParticipants, nil) + mockArchive.On("GetOperationParticipants", expectedLedger2Transaction2, mock.Anything, int(0)).Return(allParticipants, nil) + mockArchive.On("GetOperationParticipants", expectedLedger3Transaction1, mock.Anything, int(0)).Return(allParticipants, nil) + mockArchive.On("GetOperationParticipants", expectedLedger3Transaction2, mock.Anything, int(0)).Return(partialParticipants, nil) mockReaderLedger1.On("Read").Return(expectedLedger1Transaction1, nil).Once() mockReaderLedger1.On("Read").Return(expectedLedger1Transaction2, nil).Once()