Skip to content

Commit

Permalink
change runtime api methods to return slices of values
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew7234 committed Apr 7, 2023
1 parent ff5320b commit 008765a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
10 changes: 5 additions & 5 deletions analyzer/runtime/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func registerTokenDecrease(tokenChanges map[TokenChangeKey]*big.Int, contractAdd
change.Sub(change, amount)
}

func ExtractRound(blockHeader nodeapi.RuntimeBlockHeader, txrs []*nodeapi.RuntimeTransactionWithResults, rawEvents []*nodeapi.RuntimeEvent, logger *log.Logger) (*BlockData, error) { //nolint:gocyclo
func ExtractRound(blockHeader nodeapi.RuntimeBlockHeader, txrs []nodeapi.RuntimeTransactionWithResults, rawEvents []nodeapi.RuntimeEvent, logger *log.Logger) (*BlockData, error) { //nolint:gocyclo
blockData := BlockData{
Header: blockHeader,
NumTransactions: len(txrs),
Expand All @@ -259,7 +259,7 @@ func ExtractRound(blockHeader nodeapi.RuntimeBlockHeader, txrs []*nodeapi.Runtim
}

// Extract info from non-tx events.
rawNonTxEvents := []*nodeapi.RuntimeEvent{}
rawNonTxEvents := []nodeapi.RuntimeEvent{}
for _, e := range rawEvents {
if e.TxHash.String() == util.ZeroTxHash {
rawNonTxEvents = append(rawNonTxEvents, e)
Expand Down Expand Up @@ -390,9 +390,9 @@ func ExtractRound(blockHeader nodeapi.RuntimeBlockHeader, txrs []*nodeapi.Runtim
}
blockTransactionData.Amount = common.Ptr(common.BigIntFromQuantity(amount))
}
txEvents := make([]*nodeapi.RuntimeEvent, len(txr.Events))
txEvents := make([]nodeapi.RuntimeEvent, len(txr.Events))
for i, e := range txr.Events {
txEvents[i] = (*nodeapi.RuntimeEvent)(e)
txEvents[i] = (nodeapi.RuntimeEvent)(*e)
}
extractedTxEvents, err := extractEvents(&blockData, blockTransactionData.RelatedAccountAddresses, txEvents)
if err != nil {
Expand Down Expand Up @@ -448,7 +448,7 @@ func sumGasUsed(events []*EventData) (sum uint64, foundGasUsedEvent bool) {
return
}

func extractEvents(blockData *BlockData, relatedAccountAddresses map[apiTypes.Address]bool, eventsRaw []*nodeapi.RuntimeEvent) ([]*EventData, error) {
func extractEvents(blockData *BlockData, relatedAccountAddresses map[apiTypes.Address]bool, eventsRaw []nodeapi.RuntimeEvent) ([]*EventData, error) {
extractedEvents := []*EventData{}
if err := VisitSdkEvents(eventsRaw, &SdkEventHandler{
Core: func(event *core.Event) error {
Expand Down
4 changes: 2 additions & 2 deletions analyzer/runtime/visitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ func VisitSdkEvent(event *nodeapi.RuntimeEvent, handler *SdkEventHandler) error
return nil
}

func VisitSdkEvents(events []*nodeapi.RuntimeEvent, handler *SdkEventHandler) error {
func VisitSdkEvents(events []nodeapi.RuntimeEvent, handler *SdkEventHandler) error {
for i, event := range events {
if err := VisitSdkEvent(event, handler); err != nil {
if err := VisitSdkEvent(&event, handler); err != nil {
return fmt.Errorf("event %d: %w", i, err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions storage/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ type RuntimeSourceStorage interface {
type RuntimeAllData struct {
Round uint64
BlockHeader nodeapi.RuntimeBlockHeader
RawEvents []*nodeapi.RuntimeEvent
TransactionsWithResults []*nodeapi.RuntimeTransactionWithResults
RawEvents []nodeapi.RuntimeEvent
TransactionsWithResults []nodeapi.RuntimeTransactionWithResults
}

// TransactionWithResults contains a verified transaction, and the results of
Expand Down
4 changes: 2 additions & 2 deletions storage/oasis/nodeapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ type Proposal governance.Proposal

// Like ConsensusApiLite, but for the runtime API.
type RuntimeApiLite interface {
GetEventsRaw(ctx context.Context, round uint64) ([]*RuntimeEvent, error)
GetEventsRaw(ctx context.Context, round uint64) ([]RuntimeEvent, error)
EVMSimulateCall(ctx context.Context, round uint64, gasPrice []byte, gasLimit uint64, caller []byte, address []byte, value []byte, data []byte) ([]byte, error)
GetBlockHeader(ctx context.Context, round uint64) (*RuntimeBlockHeader, error)
GetTransactionsWithResults(ctx context.Context, round uint64) ([]*RuntimeTransactionWithResults, error)
GetTransactionsWithResults(ctx context.Context, round uint64) ([]RuntimeTransactionWithResults, error)
}

type (
Expand Down
12 changes: 6 additions & 6 deletions storage/oasis/nodeapi/file/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,29 @@ func (r *FileRuntimeApiLite) GetBlockHeader(ctx context.Context, round uint64) (
return &blockHeader, nil
}

func (r *FileRuntimeApiLite) GetTransactionsWithResults(ctx context.Context, round uint64) ([]*nodeapi.RuntimeTransactionWithResults, error) {
func (r *FileRuntimeApiLite) GetTransactionsWithResults(ctx context.Context, round uint64) ([]nodeapi.RuntimeTransactionWithResults, error) {
key := generateCacheKey("GetRuntimeTransactionsWithResults", round) // todo: maybe remove "runtime" from key; if we don't need to worry about collisions with the consensus api method of the same name. are we always guaranteed the diff db between consensus/runtime?
if r.runtimeApi != nil {
if err := r.updateCache(key, func() (interface{}, error) { return r.runtimeApi.GetTransactionsWithResults(ctx, round) }); err != nil {
return nil, err
}
}
txr := []*nodeapi.RuntimeTransactionWithResults{}
err := r.get(key, &txr)
txrs := []nodeapi.RuntimeTransactionWithResults{}
err := r.get(key, &txrs)
if err != nil {
return nil, err
}
return txr, nil
return txrs, nil
}

func (r *FileRuntimeApiLite) GetEventsRaw(ctx context.Context, round uint64) ([]*nodeapi.RuntimeEvent, error) {
func (r *FileRuntimeApiLite) GetEventsRaw(ctx context.Context, round uint64) ([]nodeapi.RuntimeEvent, error) {
key := generateCacheKey("GetEventsRaw", round)
if r.runtimeApi != nil {
if err := r.updateCache(key, func() (interface{}, error) { return r.runtimeApi.GetEventsRaw(ctx, round) }); err != nil {
return nil, err
}
}
events := []*nodeapi.RuntimeEvent{}
events := []nodeapi.RuntimeEvent{}
err := r.get(key, &events)
if err != nil {
return nil, err
Expand Down
12 changes: 6 additions & 6 deletions storage/oasis/nodeapi/universal_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,31 +99,31 @@ func (rc *UniversalRuntimeApiLite) GetBlockHeader(ctx context.Context, round uin
return &header, nil
}

func (rc *UniversalRuntimeApiLite) GetTransactionsWithResults(ctx context.Context, round uint64) ([]*RuntimeTransactionWithResults, error) {
func (rc *UniversalRuntimeApiLite) GetTransactionsWithResults(ctx context.Context, round uint64) ([]RuntimeTransactionWithResults, error) {
rsp, err := rc.sdkClient.GetTransactionsWithResults(ctx, round)
if err != nil {
return nil, err
}

// Convert to indexer-internal type.
txrs := make([]*RuntimeTransactionWithResults, len(rsp))
txrs := make([]RuntimeTransactionWithResults, len(rsp))
for i, txr := range rsp {
txrs[i] = (*RuntimeTransactionWithResults)(txr)
txrs[i] = (RuntimeTransactionWithResults)(*txr)
}

return txrs, nil
}

func (rc *UniversalRuntimeApiLite) GetEventsRaw(ctx context.Context, round uint64) ([]*RuntimeEvent, error) {
func (rc *UniversalRuntimeApiLite) GetEventsRaw(ctx context.Context, round uint64) ([]RuntimeEvent, error) {
rsp, err := rc.sdkClient.GetEventsRaw(ctx, round)
if err != nil {
return nil, err
}

// Convert to indexer-internal type.
evs := make([]*RuntimeEvent, len(rsp))
evs := make([]RuntimeEvent, len(rsp))
for i, ev := range rsp {
evs[i] = (*RuntimeEvent)(ev)
evs[i] = (RuntimeEvent)(*ev)
}

return evs, nil
Expand Down

0 comments on commit 008765a

Please sign in to comment.