-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #527 from tablelandnetwork/bcalza/blocknum2
changes the behavior of block_num(<chain_id>)
- Loading branch information
Showing
11 changed files
with
116 additions
and
35 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
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
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,21 @@ | ||
package parsing | ||
|
||
import ( | ||
"github.com/textileio/go-tableland/internal/tableland" | ||
"github.com/textileio/go-tableland/pkg/sharedmemory" | ||
) | ||
|
||
// ReadStatementResolver implements the interface for custom functions resolution of read statements. | ||
type ReadStatementResolver struct { | ||
sm *sharedmemory.SharedMemory | ||
} | ||
|
||
// NewReadStatementResolver creates a new ReadStatementResolver. | ||
func NewReadStatementResolver(sm *sharedmemory.SharedMemory) *ReadStatementResolver { | ||
return &ReadStatementResolver{sm: sm} | ||
} | ||
|
||
// GetBlockNumber returns the block number for a given chain id. | ||
func (rqr *ReadStatementResolver) GetBlockNumber(chainID int64) (int64, bool) { | ||
return rqr.sm.GetLastSeenBlockNumber(tableland.ChainID(chainID)) | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package sharedmemory | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/textileio/go-tableland/internal/tableland" | ||
) | ||
|
||
// SharedMemory is a in-memory thread-safe data structure to exchange data between the validator and gateway. | ||
type SharedMemory struct { | ||
mu sync.RWMutex | ||
lastSeenBlockNumber map[tableland.ChainID]int64 | ||
} | ||
|
||
// NewSharedMemory creates new SharedMemory object. | ||
func NewSharedMemory() *SharedMemory { | ||
return &SharedMemory{ | ||
lastSeenBlockNumber: make(map[tableland.ChainID]int64), | ||
} | ||
} | ||
|
||
// SetLastSeenBlockNumber sets the last seen block number of a specific chain. | ||
func (sm *SharedMemory) SetLastSeenBlockNumber(chainID tableland.ChainID, blockNumber int64) { | ||
sm.mu.Lock() | ||
defer sm.mu.Unlock() | ||
sm.lastSeenBlockNumber[chainID] = blockNumber | ||
} | ||
|
||
// GetLastSeenBlockNumber get the last seen block number of a specific chain. | ||
func (sm *SharedMemory) GetLastSeenBlockNumber(chainID tableland.ChainID) (int64, bool) { | ||
sm.mu.RLock() | ||
defer sm.mu.RUnlock() | ||
blockNumber, ok := sm.lastSeenBlockNumber[chainID] | ||
if !ok { | ||
return 0, false | ||
} | ||
return blockNumber, true | ||
} |
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