-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create type for state * Update mock store * Group tx events * Fix tests * Remove unnecessary mutex
- Loading branch information
Showing
12 changed files
with
327 additions
and
125 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ on: | |
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 20 | ||
permissions: | ||
pull-requests: write | ||
steps: | ||
|
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,59 @@ | ||
package api | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/gevulotnetwork/devnet-explorer/api/templates" | ||
"github.com/gevulotnetwork/devnet-explorer/model" | ||
) | ||
|
||
type eventBuffer struct { | ||
headIndex int | ||
head []eventData | ||
headMap map[string]header | ||
} | ||
|
||
type eventData struct { | ||
txID string | ||
data []byte | ||
} | ||
|
||
type header struct { | ||
state model.State | ||
index int | ||
} | ||
|
||
func newEventBuffer(size uint) *eventBuffer { | ||
return &eventBuffer{ | ||
head: make([]eventData, size), | ||
headMap: make(map[string]header, size), | ||
} | ||
} | ||
|
||
func (b *eventBuffer) add(e model.Event, data []byte) { | ||
data = bytes.Replace(data, []byte("event: "+e.TxID), []byte("event: "+templates.EventTXRow), 1) | ||
old, ok := b.headMap[e.TxID] | ||
if !ok { | ||
delete(b.headMap, b.head[b.headIndex].txID) | ||
b.head[b.headIndex] = eventData{txID: e.TxID, data: data} | ||
b.headMap[e.TxID] = header{state: e.State, index: b.headIndex} | ||
b.headIndex = (b.headIndex + 1) % len(b.head) | ||
return | ||
} | ||
|
||
if e.State < old.state { | ||
return | ||
} | ||
|
||
b.head[old.index] = eventData{txID: e.TxID, data: data} | ||
b.headMap[e.TxID] = header{state: e.State, index: old.index} | ||
} | ||
|
||
func (b *eventBuffer) writeAllToCh(ch chan<- []byte) { | ||
for i := 1; i <= len(b.head); i++ { | ||
data := b.head[(b.headIndex+i)%len(b.head)].data | ||
if data != nil { | ||
ch <- data | ||
} | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.