forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 6
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 #1 from maticnetwork/span-sync
MAT-156 Span sync
- Loading branch information
Showing
15 changed files
with
610 additions
and
592 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
Large diffs are not rendered by default.
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,14 @@ | ||
package bor | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
// EventRecord represents state record | ||
type EventRecord struct { | ||
ID uint64 `json:"id" yaml:"id"` | ||
Contract common.Address `json:"contract" yaml:"contract"` | ||
Data []byte `json:"data" yaml:"data"` | ||
TxHash common.Hash `json:"tx_hash" yaml:"tx_hash"` | ||
LogIndex uint64 `json:"log_index" yaml:"log_index"` | ||
} |
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,56 @@ | ||
package bor | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"net/url" | ||
"path" | ||
) | ||
|
||
// ResponseWithHeight defines a response object type that wraps an original | ||
// response with a height. | ||
type ResponseWithHeight struct { | ||
Height string `json:"height"` | ||
Result json.RawMessage `json:"result"` | ||
} | ||
|
||
// FetchFromHeimdall returns data from heimdall | ||
func FetchFromHeimdall(client http.Client, urlString string, paths ...string) (*ResponseWithHeight, error) { | ||
u, err := url.Parse(urlString) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, e := range paths { | ||
if e != "" { | ||
u.Path = path.Join(u.Path, e) | ||
} | ||
} | ||
|
||
res, err := client.Get(u.String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer res.Body.Close() | ||
|
||
// check status code | ||
if res.StatusCode != 200 { | ||
return nil, fmt.Errorf("Error while fetching data from Heimdall") | ||
} | ||
|
||
// get response | ||
body, err := ioutil.ReadAll(res.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// unmarshall data from buffer | ||
var response ResponseWithHeight | ||
if err := json.Unmarshal(body, &response); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &response, nil | ||
} |
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,16 @@ | ||
package bor | ||
|
||
// Span represents a current bor span | ||
type Span struct { | ||
ID uint64 `json:"span_id" yaml:"span_id"` | ||
StartBlock uint64 `json:"start_block" yaml:"start_block"` | ||
EndBlock uint64 `json:"end_block" yaml:"end_block"` | ||
} | ||
|
||
// HeimdallSpan represents span from heimdall APIs | ||
type HeimdallSpan struct { | ||
Span | ||
ValidatorSet ValidatorSet `json:"validator_set" yaml:"validator_set"` | ||
SelectedProducers []Validator `json:"selected_producers" yaml:"selected_producers"` | ||
ChainID string `json:"bor_chain_id" yaml:"bor_chain_id"` | ||
} |
Oops, something went wrong.