-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use transaction results stream & state to get correct state of transa…
…ction
- Loading branch information
Showing
7 changed files
with
198 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package collector | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
pb "github.com/spacemeshos/api/release/go/spacemesh/v1" | ||
"github.com/spacemeshos/go-spacemesh/log" | ||
"io" | ||
) | ||
|
||
func (c *Collector) transactionsPump() error { | ||
req := pb.TransactionResultsRequest{ | ||
Start: 1, | ||
Watch: true, | ||
} | ||
|
||
log.Info("Start transactions pump") | ||
defer func() { | ||
c.notify <- -streamType_transactions | ||
log.Info("Stop transactions pump") | ||
}() | ||
|
||
c.notify <- +streamType_transactions | ||
|
||
stream, err := c.transactionsClient.StreamResults(context.Background(), &req) | ||
if err != nil { | ||
log.Err(fmt.Errorf("cannot get transactions stream results: %v", err)) | ||
return err | ||
} | ||
|
||
for { | ||
response, err := stream.Recv() | ||
if err == io.EOF { | ||
return err | ||
} | ||
if err != nil { | ||
log.Err(fmt.Errorf("cannot receive transaction result: %v", err)) | ||
return err | ||
} | ||
if response == nil { | ||
continue | ||
} | ||
|
||
state, err := c.transactionsClient.TransactionsState(context.TODO(), &pb.TransactionsStateRequest{ | ||
TransactionId: []*pb.TransactionId{{Id: response.Tx.Id}}, | ||
IncludeTransactions: false, | ||
}) | ||
if err != nil { | ||
log.Err(fmt.Errorf("cannot receive transaction state: %v", err)) | ||
return err | ||
} | ||
|
||
if len(state.GetTransactionsState()) > 0 { | ||
c.listener.OnTransactionResult(response, state.GetTransactionsState()[0]) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.