Skip to content

Commit

Permalink
Fix genesis block response (#42)
Browse files Browse the repository at this point in the history
* Get genesis hash from env

* Print error message if hash env is not set
  • Loading branch information
raynaudoe authored Oct 18, 2022
1 parent b392c12 commit 9426399
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions server/rosetta/lib/internal/service/online.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package service

import (
"context"
"fmt"
"os"
"time"

"github.com/coinbase/rosetta-sdk-go/types"
Expand All @@ -11,30 +13,37 @@ import (
)

// genesisBlockFetchTimeout defines a timeout to fetch the genesis block
const genesisBlockFetchTimeout = 15 * time.Second
const (
genesisBlockFetchTimeout = 15 * time.Second
genesisHashEnv = "GENESIS_HASH"
)

// NewOnlineNetwork builds a single network adapter.
// It will get the Genesis block on the beginning to avoid calling it everytime.
func NewOnlineNetwork(network *types.NetworkIdentifier, client crgtypes.Client) (crgtypes.API, error) {
//ctx, cancel := context.WithTimeout(context.Background(), genesisBlockFetchTimeout)
//defer cancel()
ctx, cancel := context.WithTimeout(context.Background(), genesisBlockFetchTimeout)
defer cancel()

/*var genesisHeight int64 = -1 // to use initial_height in genesis.json
var genesisHeight int64 = -1 // to use initial_height in genesis.json
block, err := client.BlockByHeight(ctx, &genesisHeight)
if err != nil {
return OnlineNetwork{}, err
}*/
}

block := types.BlockIdentifier{
Index: 9283650, // Theta upgrade height
Hash: "0x09E5CC1760C63AB706C79D936024E35AE226D983724F3BB026C4BD1407CDB7FD",
// Get genesis hash from ENV. It should be set by an external script since is not possible to get
// using tendermint API
genesisHash := os.Getenv(genesisHashEnv)
if genesisHash == "" {
_ = fmt.Sprintf("[Warning]- Genesis hash env '%s' is not properly set!", genesisHashEnv)
}

block.Block.Hash = genesisHash

return OnlineNetwork{
client: client,
network: network,
networkOptions: networkOptionsFromClient(client, &block),
genesisBlockIdentifier: &block,
networkOptions: networkOptionsFromClient(client, block.Block),
genesisBlockIdentifier: block.Block,
}, nil
}

Expand Down

0 comments on commit 9426399

Please sign in to comment.