github.com/filecoin-project/specs-actors/v4@v4.0.2/actors/builtin/multisig/cbor_gen.go (about)

     1  // Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
     2  
     3  package multisig
     4  
     5  import (
     6  	"fmt"
     7  	"io"
     8  
     9  	address "github.com/filecoin-project/go-address"
    10  	abi "github.com/filecoin-project/go-state-types/abi"
    11  	multisig "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
    12  	cbg "github.com/whyrusleeping/cbor-gen"
    13  	xerrors "golang.org/x/xerrors"
    14  )
    15  
    16  var _ = xerrors.Errorf
    17  
    18  var lengthBufState = []byte{135}
    19  
    20  func (t *State) MarshalCBOR(w io.Writer) error {
    21  	if t == nil {
    22  		_, err := w.Write(cbg.CborNull)
    23  		return err
    24  	}
    25  	if _, err := w.Write(lengthBufState); err != nil {
    26  		return err
    27  	}
    28  
    29  	scratch := make([]byte, 9)
    30  
    31  	// t.Signers ([]address.Address) (slice)
    32  	if len(t.Signers) > cbg.MaxLength {
    33  		return xerrors.Errorf("Slice value in field t.Signers was too long")
    34  	}
    35  
    36  	if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Signers))); err != nil {
    37  		return err
    38  	}
    39  	for _, v := range t.Signers {
    40  		if err := v.MarshalCBOR(w); err != nil {
    41  			return err
    42  		}
    43  	}
    44  
    45  	// t.NumApprovalsThreshold (uint64) (uint64)
    46  
    47  	if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.NumApprovalsThreshold)); err != nil {
    48  		return err
    49  	}
    50  
    51  	// t.NextTxnID (multisig.TxnID) (int64)
    52  	if t.NextTxnID >= 0 {
    53  		if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.NextTxnID)); err != nil {
    54  			return err
    55  		}
    56  	} else {
    57  		if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.NextTxnID-1)); err != nil {
    58  			return err
    59  		}
    60  	}
    61  
    62  	// t.InitialBalance (big.Int) (struct)
    63  	if err := t.InitialBalance.MarshalCBOR(w); err != nil {
    64  		return err
    65  	}
    66  
    67  	// t.StartEpoch (abi.ChainEpoch) (int64)
    68  	if t.StartEpoch >= 0 {
    69  		if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.StartEpoch)); err != nil {
    70  			return err
    71  		}
    72  	} else {
    73  		if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.StartEpoch-1)); err != nil {
    74  			return err
    75  		}
    76  	}
    77  
    78  	// t.UnlockDuration (abi.ChainEpoch) (int64)
    79  	if t.UnlockDuration >= 0 {
    80  		if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.UnlockDuration)); err != nil {
    81  			return err
    82  		}
    83  	} else {
    84  		if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.UnlockDuration-1)); err != nil {
    85  			return err
    86  		}
    87  	}
    88  
    89  	// t.PendingTxns (cid.Cid) (struct)
    90  
    91  	if err := cbg.WriteCidBuf(scratch, w, t.PendingTxns); err != nil {
    92  		return xerrors.Errorf("failed to write cid field t.PendingTxns: %w", err)
    93  	}
    94  
    95  	return nil
    96  }
    97  
    98  func (t *State) UnmarshalCBOR(r io.Reader) error {
    99  	*t = State{}
   100  
   101  	br := cbg.GetPeeker(r)
   102  	scratch := make([]byte, 8)
   103  
   104  	maj, extra, err := cbg.CborReadHeaderBuf(br, scratch)
   105  	if err != nil {
   106  		return err
   107  	}
   108  	if maj != cbg.MajArray {
   109  		return fmt.Errorf("cbor input should be of type array")
   110  	}
   111  
   112  	if extra != 7 {
   113  		return fmt.Errorf("cbor input had wrong number of fields")
   114  	}
   115  
   116  	// t.Signers ([]address.Address) (slice)
   117  
   118  	maj, extra, err = cbg.CborReadHeaderBuf(br, scratch)
   119  	if err != nil {
   120  		return err
   121  	}
   122  
   123  	if extra > cbg.MaxLength {
   124  		return fmt.Errorf("t.Signers: array too large (%d)", extra)
   125  	}
   126  
   127  	if maj != cbg.MajArray {
   128  		return fmt.Errorf("expected cbor array")
   129  	}
   130  
   131  	if extra > 0 {
   132  		t.Signers = make([]address.Address, extra)
   133  	}
   134  
   135  	for i := 0; i < int(extra); i++ {
   136  
   137  		var v address.Address
   138  		if err := v.UnmarshalCBOR(br); err != nil {
   139  			return err
   140  		}
   141  
   142  		t.Signers[i] = v
   143  	}
   144  
   145  	// t.NumApprovalsThreshold (uint64) (uint64)
   146  
   147  	{
   148  
   149  		maj, extra, err = cbg.CborReadHeaderBuf(br, scratch)
   150  		if err != nil {
   151  			return err
   152  		}
   153  		if maj != cbg.MajUnsignedInt {
   154  			return fmt.Errorf("wrong type for uint64 field")
   155  		}
   156  		t.NumApprovalsThreshold = uint64(extra)
   157  
   158  	}
   159  	// t.NextTxnID (multisig.TxnID) (int64)
   160  	{
   161  		maj, extra, err := cbg.CborReadHeaderBuf(br, scratch)
   162  		var extraI int64
   163  		if err != nil {
   164  			return err
   165  		}
   166  		switch maj {
   167  		case cbg.MajUnsignedInt:
   168  			extraI = int64(extra)
   169  			if extraI < 0 {
   170  				return fmt.Errorf("int64 positive overflow")
   171  			}
   172  		case cbg.MajNegativeInt:
   173  			extraI = int64(extra)
   174  			if extraI < 0 {
   175  				return fmt.Errorf("int64 negative oveflow")
   176  			}
   177  			extraI = -1 - extraI
   178  		default:
   179  			return fmt.Errorf("wrong type for int64 field: %d", maj)
   180  		}
   181  
   182  		t.NextTxnID = multisig.TxnID(extraI)
   183  	}
   184  	// t.InitialBalance (big.Int) (struct)
   185  
   186  	{
   187  
   188  		if err := t.InitialBalance.UnmarshalCBOR(br); err != nil {
   189  			return xerrors.Errorf("unmarshaling t.InitialBalance: %w", err)
   190  		}
   191  
   192  	}
   193  	// t.StartEpoch (abi.ChainEpoch) (int64)
   194  	{
   195  		maj, extra, err := cbg.CborReadHeaderBuf(br, scratch)
   196  		var extraI int64
   197  		if err != nil {
   198  			return err
   199  		}
   200  		switch maj {
   201  		case cbg.MajUnsignedInt:
   202  			extraI = int64(extra)
   203  			if extraI < 0 {
   204  				return fmt.Errorf("int64 positive overflow")
   205  			}
   206  		case cbg.MajNegativeInt:
   207  			extraI = int64(extra)
   208  			if extraI < 0 {
   209  				return fmt.Errorf("int64 negative oveflow")
   210  			}
   211  			extraI = -1 - extraI
   212  		default:
   213  			return fmt.Errorf("wrong type for int64 field: %d", maj)
   214  		}
   215  
   216  		t.StartEpoch = abi.ChainEpoch(extraI)
   217  	}
   218  	// t.UnlockDuration (abi.ChainEpoch) (int64)
   219  	{
   220  		maj, extra, err := cbg.CborReadHeaderBuf(br, scratch)
   221  		var extraI int64
   222  		if err != nil {
   223  			return err
   224  		}
   225  		switch maj {
   226  		case cbg.MajUnsignedInt:
   227  			extraI = int64(extra)
   228  			if extraI < 0 {
   229  				return fmt.Errorf("int64 positive overflow")
   230  			}
   231  		case cbg.MajNegativeInt:
   232  			extraI = int64(extra)
   233  			if extraI < 0 {
   234  				return fmt.Errorf("int64 negative oveflow")
   235  			}
   236  			extraI = -1 - extraI
   237  		default:
   238  			return fmt.Errorf("wrong type for int64 field: %d", maj)
   239  		}
   240  
   241  		t.UnlockDuration = abi.ChainEpoch(extraI)
   242  	}
   243  	// t.PendingTxns (cid.Cid) (struct)
   244  
   245  	{
   246  
   247  		c, err := cbg.ReadCid(br)
   248  		if err != nil {
   249  			return xerrors.Errorf("failed to read cid field t.PendingTxns: %w", err)
   250  		}
   251  
   252  		t.PendingTxns = c
   253  
   254  	}
   255  	return nil
   256  }