-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change...a lot of things to circumvent Amino
- Loading branch information
1 parent
34b9f9d
commit 538ba7b
Showing
31 changed files
with
328 additions
and
112 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package encode | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
|
||
"github.com/gnolang/gno/tm2/pkg/amino" | ||
) | ||
|
||
// EncodeValue encodes the given value into Amino binary, and then to base64. | ||
// | ||
// The optimal route for all responses served by this indexer implementation would | ||
// be to use plain ol' JSON. | ||
// JSON is nice. | ||
// json.Marshal works. | ||
// | ||
// However, this doesn't work with some (any, really) TM2 types (block, tx...), | ||
// which means a top-level Amino encoder needs to be present when serving the response. | ||
// This opens the pandora's box for another problem: custom type registration. | ||
// In Amino, any custom type needs to be registered using a clunky API, meaning all types need to be | ||
// accounted for beforehand, which is not something that is worth the effort of doing, | ||
// considering there are easier ways to pass around data (remember plain ol' JSON?). | ||
// So, we arrive at this imperfect solution: TM2 types are encoded using Amino binary, and then using base64, | ||
// and as such are passed to the client for processing | ||
func EncodeValue(value any) (string, error) { | ||
aminoEncoding, err := amino.Marshal(value) | ||
if err != nil { | ||
return "", fmt.Errorf("unable to amino encode value") | ||
} | ||
|
||
return base64.StdEncoding.EncodeToString(aminoEncoding), nil | ||
} |
File renamed without changes.
File renamed without changes.
20 changes: 12 additions & 8 deletions
20
serve/handlers/subs/filters/filter/block.go → serve/filters/filter/block.go
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 |
---|---|---|
@@ -1,43 +1,47 @@ | ||
package filter | ||
|
||
import "github.com/gnolang/tx-indexer/types" | ||
import ( | ||
"encoding/base64" | ||
|
||
"github.com/gnolang/gno/tm2/pkg/bft/types" | ||
) | ||
|
||
// BlockFilter type of filter for querying blocks | ||
type BlockFilter struct { | ||
*baseFilter | ||
|
||
blockHashes [][]byte // TODO keep as strings in 0x format? | ||
blockHashes []string | ||
} | ||
|
||
// NewBlockFilter creates new block filter object | ||
func NewBlockFilter() *BlockFilter { | ||
return &BlockFilter{ | ||
baseFilter: newBaseFilter(BlockFilterType), | ||
blockHashes: make([][]byte, 0), | ||
blockHashes: make([]string, 0), | ||
} | ||
} | ||
|
||
// GetChanges returns all new blocks from last query | ||
// GetChanges returns all new block headers from the last query | ||
func (b *BlockFilter) GetChanges() any { | ||
b.RLock() | ||
defer b.RUnlock() | ||
|
||
// Get hashes | ||
hashes := b.blockHashes | ||
|
||
// Empty hashes | ||
// Empty headers | ||
b.blockHashes = b.blockHashes[:0] | ||
|
||
return hashes | ||
} | ||
|
||
func (b *BlockFilter) UpdateWithBlock(block types.Block) { | ||
func (b *BlockFilter) UpdateWithBlock(block *types.Block) { | ||
b.Lock() | ||
defer b.Unlock() | ||
|
||
// Fetch block hash | ||
// Get the block hash | ||
hash := block.Hash() | ||
|
||
// Add hash into block hash array | ||
b.blockHashes = append(b.blockHashes, hash) | ||
b.blockHashes = append(b.blockHashes, base64.StdEncoding.EncodeToString(hash)) | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.