fix a few things, including marshaling of tipset
This commit is contained in:
parent
d381025ccc
commit
19c883cdfe
@ -155,8 +155,6 @@ func MakeGenesisBlock(bs bstore.Blockstore, w *Wallet) (*GenesisBootstrap, error
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fmt.Println("genesis block is: ", sb.Cid())
|
||||
|
||||
return &GenesisBootstrap{
|
||||
Genesis: b,
|
||||
MinerKey: minerAddr,
|
||||
|
@ -3,6 +3,7 @@ package chain
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
@ -229,6 +230,25 @@ func (bi *BigInt) Nil() bool {
|
||||
return bi.Int == nil
|
||||
}
|
||||
|
||||
func (bi *BigInt) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(bi.String())
|
||||
}
|
||||
|
||||
func (bi *BigInt) UnmarshalJSON(b []byte) error {
|
||||
var s string
|
||||
if err := json.Unmarshal(b, &s); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i, ok := big.NewInt(0).SetString(s, 10)
|
||||
if !ok {
|
||||
return fmt.Errorf("failed to parse bigint string")
|
||||
}
|
||||
|
||||
bi.Int = i
|
||||
return nil
|
||||
}
|
||||
|
||||
type Actor struct {
|
||||
Code cid.Cid
|
||||
Head cid.Cid
|
||||
@ -402,6 +422,34 @@ type TipSet struct {
|
||||
height uint64
|
||||
}
|
||||
|
||||
// why didnt i just export the fields? Because the struct has methods with the
|
||||
// same names already
|
||||
type expTipSet struct {
|
||||
Cids []cid.Cid
|
||||
Blocks []*BlockHeader
|
||||
Height uint64
|
||||
}
|
||||
|
||||
func (ts *TipSet) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(expTipSet{
|
||||
Cids: ts.cids,
|
||||
Blocks: ts.blks,
|
||||
Height: ts.height,
|
||||
})
|
||||
}
|
||||
|
||||
func (ts *TipSet) UnmarshalJSON(b []byte) error {
|
||||
var ets expTipSet
|
||||
if err := json.Unmarshal(b, &ets); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ts.cids = ets.Cids
|
||||
ts.blks = ets.Blocks
|
||||
ts.height = ets.Height
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewTipSet(blks []*BlockHeader) (*TipSet, error) {
|
||||
var ts TipSet
|
||||
ts.cids = []cid.Cid{blks[0].Cid()}
|
||||
|
@ -20,10 +20,6 @@ var Cmd = &cli.Command{
|
||||
Name: "api",
|
||||
Value: ":1234",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "bootstrap",
|
||||
Usage: "start node as already bootstrapped. Useful when starting a new testnet",
|
||||
},
|
||||
},
|
||||
Action: func(cctx *cli.Context) error {
|
||||
ctx := context.Background()
|
||||
|
@ -103,7 +103,7 @@ func (m *Miner) GetBestMiningCandidate() (*MiningBase, error) {
|
||||
}
|
||||
|
||||
func (m *Miner) mineOne(ctx context.Context, base *MiningBase) (*chain.BlockMsg, error) {
|
||||
log.Info("mine one on:", base.ts.Cids())
|
||||
log.Info("attempting to mine a block on:", base.ts.Cids())
|
||||
ticket, err := m.scratchTicket(ctx, base)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "scratching ticket failed")
|
||||
@ -123,8 +123,7 @@ func (m *Miner) mineOne(ctx context.Context, base *MiningBase) (*chain.BlockMsg,
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create block")
|
||||
}
|
||||
log.Infof("created new block: %s", b.Cid())
|
||||
log.Infof("new blocks parents: %s", b.Header.Parents)
|
||||
log.Infof("mined new block: %s", b.Cid())
|
||||
|
||||
return b, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user