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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("genesis block is: ", sb.Cid())
|
|
||||||
|
|
||||||
return &GenesisBootstrap{
|
return &GenesisBootstrap{
|
||||||
Genesis: b,
|
Genesis: b,
|
||||||
MinerKey: minerAddr,
|
MinerKey: minerAddr,
|
||||||
|
@ -3,6 +3,7 @@ package chain
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
@ -229,6 +230,25 @@ func (bi *BigInt) Nil() bool {
|
|||||||
return bi.Int == nil
|
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 {
|
type Actor struct {
|
||||||
Code cid.Cid
|
Code cid.Cid
|
||||||
Head cid.Cid
|
Head cid.Cid
|
||||||
@ -402,6 +422,34 @@ type TipSet struct {
|
|||||||
height uint64
|
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) {
|
func NewTipSet(blks []*BlockHeader) (*TipSet, error) {
|
||||||
var ts TipSet
|
var ts TipSet
|
||||||
ts.cids = []cid.Cid{blks[0].Cid()}
|
ts.cids = []cid.Cid{blks[0].Cid()}
|
||||||
|
@ -20,10 +20,6 @@ var Cmd = &cli.Command{
|
|||||||
Name: "api",
|
Name: "api",
|
||||||
Value: ":1234",
|
Value: ":1234",
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
|
||||||
Name: "bootstrap",
|
|
||||||
Usage: "start node as already bootstrapped. Useful when starting a new testnet",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
ctx := context.Background()
|
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) {
|
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)
|
ticket, err := m.scratchTicket(ctx, base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "scratching ticket failed")
|
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 {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to create block")
|
return nil, errors.Wrap(err, "failed to create block")
|
||||||
}
|
}
|
||||||
log.Infof("created new block: %s", b.Cid())
|
log.Infof("mined new block: %s", b.Cid())
|
||||||
log.Infof("new blocks parents: %s", b.Header.Parents)
|
|
||||||
|
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user