chain: cbor-gen

This commit is contained in:
Łukasz Magiera 2019-11-14 00:04:13 +01:00
parent 1921ab119f
commit e48949b41f
5 changed files with 155 additions and 12 deletions

View File

@ -97,6 +97,11 @@ func hash(b []byte) []byte {
panic("blake 2b hash pls")
}
type PaymentVerifyParams struct {
Extra []byte
Proof []byte
}
func (pca PaymentChannelActor) UpdateChannelState(act *types.Actor, vmctx types.VMContext, params *PCAUpdateChannelStateParams) ([]byte, ActorError) {
var self PaymentChannelActorState
oldstate := vmctx.Storage().GetHead()

View File

@ -198,7 +198,7 @@ func (t *StorageMinerActorState) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{139}); err != nil {
if _, err := w.Write([]byte{138}); err != nil {
return err
}
@ -268,6 +268,10 @@ func (t *StorageMinerActorState) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.SlashedAt (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SlashedAt))); err != nil {
return err
}
// t.t.ProvingPeriodEnd (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ProvingPeriodEnd))); err != nil {
@ -287,7 +291,7 @@ func (t *StorageMinerActorState) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 11 {
if extra != 10 {
return fmt.Errorf("cbor input had wrong number of fields")
}
@ -416,9 +420,16 @@ func (t *StorageMinerActorState) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.SlashedAt (types.BigInt) (struct)
// t.t.SlashedAt (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.SlashedAt = uint64(extra)
// t.t.ProvingPeriodEnd (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
@ -862,6 +873,85 @@ func (t *SubmitPoStParams) UnmarshalCBOR(r io.Reader) error {
return nil
}
func (t *PaymentVerifyParams) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{130}); err != nil {
return err
}
// t.t.Extra ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Extra)))); err != nil {
return err
}
if _, err := w.Write(t.Extra); err != nil {
return err
}
// t.t.Proof ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Proof)))); err != nil {
return err
}
if _, err := w.Write(t.Proof); err != nil {
return err
}
return nil
}
func (t *PaymentVerifyParams) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Extra ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Extra: array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Extra = make([]byte, extra)
if _, err := io.ReadFull(br, t.Extra); err != nil {
return err
}
// t.t.Proof ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Proof: array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Proof = make([]byte, extra)
if _, err := io.ReadFull(br, t.Proof); err != nil {
return err
}
return nil
}
func (t *UpdatePeerIDParams) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
@ -2305,7 +2395,7 @@ func (t *StoragePowerState) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{131}); err != nil {
if _, err := w.Write([]byte{132}); err != nil {
return err
}
@ -2315,6 +2405,12 @@ func (t *StoragePowerState) MarshalCBOR(w io.Writer) error {
return xerrors.Errorf("failed to write cid field t.Miners: %w", err)
}
// t.t.ProvingBuckets (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.ProvingBuckets); err != nil {
return xerrors.Errorf("failed to write cid field t.ProvingBuckets: %w", err)
}
// t.t.MinerCount (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.MinerCount))); err != nil {
return err
@ -2338,7 +2434,7 @@ func (t *StoragePowerState) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 3 {
if extra != 4 {
return fmt.Errorf("cbor input had wrong number of fields")
}
@ -2353,6 +2449,18 @@ func (t *StoragePowerState) UnmarshalCBOR(r io.Reader) error {
t.Miners = c
}
// t.t.ProvingBuckets (cid.Cid) (struct)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.ProvingBuckets: %w", err)
}
t.ProvingBuckets = c
}
// t.t.MinerCount (uint64) (uint64)
@ -2557,7 +2665,7 @@ func (t *UpdateStorageParams) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{129}); err != nil {
if _, err := w.Write([]byte{131}); err != nil {
return err
}
@ -2565,6 +2673,16 @@ func (t *UpdateStorageParams) MarshalCBOR(w io.Writer) error {
if err := t.Delta.MarshalCBOR(w); err != nil {
return err
}
// t.t.NextProvingPeriodEnd (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.NextProvingPeriodEnd))); err != nil {
return err
}
// t.t.PreviousProvingPeriodEnd (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.PreviousProvingPeriodEnd))); err != nil {
return err
}
return nil
}
@ -2579,7 +2697,7 @@ func (t *UpdateStorageParams) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 1 {
if extra != 3 {
return fmt.Errorf("cbor input had wrong number of fields")
}
@ -2592,6 +2710,26 @@ func (t *UpdateStorageParams) UnmarshalCBOR(r io.Reader) error {
}
}
// t.t.NextProvingPeriodEnd (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.NextProvingPeriodEnd = uint64(extra)
// t.t.PreviousProvingPeriodEnd (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.PreviousProvingPeriodEnd = uint64(extra)
return nil
}

View File

@ -5,7 +5,7 @@ import (
"io"
"github.com/filecoin-project/lotus/chain/types"
"github.com/ipfs/go-cid"
cid "github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors"
)

View File

@ -861,7 +861,7 @@ func (t *StorageDataTransferVoucher) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Proposal (cid.Cid)
// t.t.Proposal (cid.Cid) (struct)
if err := cbg.WriteCid(w, t.Proposal); err != nil {
return xerrors.Errorf("failed to write cid field t.Proposal: %w", err)
@ -885,7 +885,7 @@ func (t *StorageDataTransferVoucher) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Proposal (cid.Cid)
// t.t.Proposal (cid.Cid) (struct)
{

View File

@ -5,7 +5,7 @@ import (
"io"
"math"
"github.com/ipfs/go-cid"
cid "github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors"
)