2020-02-05 02:26:42 +00:00
|
|
|
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
|
|
|
|
2020-02-13 00:28:23 +00:00
|
|
|
package paychmgr
|
2019-11-04 19:03:11 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
integrate DAG store and CARv2 in deal-making (#6671)
This commit removes badger from the deal-making processes, and
moves to a new architecture with the dagstore as the cental
component on the miner-side, and CARv2s on the client-side.
Every deal that has been handed off to the sealing subsystem becomes
a shard in the dagstore. Shards are mounted via the LotusMount, which
teaches the dagstore how to load the related piece when serving
retrievals.
When the miner starts the Lotus for the first time with this patch,
we will perform a one-time migration of all active deals into the
dagstore. This is a lightweight process, and it consists simply
of registering the shards in the dagstore.
Shards are backed by the unsealed copy of the piece. This is currently
a CARv1. However, the dagstore keeps CARv2 indices for all pieces, so
when it's time to acquire a shard to serve a retrieval, the unsealed
CARv1 is joined with its index (safeguarded by the dagstore), to form
a read-only blockstore, thus taking the place of the monolithic
badger.
Data transfers have been adjusted to interface directly with CARv2 files.
On inbound transfers (client retrievals, miner storage deals), we stream
the received data into a CARv2 ReadWrite blockstore. On outbound transfers
(client storage deals, miner retrievals), we serve the data off a CARv2
ReadOnly blockstore.
Client-side imports are managed by the refactored *imports.Manager
component (when not using IPFS integration). Just like it before, we use
the go-filestore library to avoid duplicating the data from the original
file in the resulting UnixFS DAG (concretely the leaves). However, the
target of those imports are what we call "ref-CARv2s": CARv2 files placed
under the `$LOTUS_PATH/imports` directory, containing the intermediate
nodes in full, and the leaves as positional references to the original file
on disk.
Client-side retrievals are placed into CARv2 files in the location:
`$LOTUS_PATH/retrievals`.
A new set of `Dagstore*` JSON-RPC operations and `lotus-miner dagstore`
subcommands have been introduced on the miner-side to inspect and manage
the dagstore.
Despite moving to a CARv2-backed system, the IPFS integration has been
respected, and it continues to be possible to make storage deals with data
held in an IPFS node, and to perform retrievals directly into an IPFS node.
NOTE: because the "staging" and "client" Badger blockstores are no longer
used, existing imports on the client will be rendered useless. On startup,
Lotus will enumerate all imports and print WARN statements on the log for
each import that needs to be reimported. These log lines contain these
messages:
- import lacks carv2 path; import will not work; please reimport
- import has missing/broken carv2; please reimport
At the end, we will print a "sanity check completed" message indicating
the count of imports found, and how many were deemed broken.
Co-authored-by: Aarsh Shah <aarshkshah1992@gmail.com>
Co-authored-by: Dirk McCormick <dirkmdev@gmail.com>
Co-authored-by: Raúl Kripalani <raul@protocol.ai>
Co-authored-by: Dirk McCormick <dirkmdev@gmail.com>
2021-08-16 22:34:32 +00:00
|
|
|
"math"
|
2021-02-19 19:11:43 +00:00
|
|
|
"sort"
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2021-02-19 19:11:43 +00:00
|
|
|
cid "github.com/ipfs/go-cid"
|
2019-11-04 19:03:11 +00:00
|
|
|
cbg "github.com/whyrusleeping/cbor-gen"
|
|
|
|
xerrors "golang.org/x/xerrors"
|
2022-09-07 23:30:55 +00:00
|
|
|
|
|
|
|
address "github.com/filecoin-project/go-address"
|
|
|
|
paych "github.com/filecoin-project/go-state-types/builtin/v8/paych"
|
2019-11-04 19:03:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = xerrors.Errorf
|
2021-02-19 19:11:43 +00:00
|
|
|
var _ = cid.Undef
|
integrate DAG store and CARv2 in deal-making (#6671)
This commit removes badger from the deal-making processes, and
moves to a new architecture with the dagstore as the cental
component on the miner-side, and CARv2s on the client-side.
Every deal that has been handed off to the sealing subsystem becomes
a shard in the dagstore. Shards are mounted via the LotusMount, which
teaches the dagstore how to load the related piece when serving
retrievals.
When the miner starts the Lotus for the first time with this patch,
we will perform a one-time migration of all active deals into the
dagstore. This is a lightweight process, and it consists simply
of registering the shards in the dagstore.
Shards are backed by the unsealed copy of the piece. This is currently
a CARv1. However, the dagstore keeps CARv2 indices for all pieces, so
when it's time to acquire a shard to serve a retrieval, the unsealed
CARv1 is joined with its index (safeguarded by the dagstore), to form
a read-only blockstore, thus taking the place of the monolithic
badger.
Data transfers have been adjusted to interface directly with CARv2 files.
On inbound transfers (client retrievals, miner storage deals), we stream
the received data into a CARv2 ReadWrite blockstore. On outbound transfers
(client storage deals, miner retrievals), we serve the data off a CARv2
ReadOnly blockstore.
Client-side imports are managed by the refactored *imports.Manager
component (when not using IPFS integration). Just like it before, we use
the go-filestore library to avoid duplicating the data from the original
file in the resulting UnixFS DAG (concretely the leaves). However, the
target of those imports are what we call "ref-CARv2s": CARv2 files placed
under the `$LOTUS_PATH/imports` directory, containing the intermediate
nodes in full, and the leaves as positional references to the original file
on disk.
Client-side retrievals are placed into CARv2 files in the location:
`$LOTUS_PATH/retrievals`.
A new set of `Dagstore*` JSON-RPC operations and `lotus-miner dagstore`
subcommands have been introduced on the miner-side to inspect and manage
the dagstore.
Despite moving to a CARv2-backed system, the IPFS integration has been
respected, and it continues to be possible to make storage deals with data
held in an IPFS node, and to perform retrievals directly into an IPFS node.
NOTE: because the "staging" and "client" Badger blockstores are no longer
used, existing imports on the client will be rendered useless. On startup,
Lotus will enumerate all imports and print WARN statements on the log for
each import that needs to be reimported. These log lines contain these
messages:
- import lacks carv2 path; import will not work; please reimport
- import has missing/broken carv2; please reimport
At the end, we will print a "sanity check completed" message indicating
the count of imports found, and how many were deemed broken.
Co-authored-by: Aarsh Shah <aarshkshah1992@gmail.com>
Co-authored-by: Dirk McCormick <dirkmdev@gmail.com>
Co-authored-by: Raúl Kripalani <raul@protocol.ai>
Co-authored-by: Dirk McCormick <dirkmdev@gmail.com>
2021-08-16 22:34:32 +00:00
|
|
|
var _ = math.E
|
2021-02-19 19:11:43 +00:00
|
|
|
var _ = sort.Sort
|
2019-11-04 19:03:11 +00:00
|
|
|
|
|
|
|
func (t *VoucherInfo) MarshalCBOR(w io.Writer) error {
|
|
|
|
if t == nil {
|
|
|
|
_, err := w.Write(cbg.CborNull)
|
|
|
|
return err
|
|
|
|
}
|
2022-04-20 21:34:28 +00:00
|
|
|
|
|
|
|
cw := cbg.NewCborWriter(w)
|
|
|
|
|
|
|
|
if _, err := cw.Write([]byte{163}); err != nil {
|
2019-11-04 19:03:11 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-12 23:52:19 +00:00
|
|
|
// t.Voucher (paych.SignedVoucher) (struct)
|
2020-02-13 00:10:07 +00:00
|
|
|
if len("Voucher") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"Voucher\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Voucher"))); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-07-30 20:25:18 +00:00
|
|
|
if _, err := io.WriteString(w, string("Voucher")); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := t.Voucher.MarshalCBOR(cw); err != nil {
|
2019-11-04 19:03:11 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Proof ([]uint8) (slice)
|
2020-02-13 00:10:07 +00:00
|
|
|
if len("Proof") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"Proof\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Proof"))); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-07-30 20:25:18 +00:00
|
|
|
if _, err := io.WriteString(w, string("Proof")); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-16 23:44:14 +00:00
|
|
|
if len(t.Proof) > cbg.ByteArrayMaxLen {
|
|
|
|
return xerrors.Errorf("Byte array in field t.Proof was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.Proof))); err != nil {
|
2019-11-04 19:03:11 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-05-04 22:19:48 +00:00
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if _, err := cw.Write(t.Proof[:]); err != nil {
|
2019-11-04 19:03:11 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-08-20 16:09:52 +00:00
|
|
|
|
|
|
|
// t.Submitted (bool) (bool)
|
|
|
|
if len("Submitted") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"Submitted\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Submitted"))); err != nil {
|
2020-08-20 16:09:52 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := io.WriteString(w, string("Submitted")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := cbg.WriteBool(w, t.Submitted); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-11-04 19:03:11 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func (t *VoucherInfo) UnmarshalCBOR(r io.Reader) (err error) {
|
2020-07-14 11:45:45 +00:00
|
|
|
*t = VoucherInfo{}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
cr := cbg.NewCborReader(r)
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
maj, extra, err := cr.ReadHeader()
|
2019-11-04 19:03:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-04-20 21:34:28 +00:00
|
|
|
defer func() {
|
|
|
|
if err == io.EOF {
|
|
|
|
err = io.ErrUnexpectedEOF
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
if maj != cbg.MajMap {
|
|
|
|
return fmt.Errorf("cbor input should be of type map")
|
2019-11-04 19:03:11 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
if extra > cbg.MaxLength {
|
|
|
|
return fmt.Errorf("VoucherInfo: map struct too large (%d)", extra)
|
2019-11-04 19:03:11 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
var name string
|
|
|
|
n := extra
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
for i := uint64(0); i < n; i++ {
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
{
|
2022-04-20 21:34:28 +00:00
|
|
|
sval, err := cbg.ReadString(cr)
|
2020-02-13 00:10:07 +00:00
|
|
|
if err != nil {
|
2019-11-04 19:03:11 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-02-13 00:10:07 +00:00
|
|
|
|
|
|
|
name = string(sval)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch name {
|
|
|
|
// t.Voucher (paych.SignedVoucher) (struct)
|
|
|
|
case "Voucher":
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
b, err := cr.ReadByte()
|
2020-02-13 00:10:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-12 02:47:24 +00:00
|
|
|
if b != cbg.CborNull[0] {
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cr.UnreadByte(); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-02-13 00:28:23 +00:00
|
|
|
t.Voucher = new(paych.SignedVoucher)
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := t.Voucher.UnmarshalCBOR(cr); err != nil {
|
2020-03-21 21:17:01 +00:00
|
|
|
return xerrors.Errorf("unmarshaling t.Voucher pointer: %w", err)
|
2020-02-13 00:10:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// t.Proof ([]uint8) (slice)
|
|
|
|
case "Proof":
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
maj, extra, err = cr.ReadHeader()
|
2020-02-13 00:10:07 +00:00
|
|
|
if err != nil {
|
2019-11-04 19:03:11 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
if extra > cbg.ByteArrayMaxLen {
|
|
|
|
return fmt.Errorf("t.Proof: byte array too large (%d)", extra)
|
|
|
|
}
|
|
|
|
if maj != cbg.MajByteString {
|
|
|
|
return fmt.Errorf("expected byte array")
|
|
|
|
}
|
2020-07-30 20:25:18 +00:00
|
|
|
|
|
|
|
if extra > 0 {
|
|
|
|
t.Proof = make([]uint8, extra)
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if _, err := io.ReadFull(cr, t.Proof[:]); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-08-20 16:09:52 +00:00
|
|
|
// t.Submitted (bool) (bool)
|
|
|
|
case "Submitted":
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
maj, extra, err = cr.ReadHeader()
|
2020-08-20 16:09:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if maj != cbg.MajOther {
|
|
|
|
return fmt.Errorf("booleans must be major type 7")
|
|
|
|
}
|
|
|
|
switch extra {
|
|
|
|
case 20:
|
|
|
|
t.Submitted = false
|
|
|
|
case 21:
|
|
|
|
t.Submitted = true
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra)
|
|
|
|
}
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
default:
|
2021-02-19 19:11:43 +00:00
|
|
|
// Field doesn't exist on this type, so ignore it
|
|
|
|
cbg.ScanForLinks(r, func(cid.Cid) {})
|
2020-02-13 00:10:07 +00:00
|
|
|
}
|
2019-11-04 19:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (t *ChannelInfo) MarshalCBOR(w io.Writer) error {
|
|
|
|
if t == nil {
|
|
|
|
_, err := w.Write(cbg.CborNull)
|
|
|
|
return err
|
|
|
|
}
|
2022-04-20 21:34:28 +00:00
|
|
|
|
|
|
|
cw := cbg.NewCborWriter(w)
|
|
|
|
|
|
|
|
if _, err := cw.Write([]byte{174}); err != nil {
|
2019-11-04 19:03:11 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-28 23:16:47 +00:00
|
|
|
// t.ChannelID (string) (string)
|
|
|
|
if len("ChannelID") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"ChannelID\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("ChannelID"))); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := io.WriteString(w, string("ChannelID")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(t.ChannelID) > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field t.ChannelID was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.ChannelID))); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := io.WriteString(w, string(t.ChannelID)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Channel (address.Address) (struct)
|
2020-02-13 00:10:07 +00:00
|
|
|
if len("Channel") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"Channel\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Channel"))); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-07-30 20:25:18 +00:00
|
|
|
if _, err := io.WriteString(w, string("Channel")); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := t.Channel.MarshalCBOR(cw); err != nil {
|
2019-11-04 19:03:11 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Control (address.Address) (struct)
|
2020-02-13 00:10:07 +00:00
|
|
|
if len("Control") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"Control\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Control"))); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-07-30 20:25:18 +00:00
|
|
|
if _, err := io.WriteString(w, string("Control")); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := t.Control.MarshalCBOR(cw); err != nil {
|
2019-11-04 19:03:11 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Target (address.Address) (struct)
|
2020-02-13 00:10:07 +00:00
|
|
|
if len("Target") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"Target\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Target"))); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-07-30 20:25:18 +00:00
|
|
|
if _, err := io.WriteString(w, string("Target")); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := t.Target.MarshalCBOR(cw); err != nil {
|
2019-11-04 19:03:11 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Direction (uint64) (uint64)
|
2020-02-13 00:10:07 +00:00
|
|
|
if len("Direction") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"Direction\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Direction"))); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-07-30 20:25:18 +00:00
|
|
|
if _, err := io.WriteString(w, string("Direction")); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Direction)); err != nil {
|
2019-11-04 19:03:11 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-13 00:28:23 +00:00
|
|
|
// t.Vouchers ([]*paychmgr.VoucherInfo) (slice)
|
2020-02-13 00:10:07 +00:00
|
|
|
if len("Vouchers") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"Vouchers\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Vouchers"))); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-07-30 20:25:18 +00:00
|
|
|
if _, err := io.WriteString(w, string("Vouchers")); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-16 23:44:14 +00:00
|
|
|
if len(t.Vouchers) > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Slice value in field t.Vouchers was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Vouchers))); err != nil {
|
2019-11-04 19:03:11 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, v := range t.Vouchers {
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := v.MarshalCBOR(cw); err != nil {
|
2019-11-04 19:03:11 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.NextLane (uint64) (uint64)
|
2020-02-13 00:10:07 +00:00
|
|
|
if len("NextLane") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"NextLane\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("NextLane"))); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-07-30 20:25:18 +00:00
|
|
|
if _, err := io.WriteString(w, string("NextLane")); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.NextLane)); err != nil {
|
2019-11-04 19:03:11 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-02-23 00:47:47 +00:00
|
|
|
|
2020-07-28 23:16:47 +00:00
|
|
|
// t.Amount (big.Int) (struct)
|
|
|
|
if len("Amount") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"Amount\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Amount"))); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := io.WriteString(w, string("Amount")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := t.Amount.MarshalCBOR(cw); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-01-04 19:33:49 +00:00
|
|
|
// t.AvailableAmount (big.Int) (struct)
|
|
|
|
if len("AvailableAmount") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"AvailableAmount\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("AvailableAmount"))); err != nil {
|
2022-01-04 19:33:49 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := io.WriteString(w, string("AvailableAmount")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := t.AvailableAmount.MarshalCBOR(cw); err != nil {
|
2022-01-04 19:33:49 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// t.PendingAvailableAmount (big.Int) (struct)
|
|
|
|
if len("PendingAvailableAmount") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"PendingAvailableAmount\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("PendingAvailableAmount"))); err != nil {
|
2022-01-04 19:33:49 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := io.WriteString(w, string("PendingAvailableAmount")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := t.PendingAvailableAmount.MarshalCBOR(cw); err != nil {
|
2022-01-04 19:33:49 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-28 23:16:47 +00:00
|
|
|
// t.PendingAmount (big.Int) (struct)
|
|
|
|
if len("PendingAmount") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"PendingAmount\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("PendingAmount"))); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := io.WriteString(w, string("PendingAmount")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := t.PendingAmount.MarshalCBOR(cw); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// t.CreateMsg (cid.Cid) (struct)
|
|
|
|
if len("CreateMsg") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"CreateMsg\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("CreateMsg"))); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := io.WriteString(w, string("CreateMsg")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if t.CreateMsg == nil {
|
2022-04-20 21:34:28 +00:00
|
|
|
if _, err := cw.Write(cbg.CborNull); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cbg.WriteCid(cw, *t.CreateMsg); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return xerrors.Errorf("failed to write cid field t.CreateMsg: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// t.AddFundsMsg (cid.Cid) (struct)
|
|
|
|
if len("AddFundsMsg") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"AddFundsMsg\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("AddFundsMsg"))); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := io.WriteString(w, string("AddFundsMsg")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if t.AddFundsMsg == nil {
|
2022-04-20 21:34:28 +00:00
|
|
|
if _, err := cw.Write(cbg.CborNull); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cbg.WriteCid(cw, *t.AddFundsMsg); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return xerrors.Errorf("failed to write cid field t.AddFundsMsg: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// t.Settling (bool) (bool)
|
|
|
|
if len("Settling") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"Settling\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Settling"))); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := io.WriteString(w, string("Settling")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := cbg.WriteBool(w, t.Settling); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-11-04 19:03:11 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) (err error) {
|
2020-07-14 11:45:45 +00:00
|
|
|
*t = ChannelInfo{}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
cr := cbg.NewCborReader(r)
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
maj, extra, err := cr.ReadHeader()
|
2019-11-04 19:03:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-04-20 21:34:28 +00:00
|
|
|
defer func() {
|
|
|
|
if err == io.EOF {
|
|
|
|
err = io.ErrUnexpectedEOF
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
if maj != cbg.MajMap {
|
|
|
|
return fmt.Errorf("cbor input should be of type map")
|
2019-11-04 19:03:11 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
if extra > cbg.MaxLength {
|
|
|
|
return fmt.Errorf("ChannelInfo: map struct too large (%d)", extra)
|
2019-11-04 19:03:11 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
var name string
|
|
|
|
n := extra
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
for i := uint64(0); i < n; i++ {
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
{
|
2022-04-20 21:34:28 +00:00
|
|
|
sval, err := cbg.ReadString(cr)
|
2020-02-13 00:10:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
name = string(sval)
|
2019-11-04 19:03:11 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
switch name {
|
2020-07-28 23:16:47 +00:00
|
|
|
// t.ChannelID (string) (string)
|
|
|
|
case "ChannelID":
|
|
|
|
|
|
|
|
{
|
2022-04-20 21:34:28 +00:00
|
|
|
sval, err := cbg.ReadString(cr)
|
2020-07-28 23:16:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
t.ChannelID = string(sval)
|
|
|
|
}
|
|
|
|
// t.Channel (address.Address) (struct)
|
2020-02-13 00:10:07 +00:00
|
|
|
case "Channel":
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
{
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
b, err := cr.ReadByte()
|
2020-07-28 23:16:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-12 02:47:24 +00:00
|
|
|
if b != cbg.CborNull[0] {
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cr.UnreadByte(); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
t.Channel = new(address.Address)
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := t.Channel.UnmarshalCBOR(cr); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return xerrors.Errorf("unmarshaling t.Channel pointer: %w", err)
|
|
|
|
}
|
2020-02-13 00:10:07 +00:00
|
|
|
}
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
}
|
|
|
|
// t.Control (address.Address) (struct)
|
|
|
|
case "Control":
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
{
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := t.Control.UnmarshalCBOR(cr); err != nil {
|
2020-03-21 21:17:01 +00:00
|
|
|
return xerrors.Errorf("unmarshaling t.Control: %w", err)
|
2020-02-13 00:10:07 +00:00
|
|
|
}
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
}
|
|
|
|
// t.Target (address.Address) (struct)
|
|
|
|
case "Target":
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
{
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := t.Target.UnmarshalCBOR(cr); err != nil {
|
2020-03-21 21:17:01 +00:00
|
|
|
return xerrors.Errorf("unmarshaling t.Target: %w", err)
|
2020-02-13 00:10:07 +00:00
|
|
|
}
|
2019-12-09 16:40:15 +00:00
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
}
|
|
|
|
// t.Direction (uint64) (uint64)
|
|
|
|
case "Direction":
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2020-02-23 00:47:47 +00:00
|
|
|
{
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
maj, extra, err = cr.ReadHeader()
|
2020-02-23 00:47:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if maj != cbg.MajUnsignedInt {
|
|
|
|
return fmt.Errorf("wrong type for uint64 field")
|
|
|
|
}
|
|
|
|
t.Direction = uint64(extra)
|
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
}
|
2020-02-13 00:28:23 +00:00
|
|
|
// t.Vouchers ([]*paychmgr.VoucherInfo) (slice)
|
2020-02-13 00:10:07 +00:00
|
|
|
case "Vouchers":
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
maj, extra, err = cr.ReadHeader()
|
2020-02-13 00:10:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
if extra > cbg.MaxLength {
|
|
|
|
return fmt.Errorf("t.Vouchers: array too large (%d)", extra)
|
|
|
|
}
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
if maj != cbg.MajArray {
|
|
|
|
return fmt.Errorf("expected cbor array")
|
|
|
|
}
|
2020-04-17 17:53:09 +00:00
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
if extra > 0 {
|
|
|
|
t.Vouchers = make([]*VoucherInfo, extra)
|
|
|
|
}
|
2020-04-17 17:53:09 +00:00
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
for i := 0; i < int(extra); i++ {
|
2019-11-04 19:03:11 +00:00
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
var v VoucherInfo
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := v.UnmarshalCBOR(cr); err != nil {
|
2020-02-13 00:10:07 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Vouchers[i] = &v
|
|
|
|
}
|
|
|
|
|
|
|
|
// t.NextLane (uint64) (uint64)
|
|
|
|
case "NextLane":
|
|
|
|
|
2020-02-23 00:47:47 +00:00
|
|
|
{
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
maj, extra, err = cr.ReadHeader()
|
2020-02-23 00:47:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if maj != cbg.MajUnsignedInt {
|
|
|
|
return fmt.Errorf("wrong type for uint64 field")
|
|
|
|
}
|
|
|
|
t.NextLane = uint64(extra)
|
|
|
|
|
2020-02-13 00:10:07 +00:00
|
|
|
}
|
2020-07-28 23:16:47 +00:00
|
|
|
// t.Amount (big.Int) (struct)
|
|
|
|
case "Amount":
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := t.Amount.UnmarshalCBOR(cr); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return xerrors.Errorf("unmarshaling t.Amount: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-01-04 19:33:49 +00:00
|
|
|
}
|
|
|
|
// t.AvailableAmount (big.Int) (struct)
|
|
|
|
case "AvailableAmount":
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := t.AvailableAmount.UnmarshalCBOR(cr); err != nil {
|
2022-01-04 19:33:49 +00:00
|
|
|
return xerrors.Errorf("unmarshaling t.AvailableAmount: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// t.PendingAvailableAmount (big.Int) (struct)
|
|
|
|
case "PendingAvailableAmount":
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := t.PendingAvailableAmount.UnmarshalCBOR(cr); err != nil {
|
2022-01-04 19:33:49 +00:00
|
|
|
return xerrors.Errorf("unmarshaling t.PendingAvailableAmount: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-07-28 23:16:47 +00:00
|
|
|
}
|
|
|
|
// t.PendingAmount (big.Int) (struct)
|
|
|
|
case "PendingAmount":
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := t.PendingAmount.UnmarshalCBOR(cr); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return xerrors.Errorf("unmarshaling t.PendingAmount: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// t.CreateMsg (cid.Cid) (struct)
|
|
|
|
case "CreateMsg":
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
b, err := cr.ReadByte()
|
2020-07-28 23:16:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-12 02:47:24 +00:00
|
|
|
if b != cbg.CborNull[0] {
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cr.UnreadByte(); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
c, err := cbg.ReadCid(cr)
|
2020-07-28 23:16:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("failed to read cid field t.CreateMsg: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.CreateMsg = &c
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// t.AddFundsMsg (cid.Cid) (struct)
|
|
|
|
case "AddFundsMsg":
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
b, err := cr.ReadByte()
|
2020-07-28 23:16:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-12 02:47:24 +00:00
|
|
|
if b != cbg.CborNull[0] {
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cr.UnreadByte(); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
c, err := cbg.ReadCid(cr)
|
2020-07-28 23:16:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("failed to read cid field t.AddFundsMsg: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.AddFundsMsg = &c
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// t.Settling (bool) (bool)
|
|
|
|
case "Settling":
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
maj, extra, err = cr.ReadHeader()
|
2020-07-28 23:16:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if maj != cbg.MajOther {
|
|
|
|
return fmt.Errorf("booleans must be major type 7")
|
|
|
|
}
|
|
|
|
switch extra {
|
|
|
|
case 20:
|
|
|
|
t.Settling = false
|
|
|
|
case 21:
|
|
|
|
t.Settling = true
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra)
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2021-02-19 19:11:43 +00:00
|
|
|
// Field doesn't exist on this type, so ignore it
|
|
|
|
cbg.ScanForLinks(r, func(cid.Cid) {})
|
2020-07-28 23:16:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (t *MsgInfo) MarshalCBOR(w io.Writer) error {
|
|
|
|
if t == nil {
|
|
|
|
_, err := w.Write(cbg.CborNull)
|
|
|
|
return err
|
|
|
|
}
|
2022-04-20 21:34:28 +00:00
|
|
|
|
|
|
|
cw := cbg.NewCborWriter(w)
|
|
|
|
|
|
|
|
if _, err := cw.Write([]byte{164}); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// t.ChannelID (string) (string)
|
|
|
|
if len("ChannelID") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"ChannelID\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("ChannelID"))); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := io.WriteString(w, string("ChannelID")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(t.ChannelID) > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field t.ChannelID was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.ChannelID))); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := io.WriteString(w, string(t.ChannelID)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// t.MsgCid (cid.Cid) (struct)
|
|
|
|
if len("MsgCid") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"MsgCid\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("MsgCid"))); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := io.WriteString(w, string("MsgCid")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cbg.WriteCid(cw, t.MsgCid); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return xerrors.Errorf("failed to write cid field t.MsgCid: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// t.Received (bool) (bool)
|
|
|
|
if len("Received") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"Received\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Received"))); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := io.WriteString(w, string("Received")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := cbg.WriteBool(w, t.Received); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// t.Err (string) (string)
|
|
|
|
if len("Err") > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field \"Err\" was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Err"))); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := io.WriteString(w, string("Err")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(t.Err) > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field t.Err was too long")
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Err))); err != nil {
|
2020-07-28 23:16:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := io.WriteString(w, string(t.Err)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func (t *MsgInfo) UnmarshalCBOR(r io.Reader) (err error) {
|
2020-07-28 23:16:47 +00:00
|
|
|
*t = MsgInfo{}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
cr := cbg.NewCborReader(r)
|
2020-07-28 23:16:47 +00:00
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
maj, extra, err := cr.ReadHeader()
|
2020-07-28 23:16:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-04-20 21:34:28 +00:00
|
|
|
defer func() {
|
|
|
|
if err == io.EOF {
|
|
|
|
err = io.ErrUnexpectedEOF
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2020-07-28 23:16:47 +00:00
|
|
|
if maj != cbg.MajMap {
|
|
|
|
return fmt.Errorf("cbor input should be of type map")
|
|
|
|
}
|
|
|
|
|
|
|
|
if extra > cbg.MaxLength {
|
|
|
|
return fmt.Errorf("MsgInfo: map struct too large (%d)", extra)
|
|
|
|
}
|
|
|
|
|
|
|
|
var name string
|
|
|
|
n := extra
|
|
|
|
|
|
|
|
for i := uint64(0); i < n; i++ {
|
|
|
|
|
|
|
|
{
|
2022-04-20 21:34:28 +00:00
|
|
|
sval, err := cbg.ReadString(cr)
|
2020-07-28 23:16:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
name = string(sval)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch name {
|
|
|
|
// t.ChannelID (string) (string)
|
|
|
|
case "ChannelID":
|
|
|
|
|
|
|
|
{
|
2022-04-20 21:34:28 +00:00
|
|
|
sval, err := cbg.ReadString(cr)
|
2020-07-28 23:16:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
t.ChannelID = string(sval)
|
|
|
|
}
|
|
|
|
// t.MsgCid (cid.Cid) (struct)
|
|
|
|
case "MsgCid":
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
c, err := cbg.ReadCid(cr)
|
2020-07-28 23:16:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("failed to read cid field t.MsgCid: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.MsgCid = c
|
|
|
|
|
|
|
|
}
|
|
|
|
// t.Received (bool) (bool)
|
|
|
|
case "Received":
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
maj, extra, err = cr.ReadHeader()
|
2020-07-28 23:16:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if maj != cbg.MajOther {
|
|
|
|
return fmt.Errorf("booleans must be major type 7")
|
|
|
|
}
|
|
|
|
switch extra {
|
|
|
|
case 20:
|
|
|
|
t.Received = false
|
|
|
|
case 21:
|
|
|
|
t.Received = true
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra)
|
|
|
|
}
|
|
|
|
// t.Err (string) (string)
|
|
|
|
case "Err":
|
|
|
|
|
|
|
|
{
|
2022-04-20 21:34:28 +00:00
|
|
|
sval, err := cbg.ReadString(cr)
|
2020-07-28 23:16:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Err = string(sval)
|
|
|
|
}
|
2020-02-13 00:10:07 +00:00
|
|
|
|
|
|
|
default:
|
2021-02-19 19:11:43 +00:00
|
|
|
// Field doesn't exist on this type, so ignore it
|
|
|
|
cbg.ScanForLinks(r, func(cid.Cid) {})
|
2020-02-13 00:10:07 +00:00
|
|
|
}
|
2019-11-04 19:03:11 +00:00
|
|
|
}
|
2020-02-13 00:10:07 +00:00
|
|
|
|
2019-11-04 19:03:11 +00:00
|
|
|
return nil
|
|
|
|
}
|