-
Notifications
You must be signed in to change notification settings - Fork 4
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 #31 from shruggr/mnee
Mnee
- Loading branch information
Showing
42 changed files
with
874 additions
and
990 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,6 @@ app.yaml | |
.gcloudignore | ||
|
||
*.run | ||
config/config.go | ||
config/config.go | ||
redis.sh | ||
settings.json |
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 |
---|---|---|
@@ -1,47 +1,28 @@ | ||
package blk | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/bitcoin-sv/go-sdk/chainhash" | ||
) | ||
|
||
// BlockHeader defines a single block header, used in SPV validations. | ||
type BlockHeader struct { | ||
Hash *chainhash.Hash `json:"hash"` | ||
Coin uint32 `json:"coin"` | ||
Height uint32 `json:"height"` | ||
Time uint32 `json:"time"` | ||
Nonce uint32 `json:"nonce"` | ||
Version uint32 `json:"version"` | ||
MerkleRoot *chainhash.Hash `json:"merkleroot"` | ||
Bits string `json:"bits"` | ||
Synced uint64 `json:"synced"` | ||
} | ||
|
||
func (b BlockHeader) MarshalBinary() (data []byte, err error) { | ||
return json.Marshal(b) | ||
} | ||
|
||
func (b *BlockHeader) UnmarshalBinary(data []byte) (err error) { | ||
return json.Unmarshal(data, b) | ||
Height uint32 `json:"height"` | ||
Hash chainhash.Hash `json:"hash"` | ||
Version uint32 `json:"version"` | ||
MerkleRoot chainhash.Hash `json:"merkleRoot"` | ||
Timestamp uint32 `json:"creationTimestamp"` | ||
Bits uint32 `json:"-"` | ||
Nonce uint32 `json:"nonce"` | ||
// ChainWork *big.Int `json:"chainWork"` | ||
// CumulatedWork *big.Int `json:"work"` | ||
PreviousBlock chainhash.Hash `json:"prevBlockHash"` | ||
} | ||
|
||
func FetchBlockHeaders(fromBlock uint64, pageSize uint) (blocks []*BlockHeader, err error) { | ||
url := fmt.Sprintf("%s/v1/block_header/list/%d?limit=%d", JUNGLEBUS, fromBlock, pageSize) | ||
log.Printf("Requesting %d blocks from height %d\n", pageSize, fromBlock) | ||
if resp, err := http.Get(url); err != nil { | ||
log.Panicln("Failed to get blocks from junglebus", err) | ||
} else if resp.StatusCode != http.StatusOK { | ||
log.Panicln("Failed to get blocks from junglebus", resp.StatusCode) | ||
} else { | ||
err := json.NewDecoder(resp.Body).Decode(&blocks) | ||
resp.Body.Close() | ||
if err != nil { | ||
log.Panic(err) | ||
} | ||
} | ||
return | ||
// BlockHeaderState is an extended version of the BlockHeader | ||
// that has more important informations. Mostly used in http server endpoints. | ||
type BlockHeaderState struct { | ||
Header BlockHeader `json:"header"` | ||
State string `json:"state"` | ||
// ChainWork *big.Int `json:"chainWork" swaggertype:"string"` | ||
Height uint32 `json:"height"` | ||
} |
Oops, something went wrong.