diff --git a/Makefile b/Makefile index 2ef6596..6e96c4d 100644 --- a/Makefile +++ b/Makefile @@ -12,8 +12,3 @@ build: test: go test ./... -short -race -timeout 1m .PHONY: test - -generate: - capnp compile -I ../go-capnp/std -ogo pkg/capnp/definitions.capnp - capnp compile -I ../go-capnp/std -ogo pkg/basinprovider/provider.capnp -.PHONY: generate diff --git a/README.md b/README.md index 8c7d7a1..0ade378 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,6 @@ - [Listing Deals](#listing-deals) - [Running](#running) - [Run tests](#run-tests) -- [Generate Cap'N Proto code](#generate-capn-proto-code) - [Retrieving](#retrieving) # Background @@ -197,11 +196,6 @@ make test Note: One of the tests requires Docker Engine to be running. -## Generate Cap'N Proto code - -```bash -make generate -``` # Contributing diff --git a/cmd/basin/config.go b/cmd/basin/config.go index 9bc518d..63b4e61 100644 --- a/cmd/basin/config.go +++ b/cmd/basin/config.go @@ -10,7 +10,7 @@ import ( ) // DefaultProviderHost is the address of Basin Provider. -const DefaultProviderHost = "basin.tableland.xyz:3000" +const DefaultProviderHost = "https://basin.tableland.xyz" // DefaultWindowSize is the number of seconds for which WAL updates // are buffered before being sent to the provider. diff --git a/cmd/basin/publication.go b/cmd/basin/publication.go index e83de63..6cfacfc 100644 --- a/cmd/basin/publication.go +++ b/cmd/basin/publication.go @@ -11,7 +11,6 @@ import ( "strings" "time" - "capnproto.org/go/capnp/v3" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/filecoin-project/lassie/pkg/lassie" @@ -27,7 +26,6 @@ import ( "github.com/schollz/progressbar/v3" "github.com/tablelandnetwork/basin-cli/internal/app" "github.com/tablelandnetwork/basin-cli/pkg/basinprovider" - basincapnp "github.com/tablelandnetwork/basin-cli/pkg/capnp" "github.com/tablelandnetwork/basin-cli/pkg/pgrepl" "github.com/urfave/cli/v2" "gopkg.in/yaml.v3" @@ -58,7 +56,6 @@ func newPublicationCommand() *cli.Command { func newPublicationCreateCommand() *cli.Command { var owner, dburi, provider string - var secure bool var winSize, cache int64 return &cli.Command{ @@ -82,12 +79,6 @@ func newPublicationCreateCommand() *cli.Command { Destination: &provider, Value: DefaultProviderHost, }, - &cli.BoolFlag{ - Name: "secure", - Usage: "Uses TLS connection", - Destination: &secure, - Value: true, - }, &cli.Int64Flag{ Name: "window-size", Usage: "Number of seconds for which WAL updates are buffered before being sent to the provider", @@ -153,7 +144,7 @@ func newPublicationCreateCommand() *cli.Command { return fmt.Errorf("encode: %s", err) } - exists, err := createPublication(cCtx.Context, dburi, ns, rel, provider, owner, secure, cache) + exists, err := createPublication(cCtx.Context, dburi, ns, rel, provider, owner, cache) if err != nil { return fmt.Errorf("failed to create publication: %s", err) } @@ -175,7 +166,6 @@ func newPublicationCreateCommand() *cli.Command { func newPublicationStartCommand() *cli.Command { var privateKey string - var secure bool return &cli.Command{ Name: "start", @@ -187,12 +177,6 @@ func newPublicationStartCommand() *cli.Command { Destination: &privateKey, Required: true, }, - &cli.BoolFlag{ - Name: "secure", - Usage: "Uses TLS connection", - Destination: &secure, - Value: true, - }, }, Action: func(cCtx *cli.Context) error { if cCtx.NArg() != 1 { @@ -233,11 +217,7 @@ func newPublicationStartCommand() *cli.Command { return err } - bp, err := basinprovider.New(cCtx.Context, cfg.Publications[publication].ProviderHost, secure) - if err != nil { - return err - } - defer bp.Close() + bp := basinprovider.New(cfg.Publications[publication].ProviderHost) pgxConn, err := pgx.Connect(cCtx.Context, connString) if err != nil { @@ -285,7 +265,6 @@ func newPublicationStartCommand() *cli.Command { func newPublicationUploadCommand() *cli.Command { var privateKey, publicationName string - var secure bool var timestamp string return &cli.Command{ @@ -304,12 +283,6 @@ func newPublicationUploadCommand() *cli.Command { Destination: &publicationName, Required: true, }, - &cli.BoolFlag{ - Name: "secure", - Usage: "Uses TLS connection", - Destination: &secure, - Value: true, - }, &cli.StringFlag{ Name: "timestamp", Usage: "The time the file was created (default: current epoch in UTC)", @@ -340,11 +313,7 @@ func newPublicationUploadCommand() *cli.Command { return fmt.Errorf("load config: %s", err) } - bp, err := basinprovider.New(cCtx.Context, cfg.Publications[publicationName].ProviderHost, secure) - if err != nil { - return err - } - defer bp.Close() + bp := basinprovider.New(cfg.Publications[publicationName].ProviderHost) filepath := cCtx.Args().First() @@ -376,7 +345,7 @@ func newPublicationUploadCommand() *cli.Command { } basinStreamer := app.NewBasinUploader(ns, rel, bp, privateKey) - if err := basinStreamer.Upload(cCtx.Context, filepath, bar, ts); err != nil { + if err := basinStreamer.Upload(cCtx.Context, filepath, bar, ts, fi.Size()); err != nil { return fmt.Errorf("upload: %s", err) } @@ -387,7 +356,6 @@ func newPublicationUploadCommand() *cli.Command { func newPublicationListCommand() *cli.Command { var owner, provider string - var secure bool return &cli.Command{ Name: "list", @@ -405,31 +373,21 @@ func newPublicationListCommand() *cli.Command { Destination: &provider, Value: DefaultProviderHost, }, - &cli.BoolFlag{ - Name: "secure", - Usage: "Uses TLS connection", - Destination: &secure, - Value: true, - }, }, Action: func(cCtx *cli.Context) error { - if !common.IsHexAddress(owner) { - return fmt.Errorf("%s is not a valid Ethereum wallet address", owner) - } - - bp, err := basinprovider.New(cCtx.Context, provider, secure) + account, err := app.NewAccount(owner) if err != nil { - return fmt.Errorf("new basin provider: %s", err) + return fmt.Errorf("%s is not a valid Ethereum wallet address", owner) } - defer bp.Close() - publications, err := bp.List(cCtx.Context, common.HexToAddress(owner)) + bp := basinprovider.New(provider) + vaults, err := bp.ListVaults(cCtx.Context, app.ListVaultsParams{Account: account}) if err != nil { return fmt.Errorf("failed to list publications: %s", err) } - for _, pub := range publications { - fmt.Printf("%s\n", pub) + for _, vault := range vaults { + fmt.Printf("%s\n", vault) } return nil @@ -439,9 +397,7 @@ func newPublicationListCommand() *cli.Command { func newPublicationDealsCommand() *cli.Command { var publication, provider, before, after, at, format string - var limit, latest int - var offset int64 - var secure bool + var limit, offset, latest int return &cli.Command{ Name: "deals", @@ -470,18 +426,12 @@ func newPublicationDealsCommand() *cli.Command { Usage: "The latest N deals to fetch", Destination: &latest, }, - &cli.Int64Flag{ + &cli.IntFlag{ Name: "offset", Usage: "The epoch to start from", Destination: &offset, Value: 0, }, - &cli.BoolFlag{ - Name: "secure", - Usage: "Uses TLS connection", - Destination: &secure, - Value: true, - }, &cli.StringFlag{ Name: "before", Usage: "Filter deals created before this timestamp", @@ -513,22 +463,21 @@ func newPublicationDealsCommand() *cli.Command { return err } - bp, err := basinprovider.New(cCtx.Context, provider, secure) - if err != nil { - return fmt.Errorf("new basin provider: %s", err) - } - defer bp.Close() + bp := basinprovider.New(provider) b, a, err := validateBeforeAndAfter(before, after, at) if err != nil { return err } - var deals []app.DealInfo + var req app.ListVaultEventsParams if latest > 0 { - deals, err = bp.LatestDeals(cCtx.Context, ns, rel, uint32(latest), b, a) - if err != nil { - return fmt.Errorf("failed to fetch deals: %s", err) + req = app.ListVaultEventsParams{ + Vault: app.Vault(fmt.Sprintf("%s.%s", ns, rel)), + Limit: uint32(latest), + Offset: 0, + Before: b, + After: a, } } else { if offset < 0 { @@ -539,34 +488,42 @@ func newPublicationDealsCommand() *cli.Command { return errors.New("limit has to be greater than 0") } - deals, err = bp.Deals(cCtx.Context, ns, rel, uint32(limit), uint64(offset), b, a) - if err != nil { - return fmt.Errorf("failed to fetch deals: %s", err) + req = app.ListVaultEventsParams{ + Vault: app.Vault(fmt.Sprintf("%s.%s", ns, rel)), + Limit: uint32(limit), + Offset: uint32(offset), + Before: b, + After: a, } } + events, err := bp.ListVaultEvents(cCtx.Context, req) + if err != nil { + return fmt.Errorf("failed to fetch deals: %s", err) + } + if format == "table" { table := tablewriter.NewWriter(os.Stdout) table.SetHeader([]string{"CID", "Size", "Timestamp", "Archived", "Cache Expiry"}) - for _, deal := range deals { + for _, event := range events { isArchived := "N" - if deal.IsArchived { + if event.IsArchived { isArchived = "Y" } timestamp := "(null)" - if deal.Timestamp > 0 { - timestamp = time.Unix(deal.Timestamp, 0).Format(time.RFC3339) + if event.Timestamp > 0 { + timestamp = time.Unix(event.Timestamp, 0).Format(time.RFC3339) } table.Append([]string{ - deal.CID, fmt.Sprintf("%d", deal.Size), timestamp, isArchived, deal.CacheExpiry, + event.CID, fmt.Sprintf("%d", event.Size), timestamp, isArchived, event.CacheExpiry, }) } table.Render() } else if format == "json" { - jsonData, err := json.Marshal(deals) + jsonData, err := json.Marshal(events) if err != nil { - return fmt.Errorf("error serializing deals to JSON") + return fmt.Errorf("error serializing events to JSON") } fmt.Println(string(jsonData)) } else { @@ -701,19 +658,23 @@ func createPublication( rel string, provider string, owner string, - secure bool, cacheDuration int64, ) (exists bool, err error) { - bp, err := basinprovider.New(ctx, provider, secure) + account, err := app.NewAccount(owner) if err != nil { - return false, err + return false, fmt.Errorf("not a valid account: %s", err) + } + + bp := basinprovider.New(provider) + req := app.CreateVaultParams{ + Account: account, + Vault: app.Vault(fmt.Sprintf("%s.%s", ns, rel)), + CacheDuration: app.CacheDuration(cacheDuration), } - defer bp.Close() if dburi == "" { - exists, err := bp.Create(ctx, ns, rel, basincapnp.Schema{}, common.HexToAddress(owner), cacheDuration) - if err != nil { - return false, fmt.Errorf("create call: %s", err) + if err := bp.CreateVault(ctx, req); err != nil { + return false, fmt.Errorf("create vault: %s", err) } return exists, nil @@ -737,36 +698,6 @@ func createPublication( } }() - columns, err := inspectTable(ctx, tx, rel) - if err != nil { - return false, fmt.Errorf("failed to inspect table: %s", err) - } - - _, seg, err := capnp.NewMessage(capnp.SingleSegment(nil)) - if err != nil { - return false, fmt.Errorf("capnp new message: %s", err) - } - - capnpSchema, err := basincapnp.NewRootSchema(seg) - if err != nil { - return false, fmt.Errorf("capnp new tx: %s", err) - } - - columnsList, err := basincapnp.NewSchema_Column_List(seg, int32(len(columns))) - if err != nil { - return false, fmt.Errorf("capnp new columns list: %s", err) - } - - for i, col := range columns { - column := columnsList.At(i) - - _ = column.SetName(col.Name) - _ = column.SetType(col.Typ) - column.SetIsNullable(col.IsNull) - column.SetIsPartOfPrimaryKey(col.IsPrimary) - } - _ = capnpSchema.SetColumns(columnsList) - if _, err := tx.Exec( ctx, fmt.Sprintf("CREATE PUBLICATION %s FOR TABLE %s", pgrepl.Publication(rel).FullName(), rel), ); err != nil { @@ -776,7 +707,7 @@ func createPublication( return false, fmt.Errorf("failed to create publication: %s", err) } - if _, err := bp.Create(ctx, ns, rel, capnpSchema, common.HexToAddress(owner), cacheDuration); err != nil { + if err := bp.CreateVault(ctx, req); err != nil { return false, fmt.Errorf("create call: %s", err) } diff --git a/examples/provider/README.md b/examples/provider/README.md deleted file mode 100644 index 581f830..0000000 --- a/examples/provider/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Provider Server Example - -Implements a simple provider server for testing. diff --git a/examples/provider/server.go b/examples/provider/server.go deleted file mode 100644 index a311dc4..0000000 --- a/examples/provider/server.go +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "context" - "log/slog" - "net" - "os" - - "capnproto.org/go/capnp/v3" - "capnproto.org/go/capnp/v3/rpc" - "github.com/tablelandnetwork/basin-cli/pkg/basinprovider" -) - -func main() { - listener, err := net.Listen("tcp", "localhost:"+os.Getenv("PORT")) - if err != nil { - slog.Error(err.Error()) - os.Exit(1) - } - - slog.Info("Listening", "port", os.Getenv("PORT")) - - server := basinprovider.NewBasinServerMock() - for { - conn, err := listener.Accept() - if err != nil { - slog.Error(err.Error()) - os.Exit(1) - } - defer conn.Close() - - client := basinprovider.Publications_ServerToClient(server) - rpcConn := rpc.NewConn(rpc.NewStreamTransport(conn), &rpc.Options{ - BootstrapClient: capnp.Client(client), - }) - defer rpcConn.Close() - - ctx := context.Background() - - // Block until the connection terminates. - select { - case <-rpcConn.Done(): - slog.Info("connection closed") - case <-ctx.Done(): - conn.Close() - } - - } -} diff --git a/internal/app/basin_provider.go b/internal/app/basin_provider.go index 7535ed9..8dec2b4 100644 --- a/internal/app/basin_provider.go +++ b/internal/app/basin_provider.go @@ -2,26 +2,44 @@ package app import ( "context" + "io" +) - "github.com/ethereum/go-ethereum/common" +// BasinProvider ... +type BasinProvider interface { + CreateVault(context.Context, CreateVaultParams) error + ListVaults(context.Context, ListVaultsParams) ([]Vault, error) + ListVaultEvents(context.Context, ListVaultEventsParams) ([]EventInfo, error) + WriteVaultEvent(context.Context, WriteVaultEventParams) error +} - basincapnp "github.com/tablelandnetwork/basin-cli/pkg/capnp" -) +// CreateVaultParams ... +type CreateVaultParams struct { + Vault Vault + Account *Account + CacheDuration CacheDuration +} -// DealInfo represents information about a deal. -type DealInfo struct { - CID string `json:"cid"` - Timestamp int64 `json:"timestamp"` - Size uint32 `json:"size"` - IsArchived bool `json:"is_archived"` - CacheExpiry string `json:"cache_expiry"` +// ListVaultsParams ... +type ListVaultsParams struct { + Account *Account } -// BasinProvider ... -type BasinProvider interface { - Create(context.Context, string, string, basincapnp.Schema, common.Address, int64) (bool, error) - List(context.Context, common.Address) ([]string, error) - Deals(context.Context, string, string, uint32, uint64, Timestamp, Timestamp) ([]DealInfo, error) - LatestDeals(context.Context, string, string, uint32, Timestamp, Timestamp) ([]DealInfo, error) - Reconnect() error +// ListVaultEventsParams ... +type ListVaultEventsParams struct { + Vault Vault + Limit uint32 + Offset uint32 + Before Timestamp + After Timestamp +} + +// WriteVaultEventParams ... +type WriteVaultEventParams struct { + Vault Vault + Signature string + Timestamp Timestamp + Content io.Reader + ProgressBar io.Writer + Size int64 } diff --git a/internal/app/db.go b/internal/app/db.go index 723616b..88242cf 100644 --- a/internal/app/db.go +++ b/internal/app/db.go @@ -324,7 +324,7 @@ func (dbm *DBManager) UploadAt(ctx context.Context, exportPath string) error { ) ts := NewTimestamp(time.Now().UTC()) - if err := dbm.uploader.Upload(ctx, exportPath, progress, ts); err != nil { + if err := dbm.uploader.Upload(ctx, exportPath, progress, ts, fi.Size()); err != nil { return fmt.Errorf("upload: %s", err) } diff --git a/internal/app/models.go b/internal/app/models.go new file mode 100644 index 0000000..d7b4909 --- /dev/null +++ b/internal/app/models.go @@ -0,0 +1,41 @@ +package app + +import ( + "errors" + + "github.com/ethereum/go-ethereum/common" +) + +// Vault represents a vault. +type Vault string + +// Account represents an account. +type Account struct { + address common.Address +} + +// NewAccount creates a new account. +func NewAccount(address string) (*Account, error) { + if !common.IsHexAddress(address) { + return nil, errors.New("address not valit") + } + + return &Account{address: common.HexToAddress(address)}, nil +} + +// Hex returns the hex-enconded address. +func (a *Account) Hex() string { + return a.address.Hex() +} + +// CacheDuration how long data stays in cache in minutes. +type CacheDuration uint32 + +// EventInfo represents information about a deal. +type EventInfo struct { + CID string `json:"cid"` + Timestamp int64 `json:"timestamp"` + Size uint32 `json:"size"` + IsArchived bool `json:"is_archived"` + CacheExpiry string `json:"cache_expiry"` +} diff --git a/internal/app/streamer_test.go b/internal/app/streamer_test.go index 353286a..281180e 100644 --- a/internal/app/streamer_test.go +++ b/internal/app/streamer_test.go @@ -9,12 +9,10 @@ import ( "testing" "time" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/jackc/pglogrepl" "github.com/stretchr/testify/require" - basincapnp "github.com/tablelandnetwork/basin-cli/pkg/capnp" "github.com/tablelandnetwork/basin-cli/pkg/pgrepl" ) @@ -241,37 +239,27 @@ type basinProviderMock struct { uploaderInputs chan *os.File } -func (bp *basinProviderMock) Create( - _ context.Context, ns string, _ string, _ basincapnp.Schema, owner common.Address, _ int64, -) (bool, error) { - bp.owner[ns] = owner.Hex() - return false, nil -} - -func (bp *basinProviderMock) List(_ context.Context, _ common.Address) ([]string, error) { - return []string{}, nil -} - -func (bp *basinProviderMock) Deals( - context.Context, string, string, uint32, uint64, Timestamp, Timestamp, -) ([]DealInfo, error) { - return []DealInfo{}, nil +func (bp *basinProviderMock) CreateVault( + _ context.Context, params CreateVaultParams, +) error { + bp.owner[string(params.Vault)] = params.Account.Hex() + return nil } -func (bp *basinProviderMock) LatestDeals( - context.Context, string, string, uint32, Timestamp, Timestamp, -) ([]DealInfo, error) { - return []DealInfo{}, nil +func (bp *basinProviderMock) ListVaults(_ context.Context, _ ListVaultsParams) ([]Vault, error) { + return []Vault{}, nil } -func (bp *basinProviderMock) Reconnect() error { - return nil +func (bp *basinProviderMock) ListVaultEvents( + context.Context, ListVaultEventsParams, +) ([]EventInfo, error) { + return []EventInfo{}, nil } -func (bp *basinProviderMock) Upload( - _ context.Context, _ string, _ string, _ uint64, f io.Reader, _ *Signer, _ io.Writer, _ Timestamp, +func (bp *basinProviderMock) WriteVaultEvent( + _ context.Context, params WriteVaultEventParams, ) error { - file := f.(*os.File) + file := params.Content.(*os.File) file.Fd() // re-create a copy of the file for assertions diff --git a/internal/app/uploader.go b/internal/app/uploader.go index a231154..6bd54d0 100644 --- a/internal/app/uploader.go +++ b/internal/app/uploader.go @@ -1,10 +1,13 @@ package app import ( + "bufio" "context" "crypto/ecdsa" + "encoding/hex" "fmt" "io" + "log" "os" "github.com/ethereum/go-ethereum/common" @@ -12,22 +15,17 @@ import ( "golang.org/x/crypto/sha3" ) -// BasinProviderUploader ... -type BasinProviderUploader interface { - Upload(context.Context, string, string, uint64, io.Reader, *Signer, io.Writer, Timestamp) error -} - // BasinUploader contains logic of uploading Parquet files to Basin Provider. type BasinUploader struct { namespace string relation string privateKey *ecdsa.PrivateKey - provider BasinProviderUploader + provider BasinProvider } // NewBasinUploader creates new uploader. func NewBasinUploader( - ns string, rel string, bp BasinProviderUploader, pk *ecdsa.PrivateKey, + ns string, rel string, bp BasinProvider, pk *ecdsa.PrivateKey, ) *BasinUploader { return &BasinUploader{ namespace: ns, @@ -38,7 +36,9 @@ func NewBasinUploader( } // Upload sends file to provider for upload. -func (bu *BasinUploader) Upload(ctx context.Context, filepath string, progress io.Writer, ts Timestamp) error { +func (bu *BasinUploader) Upload( + ctx context.Context, filepath string, progress io.Writer, ts Timestamp, sz int64, +) error { f, err := os.Open(filepath) if err != nil { return fmt.Errorf("open file: %s", err) @@ -47,15 +47,23 @@ func (bu *BasinUploader) Upload(ctx context.Context, filepath string, progress i _ = f.Close() }() - fi, err := f.Stat() + signer := NewSigner(bu.privateKey) + signature, err := signer.SignFile(filepath) if err != nil { - return fmt.Errorf("file stat: %s", err) + return fmt.Errorf("signing the file: %s", err) + } + + params := WriteVaultEventParams{ + Vault: Vault(fmt.Sprintf("%s.%s", bu.namespace, bu.relation)), + Timestamp: ts, + Content: f, + ProgressBar: progress, + Signature: hex.EncodeToString(signature), + Size: sz, } - if err := bu.provider.Upload( - ctx, bu.namespace, bu.relation, uint64(fi.Size()), f, NewSigner(bu.privateKey), progress, ts, - ); err != nil { - return fmt.Errorf("upload: %s", err) + if err := bu.provider.WriteVaultEvent(ctx, params); err != nil { + return fmt.Errorf("write vault event: %s", err) } return nil @@ -91,3 +99,47 @@ func (s *Signer) Sign() ([]byte, error) { return signature, nil } + +// SignFile signs an entier file. +func (s *Signer) SignFile(filename string) ([]byte, error) { + f, err := os.Open(filename) + if err != nil { + return []byte{}, fmt.Errorf("error to read [file=%v]: %v", filename, err.Error()) + } + + defer func() { + _ = f.Close() + }() + + nBytes, nChunks := int64(0), int64(0) + r := bufio.NewReader(f) + buf := make([]byte, 0, 4*1024) + for { + n, err := r.Read(buf[:cap(buf)]) + buf = buf[:n] + if n == 0 { + if err == nil { + continue + } + if err == io.EOF { + break + } + log.Fatal(err) + } + nChunks++ + nBytes += int64(len(buf)) + + s.Sum(buf) + + if err != nil && err != io.EOF { + log.Fatal(err) + } + } + + signature, err := s.Sign() + if err != nil { + log.Fatal("failed to sign") + } + + return signature, nil +} diff --git a/internal/app/uploader_test.go b/internal/app/uploader_test.go deleted file mode 100644 index 8c3f948..0000000 --- a/internal/app/uploader_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package app - -import ( - "bytes" - "context" - "io" - "testing" - - "github.com/ethereum/go-ethereum/crypto" - "github.com/stretchr/testify/require" -) - -func TestBasinUploader(t *testing.T) { - // used for testing - pk := "f81ab2709b7cf1f2ebbbd50bd730b267879a495318f7aac16bbe7caa8a8f2d8d" - privateKey, err := crypto.HexToECDSA(pk) - require.NoError(t, err) - - mock := &basinProviderUploderMock{} - - uploader := NewBasinUploader("test", "test", mock, privateKey) - - buf := bytes.NewBuffer(make([]byte, 0, 10)) - err = uploader.Upload(context.Background(), "testdata/test.parquet", buf, Timestamp{}) - require.NoError(t, err) - // there's no much logic to test in this component apart from the fact that the file was read - // the test file has 113629 bytes - require.Equal(t, 113629, mock.bytesRead) -} - -type basinProviderUploderMock struct { - bytesRead int -} - -func (bp *basinProviderUploderMock) Upload( - _ context.Context, _ string, _ string, _ uint64, r io.Reader, _ *Signer, _ io.Writer, _ Timestamp, -) error { - buf := make([]byte, 4*1024) - for { - n, err := r.Read(buf) - if err == io.EOF { - break - } - bp.bytesRead += n - } - - return nil -} diff --git a/pkg/basinprovider/provider.capnp b/pkg/basinprovider/provider.capnp deleted file mode 100644 index a9000b4..0000000 --- a/pkg/basinprovider/provider.capnp +++ /dev/null @@ -1,21 +0,0 @@ -using Go = import "/go.capnp"; - -@0x9cf9878fd3dd8473; - -$Go.package("basinprovider"); -$Go.import("github.com/tablelandnetwork/basin-cli/pkg/basinprovider"); - -interface Publications { - create @0 (ns :Text, rel :Text, schema :import "../capnp/definitions.capnp" .Schema, owner :Data, cache_duration :Int64) -> (exists :Bool); - push @1 (ns :Text, rel :Text, tx :import "../capnp/definitions.capnp" .Tx, sig :Data); - - upload @2 (ns :Text, rel :Text, size: UInt64, timestamp: Int64) -> (callback :Callback); - interface Callback { - write @0 (chunk :Data); - done @1 (sig :Data); - } - - list @3 (owner :Data) -> (publications :List(Text)); - deals @4 (ns :Text, rel :Text, limit :UInt32, offset :UInt64, before :Int64, after :Int64) -> (deals :List(import "../capnp/definitions.capnp" .DealInfo)); - latestDeals @5 (ns :Text, rel :Text, n :UInt32, before :Int64, after :Int64) -> (deals :List(import "../capnp/definitions.capnp" .DealInfo)); -} diff --git a/pkg/basinprovider/provider.capnp.go b/pkg/basinprovider/provider.capnp.go deleted file mode 100644 index 54c11c5..0000000 --- a/pkg/basinprovider/provider.capnp.go +++ /dev/null @@ -1,2262 +0,0 @@ -// Code generated by capnpc-go. DO NOT EDIT. - -package basinprovider - -import ( - capnp "capnproto.org/go/capnp/v3" - text "capnproto.org/go/capnp/v3/encoding/text" - fc "capnproto.org/go/capnp/v3/flowcontrol" - schemas "capnproto.org/go/capnp/v3/schemas" - server "capnproto.org/go/capnp/v3/server" - context "context" - capnp2 "github.com/tablelandnetwork/basin-cli/pkg/capnp" -) - -type Publications capnp.Client - -// Publications_TypeID is the unique identifier for the type Publications. -const Publications_TypeID = 0xfddc20d968f417dd - -func (c Publications) Create(ctx context.Context, params func(Publications_create_Params) error) (Publications_create_Results_Future, capnp.ReleaseFunc) { - - s := capnp.Send{ - Method: capnp.Method{ - InterfaceID: 0xfddc20d968f417dd, - MethodID: 0, - InterfaceName: "pkg/basinprovider/provider.capnp:Publications", - MethodName: "create", - }, - } - if params != nil { - s.ArgsSize = capnp.ObjectSize{DataSize: 8, PointerCount: 4} - s.PlaceArgs = func(s capnp.Struct) error { return params(Publications_create_Params(s)) } - } - - ans, release := capnp.Client(c).SendCall(ctx, s) - return Publications_create_Results_Future{Future: ans.Future()}, release - -} - -func (c Publications) Push(ctx context.Context, params func(Publications_push_Params) error) (Publications_push_Results_Future, capnp.ReleaseFunc) { - - s := capnp.Send{ - Method: capnp.Method{ - InterfaceID: 0xfddc20d968f417dd, - MethodID: 1, - InterfaceName: "pkg/basinprovider/provider.capnp:Publications", - MethodName: "push", - }, - } - if params != nil { - s.ArgsSize = capnp.ObjectSize{DataSize: 0, PointerCount: 4} - s.PlaceArgs = func(s capnp.Struct) error { return params(Publications_push_Params(s)) } - } - - ans, release := capnp.Client(c).SendCall(ctx, s) - return Publications_push_Results_Future{Future: ans.Future()}, release - -} - -func (c Publications) Upload(ctx context.Context, params func(Publications_upload_Params) error) (Publications_upload_Results_Future, capnp.ReleaseFunc) { - - s := capnp.Send{ - Method: capnp.Method{ - InterfaceID: 0xfddc20d968f417dd, - MethodID: 2, - InterfaceName: "pkg/basinprovider/provider.capnp:Publications", - MethodName: "upload", - }, - } - if params != nil { - s.ArgsSize = capnp.ObjectSize{DataSize: 16, PointerCount: 2} - s.PlaceArgs = func(s capnp.Struct) error { return params(Publications_upload_Params(s)) } - } - - ans, release := capnp.Client(c).SendCall(ctx, s) - return Publications_upload_Results_Future{Future: ans.Future()}, release - -} - -func (c Publications) List(ctx context.Context, params func(Publications_list_Params) error) (Publications_list_Results_Future, capnp.ReleaseFunc) { - - s := capnp.Send{ - Method: capnp.Method{ - InterfaceID: 0xfddc20d968f417dd, - MethodID: 3, - InterfaceName: "pkg/basinprovider/provider.capnp:Publications", - MethodName: "list", - }, - } - if params != nil { - s.ArgsSize = capnp.ObjectSize{DataSize: 0, PointerCount: 1} - s.PlaceArgs = func(s capnp.Struct) error { return params(Publications_list_Params(s)) } - } - - ans, release := capnp.Client(c).SendCall(ctx, s) - return Publications_list_Results_Future{Future: ans.Future()}, release - -} - -func (c Publications) Deals(ctx context.Context, params func(Publications_deals_Params) error) (Publications_deals_Results_Future, capnp.ReleaseFunc) { - - s := capnp.Send{ - Method: capnp.Method{ - InterfaceID: 0xfddc20d968f417dd, - MethodID: 4, - InterfaceName: "pkg/basinprovider/provider.capnp:Publications", - MethodName: "deals", - }, - } - if params != nil { - s.ArgsSize = capnp.ObjectSize{DataSize: 32, PointerCount: 2} - s.PlaceArgs = func(s capnp.Struct) error { return params(Publications_deals_Params(s)) } - } - - ans, release := capnp.Client(c).SendCall(ctx, s) - return Publications_deals_Results_Future{Future: ans.Future()}, release - -} - -func (c Publications) LatestDeals(ctx context.Context, params func(Publications_latestDeals_Params) error) (Publications_latestDeals_Results_Future, capnp.ReleaseFunc) { - - s := capnp.Send{ - Method: capnp.Method{ - InterfaceID: 0xfddc20d968f417dd, - MethodID: 5, - InterfaceName: "pkg/basinprovider/provider.capnp:Publications", - MethodName: "latestDeals", - }, - } - if params != nil { - s.ArgsSize = capnp.ObjectSize{DataSize: 24, PointerCount: 2} - s.PlaceArgs = func(s capnp.Struct) error { return params(Publications_latestDeals_Params(s)) } - } - - ans, release := capnp.Client(c).SendCall(ctx, s) - return Publications_latestDeals_Results_Future{Future: ans.Future()}, release - -} - -func (c Publications) WaitStreaming() error { - return capnp.Client(c).WaitStreaming() -} - -// String returns a string that identifies this capability for debugging -// purposes. Its format should not be depended on: in particular, it -// should not be used to compare clients. Use IsSame to compare clients -// for equality. -func (c Publications) String() string { - return "Publications(" + capnp.Client(c).String() + ")" -} - -// AddRef creates a new Client that refers to the same capability as c. -// If c is nil or has resolved to null, then AddRef returns nil. -func (c Publications) AddRef() Publications { - return Publications(capnp.Client(c).AddRef()) -} - -// Release releases a capability reference. If this is the last -// reference to the capability, then the underlying resources associated -// with the capability will be released. -// -// Release will panic if c has already been released, but not if c is -// nil or resolved to null. -func (c Publications) Release() { - capnp.Client(c).Release() -} - -// Resolve blocks until the capability is fully resolved or the Context -// expires. -func (c Publications) Resolve(ctx context.Context) error { - return capnp.Client(c).Resolve(ctx) -} - -func (c Publications) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Client(c).EncodeAsPtr(seg) -} - -func (Publications) DecodeFromPtr(p capnp.Ptr) Publications { - return Publications(capnp.Client{}.DecodeFromPtr(p)) -} - -// IsValid reports whether c is a valid reference to a capability. -// A reference is invalid if it is nil, has resolved to null, or has -// been released. -func (c Publications) IsValid() bool { - return capnp.Client(c).IsValid() -} - -// IsSame reports whether c and other refer to a capability created by the -// same call to NewClient. This can return false negatives if c or other -// are not fully resolved: use Resolve if this is an issue. If either -// c or other are released, then IsSame panics. -func (c Publications) IsSame(other Publications) bool { - return capnp.Client(c).IsSame(capnp.Client(other)) -} - -// Update the flowcontrol.FlowLimiter used to manage flow control for -// this client. This affects all future calls, but not calls already -// waiting to send. Passing nil sets the value to flowcontrol.NopLimiter, -// which is also the default. -func (c Publications) SetFlowLimiter(lim fc.FlowLimiter) { - capnp.Client(c).SetFlowLimiter(lim) -} - -// Get the current flowcontrol.FlowLimiter used to manage flow control -// for this client. -func (c Publications) GetFlowLimiter() fc.FlowLimiter { - return capnp.Client(c).GetFlowLimiter() -} - -// A Publications_Server is a Publications with a local implementation. -type Publications_Server interface { - Create(context.Context, Publications_create) error - - Push(context.Context, Publications_push) error - - Upload(context.Context, Publications_upload) error - - List(context.Context, Publications_list) error - - Deals(context.Context, Publications_deals) error - - LatestDeals(context.Context, Publications_latestDeals) error -} - -// Publications_NewServer creates a new Server from an implementation of Publications_Server. -func Publications_NewServer(s Publications_Server) *server.Server { - c, _ := s.(server.Shutdowner) - return server.New(Publications_Methods(nil, s), s, c) -} - -// Publications_ServerToClient creates a new Client from an implementation of Publications_Server. -// The caller is responsible for calling Release on the returned Client. -func Publications_ServerToClient(s Publications_Server) Publications { - return Publications(capnp.NewClient(Publications_NewServer(s))) -} - -// Publications_Methods appends Methods to a slice that invoke the methods on s. -// This can be used to create a more complicated Server. -func Publications_Methods(methods []server.Method, s Publications_Server) []server.Method { - if cap(methods) == 0 { - methods = make([]server.Method, 0, 6) - } - - methods = append(methods, server.Method{ - Method: capnp.Method{ - InterfaceID: 0xfddc20d968f417dd, - MethodID: 0, - InterfaceName: "pkg/basinprovider/provider.capnp:Publications", - MethodName: "create", - }, - Impl: func(ctx context.Context, call *server.Call) error { - return s.Create(ctx, Publications_create{call}) - }, - }) - - methods = append(methods, server.Method{ - Method: capnp.Method{ - InterfaceID: 0xfddc20d968f417dd, - MethodID: 1, - InterfaceName: "pkg/basinprovider/provider.capnp:Publications", - MethodName: "push", - }, - Impl: func(ctx context.Context, call *server.Call) error { - return s.Push(ctx, Publications_push{call}) - }, - }) - - methods = append(methods, server.Method{ - Method: capnp.Method{ - InterfaceID: 0xfddc20d968f417dd, - MethodID: 2, - InterfaceName: "pkg/basinprovider/provider.capnp:Publications", - MethodName: "upload", - }, - Impl: func(ctx context.Context, call *server.Call) error { - return s.Upload(ctx, Publications_upload{call}) - }, - }) - - methods = append(methods, server.Method{ - Method: capnp.Method{ - InterfaceID: 0xfddc20d968f417dd, - MethodID: 3, - InterfaceName: "pkg/basinprovider/provider.capnp:Publications", - MethodName: "list", - }, - Impl: func(ctx context.Context, call *server.Call) error { - return s.List(ctx, Publications_list{call}) - }, - }) - - methods = append(methods, server.Method{ - Method: capnp.Method{ - InterfaceID: 0xfddc20d968f417dd, - MethodID: 4, - InterfaceName: "pkg/basinprovider/provider.capnp:Publications", - MethodName: "deals", - }, - Impl: func(ctx context.Context, call *server.Call) error { - return s.Deals(ctx, Publications_deals{call}) - }, - }) - - methods = append(methods, server.Method{ - Method: capnp.Method{ - InterfaceID: 0xfddc20d968f417dd, - MethodID: 5, - InterfaceName: "pkg/basinprovider/provider.capnp:Publications", - MethodName: "latestDeals", - }, - Impl: func(ctx context.Context, call *server.Call) error { - return s.LatestDeals(ctx, Publications_latestDeals{call}) - }, - }) - - return methods -} - -// Publications_create holds the state for a server call to Publications.create. -// See server.Call for documentation. -type Publications_create struct { - *server.Call -} - -// Args returns the call's arguments. -func (c Publications_create) Args() Publications_create_Params { - return Publications_create_Params(c.Call.Args()) -} - -// AllocResults allocates the results struct. -func (c Publications_create) AllocResults() (Publications_create_Results, error) { - r, err := c.Call.AllocResults(capnp.ObjectSize{DataSize: 8, PointerCount: 0}) - return Publications_create_Results(r), err -} - -// Publications_push holds the state for a server call to Publications.push. -// See server.Call for documentation. -type Publications_push struct { - *server.Call -} - -// Args returns the call's arguments. -func (c Publications_push) Args() Publications_push_Params { - return Publications_push_Params(c.Call.Args()) -} - -// AllocResults allocates the results struct. -func (c Publications_push) AllocResults() (Publications_push_Results, error) { - r, err := c.Call.AllocResults(capnp.ObjectSize{DataSize: 0, PointerCount: 0}) - return Publications_push_Results(r), err -} - -// Publications_upload holds the state for a server call to Publications.upload. -// See server.Call for documentation. -type Publications_upload struct { - *server.Call -} - -// Args returns the call's arguments. -func (c Publications_upload) Args() Publications_upload_Params { - return Publications_upload_Params(c.Call.Args()) -} - -// AllocResults allocates the results struct. -func (c Publications_upload) AllocResults() (Publications_upload_Results, error) { - r, err := c.Call.AllocResults(capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Publications_upload_Results(r), err -} - -// Publications_list holds the state for a server call to Publications.list. -// See server.Call for documentation. -type Publications_list struct { - *server.Call -} - -// Args returns the call's arguments. -func (c Publications_list) Args() Publications_list_Params { - return Publications_list_Params(c.Call.Args()) -} - -// AllocResults allocates the results struct. -func (c Publications_list) AllocResults() (Publications_list_Results, error) { - r, err := c.Call.AllocResults(capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Publications_list_Results(r), err -} - -// Publications_deals holds the state for a server call to Publications.deals. -// See server.Call for documentation. -type Publications_deals struct { - *server.Call -} - -// Args returns the call's arguments. -func (c Publications_deals) Args() Publications_deals_Params { - return Publications_deals_Params(c.Call.Args()) -} - -// AllocResults allocates the results struct. -func (c Publications_deals) AllocResults() (Publications_deals_Results, error) { - r, err := c.Call.AllocResults(capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Publications_deals_Results(r), err -} - -// Publications_latestDeals holds the state for a server call to Publications.latestDeals. -// See server.Call for documentation. -type Publications_latestDeals struct { - *server.Call -} - -// Args returns the call's arguments. -func (c Publications_latestDeals) Args() Publications_latestDeals_Params { - return Publications_latestDeals_Params(c.Call.Args()) -} - -// AllocResults allocates the results struct. -func (c Publications_latestDeals) AllocResults() (Publications_latestDeals_Results, error) { - r, err := c.Call.AllocResults(capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Publications_latestDeals_Results(r), err -} - -// Publications_List is a list of Publications. -type Publications_List = capnp.CapList[Publications] - -// NewPublications creates a new list of Publications. -func NewPublications_List(s *capnp.Segment, sz int32) (Publications_List, error) { - l, err := capnp.NewPointerList(s, sz) - return capnp.CapList[Publications](l), err -} - -type Publications_Callback capnp.Client - -// Publications_Callback_TypeID is the unique identifier for the type Publications_Callback. -const Publications_Callback_TypeID = 0xb4928ae23403b190 - -func (c Publications_Callback) Write(ctx context.Context, params func(Publications_Callback_write_Params) error) (Publications_Callback_write_Results_Future, capnp.ReleaseFunc) { - - s := capnp.Send{ - Method: capnp.Method{ - InterfaceID: 0xb4928ae23403b190, - MethodID: 0, - InterfaceName: "pkg/basinprovider/provider.capnp:Publications.Callback", - MethodName: "write", - }, - } - if params != nil { - s.ArgsSize = capnp.ObjectSize{DataSize: 0, PointerCount: 1} - s.PlaceArgs = func(s capnp.Struct) error { return params(Publications_Callback_write_Params(s)) } - } - - ans, release := capnp.Client(c).SendCall(ctx, s) - return Publications_Callback_write_Results_Future{Future: ans.Future()}, release - -} - -func (c Publications_Callback) Done(ctx context.Context, params func(Publications_Callback_done_Params) error) (Publications_Callback_done_Results_Future, capnp.ReleaseFunc) { - - s := capnp.Send{ - Method: capnp.Method{ - InterfaceID: 0xb4928ae23403b190, - MethodID: 1, - InterfaceName: "pkg/basinprovider/provider.capnp:Publications.Callback", - MethodName: "done", - }, - } - if params != nil { - s.ArgsSize = capnp.ObjectSize{DataSize: 0, PointerCount: 1} - s.PlaceArgs = func(s capnp.Struct) error { return params(Publications_Callback_done_Params(s)) } - } - - ans, release := capnp.Client(c).SendCall(ctx, s) - return Publications_Callback_done_Results_Future{Future: ans.Future()}, release - -} - -func (c Publications_Callback) WaitStreaming() error { - return capnp.Client(c).WaitStreaming() -} - -// String returns a string that identifies this capability for debugging -// purposes. Its format should not be depended on: in particular, it -// should not be used to compare clients. Use IsSame to compare clients -// for equality. -func (c Publications_Callback) String() string { - return "Publications_Callback(" + capnp.Client(c).String() + ")" -} - -// AddRef creates a new Client that refers to the same capability as c. -// If c is nil or has resolved to null, then AddRef returns nil. -func (c Publications_Callback) AddRef() Publications_Callback { - return Publications_Callback(capnp.Client(c).AddRef()) -} - -// Release releases a capability reference. If this is the last -// reference to the capability, then the underlying resources associated -// with the capability will be released. -// -// Release will panic if c has already been released, but not if c is -// nil or resolved to null. -func (c Publications_Callback) Release() { - capnp.Client(c).Release() -} - -// Resolve blocks until the capability is fully resolved or the Context -// expires. -func (c Publications_Callback) Resolve(ctx context.Context) error { - return capnp.Client(c).Resolve(ctx) -} - -func (c Publications_Callback) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Client(c).EncodeAsPtr(seg) -} - -func (Publications_Callback) DecodeFromPtr(p capnp.Ptr) Publications_Callback { - return Publications_Callback(capnp.Client{}.DecodeFromPtr(p)) -} - -// IsValid reports whether c is a valid reference to a capability. -// A reference is invalid if it is nil, has resolved to null, or has -// been released. -func (c Publications_Callback) IsValid() bool { - return capnp.Client(c).IsValid() -} - -// IsSame reports whether c and other refer to a capability created by the -// same call to NewClient. This can return false negatives if c or other -// are not fully resolved: use Resolve if this is an issue. If either -// c or other are released, then IsSame panics. -func (c Publications_Callback) IsSame(other Publications_Callback) bool { - return capnp.Client(c).IsSame(capnp.Client(other)) -} - -// Update the flowcontrol.FlowLimiter used to manage flow control for -// this client. This affects all future calls, but not calls already -// waiting to send. Passing nil sets the value to flowcontrol.NopLimiter, -// which is also the default. -func (c Publications_Callback) SetFlowLimiter(lim fc.FlowLimiter) { - capnp.Client(c).SetFlowLimiter(lim) -} - -// Get the current flowcontrol.FlowLimiter used to manage flow control -// for this client. -func (c Publications_Callback) GetFlowLimiter() fc.FlowLimiter { - return capnp.Client(c).GetFlowLimiter() -} - -// A Publications_Callback_Server is a Publications_Callback with a local implementation. -type Publications_Callback_Server interface { - Write(context.Context, Publications_Callback_write) error - - Done(context.Context, Publications_Callback_done) error -} - -// Publications_Callback_NewServer creates a new Server from an implementation of Publications_Callback_Server. -func Publications_Callback_NewServer(s Publications_Callback_Server) *server.Server { - c, _ := s.(server.Shutdowner) - return server.New(Publications_Callback_Methods(nil, s), s, c) -} - -// Publications_Callback_ServerToClient creates a new Client from an implementation of Publications_Callback_Server. -// The caller is responsible for calling Release on the returned Client. -func Publications_Callback_ServerToClient(s Publications_Callback_Server) Publications_Callback { - return Publications_Callback(capnp.NewClient(Publications_Callback_NewServer(s))) -} - -// Publications_Callback_Methods appends Methods to a slice that invoke the methods on s. -// This can be used to create a more complicated Server. -func Publications_Callback_Methods(methods []server.Method, s Publications_Callback_Server) []server.Method { - if cap(methods) == 0 { - methods = make([]server.Method, 0, 2) - } - - methods = append(methods, server.Method{ - Method: capnp.Method{ - InterfaceID: 0xb4928ae23403b190, - MethodID: 0, - InterfaceName: "pkg/basinprovider/provider.capnp:Publications.Callback", - MethodName: "write", - }, - Impl: func(ctx context.Context, call *server.Call) error { - return s.Write(ctx, Publications_Callback_write{call}) - }, - }) - - methods = append(methods, server.Method{ - Method: capnp.Method{ - InterfaceID: 0xb4928ae23403b190, - MethodID: 1, - InterfaceName: "pkg/basinprovider/provider.capnp:Publications.Callback", - MethodName: "done", - }, - Impl: func(ctx context.Context, call *server.Call) error { - return s.Done(ctx, Publications_Callback_done{call}) - }, - }) - - return methods -} - -// Publications_Callback_write holds the state for a server call to Publications_Callback.write. -// See server.Call for documentation. -type Publications_Callback_write struct { - *server.Call -} - -// Args returns the call's arguments. -func (c Publications_Callback_write) Args() Publications_Callback_write_Params { - return Publications_Callback_write_Params(c.Call.Args()) -} - -// AllocResults allocates the results struct. -func (c Publications_Callback_write) AllocResults() (Publications_Callback_write_Results, error) { - r, err := c.Call.AllocResults(capnp.ObjectSize{DataSize: 0, PointerCount: 0}) - return Publications_Callback_write_Results(r), err -} - -// Publications_Callback_done holds the state for a server call to Publications_Callback.done. -// See server.Call for documentation. -type Publications_Callback_done struct { - *server.Call -} - -// Args returns the call's arguments. -func (c Publications_Callback_done) Args() Publications_Callback_done_Params { - return Publications_Callback_done_Params(c.Call.Args()) -} - -// AllocResults allocates the results struct. -func (c Publications_Callback_done) AllocResults() (Publications_Callback_done_Results, error) { - r, err := c.Call.AllocResults(capnp.ObjectSize{DataSize: 0, PointerCount: 0}) - return Publications_Callback_done_Results(r), err -} - -// Publications_Callback_List is a list of Publications_Callback. -type Publications_Callback_List = capnp.CapList[Publications_Callback] - -// NewPublications_Callback creates a new list of Publications_Callback. -func NewPublications_Callback_List(s *capnp.Segment, sz int32) (Publications_Callback_List, error) { - l, err := capnp.NewPointerList(s, sz) - return capnp.CapList[Publications_Callback](l), err -} - -type Publications_Callback_write_Params capnp.Struct - -// Publications_Callback_write_Params_TypeID is the unique identifier for the type Publications_Callback_write_Params. -const Publications_Callback_write_Params_TypeID = 0x8c6625092276093d - -func NewPublications_Callback_write_Params(s *capnp.Segment) (Publications_Callback_write_Params, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Publications_Callback_write_Params(st), err -} - -func NewRootPublications_Callback_write_Params(s *capnp.Segment) (Publications_Callback_write_Params, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Publications_Callback_write_Params(st), err -} - -func ReadRootPublications_Callback_write_Params(msg *capnp.Message) (Publications_Callback_write_Params, error) { - root, err := msg.Root() - return Publications_Callback_write_Params(root.Struct()), err -} - -func (s Publications_Callback_write_Params) String() string { - str, _ := text.Marshal(0x8c6625092276093d, capnp.Struct(s)) - return str -} - -func (s Publications_Callback_write_Params) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Publications_Callback_write_Params) DecodeFromPtr(p capnp.Ptr) Publications_Callback_write_Params { - return Publications_Callback_write_Params(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Publications_Callback_write_Params) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Publications_Callback_write_Params) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Publications_Callback_write_Params) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Publications_Callback_write_Params) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Publications_Callback_write_Params) Chunk() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(0) - return []byte(p.Data()), err -} - -func (s Publications_Callback_write_Params) HasChunk() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s Publications_Callback_write_Params) SetChunk(v []byte) error { - return capnp.Struct(s).SetData(0, v) -} - -// Publications_Callback_write_Params_List is a list of Publications_Callback_write_Params. -type Publications_Callback_write_Params_List = capnp.StructList[Publications_Callback_write_Params] - -// NewPublications_Callback_write_Params creates a new list of Publications_Callback_write_Params. -func NewPublications_Callback_write_Params_List(s *capnp.Segment, sz int32) (Publications_Callback_write_Params_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}, sz) - return capnp.StructList[Publications_Callback_write_Params](l), err -} - -// Publications_Callback_write_Params_Future is a wrapper for a Publications_Callback_write_Params promised by a client call. -type Publications_Callback_write_Params_Future struct{ *capnp.Future } - -func (f Publications_Callback_write_Params_Future) Struct() (Publications_Callback_write_Params, error) { - p, err := f.Future.Ptr() - return Publications_Callback_write_Params(p.Struct()), err -} - -type Publications_Callback_write_Results capnp.Struct - -// Publications_Callback_write_Results_TypeID is the unique identifier for the type Publications_Callback_write_Results. -const Publications_Callback_write_Results_TypeID = 0xc7b7a97070ce93e5 - -func NewPublications_Callback_write_Results(s *capnp.Segment) (Publications_Callback_write_Results, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 0}) - return Publications_Callback_write_Results(st), err -} - -func NewRootPublications_Callback_write_Results(s *capnp.Segment) (Publications_Callback_write_Results, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 0}) - return Publications_Callback_write_Results(st), err -} - -func ReadRootPublications_Callback_write_Results(msg *capnp.Message) (Publications_Callback_write_Results, error) { - root, err := msg.Root() - return Publications_Callback_write_Results(root.Struct()), err -} - -func (s Publications_Callback_write_Results) String() string { - str, _ := text.Marshal(0xc7b7a97070ce93e5, capnp.Struct(s)) - return str -} - -func (s Publications_Callback_write_Results) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Publications_Callback_write_Results) DecodeFromPtr(p capnp.Ptr) Publications_Callback_write_Results { - return Publications_Callback_write_Results(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Publications_Callback_write_Results) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Publications_Callback_write_Results) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Publications_Callback_write_Results) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Publications_Callback_write_Results) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} - -// Publications_Callback_write_Results_List is a list of Publications_Callback_write_Results. -type Publications_Callback_write_Results_List = capnp.StructList[Publications_Callback_write_Results] - -// NewPublications_Callback_write_Results creates a new list of Publications_Callback_write_Results. -func NewPublications_Callback_write_Results_List(s *capnp.Segment, sz int32) (Publications_Callback_write_Results_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 0}, sz) - return capnp.StructList[Publications_Callback_write_Results](l), err -} - -// Publications_Callback_write_Results_Future is a wrapper for a Publications_Callback_write_Results promised by a client call. -type Publications_Callback_write_Results_Future struct{ *capnp.Future } - -func (f Publications_Callback_write_Results_Future) Struct() (Publications_Callback_write_Results, error) { - p, err := f.Future.Ptr() - return Publications_Callback_write_Results(p.Struct()), err -} - -type Publications_Callback_done_Params capnp.Struct - -// Publications_Callback_done_Params_TypeID is the unique identifier for the type Publications_Callback_done_Params. -const Publications_Callback_done_Params_TypeID = 0x90be9e0983809cf5 - -func NewPublications_Callback_done_Params(s *capnp.Segment) (Publications_Callback_done_Params, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Publications_Callback_done_Params(st), err -} - -func NewRootPublications_Callback_done_Params(s *capnp.Segment) (Publications_Callback_done_Params, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Publications_Callback_done_Params(st), err -} - -func ReadRootPublications_Callback_done_Params(msg *capnp.Message) (Publications_Callback_done_Params, error) { - root, err := msg.Root() - return Publications_Callback_done_Params(root.Struct()), err -} - -func (s Publications_Callback_done_Params) String() string { - str, _ := text.Marshal(0x90be9e0983809cf5, capnp.Struct(s)) - return str -} - -func (s Publications_Callback_done_Params) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Publications_Callback_done_Params) DecodeFromPtr(p capnp.Ptr) Publications_Callback_done_Params { - return Publications_Callback_done_Params(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Publications_Callback_done_Params) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Publications_Callback_done_Params) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Publications_Callback_done_Params) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Publications_Callback_done_Params) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Publications_Callback_done_Params) Sig() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(0) - return []byte(p.Data()), err -} - -func (s Publications_Callback_done_Params) HasSig() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s Publications_Callback_done_Params) SetSig(v []byte) error { - return capnp.Struct(s).SetData(0, v) -} - -// Publications_Callback_done_Params_List is a list of Publications_Callback_done_Params. -type Publications_Callback_done_Params_List = capnp.StructList[Publications_Callback_done_Params] - -// NewPublications_Callback_done_Params creates a new list of Publications_Callback_done_Params. -func NewPublications_Callback_done_Params_List(s *capnp.Segment, sz int32) (Publications_Callback_done_Params_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}, sz) - return capnp.StructList[Publications_Callback_done_Params](l), err -} - -// Publications_Callback_done_Params_Future is a wrapper for a Publications_Callback_done_Params promised by a client call. -type Publications_Callback_done_Params_Future struct{ *capnp.Future } - -func (f Publications_Callback_done_Params_Future) Struct() (Publications_Callback_done_Params, error) { - p, err := f.Future.Ptr() - return Publications_Callback_done_Params(p.Struct()), err -} - -type Publications_Callback_done_Results capnp.Struct - -// Publications_Callback_done_Results_TypeID is the unique identifier for the type Publications_Callback_done_Results. -const Publications_Callback_done_Results_TypeID = 0xcd754537fa2ac00e - -func NewPublications_Callback_done_Results(s *capnp.Segment) (Publications_Callback_done_Results, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 0}) - return Publications_Callback_done_Results(st), err -} - -func NewRootPublications_Callback_done_Results(s *capnp.Segment) (Publications_Callback_done_Results, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 0}) - return Publications_Callback_done_Results(st), err -} - -func ReadRootPublications_Callback_done_Results(msg *capnp.Message) (Publications_Callback_done_Results, error) { - root, err := msg.Root() - return Publications_Callback_done_Results(root.Struct()), err -} - -func (s Publications_Callback_done_Results) String() string { - str, _ := text.Marshal(0xcd754537fa2ac00e, capnp.Struct(s)) - return str -} - -func (s Publications_Callback_done_Results) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Publications_Callback_done_Results) DecodeFromPtr(p capnp.Ptr) Publications_Callback_done_Results { - return Publications_Callback_done_Results(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Publications_Callback_done_Results) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Publications_Callback_done_Results) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Publications_Callback_done_Results) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Publications_Callback_done_Results) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} - -// Publications_Callback_done_Results_List is a list of Publications_Callback_done_Results. -type Publications_Callback_done_Results_List = capnp.StructList[Publications_Callback_done_Results] - -// NewPublications_Callback_done_Results creates a new list of Publications_Callback_done_Results. -func NewPublications_Callback_done_Results_List(s *capnp.Segment, sz int32) (Publications_Callback_done_Results_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 0}, sz) - return capnp.StructList[Publications_Callback_done_Results](l), err -} - -// Publications_Callback_done_Results_Future is a wrapper for a Publications_Callback_done_Results promised by a client call. -type Publications_Callback_done_Results_Future struct{ *capnp.Future } - -func (f Publications_Callback_done_Results_Future) Struct() (Publications_Callback_done_Results, error) { - p, err := f.Future.Ptr() - return Publications_Callback_done_Results(p.Struct()), err -} - -type Publications_create_Params capnp.Struct - -// Publications_create_Params_TypeID is the unique identifier for the type Publications_create_Params. -const Publications_create_Params_TypeID = 0x8986414763ed9fe4 - -func NewPublications_create_Params(s *capnp.Segment) (Publications_create_Params, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 8, PointerCount: 4}) - return Publications_create_Params(st), err -} - -func NewRootPublications_create_Params(s *capnp.Segment) (Publications_create_Params, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 8, PointerCount: 4}) - return Publications_create_Params(st), err -} - -func ReadRootPublications_create_Params(msg *capnp.Message) (Publications_create_Params, error) { - root, err := msg.Root() - return Publications_create_Params(root.Struct()), err -} - -func (s Publications_create_Params) String() string { - str, _ := text.Marshal(0x8986414763ed9fe4, capnp.Struct(s)) - return str -} - -func (s Publications_create_Params) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Publications_create_Params) DecodeFromPtr(p capnp.Ptr) Publications_create_Params { - return Publications_create_Params(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Publications_create_Params) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Publications_create_Params) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Publications_create_Params) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Publications_create_Params) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Publications_create_Params) Ns() (string, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.Text(), err -} - -func (s Publications_create_Params) HasNs() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s Publications_create_Params) NsBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.TextBytes(), err -} - -func (s Publications_create_Params) SetNs(v string) error { - return capnp.Struct(s).SetText(0, v) -} - -func (s Publications_create_Params) Rel() (string, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.Text(), err -} - -func (s Publications_create_Params) HasRel() bool { - return capnp.Struct(s).HasPtr(1) -} - -func (s Publications_create_Params) RelBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.TextBytes(), err -} - -func (s Publications_create_Params) SetRel(v string) error { - return capnp.Struct(s).SetText(1, v) -} - -func (s Publications_create_Params) Schema() (capnp2.Schema, error) { - p, err := capnp.Struct(s).Ptr(2) - return capnp2.Schema(p.Struct()), err -} - -func (s Publications_create_Params) HasSchema() bool { - return capnp.Struct(s).HasPtr(2) -} - -func (s Publications_create_Params) SetSchema(v capnp2.Schema) error { - return capnp.Struct(s).SetPtr(2, capnp.Struct(v).ToPtr()) -} - -// NewSchema sets the schema field to a newly -// allocated capnp2.Schema struct, preferring placement in s's segment. -func (s Publications_create_Params) NewSchema() (capnp2.Schema, error) { - ss, err := capnp2.NewSchema(capnp.Struct(s).Segment()) - if err != nil { - return capnp2.Schema{}, err - } - err = capnp.Struct(s).SetPtr(2, capnp.Struct(ss).ToPtr()) - return ss, err -} - -func (s Publications_create_Params) Owner() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(3) - return []byte(p.Data()), err -} - -func (s Publications_create_Params) HasOwner() bool { - return capnp.Struct(s).HasPtr(3) -} - -func (s Publications_create_Params) SetOwner(v []byte) error { - return capnp.Struct(s).SetData(3, v) -} - -func (s Publications_create_Params) Cache_duration() int64 { - return int64(capnp.Struct(s).Uint64(0)) -} - -func (s Publications_create_Params) SetCache_duration(v int64) { - capnp.Struct(s).SetUint64(0, uint64(v)) -} - -// Publications_create_Params_List is a list of Publications_create_Params. -type Publications_create_Params_List = capnp.StructList[Publications_create_Params] - -// NewPublications_create_Params creates a new list of Publications_create_Params. -func NewPublications_create_Params_List(s *capnp.Segment, sz int32) (Publications_create_Params_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 8, PointerCount: 4}, sz) - return capnp.StructList[Publications_create_Params](l), err -} - -// Publications_create_Params_Future is a wrapper for a Publications_create_Params promised by a client call. -type Publications_create_Params_Future struct{ *capnp.Future } - -func (f Publications_create_Params_Future) Struct() (Publications_create_Params, error) { - p, err := f.Future.Ptr() - return Publications_create_Params(p.Struct()), err -} -func (p Publications_create_Params_Future) Schema() capnp2.Schema_Future { - return capnp2.Schema_Future{Future: p.Future.Field(2, nil)} -} - -type Publications_create_Results capnp.Struct - -// Publications_create_Results_TypeID is the unique identifier for the type Publications_create_Results. -const Publications_create_Results_TypeID = 0x9d09768207bbb14b - -func NewPublications_create_Results(s *capnp.Segment) (Publications_create_Results, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 8, PointerCount: 0}) - return Publications_create_Results(st), err -} - -func NewRootPublications_create_Results(s *capnp.Segment) (Publications_create_Results, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 8, PointerCount: 0}) - return Publications_create_Results(st), err -} - -func ReadRootPublications_create_Results(msg *capnp.Message) (Publications_create_Results, error) { - root, err := msg.Root() - return Publications_create_Results(root.Struct()), err -} - -func (s Publications_create_Results) String() string { - str, _ := text.Marshal(0x9d09768207bbb14b, capnp.Struct(s)) - return str -} - -func (s Publications_create_Results) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Publications_create_Results) DecodeFromPtr(p capnp.Ptr) Publications_create_Results { - return Publications_create_Results(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Publications_create_Results) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Publications_create_Results) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Publications_create_Results) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Publications_create_Results) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Publications_create_Results) Exists() bool { - return capnp.Struct(s).Bit(0) -} - -func (s Publications_create_Results) SetExists(v bool) { - capnp.Struct(s).SetBit(0, v) -} - -// Publications_create_Results_List is a list of Publications_create_Results. -type Publications_create_Results_List = capnp.StructList[Publications_create_Results] - -// NewPublications_create_Results creates a new list of Publications_create_Results. -func NewPublications_create_Results_List(s *capnp.Segment, sz int32) (Publications_create_Results_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 8, PointerCount: 0}, sz) - return capnp.StructList[Publications_create_Results](l), err -} - -// Publications_create_Results_Future is a wrapper for a Publications_create_Results promised by a client call. -type Publications_create_Results_Future struct{ *capnp.Future } - -func (f Publications_create_Results_Future) Struct() (Publications_create_Results, error) { - p, err := f.Future.Ptr() - return Publications_create_Results(p.Struct()), err -} - -type Publications_push_Params capnp.Struct - -// Publications_push_Params_TypeID is the unique identifier for the type Publications_push_Params. -const Publications_push_Params_TypeID = 0x85cf10ba0781d1d9 - -func NewPublications_push_Params(s *capnp.Segment) (Publications_push_Params, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 4}) - return Publications_push_Params(st), err -} - -func NewRootPublications_push_Params(s *capnp.Segment) (Publications_push_Params, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 4}) - return Publications_push_Params(st), err -} - -func ReadRootPublications_push_Params(msg *capnp.Message) (Publications_push_Params, error) { - root, err := msg.Root() - return Publications_push_Params(root.Struct()), err -} - -func (s Publications_push_Params) String() string { - str, _ := text.Marshal(0x85cf10ba0781d1d9, capnp.Struct(s)) - return str -} - -func (s Publications_push_Params) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Publications_push_Params) DecodeFromPtr(p capnp.Ptr) Publications_push_Params { - return Publications_push_Params(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Publications_push_Params) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Publications_push_Params) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Publications_push_Params) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Publications_push_Params) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Publications_push_Params) Ns() (string, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.Text(), err -} - -func (s Publications_push_Params) HasNs() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s Publications_push_Params) NsBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.TextBytes(), err -} - -func (s Publications_push_Params) SetNs(v string) error { - return capnp.Struct(s).SetText(0, v) -} - -func (s Publications_push_Params) Rel() (string, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.Text(), err -} - -func (s Publications_push_Params) HasRel() bool { - return capnp.Struct(s).HasPtr(1) -} - -func (s Publications_push_Params) RelBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.TextBytes(), err -} - -func (s Publications_push_Params) SetRel(v string) error { - return capnp.Struct(s).SetText(1, v) -} - -func (s Publications_push_Params) Tx() (capnp2.Tx, error) { - p, err := capnp.Struct(s).Ptr(2) - return capnp2.Tx(p.Struct()), err -} - -func (s Publications_push_Params) HasTx() bool { - return capnp.Struct(s).HasPtr(2) -} - -func (s Publications_push_Params) SetTx(v capnp2.Tx) error { - return capnp.Struct(s).SetPtr(2, capnp.Struct(v).ToPtr()) -} - -// NewTx sets the tx field to a newly -// allocated capnp2.Tx struct, preferring placement in s's segment. -func (s Publications_push_Params) NewTx() (capnp2.Tx, error) { - ss, err := capnp2.NewTx(capnp.Struct(s).Segment()) - if err != nil { - return capnp2.Tx{}, err - } - err = capnp.Struct(s).SetPtr(2, capnp.Struct(ss).ToPtr()) - return ss, err -} - -func (s Publications_push_Params) Sig() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(3) - return []byte(p.Data()), err -} - -func (s Publications_push_Params) HasSig() bool { - return capnp.Struct(s).HasPtr(3) -} - -func (s Publications_push_Params) SetSig(v []byte) error { - return capnp.Struct(s).SetData(3, v) -} - -// Publications_push_Params_List is a list of Publications_push_Params. -type Publications_push_Params_List = capnp.StructList[Publications_push_Params] - -// NewPublications_push_Params creates a new list of Publications_push_Params. -func NewPublications_push_Params_List(s *capnp.Segment, sz int32) (Publications_push_Params_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 4}, sz) - return capnp.StructList[Publications_push_Params](l), err -} - -// Publications_push_Params_Future is a wrapper for a Publications_push_Params promised by a client call. -type Publications_push_Params_Future struct{ *capnp.Future } - -func (f Publications_push_Params_Future) Struct() (Publications_push_Params, error) { - p, err := f.Future.Ptr() - return Publications_push_Params(p.Struct()), err -} -func (p Publications_push_Params_Future) Tx() capnp2.Tx_Future { - return capnp2.Tx_Future{Future: p.Future.Field(2, nil)} -} - -type Publications_push_Results capnp.Struct - -// Publications_push_Results_TypeID is the unique identifier for the type Publications_push_Results. -const Publications_push_Results_TypeID = 0xdf7b33d89ff629bd - -func NewPublications_push_Results(s *capnp.Segment) (Publications_push_Results, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 0}) - return Publications_push_Results(st), err -} - -func NewRootPublications_push_Results(s *capnp.Segment) (Publications_push_Results, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 0}) - return Publications_push_Results(st), err -} - -func ReadRootPublications_push_Results(msg *capnp.Message) (Publications_push_Results, error) { - root, err := msg.Root() - return Publications_push_Results(root.Struct()), err -} - -func (s Publications_push_Results) String() string { - str, _ := text.Marshal(0xdf7b33d89ff629bd, capnp.Struct(s)) - return str -} - -func (s Publications_push_Results) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Publications_push_Results) DecodeFromPtr(p capnp.Ptr) Publications_push_Results { - return Publications_push_Results(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Publications_push_Results) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Publications_push_Results) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Publications_push_Results) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Publications_push_Results) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} - -// Publications_push_Results_List is a list of Publications_push_Results. -type Publications_push_Results_List = capnp.StructList[Publications_push_Results] - -// NewPublications_push_Results creates a new list of Publications_push_Results. -func NewPublications_push_Results_List(s *capnp.Segment, sz int32) (Publications_push_Results_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 0}, sz) - return capnp.StructList[Publications_push_Results](l), err -} - -// Publications_push_Results_Future is a wrapper for a Publications_push_Results promised by a client call. -type Publications_push_Results_Future struct{ *capnp.Future } - -func (f Publications_push_Results_Future) Struct() (Publications_push_Results, error) { - p, err := f.Future.Ptr() - return Publications_push_Results(p.Struct()), err -} - -type Publications_upload_Params capnp.Struct - -// Publications_upload_Params_TypeID is the unique identifier for the type Publications_upload_Params. -const Publications_upload_Params_TypeID = 0xd067b888abba0bca - -func NewPublications_upload_Params(s *capnp.Segment) (Publications_upload_Params, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 16, PointerCount: 2}) - return Publications_upload_Params(st), err -} - -func NewRootPublications_upload_Params(s *capnp.Segment) (Publications_upload_Params, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 16, PointerCount: 2}) - return Publications_upload_Params(st), err -} - -func ReadRootPublications_upload_Params(msg *capnp.Message) (Publications_upload_Params, error) { - root, err := msg.Root() - return Publications_upload_Params(root.Struct()), err -} - -func (s Publications_upload_Params) String() string { - str, _ := text.Marshal(0xd067b888abba0bca, capnp.Struct(s)) - return str -} - -func (s Publications_upload_Params) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Publications_upload_Params) DecodeFromPtr(p capnp.Ptr) Publications_upload_Params { - return Publications_upload_Params(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Publications_upload_Params) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Publications_upload_Params) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Publications_upload_Params) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Publications_upload_Params) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Publications_upload_Params) Ns() (string, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.Text(), err -} - -func (s Publications_upload_Params) HasNs() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s Publications_upload_Params) NsBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.TextBytes(), err -} - -func (s Publications_upload_Params) SetNs(v string) error { - return capnp.Struct(s).SetText(0, v) -} - -func (s Publications_upload_Params) Rel() (string, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.Text(), err -} - -func (s Publications_upload_Params) HasRel() bool { - return capnp.Struct(s).HasPtr(1) -} - -func (s Publications_upload_Params) RelBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.TextBytes(), err -} - -func (s Publications_upload_Params) SetRel(v string) error { - return capnp.Struct(s).SetText(1, v) -} - -func (s Publications_upload_Params) Size() uint64 { - return capnp.Struct(s).Uint64(0) -} - -func (s Publications_upload_Params) SetSize(v uint64) { - capnp.Struct(s).SetUint64(0, v) -} - -func (s Publications_upload_Params) Timestamp() int64 { - return int64(capnp.Struct(s).Uint64(8)) -} - -func (s Publications_upload_Params) SetTimestamp(v int64) { - capnp.Struct(s).SetUint64(8, uint64(v)) -} - -// Publications_upload_Params_List is a list of Publications_upload_Params. -type Publications_upload_Params_List = capnp.StructList[Publications_upload_Params] - -// NewPublications_upload_Params creates a new list of Publications_upload_Params. -func NewPublications_upload_Params_List(s *capnp.Segment, sz int32) (Publications_upload_Params_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 16, PointerCount: 2}, sz) - return capnp.StructList[Publications_upload_Params](l), err -} - -// Publications_upload_Params_Future is a wrapper for a Publications_upload_Params promised by a client call. -type Publications_upload_Params_Future struct{ *capnp.Future } - -func (f Publications_upload_Params_Future) Struct() (Publications_upload_Params, error) { - p, err := f.Future.Ptr() - return Publications_upload_Params(p.Struct()), err -} - -type Publications_upload_Results capnp.Struct - -// Publications_upload_Results_TypeID is the unique identifier for the type Publications_upload_Results. -const Publications_upload_Results_TypeID = 0xd422be623bb0f731 - -func NewPublications_upload_Results(s *capnp.Segment) (Publications_upload_Results, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Publications_upload_Results(st), err -} - -func NewRootPublications_upload_Results(s *capnp.Segment) (Publications_upload_Results, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Publications_upload_Results(st), err -} - -func ReadRootPublications_upload_Results(msg *capnp.Message) (Publications_upload_Results, error) { - root, err := msg.Root() - return Publications_upload_Results(root.Struct()), err -} - -func (s Publications_upload_Results) String() string { - str, _ := text.Marshal(0xd422be623bb0f731, capnp.Struct(s)) - return str -} - -func (s Publications_upload_Results) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Publications_upload_Results) DecodeFromPtr(p capnp.Ptr) Publications_upload_Results { - return Publications_upload_Results(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Publications_upload_Results) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Publications_upload_Results) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Publications_upload_Results) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Publications_upload_Results) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Publications_upload_Results) Callback() Publications_Callback { - p, _ := capnp.Struct(s).Ptr(0) - return Publications_Callback(p.Interface().Client()) -} - -func (s Publications_upload_Results) HasCallback() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s Publications_upload_Results) SetCallback(v Publications_Callback) error { - if !v.IsValid() { - return capnp.Struct(s).SetPtr(0, capnp.Ptr{}) - } - seg := s.Segment() - in := capnp.NewInterface(seg, seg.Message().CapTable().Add(capnp.Client(v))) - return capnp.Struct(s).SetPtr(0, in.ToPtr()) -} - -// Publications_upload_Results_List is a list of Publications_upload_Results. -type Publications_upload_Results_List = capnp.StructList[Publications_upload_Results] - -// NewPublications_upload_Results creates a new list of Publications_upload_Results. -func NewPublications_upload_Results_List(s *capnp.Segment, sz int32) (Publications_upload_Results_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}, sz) - return capnp.StructList[Publications_upload_Results](l), err -} - -// Publications_upload_Results_Future is a wrapper for a Publications_upload_Results promised by a client call. -type Publications_upload_Results_Future struct{ *capnp.Future } - -func (f Publications_upload_Results_Future) Struct() (Publications_upload_Results, error) { - p, err := f.Future.Ptr() - return Publications_upload_Results(p.Struct()), err -} -func (p Publications_upload_Results_Future) Callback() Publications_Callback { - return Publications_Callback(p.Future.Field(0, nil).Client()) -} - -type Publications_list_Params capnp.Struct - -// Publications_list_Params_TypeID is the unique identifier for the type Publications_list_Params. -const Publications_list_Params_TypeID = 0xa202984178fc6068 - -func NewPublications_list_Params(s *capnp.Segment) (Publications_list_Params, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Publications_list_Params(st), err -} - -func NewRootPublications_list_Params(s *capnp.Segment) (Publications_list_Params, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Publications_list_Params(st), err -} - -func ReadRootPublications_list_Params(msg *capnp.Message) (Publications_list_Params, error) { - root, err := msg.Root() - return Publications_list_Params(root.Struct()), err -} - -func (s Publications_list_Params) String() string { - str, _ := text.Marshal(0xa202984178fc6068, capnp.Struct(s)) - return str -} - -func (s Publications_list_Params) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Publications_list_Params) DecodeFromPtr(p capnp.Ptr) Publications_list_Params { - return Publications_list_Params(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Publications_list_Params) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Publications_list_Params) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Publications_list_Params) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Publications_list_Params) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Publications_list_Params) Owner() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(0) - return []byte(p.Data()), err -} - -func (s Publications_list_Params) HasOwner() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s Publications_list_Params) SetOwner(v []byte) error { - return capnp.Struct(s).SetData(0, v) -} - -// Publications_list_Params_List is a list of Publications_list_Params. -type Publications_list_Params_List = capnp.StructList[Publications_list_Params] - -// NewPublications_list_Params creates a new list of Publications_list_Params. -func NewPublications_list_Params_List(s *capnp.Segment, sz int32) (Publications_list_Params_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}, sz) - return capnp.StructList[Publications_list_Params](l), err -} - -// Publications_list_Params_Future is a wrapper for a Publications_list_Params promised by a client call. -type Publications_list_Params_Future struct{ *capnp.Future } - -func (f Publications_list_Params_Future) Struct() (Publications_list_Params, error) { - p, err := f.Future.Ptr() - return Publications_list_Params(p.Struct()), err -} - -type Publications_list_Results capnp.Struct - -// Publications_list_Results_TypeID is the unique identifier for the type Publications_list_Results. -const Publications_list_Results_TypeID = 0xec1df2a9965771fc - -func NewPublications_list_Results(s *capnp.Segment) (Publications_list_Results, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Publications_list_Results(st), err -} - -func NewRootPublications_list_Results(s *capnp.Segment) (Publications_list_Results, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Publications_list_Results(st), err -} - -func ReadRootPublications_list_Results(msg *capnp.Message) (Publications_list_Results, error) { - root, err := msg.Root() - return Publications_list_Results(root.Struct()), err -} - -func (s Publications_list_Results) String() string { - str, _ := text.Marshal(0xec1df2a9965771fc, capnp.Struct(s)) - return str -} - -func (s Publications_list_Results) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Publications_list_Results) DecodeFromPtr(p capnp.Ptr) Publications_list_Results { - return Publications_list_Results(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Publications_list_Results) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Publications_list_Results) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Publications_list_Results) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Publications_list_Results) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Publications_list_Results) Publications() (capnp.TextList, error) { - p, err := capnp.Struct(s).Ptr(0) - return capnp.TextList(p.List()), err -} - -func (s Publications_list_Results) HasPublications() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s Publications_list_Results) SetPublications(v capnp.TextList) error { - return capnp.Struct(s).SetPtr(0, v.ToPtr()) -} - -// NewPublications sets the publications field to a newly -// allocated capnp.TextList, preferring placement in s's segment. -func (s Publications_list_Results) NewPublications(n int32) (capnp.TextList, error) { - l, err := capnp.NewTextList(capnp.Struct(s).Segment(), n) - if err != nil { - return capnp.TextList{}, err - } - err = capnp.Struct(s).SetPtr(0, l.ToPtr()) - return l, err -} - -// Publications_list_Results_List is a list of Publications_list_Results. -type Publications_list_Results_List = capnp.StructList[Publications_list_Results] - -// NewPublications_list_Results creates a new list of Publications_list_Results. -func NewPublications_list_Results_List(s *capnp.Segment, sz int32) (Publications_list_Results_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}, sz) - return capnp.StructList[Publications_list_Results](l), err -} - -// Publications_list_Results_Future is a wrapper for a Publications_list_Results promised by a client call. -type Publications_list_Results_Future struct{ *capnp.Future } - -func (f Publications_list_Results_Future) Struct() (Publications_list_Results, error) { - p, err := f.Future.Ptr() - return Publications_list_Results(p.Struct()), err -} - -type Publications_deals_Params capnp.Struct - -// Publications_deals_Params_TypeID is the unique identifier for the type Publications_deals_Params. -const Publications_deals_Params_TypeID = 0x889bad5ee80bd4ae - -func NewPublications_deals_Params(s *capnp.Segment) (Publications_deals_Params, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 32, PointerCount: 2}) - return Publications_deals_Params(st), err -} - -func NewRootPublications_deals_Params(s *capnp.Segment) (Publications_deals_Params, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 32, PointerCount: 2}) - return Publications_deals_Params(st), err -} - -func ReadRootPublications_deals_Params(msg *capnp.Message) (Publications_deals_Params, error) { - root, err := msg.Root() - return Publications_deals_Params(root.Struct()), err -} - -func (s Publications_deals_Params) String() string { - str, _ := text.Marshal(0x889bad5ee80bd4ae, capnp.Struct(s)) - return str -} - -func (s Publications_deals_Params) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Publications_deals_Params) DecodeFromPtr(p capnp.Ptr) Publications_deals_Params { - return Publications_deals_Params(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Publications_deals_Params) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Publications_deals_Params) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Publications_deals_Params) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Publications_deals_Params) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Publications_deals_Params) Ns() (string, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.Text(), err -} - -func (s Publications_deals_Params) HasNs() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s Publications_deals_Params) NsBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.TextBytes(), err -} - -func (s Publications_deals_Params) SetNs(v string) error { - return capnp.Struct(s).SetText(0, v) -} - -func (s Publications_deals_Params) Rel() (string, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.Text(), err -} - -func (s Publications_deals_Params) HasRel() bool { - return capnp.Struct(s).HasPtr(1) -} - -func (s Publications_deals_Params) RelBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.TextBytes(), err -} - -func (s Publications_deals_Params) SetRel(v string) error { - return capnp.Struct(s).SetText(1, v) -} - -func (s Publications_deals_Params) Limit() uint32 { - return capnp.Struct(s).Uint32(0) -} - -func (s Publications_deals_Params) SetLimit(v uint32) { - capnp.Struct(s).SetUint32(0, v) -} - -func (s Publications_deals_Params) Offset() uint64 { - return capnp.Struct(s).Uint64(8) -} - -func (s Publications_deals_Params) SetOffset(v uint64) { - capnp.Struct(s).SetUint64(8, v) -} - -func (s Publications_deals_Params) Before() int64 { - return int64(capnp.Struct(s).Uint64(16)) -} - -func (s Publications_deals_Params) SetBefore(v int64) { - capnp.Struct(s).SetUint64(16, uint64(v)) -} - -func (s Publications_deals_Params) After() int64 { - return int64(capnp.Struct(s).Uint64(24)) -} - -func (s Publications_deals_Params) SetAfter(v int64) { - capnp.Struct(s).SetUint64(24, uint64(v)) -} - -// Publications_deals_Params_List is a list of Publications_deals_Params. -type Publications_deals_Params_List = capnp.StructList[Publications_deals_Params] - -// NewPublications_deals_Params creates a new list of Publications_deals_Params. -func NewPublications_deals_Params_List(s *capnp.Segment, sz int32) (Publications_deals_Params_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 32, PointerCount: 2}, sz) - return capnp.StructList[Publications_deals_Params](l), err -} - -// Publications_deals_Params_Future is a wrapper for a Publications_deals_Params promised by a client call. -type Publications_deals_Params_Future struct{ *capnp.Future } - -func (f Publications_deals_Params_Future) Struct() (Publications_deals_Params, error) { - p, err := f.Future.Ptr() - return Publications_deals_Params(p.Struct()), err -} - -type Publications_deals_Results capnp.Struct - -// Publications_deals_Results_TypeID is the unique identifier for the type Publications_deals_Results. -const Publications_deals_Results_TypeID = 0x8b0e78e7cb3c1c68 - -func NewPublications_deals_Results(s *capnp.Segment) (Publications_deals_Results, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Publications_deals_Results(st), err -} - -func NewRootPublications_deals_Results(s *capnp.Segment) (Publications_deals_Results, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Publications_deals_Results(st), err -} - -func ReadRootPublications_deals_Results(msg *capnp.Message) (Publications_deals_Results, error) { - root, err := msg.Root() - return Publications_deals_Results(root.Struct()), err -} - -func (s Publications_deals_Results) String() string { - str, _ := text.Marshal(0x8b0e78e7cb3c1c68, capnp.Struct(s)) - return str -} - -func (s Publications_deals_Results) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Publications_deals_Results) DecodeFromPtr(p capnp.Ptr) Publications_deals_Results { - return Publications_deals_Results(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Publications_deals_Results) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Publications_deals_Results) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Publications_deals_Results) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Publications_deals_Results) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Publications_deals_Results) Deals() (capnp2.DealInfo_List, error) { - p, err := capnp.Struct(s).Ptr(0) - return capnp2.DealInfo_List(p.List()), err -} - -func (s Publications_deals_Results) HasDeals() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s Publications_deals_Results) SetDeals(v capnp2.DealInfo_List) error { - return capnp.Struct(s).SetPtr(0, v.ToPtr()) -} - -// NewDeals sets the deals field to a newly -// allocated capnp2.DealInfo_List, preferring placement in s's segment. -func (s Publications_deals_Results) NewDeals(n int32) (capnp2.DealInfo_List, error) { - l, err := capnp2.NewDealInfo_List(capnp.Struct(s).Segment(), n) - if err != nil { - return capnp2.DealInfo_List{}, err - } - err = capnp.Struct(s).SetPtr(0, l.ToPtr()) - return l, err -} - -// Publications_deals_Results_List is a list of Publications_deals_Results. -type Publications_deals_Results_List = capnp.StructList[Publications_deals_Results] - -// NewPublications_deals_Results creates a new list of Publications_deals_Results. -func NewPublications_deals_Results_List(s *capnp.Segment, sz int32) (Publications_deals_Results_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}, sz) - return capnp.StructList[Publications_deals_Results](l), err -} - -// Publications_deals_Results_Future is a wrapper for a Publications_deals_Results promised by a client call. -type Publications_deals_Results_Future struct{ *capnp.Future } - -func (f Publications_deals_Results_Future) Struct() (Publications_deals_Results, error) { - p, err := f.Future.Ptr() - return Publications_deals_Results(p.Struct()), err -} - -type Publications_latestDeals_Params capnp.Struct - -// Publications_latestDeals_Params_TypeID is the unique identifier for the type Publications_latestDeals_Params. -const Publications_latestDeals_Params_TypeID = 0x90b6622e0669b417 - -func NewPublications_latestDeals_Params(s *capnp.Segment) (Publications_latestDeals_Params, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 24, PointerCount: 2}) - return Publications_latestDeals_Params(st), err -} - -func NewRootPublications_latestDeals_Params(s *capnp.Segment) (Publications_latestDeals_Params, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 24, PointerCount: 2}) - return Publications_latestDeals_Params(st), err -} - -func ReadRootPublications_latestDeals_Params(msg *capnp.Message) (Publications_latestDeals_Params, error) { - root, err := msg.Root() - return Publications_latestDeals_Params(root.Struct()), err -} - -func (s Publications_latestDeals_Params) String() string { - str, _ := text.Marshal(0x90b6622e0669b417, capnp.Struct(s)) - return str -} - -func (s Publications_latestDeals_Params) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Publications_latestDeals_Params) DecodeFromPtr(p capnp.Ptr) Publications_latestDeals_Params { - return Publications_latestDeals_Params(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Publications_latestDeals_Params) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Publications_latestDeals_Params) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Publications_latestDeals_Params) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Publications_latestDeals_Params) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Publications_latestDeals_Params) Ns() (string, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.Text(), err -} - -func (s Publications_latestDeals_Params) HasNs() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s Publications_latestDeals_Params) NsBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.TextBytes(), err -} - -func (s Publications_latestDeals_Params) SetNs(v string) error { - return capnp.Struct(s).SetText(0, v) -} - -func (s Publications_latestDeals_Params) Rel() (string, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.Text(), err -} - -func (s Publications_latestDeals_Params) HasRel() bool { - return capnp.Struct(s).HasPtr(1) -} - -func (s Publications_latestDeals_Params) RelBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.TextBytes(), err -} - -func (s Publications_latestDeals_Params) SetRel(v string) error { - return capnp.Struct(s).SetText(1, v) -} - -func (s Publications_latestDeals_Params) N() uint32 { - return capnp.Struct(s).Uint32(0) -} - -func (s Publications_latestDeals_Params) SetN(v uint32) { - capnp.Struct(s).SetUint32(0, v) -} - -func (s Publications_latestDeals_Params) Before() int64 { - return int64(capnp.Struct(s).Uint64(8)) -} - -func (s Publications_latestDeals_Params) SetBefore(v int64) { - capnp.Struct(s).SetUint64(8, uint64(v)) -} - -func (s Publications_latestDeals_Params) After() int64 { - return int64(capnp.Struct(s).Uint64(16)) -} - -func (s Publications_latestDeals_Params) SetAfter(v int64) { - capnp.Struct(s).SetUint64(16, uint64(v)) -} - -// Publications_latestDeals_Params_List is a list of Publications_latestDeals_Params. -type Publications_latestDeals_Params_List = capnp.StructList[Publications_latestDeals_Params] - -// NewPublications_latestDeals_Params creates a new list of Publications_latestDeals_Params. -func NewPublications_latestDeals_Params_List(s *capnp.Segment, sz int32) (Publications_latestDeals_Params_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 24, PointerCount: 2}, sz) - return capnp.StructList[Publications_latestDeals_Params](l), err -} - -// Publications_latestDeals_Params_Future is a wrapper for a Publications_latestDeals_Params promised by a client call. -type Publications_latestDeals_Params_Future struct{ *capnp.Future } - -func (f Publications_latestDeals_Params_Future) Struct() (Publications_latestDeals_Params, error) { - p, err := f.Future.Ptr() - return Publications_latestDeals_Params(p.Struct()), err -} - -type Publications_latestDeals_Results capnp.Struct - -// Publications_latestDeals_Results_TypeID is the unique identifier for the type Publications_latestDeals_Results. -const Publications_latestDeals_Results_TypeID = 0xe7da36d32d5316b8 - -func NewPublications_latestDeals_Results(s *capnp.Segment) (Publications_latestDeals_Results, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Publications_latestDeals_Results(st), err -} - -func NewRootPublications_latestDeals_Results(s *capnp.Segment) (Publications_latestDeals_Results, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Publications_latestDeals_Results(st), err -} - -func ReadRootPublications_latestDeals_Results(msg *capnp.Message) (Publications_latestDeals_Results, error) { - root, err := msg.Root() - return Publications_latestDeals_Results(root.Struct()), err -} - -func (s Publications_latestDeals_Results) String() string { - str, _ := text.Marshal(0xe7da36d32d5316b8, capnp.Struct(s)) - return str -} - -func (s Publications_latestDeals_Results) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Publications_latestDeals_Results) DecodeFromPtr(p capnp.Ptr) Publications_latestDeals_Results { - return Publications_latestDeals_Results(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Publications_latestDeals_Results) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Publications_latestDeals_Results) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Publications_latestDeals_Results) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Publications_latestDeals_Results) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Publications_latestDeals_Results) Deals() (capnp2.DealInfo_List, error) { - p, err := capnp.Struct(s).Ptr(0) - return capnp2.DealInfo_List(p.List()), err -} - -func (s Publications_latestDeals_Results) HasDeals() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s Publications_latestDeals_Results) SetDeals(v capnp2.DealInfo_List) error { - return capnp.Struct(s).SetPtr(0, v.ToPtr()) -} - -// NewDeals sets the deals field to a newly -// allocated capnp2.DealInfo_List, preferring placement in s's segment. -func (s Publications_latestDeals_Results) NewDeals(n int32) (capnp2.DealInfo_List, error) { - l, err := capnp2.NewDealInfo_List(capnp.Struct(s).Segment(), n) - if err != nil { - return capnp2.DealInfo_List{}, err - } - err = capnp.Struct(s).SetPtr(0, l.ToPtr()) - return l, err -} - -// Publications_latestDeals_Results_List is a list of Publications_latestDeals_Results. -type Publications_latestDeals_Results_List = capnp.StructList[Publications_latestDeals_Results] - -// NewPublications_latestDeals_Results creates a new list of Publications_latestDeals_Results. -func NewPublications_latestDeals_Results_List(s *capnp.Segment, sz int32) (Publications_latestDeals_Results_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}, sz) - return capnp.StructList[Publications_latestDeals_Results](l), err -} - -// Publications_latestDeals_Results_Future is a wrapper for a Publications_latestDeals_Results promised by a client call. -type Publications_latestDeals_Results_Future struct{ *capnp.Future } - -func (f Publications_latestDeals_Results_Future) Struct() (Publications_latestDeals_Results, error) { - p, err := f.Future.Ptr() - return Publications_latestDeals_Results(p.Struct()), err -} - -const schema_9cf9878fd3dd8473 = "x\xda\xa4WmlTU\x1a~\x9fsfz\xe7\xab" + - "\x1f\x87)\xcbG\x96\xccnC\x13h\xb2eK7K" + - "\xb6,\x99!,\xd9\x84\xfd\xd3\xc3\xfe &\"\xdcN" + - "o\x99\x91\x99\xe90\xf7\x0e4\xa8\x09\xd5\x02E!V" + - "\x05\x03\x01\x04\x0d$4\x8a\x01C\x94\x80\x10\x7fH\x8d" + - "\x1a?\xe1\x87\x10\x1b\x13\xa2A\x8d\xfc1*\xc1@\xae" + - "9w\xe6\xde^\x95\xc6\x0e\xfd7w\xee{\xce\xf3>" + - "\xcf\xf3\xbe\xe7\xbc\xf7\xefK\x03\xa9@G\xfd\x9a\x081" + - "9\x10\xac\xb3\xaf~2\xa8\x9dk\xfah;\x89v\x10" + - "\x05\x03\x1aQ\xa7\x08~\x0aB\xbc5x\x83`\xbfz" + - "%\xfa\xf5C'\x0f\x0e\x93lG\x80(\xc8T\xc4\xed" + - "\xe05\x10:\xeb\xeb\xd6\x80`\x7fy\xe4f\xfa\xbf\xcb" + - "w\xecR!\xde&\x0fh\xd7UH^K\xa8\x90\xcc" + - "\x9f\xff\xfd\xfe\x8d\x81\x86\xa7\xaa0P\x11\x83!\x15\x11" + - "\xdf\x17J\x12\xece\xe1\xcd-\xe1\xd6\xbe\xdd$\x96x" + - "\x01\x97B-\x8c\x10\x1fw\x02f\x9d\xc9\xd6\xb5\xf7\xbc" + - ">\xa2@\xb8\x9b\xc7\xddP\x84\x11:g\x86\x1d\x90\x1f" + - "\x0fm{\"\xfc\xc2\xc5\x11\xff\x1e\xad\x91\xb9j\x8fe" + - "\x11\xb5\xc7\xffN\x9f\xd7\x1e\xdf\x1c>\\M\xd4\xc9s" + - "m\xe4[\x95\xc5&' \xb3\xfe\xce\xc0\xf2\xfd\xec%" + - "\x7f\x9a\xcfD\x1c5\x8e;\x01#\xa7\xf9?\xae?\xf9" + - "\xec\x19\x12\xed\xdc\x1e\x9f\xf5C\xe6\xea_>\xbfK\x84" + - "\xceK\x91s\x88\x8fG4\xa2\xf8\xd5\xc8\xce\xf8\xc2\xa8" + - "Fd\x7f\xf5\xdc\x87\xc5\xe2\xe8\x1b\xefT\x12\xaah\x1b" + - "mc\x14\xb0\x1b\xdej\xfby\xc9\xca\xf2\x07\xbe7\xe1" + - "h\x8bz\xf3^\xf4\xdc\xcb\xc3g7|\xacrd." + - "OD\x1d\xa9fF\x95#\x1d\xb7N-\xed\xb9\xd8r" + - "\xc5\x9f\xe4\xcd\xa8\xc3\x021\x95\xe4\x85\x85?\x1d\xf9\xac" + - "\xf3\x91/*\x01\xce\xe6\xad\xb1k\xa0\x80}\xf6O\xff" + - "\xff\xdb\xe5\x7f^\xbb\xe1_:'6C)\xd4\xe1," + - "\xbd\xb3i\xcd\xf3\xa3\xdf\xcf\xfb\xce\x1f\xa0\xab\xb5\x88\x97" + - "\x9d\x00\x8f\xb3\xf8+\xb7\xcd\xa1\xf1\xcbO\xef\xbc}H" + - "\x090\x1a+!~!6\x8b\xa8\xf3\xdd\xd8N\xc4/" + - "\xd4k4d\x177nX\xd4\xa3\x9b\xd9\xbaB\xb1\xd4" + - "\xbf9\xdbk\x94\x16\xb9?\xda\xd3z\xb1P\xec\xea." + - "\xf7\xe4\xb2i\xdd\xca\xf6\x17\xcc\xf6b\xd9\xcc\xcc\xef\xd6" + - "Kz\x1e\xa6l\xe2\x01\xa2\x00\x88\x84>\x97H>\xc8" + - "!3\x0c\x02hV\xe6\x09\xa3\x85H\xae\xe7\x909\x06" + - "\xc1X\xb3RKdUd/\x87,2\x08\xce\x9bU" + - "\xa9\x88\xbc\x8a\xccpH\x8b\x81\x17L\xc4\x88!F\xd0" + - "JF\xce\xfd\xcd\xad\x014\xd9\xebn\x97\xe7ik\xe3" + - "\xdf\x10\x01M\x04\xcd\xccn@=1\xd4\x13je\xd2" + - "k\xe89\xd3\xa1\xc2\xf3\xa6\x9c\xedQ9\xa0\x12\xdc\xcb" + - "!\x8f\xfa\xa8\x1cV\x09\xee\xe7\x90\xc7\x18Pe\xf2\xe2" + - "b\"y\x88C\x9ePLPar\xbc\x8bH\x1e\xe5" + - "\x90\xaf0\x88\x00kV\x1d)F\xd5\x9f\xc78\xe4)" + - "\x06\x11\xe4\xcd\x08\x12\x89\x93j\xf9\x09\x0eyfR\xce" + - "\x89\\6\x9f\xb5\x10\"\x86\x10!\xd9\xdf\xd7g\x1a\x16" + - "\xc2\xc4\x10&${\x8c\xbe\xfe\x92\x81 1\x04\x09\x09" + - "\xbd\xcf2J\xeeS\xadb\xa4K\x86n\x19J\x0dM" + - "\xcf\x9b\xb2\xd9S\xe31\xa5\xc6\x00\x87\x1c\xf2\xa91\xa8" + - "\xd4x\x94C\x0e\xfb\x8c\xdd\xaeHn\xe3\x90\xbb}\xc6" + - "\xeeR$\x878\xe4\x08\x03\x02\x155\xf6l%\x92\xbb" + - "9\xe4\xfeI\x89'\xcdt\xc6\xc8\xebh\xb2W\x8c\xbd" + - "9\xb6o\xf1\xd8kU\xc3\x13\xfd[\x0aF\xc9\xb3<" + - "\xad\xa73\xc6\xba\xde2%K\x0e\x91\xfb\xa5_\xa9\x85" + - "\xd5\x86Y\xd6r\x96)\x03\x1e\xfdz\x95\x7f\x88C\xce" + - "gH8Qh ts\xa0\xc9\xde\xb1\xe0|\xf9\xed" + - "[\x07\xc7Tj\x0d>Lmj\x98+\xf4\\\xaeG" + - "Ool\xdfR\xca\xfa\xa4\xbf\x07v3C\"\x9d)" + - "\x176\xfe\xae\xd4\xa7\x08\x95\xd3-\xc3\xb4\xfe\xe3\x15|" + - "\xde$\xaa\xc5c\xb7\xe2\xb7\xcf\xf0[\\\xad\xf8]]" + - "\x13\x16{\x15\xbfG\xe5>\xcc!\xf7N\xea1\x0a^" + - "aO\xa9\x92k\x95\xb5\xb7\xbf`x\xed\xedS\xb5e" + - "B\xd5\xe9\x1c\x1f\xd5\x8eYm\x98\x8d\xe5\xdf\xd4L\xd7" + - "\x04B\xd2\x18\xc8\x9a\x96\x09\x10\x03j\x07\xc9eM\xcb" + - ";m'\xa9\x8c_w\x84\x0b\x10\x9c\xaaZ\xc9\x8a\\" + - "\xdd\x80\x0c\xf1 \x91w\xcf\xc3\xbd\x1bE\xc7bb\xa2" + - "U\xc3\xc4\xfd\x0d\xf7v\x14s\xda\x88\x89z-\xe1\x14" + - "q\x0a\x8dJ\xf5\x14\xba1\xddvpu\x9d\x9e\xfdn" + - "G\xd7\xaa{\xb9\x98\xeb\xd7{\xbd\x9e\xac\xe1\x9es[" + - "%\xdb\xe6\xbf\xe6\xaa\xad\x92_M$s\x1cr`\xd2" + - "\xaeh4\xb3[\x0d\xf7\x88\xb7\xadl\xde0-=O" + - "(\xde\xef\xd1V\xa5r\xaf:]E$c\x1cr6" + - "S'iE7\"\x82\x98\x18\xa2\x08\x10\xb5c:C" + - "\x82\xd2>\xc7kw\xd0\x7fX9{X\x98\xee\x89\\" + - "K\xb7\xb9i\xfb!\x1f\xae\x0a\xb5\x80\xc1.VWP" + - "\xa3Z\xe3b+\xf7\xfc\x88\x81?BL8\x902\x00" + - "\xff\xc4\x8aU\xf6\x8a\x09\x1f\xe4l\xa7\x1f\xdd\xd9\x1d\xee" + - "l,Nw\x11\x13\xc7U?\xba\xdf\x06p\x07Jq" + - "@\xf5\xe3\x1e\x0d\xcc\x1bS\xe1N\xa3bP\xad+k" + - "\xe0\xde\x14\x0dw\x9aT\xf5\xca\xc4Z\x0d\x01\xefs\x02" + - "\xee\x17\x81\x90\xaa\xffWj\x08z#>\xdc1U\xfc" + - "\xab\x87\x98\xe8\xd0\x92\x95\xe30\x85F\xe5}\x0a\xc9J" + - "\xd9\xa5\xd0\xa8DMU\x9dJ\xc1v\xdd%\xcdy\xee" + - "\x06~\x09\x00\x00\xff\xff\x86\xb4{e" - -func RegisterSchema(reg *schemas.Registry) { - reg.Register(&schemas.Schema{ - String: schema_9cf9878fd3dd8473, - Nodes: []uint64{ - 0x85cf10ba0781d1d9, - 0x889bad5ee80bd4ae, - 0x8986414763ed9fe4, - 0x8b0e78e7cb3c1c68, - 0x8c6625092276093d, - 0x90b6622e0669b417, - 0x90be9e0983809cf5, - 0x9d09768207bbb14b, - 0xa202984178fc6068, - 0xb4928ae23403b190, - 0xc7b7a97070ce93e5, - 0xcd754537fa2ac00e, - 0xd067b888abba0bca, - 0xd422be623bb0f731, - 0xdf7b33d89ff629bd, - 0xe7da36d32d5316b8, - 0xec1df2a9965771fc, - 0xfddc20d968f417dd, - }, - Compressed: true, - }) -} diff --git a/pkg/basinprovider/provider.go b/pkg/basinprovider/provider.go index be77524..79034fa 100644 --- a/pkg/basinprovider/provider.go +++ b/pkg/basinprovider/provider.go @@ -1,662 +1,153 @@ package basinprovider import ( - "bytes" "context" - "crypto/sha1" - "crypto/tls" + "encoding/json" "errors" "fmt" "io" - "log/slog" - "net" + "net/http" + "net/url" "strings" "time" - "capnproto.org/go/capnp/v3" - "capnproto.org/go/capnp/v3/rpc" - "github.com/cenkalti/backoff/v4" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/crypto" "github.com/tablelandnetwork/basin-cli/internal/app" - basincapnp "github.com/tablelandnetwork/basin-cli/pkg/capnp" - "golang.org/x/crypto/sha3" ) -// maxPushAttempts is the max number of attempts used to dial the provider. -const maxPushAttempts = 10 - -// uploadChunk is the size of the chunk when uploading a file. -const uploadChunk = 1 << 20 // 2 ^ 20 bytes = 1MiB - // BasinProvider implements the app.BasinProvider interface. type BasinProvider struct { - p Publications provider string - secure bool - ctx context.Context - cancel context.CancelFunc + client *http.Client } var _ app.BasinProvider = (*BasinProvider)(nil) // New creates a new BasinProvider. -func New(ctx context.Context, provider string, secure bool) (*BasinProvider, error) { - client, cancel, err := connectWithBackoff(ctx, provider, secure) - if err != nil { - return nil, err +func New(provider string) *BasinProvider { + client := &http.Client{ + Timeout: 10 * time.Second, } return &BasinProvider{ - p: client, provider: provider, - secure: secure, - ctx: ctx, - cancel: cancel, - }, nil -} - -func connect(ctx context.Context, provider string, secure bool) (Publications, func(), error) { - var conn io.ReadWriteCloser - var err error - if secure { - conn, err = tls.Dial("tcp", provider, nil) - if err != nil { - return Publications{}, func() {}, fmt.Errorf("failed to connect to provider: %s", err) - } - } else { - conn, err = net.Dial("tcp", provider) - if err != nil { - return Publications{}, func() {}, fmt.Errorf("failed to connect to provider: %s", err) - } - } - - rpcConn := rpc.NewConn(rpc.NewStreamTransport(conn), nil) - cancel := func() { - if err := rpcConn.Close(); err != nil { - slog.Error(err.Error()) - } - } - - return Publications(rpcConn.Bootstrap(ctx)), cancel, nil -} - -func connectWithBackoff( - ctx context.Context, provider string, secure bool, -) (client Publications, cancel func(), err error) { - exbo := backoff.NewExponentialBackOff() - - for i := 0; i < maxPushAttempts; i++ { - client, cancel, err = connect(ctx, provider, secure) - if err != nil { - wait := exbo.NextBackOff() - slog.Info("connect failed", "attempt", i+1, "sleep", wait) - time.Sleep(wait) - continue - } - return - } - - return -} - -// Create creates a publication on Basin Provider. -func (bp *BasinProvider) Create( - ctx context.Context, ns string, rel string, schema basincapnp.Schema, owner common.Address, cacheDuration int64, -) (bool, error) { - if cacheDuration < 0 { - return false, errors.New("cache duration cannot be less than zero") - } - - f, release := bp.p.Create(ctx, func(bp Publications_create_Params) error { - if err := bp.SetNs(ns); err != nil { - return fmt.Errorf("setting ns: %s", err) - } - if err := bp.SetRel(rel); err != nil { - return fmt.Errorf("setting rel: %s", err) - } - if err := bp.SetSchema(schema); err != nil { - return fmt.Errorf("setting schema: %s", err) - } - if err := bp.SetOwner(owner.Bytes()); err != nil { - return fmt.Errorf("setting owner: %s", err) - } - - bp.SetCache_duration(cacheDuration) - - return nil - }) - defer release() - - results, err := f.Struct() - if err != nil { - return false, fmt.Errorf("waiting for create: %s", err) - } - - return results.Exists(), nil -} - -// Upload uploads a file to th server. -func (bp *BasinProvider) Upload( - ctx context.Context, - ns string, - rel string, - size uint64, - r io.Reader, - signer *app.Signer, - progress io.Writer, - timestamp app.Timestamp, -) error { - uploadFuture, uploadRelease := bp.p.Upload(ctx, func(p Publications_upload_Params) error { - if err := p.SetNs(ns); err != nil { - return fmt.Errorf("setting sig: %s", err) - } - - if err := p.SetRel(rel); err != nil { - return fmt.Errorf("setting sig: %s", err) - } - - p.SetSize(size) - p.SetTimestamp(timestamp.Seconds()) - - return nil - }) - defer uploadRelease() - - callback := uploadFuture.Callback() - - buf := make([]byte, uploadChunk) - for { - n, err := r.Read(buf[:cap(buf)]) - buf = buf[:n] - if err != nil { - if err != io.EOF { - return fmt.Errorf("read file: %s", err) - } - break - } - signer.Sum(buf) - if err := bp.write(ctx, callback, buf); err != nil { - return fmt.Errorf("write chunk: %s", err) - } - _, _ = progress.Write(buf) - } - - doneFuture, doneRelease := callback.Done(ctx, func(p Publications_Callback_done_Params) error { - signature, err := signer.Sign() - if err != nil { - return fmt.Errorf("sign: %s", err) - } - - if err := p.SetSig(signature); err != nil { - return fmt.Errorf("setting sig: %s", err) - } - - return nil - }) - defer doneRelease() - if _, err := doneFuture.Struct(); err != nil { - return fmt.Errorf("done: %s", err) - } - - if err := bp.p.WaitStreaming(); err != nil { - return fmt.Errorf("wait streaming: %s", err) - } - - return nil -} - -// List lists all publications from a given address. -func (bp *BasinProvider) List(ctx context.Context, owner common.Address) ([]string, error) { - f, release := bp.p.List(ctx, func(call Publications_list_Params) error { - if err := call.SetOwner(owner.Bytes()); err != nil { - return fmt.Errorf("setting owner") - } - return nil - }) - defer release() - - results, err := f.Struct() - if err != nil { - return []string{}, fmt.Errorf("waiting list results: %s", err) - } - - textList, err := results.Publications() - if err != nil { - return []string{}, fmt.Errorf("init publications: %s", err) - } - - pubs := make([]string, textList.Len()) - for i := 0; i < textList.Len(); i++ { - pubs[i], err = textList.At(i) - if err != nil { - return []string{}, fmt.Errorf("failed to get string from text list: %s", err) - } - } - - return pubs, nil -} - -// Deals lists deals from a given publication. -func (bp *BasinProvider) Deals( - ctx context.Context, ns string, rel string, limit uint32, offset uint64, before app.Timestamp, after app.Timestamp, -) ([]app.DealInfo, error) { - f, release := bp.p.Deals(ctx, func(call Publications_deals_Params) error { - if err := call.SetNs(ns); err != nil { - return fmt.Errorf("setting ns") - } - - if err := call.SetRel(rel); err != nil { - return fmt.Errorf("setting rel") - } - - call.SetLimit(limit) - call.SetOffset(offset) - call.SetBefore(before.Seconds()) - call.SetAfter(after.Seconds()) - - return nil - }) - defer release() - - results, err := f.Struct() - if err != nil { - return []app.DealInfo{}, fmt.Errorf("waiting list results: %s", err) - } - - list, err := results.Deals() - if err != nil { - return []app.DealInfo{}, fmt.Errorf("result deals: %s", err) - } - - deals := make([]app.DealInfo, list.Len()) - for i := 0; i < list.Len(); i++ { - deal := list.At(i) - cid, err := deal.Cid() - if err != nil { - return []app.DealInfo{}, fmt.Errorf("failed to get cid: %s", err) - } - - expiresAt, err := deal.ExpiresAt() - if err != nil { - return []app.DealInfo{}, fmt.Errorf("failed to get expires at: %s", err) - } - - deals[i] = app.DealInfo{ - CID: cid, - Timestamp: deal.Timestamp(), - IsArchived: deal.Archived(), - Size: deal.Size(), - CacheExpiry: expiresAt, - } - } - - return deals, nil -} - -// LatestDeals lists latest deals from a given publication. -func (bp *BasinProvider) LatestDeals( - ctx context.Context, ns string, rel string, n uint32, before app.Timestamp, after app.Timestamp, -) ([]app.DealInfo, error) { - f, release := bp.p.LatestDeals(ctx, func(call Publications_latestDeals_Params) error { - if err := call.SetNs(ns); err != nil { - return fmt.Errorf("setting ns") - } - - if err := call.SetRel(rel); err != nil { - return fmt.Errorf("setting rel") - } - - call.SetN(n) - call.SetBefore(before.Seconds()) - call.SetAfter(after.Seconds()) - return nil - }) - defer release() - - results, err := f.Struct() - if err != nil { - return []app.DealInfo{}, fmt.Errorf("waiting list results: %s", err) - } - - list, err := results.Deals() - if err != nil { - return []app.DealInfo{}, fmt.Errorf("result deals: %s", err) - } - - deals := make([]app.DealInfo, list.Len()) - for i := 0; i < list.Len(); i++ { - deal := list.At(i) - cid, err := deal.Cid() - if err != nil { - return []app.DealInfo{}, fmt.Errorf("failed to get cid: %s", err) - } - - expiresAt, err := deal.ExpiresAt() - if err != nil { - return []app.DealInfo{}, fmt.Errorf("failed to get expires at: %s", err) - } - - deals[i] = app.DealInfo{ - CID: cid, - Timestamp: deal.Timestamp(), - IsArchived: deal.Archived(), - Size: deal.Size(), - CacheExpiry: expiresAt, - } - } - - return deals, nil -} - -// Reconnect with the Basin Provider. -func (bp *BasinProvider) Reconnect() error { - bp.cancel() - client, cancel, err := connectWithBackoff(bp.ctx, bp.provider, bp.secure) - if err != nil { - return err + client: client, } - bp.p = client - bp.cancel = cancel - return nil -} - -// Close the connection with the Basin Provider. -func (bp *BasinProvider) Close() { - bp.cancel() } -func (bp *BasinProvider) write(ctx context.Context, callback Publications_Callback, buf []byte) error { - f, release := callback.Write(ctx, func(p Publications_Callback_write_Params) error { - return p.SetChunk(buf) - }) - defer release() - if _, err := f.Struct(); err != nil { - return fmt.Errorf("waiting for write: %s", err) - } - - return nil -} - -// BasinServerMock is a mocked version of a server implementation using for testing. -type BasinServerMock struct { - publications map[string]struct{} - owner map[string]string - txs map[basincapnp.Tx]bool - - uploads map[string]map[int]*callbackMock -} +// CreateVault creates a vault. +func (bp *BasinProvider) CreateVault(ctx context.Context, params app.CreateVaultParams) error { + form := url.Values{} + form.Add("account", params.Account.Hex()) + form.Add("cache", fmt.Sprint(params.CacheDuration)) -// NewBasinServerMock creates new *BasinServerMock. -func NewBasinServerMock() *BasinServerMock { - return &BasinServerMock{ - publications: make(map[string]struct{}), - owner: make(map[string]string), - txs: make(map[basincapnp.Tx]bool), - uploads: make(map[string]map[int]*callbackMock), - } -} - -// Push handles the Push request. -func (s *BasinServerMock) Push(_ context.Context, call Publications_push) error { - ns, err := call.Args().Ns() - if err != nil { - return err - } - - tx, err := call.Args().Tx() + req, err := http.NewRequestWithContext( + ctx, http.MethodPost, fmt.Sprintf("%s/vaults/%s", bp.provider, params.Vault), strings.NewReader(form.Encode())) if err != nil { - return err + return fmt.Errorf("could not create request: %s", err) } + req.Header.Add("Content-Type", "application/x-www-form-urlencoded") - sig, err := call.Args().Sig() + resp, err := bp.client.Do(req) if err != nil { - return err + return fmt.Errorf("request to create vault failed: %s", err) } + defer func() { + _ = resp.Body.Close() + }() - data, err := capnp.Canonicalize(tx.ToPtr().Struct()) - if err != nil { - return fmt.Errorf("canonicalize: %s", err) + if resp.StatusCode != http.StatusCreated { + return errors.New("account was not created") } - err = s.verifySignature(ns, data, sig) - s.txs[tx] = err == nil - - slog.Info("Tx received", "verified", err == nil) - return nil } -// Create handles the Create request. -func (s *BasinServerMock) Create(_ context.Context, call Publications_create) error { - ns, err := call.Args().Ns() - if err != nil { - return err - } - - rel, err := call.Args().Rel() - if err != nil { - return err - } - - schema, err := call.Args().Schema() +// ListVaults lists all vaults from a given account. +func (bp *BasinProvider) ListVaults( + ctx context.Context, params app.ListVaultsParams, +) ([]app.Vault, error) { + req, err := http.NewRequestWithContext( + ctx, http.MethodGet, fmt.Sprintf("%s/vaults/?account=%s", bp.provider, params.Account.Hex()), nil) if err != nil { - return err + return []app.Vault{}, fmt.Errorf("could not create request: %s", err) } - owner, err := call.Args().Owner() + resp, err := bp.client.Do(req) if err != nil { - return err + return []app.Vault{}, fmt.Errorf("request to list vaults failed: %s", err) } + defer func() { + _ = resp.Body.Close() + }() - slog.Info("Publication created", "namespace", ns, "relation", rel, "owner", common.BytesToAddress(owner).Hex()) - - columns, _ := schema.Columns() - for i := 0; i < columns.Len(); i++ { - name, _ := columns.At(i).Name() - typ, _ := columns.At(i).Type() - isNull := columns.At(i).IsNullable() - isPk := columns.At(i).IsPartOfPrimaryKey() - slog.Info("Column schema", "name", name, "typ", typ, "is_null", isNull, "is_pk", isPk) + var vaults []app.Vault + if err := json.NewDecoder(resp.Body).Decode(&vaults); err != nil { + return []app.Vault{}, fmt.Errorf("failed to read response: %s", err) } - - results, _ := call.AllocResults() - _, ok := s.publications[fmt.Sprintf("%s.%s", ns, rel)] - if ok { - results.SetExists(true) - } else { - s.publications[fmt.Sprintf("%s.%s", ns, rel)] = struct{}{} - results.SetExists(false) - } - - return nil + return vaults, nil } -// Upload handles the Write request. -func (s *BasinServerMock) Upload(_ context.Context, call Publications_upload) error { - ns, err := call.Args().Ns() - if err != nil { - return err - } - - rel, err := call.Args().Rel() - if err != nil { - return err - } - - fmt.Println(call.Args().Size()) - - results, err := call.AllocResults() - if err != nil { - return err - } - - callback := &callbackMock{ - ns: ns, - rel: rel, - } - err = results.SetCallback(Publications_Callback(capnp.NewClient(Publications_Callback_NewServer(callback)))) +// ListVaultEvents lists all events from a given vault. +func (bp *BasinProvider) ListVaultEvents( + ctx context.Context, params app.ListVaultEventsParams, +) ([]app.EventInfo, error) { + req, err := http.NewRequestWithContext( + ctx, http.MethodGet, fmt.Sprintf("%s/vaults/%s/events", bp.provider, params.Vault), nil) if err != nil { - return err + return []app.EventInfo{}, fmt.Errorf("could not create request: %s", err) } - pub := fmt.Sprintf("%s.%s", ns, rel) - _, ok := s.uploads[pub] - if !ok { - s.uploads[pub] = make(map[int]*callbackMock) - } - s.uploads[pub][len(s.uploads[pub])] = callback - - return nil -} - -// Deals lists deals from a given publication. -func (s *BasinServerMock) Deals(_ context.Context, call Publications_deals) error { - ns, _ := call.Args().Ns() - rel, _ := call.Args().Rel() - limit := call.Args().Limit() - offset := call.Args().Offset() - - results, _ := call.AllocResults() - dealInfoList, _ := results.NewDeals(min(int32(limit), int32(len(s.uploads)))) - var i uint32 - for pub, deals := range s.uploads { - parts := strings.Split(pub, ".") - dealNs, dealRel := parts[0], parts[1] - if dealNs != ns || dealRel != rel { - continue - } - - for id, callback := range deals { - if uint64(id) < offset { - continue - } - - if i >= limit { - continue - } - - dealInfo := dealInfoList.At(int(i)) - fakeCID := sha1.Sum(callback.bytes) - _ = dealInfo.SetCid(string(fakeCID[:])) - dealInfo.SetTimestamp(0) - dealInfo.SetArchived(false) - dealInfo.SetSize(30) - } - - return nil - } - - return nil -} - -// LatestDeals lists latest deals from a given publication. -func (s *BasinServerMock) LatestDeals(_ context.Context, call Publications_latestDeals) error { - ns, _ := call.Args().Ns() - rel, _ := call.Args().Rel() - n := call.Args().N() - - results, _ := call.AllocResults() - var i uint32 - for pub, deals := range s.uploads { - parts := strings.Split(pub, ".") - dealNs, dealRel := parts[0], parts[1] - if dealNs != ns || dealRel != rel { - continue - } - - dealInfoList, _ := results.NewDeals(int32(len(s.uploads[pub]))) - for _, callback := range deals { - if i >= n { - continue - } - - dealInfo := dealInfoList.At(int(i)) - fakeCID := sha1.Sum(callback.bytes) - _ = dealInfo.SetCid(string(fakeCID[:])) - dealInfo.SetTimestamp(0) - dealInfo.SetArchived(false) - dealInfo.SetSize(30) - } - - return nil - } - return nil -} - -// List lists all publications from a given address. -func (s *BasinServerMock) List(_ context.Context, call Publications_list) error { - results, err := call.AllocResults() - if err != nil { - return err - } + q := req.URL.Query() + q.Add("limit", fmt.Sprint(params.Limit)) + q.Add("offset", fmt.Sprint(params.Offset)) + q.Add("before", fmt.Sprint(params.Before.Seconds())) + q.Add("after", fmt.Sprint(params.After.Seconds())) + req.URL.RawQuery = q.Encode() - list, err := results.NewPublications(int32(len(s.publications))) + resp, err := bp.client.Do(req) if err != nil { - return err - } - var i int - for pub := range s.publications { - if err := list.Set(i, pub); err != nil { - return err - } - i++ + return []app.EventInfo{}, fmt.Errorf("request to list vault events failed: %s", err) } + defer func() { + _ = resp.Body.Close() + }() - if err := results.SetPublications(list); err != nil { - return fmt.Errorf("set publications: %s", err) + var events []app.EventInfo + if err := json.NewDecoder(resp.Body).Decode(&events); err != nil { + return []app.EventInfo{}, fmt.Errorf("failed to read response: %s", err) } - - return nil + return events, nil } -func (s *BasinServerMock) verifySignature(ns string, message []byte, signature []byte) error { - hash := crypto.Keccak256Hash(message) - sigPublicKey, err := crypto.Ecrecover(hash.Bytes(), signature) +// WriteVaultEvent write an event. +func (bp *BasinProvider) WriteVaultEvent(ctx context.Context, params app.WriteVaultEventParams) error { + req, err := http.NewRequestWithContext( + ctx, + http.MethodPost, + fmt.Sprintf("%s/vaults/%s/events", bp.provider, params.Vault), + io.TeeReader(params.Content, params.ProgressBar), + ) if err != nil { - return fmt.Errorf("ecrecover: %s", err) - } - - address, ok := s.owner[ns] - if !ok { - return errors.New("non existent namespace") + return fmt.Errorf("could not create request: %s", err) } - publicKeyBytes := common.HexToAddress(address).Bytes() + q := req.URL.Query() + q.Add("timestamp", fmt.Sprint(params.Timestamp.Seconds())) + q.Add("signature", fmt.Sprint(params.Signature)) + req.URL.RawQuery = q.Encode() + req.ContentLength = params.Size - h := sha3.NewLegacyKeccak256() - h.Write(sigPublicKey[1:]) - if !bytes.Equal(publicKeyBytes, h.Sum(nil)[12:]) { - return errors.New("failed to verify") + client := &http.Client{ + Timeout: 0, } - return nil -} - -type callbackMock struct { - ns string - rel string - bytes []byte - sig []byte -} - -func (c *callbackMock) Write(_ context.Context, p Publications_Callback_write) error { - chunk, err := p.Args().Chunk() - if err != nil { - return nil - } - - c.bytes = append(c.bytes, chunk...) - - return nil -} - -func (c *callbackMock) Done(_ context.Context, p Publications_Callback_done) error { - signature, err := p.Args().Sig() + resp, err := client.Do(req) if err != nil { - return nil + return fmt.Errorf("request to write vault event failed: %s", err) } + defer func() { + _ = resp.Body.Close() + }() - c.sig = signature return nil } diff --git a/pkg/basinprovider/provider_test.go b/pkg/basinprovider/provider_test.go deleted file mode 100644 index 860164c..0000000 --- a/pkg/basinprovider/provider_test.go +++ /dev/null @@ -1,127 +0,0 @@ -package basinprovider - -import ( - "bytes" - "context" - "crypto/sha1" - "encoding/hex" - "testing" - - "capnproto.org/go/capnp/v3" - "capnproto.org/go/capnp/v3/rpc" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/crypto" - - "github.com/stretchr/testify/require" - "github.com/tablelandnetwork/basin-cli/internal/app" - basincapnp "github.com/tablelandnetwork/basin-cli/pkg/capnp" - "google.golang.org/grpc/test/bufconn" -) - -func TestBasinProvider_CreateAndList(t *testing.T) { - // in this test we create a fake tx, - // send to the server, the server deserialize it and send the value back - - bp, _ := newClientAndServer() - exists, err := bp.Create(context.Background(), "n", "t", basincapnp.Schema{}, common.HexToAddress(""), 0) - require.NoError(t, err) - require.False(t, exists) - - exists, err = bp.Create(context.Background(), "n", "t2", basincapnp.Schema{}, common.HexToAddress(""), 0) - require.NoError(t, err) - require.False(t, exists) - - pubs, err := bp.List(context.Background(), common.HexToAddress("")) - require.NoError(t, err) - require.Equal(t, []string{"n.t", "n.t2"}, pubs) -} - -// Tests if the mocked server received the uploaded content. -func TestBasinProvider_Upload(t *testing.T) { - client, server := newClientAndServer() - - // used for testing - pk := "f81ab2709b7cf1f2ebbbd50bd730b267879a495318f7aac16bbe7caa8a8f2d8d" - privateKey, err := crypto.HexToECDSA(pk) - require.NoError(t, err) - - // Upload data 1 on test.test - filedata1 := []byte{'H', 'e', 'l', 'l', 'o'} - { - buf := bytes.NewReader(filedata1) - err := client.Upload( - context.Background(), - "test", - "test", - uint64(5), - buf, - app.NewSigner(privateKey), - bytes.NewBuffer([]byte{}), - app.Timestamp{}, - ) - require.NoError(t, err) - require.Equal(t, filedata1, server.uploads["test.test"][0].bytes) - require.Equal(t, "801fb03a3a34fd9d3ac5445f693df74c822d2e8cfa736191e7919e099931d8a51cd0a62fc67da6d8f0aab4302c18aa0cf381c973a8817b7062805f19d03f88ce00", hex.EncodeToString(server.uploads["test.test"][0].sig)) // nolint - } - - // Upload data 2 on test2.test2 - filedata2 := []byte{'W', 'o', 'r', 'l', 'd'} - { - buf := bytes.NewReader(filedata2) - err := client.Upload(context.Background(), "test2", "test2", uint64(5), buf, app.NewSigner(privateKey), bytes.NewBuffer([]byte{}), app.Timestamp{}) // nolint - require.NoError(t, err) - require.Equal(t, filedata2, server.uploads["test2.test2"][0].bytes) - require.Equal(t, "3ad572a3483971285f3c6dc0e71d234a58543876f98b23183dc4e60008c1a92310f42202858b48ad917588535c2234c85413e124a2dcdd0759df9c555a9f585901", hex.EncodeToString(server.uploads["test2.test2"][0].sig)) // nolint - } - - // Upload data 3 on test.test - filedata3 := []byte{'W', 'O', 'R', 'L', 'D'} - { - buf := bytes.NewReader(filedata3) - err := client.Upload(context.Background(), "test", "test", uint64(5), buf, app.NewSigner(privateKey), bytes.NewBuffer([]byte{}), app.Timestamp{}) // nolint - require.NoError(t, err) - require.Equal(t, filedata3, server.uploads["test.test"][1].bytes) - require.Equal(t, "94dcba2012dd83edf1e379bbdc640e95321ea30d5318e1f5dfd46154603bba4970729b44a71844e3f4e07955dfb529ccf60d31b74a9971649d64fd8c12a32a7d00", hex.EncodeToString(server.uploads["test.test"][1].sig)) // nolint - } - - // check latest 2 deals for test2.test2, should return filedata2 - { - dealInfo, err := client.LatestDeals(context.Background(), "test2", "test2", 2, app.Timestamp{}, app.Timestamp{}) - require.NoError(t, err) - require.Equal(t, 1, len(dealInfo)) - hash := sha1.Sum(filedata2) - require.Equal(t, "70c07ec18ef89c5309bbb0937f3a6342411e1fdd", hex.EncodeToString(hash[:])) - } - - // check deals for test.test, limit 1, offset 1, should return filedata3 - { - dealInfo, err := client.Deals(context.Background(), "test", "test", 1, 1, app.Timestamp{}, app.Timestamp{}) - require.NoError(t, err) - require.Equal(t, 1, len(dealInfo)) - hash := sha1.Sum(filedata3) - require.Equal(t, hex.EncodeToString(hash[:]), "1a5db926797b9ae16ad56ec2c143e51a5172a862") - } -} - -// creates a client and a mocked server. -func newClientAndServer() (*BasinProvider, *BasinServerMock) { - buffer := 1024 * 1024 - lis := bufconn.Listen(buffer) - - mock := NewBasinServerMock() - p := Publications_ServerToClient(mock) - bootstrapClient := capnp.Client(p) - - go func() { - _ = rpc.Serve(lis, bootstrapClient) - }() - - return &BasinProvider{ - p: p, - provider: "mock", - ctx: context.Background(), - cancel: func() { - close(make(chan struct{})) - }, - }, mock -} diff --git a/pkg/capnp/conversion.go b/pkg/capnp/conversion.go deleted file mode 100644 index 7b61352..0000000 --- a/pkg/capnp/conversion.go +++ /dev/null @@ -1,71 +0,0 @@ -package capnp - -import ( - "fmt" - - "capnproto.org/go/capnp/v3" - "github.com/tablelandnetwork/basin-cli/pkg/pgrepl" -) - -// FromPgReplTx converts Tx to its capnp verson. -func FromPgReplTx(tx *pgrepl.Tx) (Tx, error) { - // TODO: better error handling - - _, seg, err := capnp.NewMessage(capnp.SingleSegment(nil)) - if err != nil { - return Tx{}, fmt.Errorf("capnp new message: %s", err) - } - - capnpTx, err := NewRootTx(seg) - if err != nil { - return Tx{}, fmt.Errorf("capnp new tx: %s", err) - } - - capnpTx.SetCommitLSN(uint64(tx.CommitLSN)) - recordsList, err := NewTx_Record_List(seg, int32(len(tx.Records))) - if err != nil { - return Tx{}, fmt.Errorf("capnp new columns list: %s", err) - } - for i, record := range tx.Records { - r := recordsList.At(i) - if err := r.SetAction(record.Action); err != nil { - return Tx{}, fmt.Errorf("capnp new record: %s", err) - } - _ = r.SetTimestamp(record.Timestamp) - _ = r.SetSchema(record.Schema) - _ = r.SetTable(record.Table) - - columnsList, err := NewTx_Record_Column_List(seg, int32(len(record.Columns))) - if err != nil { - return Tx{}, fmt.Errorf("capnp new columns list: %s", err) - } - - for index, column := range record.Columns { - col := columnsList.At(index) - _ = col.SetName(column.Name) - _ = col.SetType(column.Type) - _ = col.SetValue(column.Value) - - _ = columnsList.Set(index, col) - } - _ = r.SetColumns(columnsList) - - pkList, err := NewTx_Record_PrimaryKey_List(seg, int32(len(record.PrimaryKey))) - if err != nil { - return Tx{}, fmt.Errorf("capnp new pk list: %s", err) - } - for index, primarKey := range record.PrimaryKey { - pk := pkList.At(index) - _ = pk.SetName(primarKey.Name) - _ = pk.SetType(primarKey.Type) - - _ = pkList.Set(index, pk) - } - _ = r.SetPrimaryKey(pkList) - _ = recordsList.Set(i, r) - } - - _ = capnpTx.SetRecords(recordsList) - - return capnpTx, nil -} diff --git a/pkg/capnp/conversion_test.go b/pkg/capnp/conversion_test.go deleted file mode 100644 index 01a45a5..0000000 --- a/pkg/capnp/conversion_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package capnp - -import ( - "testing" - "time" - - "github.com/stretchr/testify/require" - "github.com/tablelandnetwork/basin-cli/pkg/pgrepl" -) - -func TestConversion(t *testing.T) { - tx := &pgrepl.Tx{ - CommitLSN: 100, - Records: []pgrepl.Record{ - { - Action: "I", - XID: 1, - Lsn: "1", - EndLsn: "1", - Timestamp: time.Now().String(), - Schema: "public", - Table: "t", - Columns: []pgrepl.Column{ - { - Name: "a", - Type: "integer", - Value: []byte{0x0, 0x1}, - }, - }, - }, - }, - } - - capnptx, err := FromPgReplTx(tx) - require.NoError(t, err) - require.NoError(t, CompareTx(tx, capnptx)) -} diff --git a/pkg/capnp/definitions.capnp b/pkg/capnp/definitions.capnp deleted file mode 100644 index 3fe4e80..0000000 --- a/pkg/capnp/definitions.capnp +++ /dev/null @@ -1,48 +0,0 @@ -using Go = import "/go.capnp"; -@0x8c49da2775b6e7db; -$Go.package("capnp"); -$Go.import("github.com/tablelandnetwork/basin-cli/pkg/capnp"); - -struct Tx { - commitLSN @0 :UInt64; - records @1 :List(Record); - - struct Record { - action @0 :Text; - timestamp @1 :Text; - schema @2 :Text; - table @3 :Text; - columns @4 :List(Column); - primaryKey @5 :List(PrimaryKey); - - struct Column { - name @0 :Text; - type @1 :Text; - value @2 :Data; - } - - struct PrimaryKey { - name @0 :Text; - type @1 :Text; - } - } -} - -struct Schema { - columns @0 :List(Column); - - struct Column { - name @0 :Text; - type @1 :Text; - isNullable @2 :Bool; - isPartOfPrimaryKey @3 :Bool; - } -} - -struct DealInfo { - cid @0 :Text; - size @1 :UInt32; - timestamp @2 :Int64; - archived @3 :Bool; - expiresAt @4 :Text; -} \ No newline at end of file diff --git a/pkg/capnp/definitions.capnp.go b/pkg/capnp/definitions.capnp.go deleted file mode 100644 index 6150620..0000000 --- a/pkg/capnp/definitions.capnp.go +++ /dev/null @@ -1,903 +0,0 @@ -// Code generated by capnpc-go. DO NOT EDIT. - -package capnp - -import ( - capnp "capnproto.org/go/capnp/v3" - text "capnproto.org/go/capnp/v3/encoding/text" - schemas "capnproto.org/go/capnp/v3/schemas" -) - -type Tx capnp.Struct - -// Tx_TypeID is the unique identifier for the type Tx. -const Tx_TypeID = 0xe9135d071d75f95f - -func NewTx(s *capnp.Segment) (Tx, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 8, PointerCount: 1}) - return Tx(st), err -} - -func NewRootTx(s *capnp.Segment) (Tx, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 8, PointerCount: 1}) - return Tx(st), err -} - -func ReadRootTx(msg *capnp.Message) (Tx, error) { - root, err := msg.Root() - return Tx(root.Struct()), err -} - -func (s Tx) String() string { - str, _ := text.Marshal(0xe9135d071d75f95f, capnp.Struct(s)) - return str -} - -func (s Tx) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Tx) DecodeFromPtr(p capnp.Ptr) Tx { - return Tx(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Tx) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Tx) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Tx) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Tx) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Tx) CommitLSN() uint64 { - return capnp.Struct(s).Uint64(0) -} - -func (s Tx) SetCommitLSN(v uint64) { - capnp.Struct(s).SetUint64(0, v) -} - -func (s Tx) Records() (Tx_Record_List, error) { - p, err := capnp.Struct(s).Ptr(0) - return Tx_Record_List(p.List()), err -} - -func (s Tx) HasRecords() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s Tx) SetRecords(v Tx_Record_List) error { - return capnp.Struct(s).SetPtr(0, v.ToPtr()) -} - -// NewRecords sets the records field to a newly -// allocated Tx_Record_List, preferring placement in s's segment. -func (s Tx) NewRecords(n int32) (Tx_Record_List, error) { - l, err := NewTx_Record_List(capnp.Struct(s).Segment(), n) - if err != nil { - return Tx_Record_List{}, err - } - err = capnp.Struct(s).SetPtr(0, l.ToPtr()) - return l, err -} - -// Tx_List is a list of Tx. -type Tx_List = capnp.StructList[Tx] - -// NewTx creates a new list of Tx. -func NewTx_List(s *capnp.Segment, sz int32) (Tx_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 8, PointerCount: 1}, sz) - return capnp.StructList[Tx](l), err -} - -// Tx_Future is a wrapper for a Tx promised by a client call. -type Tx_Future struct{ *capnp.Future } - -func (f Tx_Future) Struct() (Tx, error) { - p, err := f.Future.Ptr() - return Tx(p.Struct()), err -} - -type Tx_Record capnp.Struct - -// Tx_Record_TypeID is the unique identifier for the type Tx_Record. -const Tx_Record_TypeID = 0xadfa24e64cb4fa48 - -func NewTx_Record(s *capnp.Segment) (Tx_Record, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 6}) - return Tx_Record(st), err -} - -func NewRootTx_Record(s *capnp.Segment) (Tx_Record, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 6}) - return Tx_Record(st), err -} - -func ReadRootTx_Record(msg *capnp.Message) (Tx_Record, error) { - root, err := msg.Root() - return Tx_Record(root.Struct()), err -} - -func (s Tx_Record) String() string { - str, _ := text.Marshal(0xadfa24e64cb4fa48, capnp.Struct(s)) - return str -} - -func (s Tx_Record) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Tx_Record) DecodeFromPtr(p capnp.Ptr) Tx_Record { - return Tx_Record(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Tx_Record) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Tx_Record) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Tx_Record) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Tx_Record) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Tx_Record) Action() (string, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.Text(), err -} - -func (s Tx_Record) HasAction() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s Tx_Record) ActionBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.TextBytes(), err -} - -func (s Tx_Record) SetAction(v string) error { - return capnp.Struct(s).SetText(0, v) -} - -func (s Tx_Record) Timestamp() (string, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.Text(), err -} - -func (s Tx_Record) HasTimestamp() bool { - return capnp.Struct(s).HasPtr(1) -} - -func (s Tx_Record) TimestampBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.TextBytes(), err -} - -func (s Tx_Record) SetTimestamp(v string) error { - return capnp.Struct(s).SetText(1, v) -} - -func (s Tx_Record) Schema() (string, error) { - p, err := capnp.Struct(s).Ptr(2) - return p.Text(), err -} - -func (s Tx_Record) HasSchema() bool { - return capnp.Struct(s).HasPtr(2) -} - -func (s Tx_Record) SchemaBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(2) - return p.TextBytes(), err -} - -func (s Tx_Record) SetSchema(v string) error { - return capnp.Struct(s).SetText(2, v) -} - -func (s Tx_Record) Table() (string, error) { - p, err := capnp.Struct(s).Ptr(3) - return p.Text(), err -} - -func (s Tx_Record) HasTable() bool { - return capnp.Struct(s).HasPtr(3) -} - -func (s Tx_Record) TableBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(3) - return p.TextBytes(), err -} - -func (s Tx_Record) SetTable(v string) error { - return capnp.Struct(s).SetText(3, v) -} - -func (s Tx_Record) Columns() (Tx_Record_Column_List, error) { - p, err := capnp.Struct(s).Ptr(4) - return Tx_Record_Column_List(p.List()), err -} - -func (s Tx_Record) HasColumns() bool { - return capnp.Struct(s).HasPtr(4) -} - -func (s Tx_Record) SetColumns(v Tx_Record_Column_List) error { - return capnp.Struct(s).SetPtr(4, v.ToPtr()) -} - -// NewColumns sets the columns field to a newly -// allocated Tx_Record_Column_List, preferring placement in s's segment. -func (s Tx_Record) NewColumns(n int32) (Tx_Record_Column_List, error) { - l, err := NewTx_Record_Column_List(capnp.Struct(s).Segment(), n) - if err != nil { - return Tx_Record_Column_List{}, err - } - err = capnp.Struct(s).SetPtr(4, l.ToPtr()) - return l, err -} -func (s Tx_Record) PrimaryKey() (Tx_Record_PrimaryKey_List, error) { - p, err := capnp.Struct(s).Ptr(5) - return Tx_Record_PrimaryKey_List(p.List()), err -} - -func (s Tx_Record) HasPrimaryKey() bool { - return capnp.Struct(s).HasPtr(5) -} - -func (s Tx_Record) SetPrimaryKey(v Tx_Record_PrimaryKey_List) error { - return capnp.Struct(s).SetPtr(5, v.ToPtr()) -} - -// NewPrimaryKey sets the primaryKey field to a newly -// allocated Tx_Record_PrimaryKey_List, preferring placement in s's segment. -func (s Tx_Record) NewPrimaryKey(n int32) (Tx_Record_PrimaryKey_List, error) { - l, err := NewTx_Record_PrimaryKey_List(capnp.Struct(s).Segment(), n) - if err != nil { - return Tx_Record_PrimaryKey_List{}, err - } - err = capnp.Struct(s).SetPtr(5, l.ToPtr()) - return l, err -} - -// Tx_Record_List is a list of Tx_Record. -type Tx_Record_List = capnp.StructList[Tx_Record] - -// NewTx_Record creates a new list of Tx_Record. -func NewTx_Record_List(s *capnp.Segment, sz int32) (Tx_Record_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 6}, sz) - return capnp.StructList[Tx_Record](l), err -} - -// Tx_Record_Future is a wrapper for a Tx_Record promised by a client call. -type Tx_Record_Future struct{ *capnp.Future } - -func (f Tx_Record_Future) Struct() (Tx_Record, error) { - p, err := f.Future.Ptr() - return Tx_Record(p.Struct()), err -} - -type Tx_Record_Column capnp.Struct - -// Tx_Record_Column_TypeID is the unique identifier for the type Tx_Record_Column. -const Tx_Record_Column_TypeID = 0xdaf0d54cc25988fc - -func NewTx_Record_Column(s *capnp.Segment) (Tx_Record_Column, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 3}) - return Tx_Record_Column(st), err -} - -func NewRootTx_Record_Column(s *capnp.Segment) (Tx_Record_Column, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 3}) - return Tx_Record_Column(st), err -} - -func ReadRootTx_Record_Column(msg *capnp.Message) (Tx_Record_Column, error) { - root, err := msg.Root() - return Tx_Record_Column(root.Struct()), err -} - -func (s Tx_Record_Column) String() string { - str, _ := text.Marshal(0xdaf0d54cc25988fc, capnp.Struct(s)) - return str -} - -func (s Tx_Record_Column) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Tx_Record_Column) DecodeFromPtr(p capnp.Ptr) Tx_Record_Column { - return Tx_Record_Column(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Tx_Record_Column) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Tx_Record_Column) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Tx_Record_Column) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Tx_Record_Column) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Tx_Record_Column) Name() (string, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.Text(), err -} - -func (s Tx_Record_Column) HasName() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s Tx_Record_Column) NameBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.TextBytes(), err -} - -func (s Tx_Record_Column) SetName(v string) error { - return capnp.Struct(s).SetText(0, v) -} - -func (s Tx_Record_Column) Type() (string, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.Text(), err -} - -func (s Tx_Record_Column) HasType() bool { - return capnp.Struct(s).HasPtr(1) -} - -func (s Tx_Record_Column) TypeBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.TextBytes(), err -} - -func (s Tx_Record_Column) SetType(v string) error { - return capnp.Struct(s).SetText(1, v) -} - -func (s Tx_Record_Column) Value() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(2) - return []byte(p.Data()), err -} - -func (s Tx_Record_Column) HasValue() bool { - return capnp.Struct(s).HasPtr(2) -} - -func (s Tx_Record_Column) SetValue(v []byte) error { - return capnp.Struct(s).SetData(2, v) -} - -// Tx_Record_Column_List is a list of Tx_Record_Column. -type Tx_Record_Column_List = capnp.StructList[Tx_Record_Column] - -// NewTx_Record_Column creates a new list of Tx_Record_Column. -func NewTx_Record_Column_List(s *capnp.Segment, sz int32) (Tx_Record_Column_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 3}, sz) - return capnp.StructList[Tx_Record_Column](l), err -} - -// Tx_Record_Column_Future is a wrapper for a Tx_Record_Column promised by a client call. -type Tx_Record_Column_Future struct{ *capnp.Future } - -func (f Tx_Record_Column_Future) Struct() (Tx_Record_Column, error) { - p, err := f.Future.Ptr() - return Tx_Record_Column(p.Struct()), err -} - -type Tx_Record_PrimaryKey capnp.Struct - -// Tx_Record_PrimaryKey_TypeID is the unique identifier for the type Tx_Record_PrimaryKey. -const Tx_Record_PrimaryKey_TypeID = 0x9722004316c0ea9f - -func NewTx_Record_PrimaryKey(s *capnp.Segment) (Tx_Record_PrimaryKey, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 2}) - return Tx_Record_PrimaryKey(st), err -} - -func NewRootTx_Record_PrimaryKey(s *capnp.Segment) (Tx_Record_PrimaryKey, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 2}) - return Tx_Record_PrimaryKey(st), err -} - -func ReadRootTx_Record_PrimaryKey(msg *capnp.Message) (Tx_Record_PrimaryKey, error) { - root, err := msg.Root() - return Tx_Record_PrimaryKey(root.Struct()), err -} - -func (s Tx_Record_PrimaryKey) String() string { - str, _ := text.Marshal(0x9722004316c0ea9f, capnp.Struct(s)) - return str -} - -func (s Tx_Record_PrimaryKey) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Tx_Record_PrimaryKey) DecodeFromPtr(p capnp.Ptr) Tx_Record_PrimaryKey { - return Tx_Record_PrimaryKey(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Tx_Record_PrimaryKey) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Tx_Record_PrimaryKey) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Tx_Record_PrimaryKey) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Tx_Record_PrimaryKey) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Tx_Record_PrimaryKey) Name() (string, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.Text(), err -} - -func (s Tx_Record_PrimaryKey) HasName() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s Tx_Record_PrimaryKey) NameBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.TextBytes(), err -} - -func (s Tx_Record_PrimaryKey) SetName(v string) error { - return capnp.Struct(s).SetText(0, v) -} - -func (s Tx_Record_PrimaryKey) Type() (string, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.Text(), err -} - -func (s Tx_Record_PrimaryKey) HasType() bool { - return capnp.Struct(s).HasPtr(1) -} - -func (s Tx_Record_PrimaryKey) TypeBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.TextBytes(), err -} - -func (s Tx_Record_PrimaryKey) SetType(v string) error { - return capnp.Struct(s).SetText(1, v) -} - -// Tx_Record_PrimaryKey_List is a list of Tx_Record_PrimaryKey. -type Tx_Record_PrimaryKey_List = capnp.StructList[Tx_Record_PrimaryKey] - -// NewTx_Record_PrimaryKey creates a new list of Tx_Record_PrimaryKey. -func NewTx_Record_PrimaryKey_List(s *capnp.Segment, sz int32) (Tx_Record_PrimaryKey_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 2}, sz) - return capnp.StructList[Tx_Record_PrimaryKey](l), err -} - -// Tx_Record_PrimaryKey_Future is a wrapper for a Tx_Record_PrimaryKey promised by a client call. -type Tx_Record_PrimaryKey_Future struct{ *capnp.Future } - -func (f Tx_Record_PrimaryKey_Future) Struct() (Tx_Record_PrimaryKey, error) { - p, err := f.Future.Ptr() - return Tx_Record_PrimaryKey(p.Struct()), err -} - -type Schema capnp.Struct - -// Schema_TypeID is the unique identifier for the type Schema. -const Schema_TypeID = 0xb2c63295c6bcc643 - -func NewSchema(s *capnp.Segment) (Schema, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Schema(st), err -} - -func NewRootSchema(s *capnp.Segment) (Schema, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) - return Schema(st), err -} - -func ReadRootSchema(msg *capnp.Message) (Schema, error) { - root, err := msg.Root() - return Schema(root.Struct()), err -} - -func (s Schema) String() string { - str, _ := text.Marshal(0xb2c63295c6bcc643, capnp.Struct(s)) - return str -} - -func (s Schema) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Schema) DecodeFromPtr(p capnp.Ptr) Schema { - return Schema(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Schema) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Schema) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Schema) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Schema) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Schema) Columns() (Schema_Column_List, error) { - p, err := capnp.Struct(s).Ptr(0) - return Schema_Column_List(p.List()), err -} - -func (s Schema) HasColumns() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s Schema) SetColumns(v Schema_Column_List) error { - return capnp.Struct(s).SetPtr(0, v.ToPtr()) -} - -// NewColumns sets the columns field to a newly -// allocated Schema_Column_List, preferring placement in s's segment. -func (s Schema) NewColumns(n int32) (Schema_Column_List, error) { - l, err := NewSchema_Column_List(capnp.Struct(s).Segment(), n) - if err != nil { - return Schema_Column_List{}, err - } - err = capnp.Struct(s).SetPtr(0, l.ToPtr()) - return l, err -} - -// Schema_List is a list of Schema. -type Schema_List = capnp.StructList[Schema] - -// NewSchema creates a new list of Schema. -func NewSchema_List(s *capnp.Segment, sz int32) (Schema_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}, sz) - return capnp.StructList[Schema](l), err -} - -// Schema_Future is a wrapper for a Schema promised by a client call. -type Schema_Future struct{ *capnp.Future } - -func (f Schema_Future) Struct() (Schema, error) { - p, err := f.Future.Ptr() - return Schema(p.Struct()), err -} - -type Schema_Column capnp.Struct - -// Schema_Column_TypeID is the unique identifier for the type Schema_Column. -const Schema_Column_TypeID = 0xc6ee33dc50be1a5a - -func NewSchema_Column(s *capnp.Segment) (Schema_Column, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 8, PointerCount: 2}) - return Schema_Column(st), err -} - -func NewRootSchema_Column(s *capnp.Segment) (Schema_Column, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 8, PointerCount: 2}) - return Schema_Column(st), err -} - -func ReadRootSchema_Column(msg *capnp.Message) (Schema_Column, error) { - root, err := msg.Root() - return Schema_Column(root.Struct()), err -} - -func (s Schema_Column) String() string { - str, _ := text.Marshal(0xc6ee33dc50be1a5a, capnp.Struct(s)) - return str -} - -func (s Schema_Column) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (Schema_Column) DecodeFromPtr(p capnp.Ptr) Schema_Column { - return Schema_Column(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s Schema_Column) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s Schema_Column) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s Schema_Column) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s Schema_Column) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s Schema_Column) Name() (string, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.Text(), err -} - -func (s Schema_Column) HasName() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s Schema_Column) NameBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.TextBytes(), err -} - -func (s Schema_Column) SetName(v string) error { - return capnp.Struct(s).SetText(0, v) -} - -func (s Schema_Column) Type() (string, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.Text(), err -} - -func (s Schema_Column) HasType() bool { - return capnp.Struct(s).HasPtr(1) -} - -func (s Schema_Column) TypeBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.TextBytes(), err -} - -func (s Schema_Column) SetType(v string) error { - return capnp.Struct(s).SetText(1, v) -} - -func (s Schema_Column) IsNullable() bool { - return capnp.Struct(s).Bit(0) -} - -func (s Schema_Column) SetIsNullable(v bool) { - capnp.Struct(s).SetBit(0, v) -} - -func (s Schema_Column) IsPartOfPrimaryKey() bool { - return capnp.Struct(s).Bit(1) -} - -func (s Schema_Column) SetIsPartOfPrimaryKey(v bool) { - capnp.Struct(s).SetBit(1, v) -} - -// Schema_Column_List is a list of Schema_Column. -type Schema_Column_List = capnp.StructList[Schema_Column] - -// NewSchema_Column creates a new list of Schema_Column. -func NewSchema_Column_List(s *capnp.Segment, sz int32) (Schema_Column_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 8, PointerCount: 2}, sz) - return capnp.StructList[Schema_Column](l), err -} - -// Schema_Column_Future is a wrapper for a Schema_Column promised by a client call. -type Schema_Column_Future struct{ *capnp.Future } - -func (f Schema_Column_Future) Struct() (Schema_Column, error) { - p, err := f.Future.Ptr() - return Schema_Column(p.Struct()), err -} - -type DealInfo capnp.Struct - -// DealInfo_TypeID is the unique identifier for the type DealInfo. -const DealInfo_TypeID = 0xc69bf7c475bb2886 - -func NewDealInfo(s *capnp.Segment) (DealInfo, error) { - st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 16, PointerCount: 2}) - return DealInfo(st), err -} - -func NewRootDealInfo(s *capnp.Segment) (DealInfo, error) { - st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 16, PointerCount: 2}) - return DealInfo(st), err -} - -func ReadRootDealInfo(msg *capnp.Message) (DealInfo, error) { - root, err := msg.Root() - return DealInfo(root.Struct()), err -} - -func (s DealInfo) String() string { - str, _ := text.Marshal(0xc69bf7c475bb2886, capnp.Struct(s)) - return str -} - -func (s DealInfo) EncodeAsPtr(seg *capnp.Segment) capnp.Ptr { - return capnp.Struct(s).EncodeAsPtr(seg) -} - -func (DealInfo) DecodeFromPtr(p capnp.Ptr) DealInfo { - return DealInfo(capnp.Struct{}.DecodeFromPtr(p)) -} - -func (s DealInfo) ToPtr() capnp.Ptr { - return capnp.Struct(s).ToPtr() -} -func (s DealInfo) IsValid() bool { - return capnp.Struct(s).IsValid() -} - -func (s DealInfo) Message() *capnp.Message { - return capnp.Struct(s).Message() -} - -func (s DealInfo) Segment() *capnp.Segment { - return capnp.Struct(s).Segment() -} -func (s DealInfo) Cid() (string, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.Text(), err -} - -func (s DealInfo) HasCid() bool { - return capnp.Struct(s).HasPtr(0) -} - -func (s DealInfo) CidBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(0) - return p.TextBytes(), err -} - -func (s DealInfo) SetCid(v string) error { - return capnp.Struct(s).SetText(0, v) -} - -func (s DealInfo) Size() uint32 { - return capnp.Struct(s).Uint32(0) -} - -func (s DealInfo) SetSize(v uint32) { - capnp.Struct(s).SetUint32(0, v) -} - -func (s DealInfo) Timestamp() int64 { - return int64(capnp.Struct(s).Uint64(8)) -} - -func (s DealInfo) SetTimestamp(v int64) { - capnp.Struct(s).SetUint64(8, uint64(v)) -} - -func (s DealInfo) Archived() bool { - return capnp.Struct(s).Bit(32) -} - -func (s DealInfo) SetArchived(v bool) { - capnp.Struct(s).SetBit(32, v) -} - -func (s DealInfo) ExpiresAt() (string, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.Text(), err -} - -func (s DealInfo) HasExpiresAt() bool { - return capnp.Struct(s).HasPtr(1) -} - -func (s DealInfo) ExpiresAtBytes() ([]byte, error) { - p, err := capnp.Struct(s).Ptr(1) - return p.TextBytes(), err -} - -func (s DealInfo) SetExpiresAt(v string) error { - return capnp.Struct(s).SetText(1, v) -} - -// DealInfo_List is a list of DealInfo. -type DealInfo_List = capnp.StructList[DealInfo] - -// NewDealInfo creates a new list of DealInfo. -func NewDealInfo_List(s *capnp.Segment, sz int32) (DealInfo_List, error) { - l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 16, PointerCount: 2}, sz) - return capnp.StructList[DealInfo](l), err -} - -// DealInfo_Future is a wrapper for a DealInfo promised by a client call. -type DealInfo_Future struct{ *capnp.Future } - -func (f DealInfo_Future) Struct() (DealInfo, error) { - p, err := f.Future.Ptr() - return DealInfo(p.Struct()), err -} - -const schema_8c49da2775b6e7db = "x\xda\x8c\x94_h\x1cU\x14\xc6\xcfw\xef\xcc&\x81" + - "\xc4t\x98E\xa5DVk\xb0\xb54i\x93\xf8\xe2\x82" + - "l5\x15\xb2\x9a\xd4=\xdb\x824Xt:\x99\xb8\xa3" + - ";\xbb\xeb\xeel\x9b\x88R\x85*E*\xf8`\xf1?" + - "\xf6A\xa1\x82E\x11\xf1E\x91*e\xdf\xc4'\x1f\xac" + - "\x05\xe9\x83\x96\x0a\x8a>\x88\x18\x84\x91\xb3\x9b\x99\x1d\xa3" + - "\x0d\xbe\xed\x9c9;\xe7\xfb\x9d\xef\xbbw\xcf\xb4\xdak" + - "L\x8d|\xadI\xf1.3\xf3\xfd\xdb?\x9d\xbf~v" + - "\xdb+\xd6m\x88\xe6\xd6>\x9e\xffq|\xed\x1c\x99j" + - "\x80h\xe6+\xbc\x00\xfb\x07\x0c\x10\xd9\x97q\x8cR\xef" + - "\xad\x1c\xa2\x87\xffl\xdf4p\xd8\xbeJfF\x9a\xef" + - "R\xd3\xb0\x17\xd4v\xa2\x19O=\x08B4\xdb\xf9\xac" + - "sz\xba\xf3\x11Yc\x88\xbe\xbb\xf2I{\xfb\xc5\xe2" + - ")2\xe5{3\xdf\xea\xad\xb0\xaf\xea\x1b\x88\xec\xdft" + - "\x81\x10=\xbf\xe3\xd3\xf6\x85?\xde\xe8\x10\x8fA\xa5\xba" + - "\xbbBn1v\xc2\x9e2\xe4\xe7\x84\x91\x93o/n" + - "\xfd\xbcti\xe6\x97\x0e\xf1\xadHM\xea\xb5\x17\xcd2" + - "\xec\xc3\xa6\xe8>d^!D\x7f\x9d<\xf4\xe5\xfc7" + - "\xbf^\xa4\x7fBji\xbe3\xf3\x18\xec\x05A\xb0\x8b" + - "\x99\x0f(\xc5\xc5c\xd8\xa8\xdb\xbe\x9cY\xb3\x7f\xce\x88" + - "\xec\xdf3\xc7h\"j<\xfe\xe8n\xd7i\xd4\xcc\xc6" + - "\xee%o\xd9\xaf\xf9\xa1_\xaf\xb5&\xa5\xd4\xc8\x1f\\" + - "\x99,{n\xbd\xb94Yj\xfa\x81\xd3\\\xbd\xdf[" + - "%*\x01<\xa8\x0d\"\x03D\xd6\xed;\x89x\\\x83" + - "\xf7(X@\x16R\x9c\x90\xe2\x0e\x0d\xbeCa\xb4\xe6" + - "\x04\x1e\x86Ia\x980\x1a\xae6\x92\x87d\xb8\xbe\xd6" + - "\xf0\\w:\x0f\"\xbd\x82\xa1|b\xb9\xb9X\x98\xad" + - "W\xdbA-\x8a\x05\x92\xf6V\xf9\xc6D\xddky\"" + - "~Y\x83\xcf\xa4\xd4\xbdU&\xe275\xf8\xac\x82\xa5" + - "T\x16\x8a\xc8zW:\xcfh\xf0\xfb\x0a\x96\xd6Yh" + - "\"\xeb\xbdi\"~G\x83?T\xb0\x0c#\x0b\x83\xc8" + - ":w\x0f\x11\x9f\xd5\xe0\x0b\x0a\x96ifa\x12Y_" + - ",\x12\xf1y\x0d\xbe\xa4Pp\\\x01I0C?\xf0" + - "Z\xa1\x13\x10\x1aq\xad\xd0r+^\xe0\xc4\x8f\xb9\xd0" + - "9RM\xf6r\xdc\xed2\xb5p\x1d\xa1\xa4\x81-}" + - "x\x82\x14\xa3F\x8a6\xe9\x8a\xb7\x12\xf7l\xb6\xdc\x03" + - "n\xc5\xd3\x81\xc3\x06RQ\xb4\x90__'\x1b\xc9\x06" + - "G\x84vP\x83\xc7\xd5\x7f\x08K\xfe\xfb\x7f\x86\xee\xf3" + - "\x9c\xeah\xb1\xb6\\\x97\x04e\x93\x09Oo#\xe2\x15" + - "\x0d>\xa1\x10[\xf4\xac\x04\xe8)\x0d>)\x16\xa1g" + - "\xd1s\xe2\xdb\x09\x0d~I,\xba\xb9g\xd1\x8b\xf7\x11" + - "\xf1)\x0d~U,B\xcf\xa2\xd3\xe5\xbe\xed\x03\xae\xbf" + - "\x94\xc4\xaf\xe5?\xe9a\x90\x14\x067\xf8b\x92\x82I" + - "\x88\x9c\xa6[\xf1\x8fzK$D\xa4 g\xd5[i" + - "\xf8M\xafu7!\xfcWt\x8dkm7p&\xbb" + - "\xbbDMh\xb7$\xb4\x8e\x90=\xa4\xc1\x95T\"=" + - ")>\xa2\xc1U\x05\xac\x07\xd2\x97DU48\x14Z" + - "\xf4h\x9fx\x9d\x88C\x0d~f\xd3\x83\xe5\xb7\xf6\xb7" + - "\xabU\xe7\x08\xe9\xaa\x97`\xf8\xad\x92\xd3\x0c\x1fXF" + - "|V$<\xf1\xcbMy\xfa\xf7\xc0l}T\x12 " + - "H\xc3\x09\xd2\xbd\xa2~\xaf\x06\xcf\xa7\x90\x8aR\xdc\xa7" + - "\xc1\xa5\xd4![\x90\xf34\xa7\xc1\x077\x93\x9f;\xea" + - "T\xdb\x1eFHa$%Mm\x94V\xe8i\xeb\x86" + - "\xb8\x7f\xb3#_(\xaf_\x1b\xfdK\xaa\xdc\xbf\x8fb" + - "\x81S\x12\xec]\x1a<\xa7\x10\xb9\xf5 \xf0\xc3\xf9\x03" + - "\x84\xfd\x18\"\x85!\xc2\xf1f\xf7+\xa9\xb0'3z" + - "a\xff;\x00\x00\xff\xff\x88\xeb\x9b\xe1" - -func RegisterSchema(reg *schemas.Registry) { - reg.Register(&schemas.Schema{ - String: schema_8c49da2775b6e7db, - Nodes: []uint64{ - 0x9722004316c0ea9f, - 0xadfa24e64cb4fa48, - 0xb2c63295c6bcc643, - 0xc69bf7c475bb2886, - 0xc6ee33dc50be1a5a, - 0xdaf0d54cc25988fc, - 0xe9135d071d75f95f, - }, - Compressed: true, - }) -} diff --git a/pkg/capnp/util.go b/pkg/capnp/util.go deleted file mode 100644 index 4df2f86..0000000 --- a/pkg/capnp/util.go +++ /dev/null @@ -1,145 +0,0 @@ -package capnp - -import ( - "fmt" - - "github.com/google/go-cmp/cmp" - "github.com/tablelandnetwork/basin-cli/pkg/pgrepl" -) - -// CompareTx compares the two types of Tx. -// Used for testing. -func CompareTx(tx *pgrepl.Tx, capnptx Tx) error { - // commit LSN - if !cmp.Equal(uint64(tx.CommitLSN), capnptx.CommitLSN()) { - return fmt.Errorf("commit lsn not equal") - } - - records, err := capnptx.Records() - if err != nil { - return fmt.Errorf("records: %s", err) - } - - for i := 0; i < records.Len(); i++ { - if err := compareRecord(tx.Records[i], records.At(i)); err != nil { - return fmt.Errorf("compare record: %s", err) - } - } - - return nil -} - -func compareRecord(record pgrepl.Record, capnpRecord Tx_Record) error { - // action - action, err := capnpRecord.Action() - if err != nil { - return fmt.Errorf("records action: %s", err) - } - - if !cmp.Equal(record.Action, action) { - return fmt.Errorf("action not equals") - } - - // timestamp - timestamp, err := capnpRecord.Timestamp() - if err != nil { - return fmt.Errorf("records timestamp: %s", err) - } - - if !cmp.Equal(record.Timestamp, timestamp) { - return fmt.Errorf("timestamp not equals") - } - - // schema - schema, err := capnpRecord.Schema() - if err != nil { - return fmt.Errorf("records schema: %s", err) - } - if !cmp.Equal(record.Schema, schema) { - return fmt.Errorf("schema not equals") - } - - // table - table, err := capnpRecord.Table() - if err != nil { - return fmt.Errorf("records table: %s", err) - } - if !cmp.Equal(record.Table, table) { - return fmt.Errorf("table not equals") - } - - // columns - columns, err := capnpRecord.Columns() - if err != nil { - return fmt.Errorf("records columns: %s", err) - } - - for i := 0; i < columns.Len(); i++ { - if err := compareColumn(record.Columns[i], columns.At(i)); err != nil { - return fmt.Errorf("compare column: %s", err) - } - } - - // pk - pk, err := capnpRecord.PrimaryKey() - if err != nil { - return fmt.Errorf("records columns: %s", err) - } - - for i := 0; i < pk.Len(); i++ { - if err := comparePrimaKey(record.PrimaryKey[i], pk.At(i)); err != nil { - return fmt.Errorf("compare column: %s", err) - } - } - - return nil -} - -func compareColumn(column pgrepl.Column, capnpColumn Tx_Record_Column) error { - colName, err := capnpColumn.Name() - if err != nil { - return fmt.Errorf("column name: %s", err) - } - if !cmp.Equal(column.Name, colName) { - return fmt.Errorf("column name not equals: (%s, %s)", column.Name, colName) - } - - colType, err := capnpColumn.Type() - if err != nil { - return fmt.Errorf("column type: %s", err) - } - if !cmp.Equal(column.Type, colType) { - return fmt.Errorf("column type not equals") - } - - value, err := capnpColumn.Value() - if err != nil { - return fmt.Errorf("column value: %s", err) - } - - if !cmp.Equal([]byte(column.Value), value) { - return fmt.Errorf("column value not equals") - } - - return nil -} - -func comparePrimaKey(primaryKey pgrepl.PrimaryKey, capnpPrimaryKey Tx_Record_PrimaryKey) error { - colName, err := capnpPrimaryKey.Name() - if err != nil { - return fmt.Errorf("primary key name: %s", err) - } - if !cmp.Equal(primaryKey.Name, colName) { - return fmt.Errorf("primarky name not equals") - } - - colType, err := capnpPrimaryKey.Type() - if err != nil { - return fmt.Errorf("primary key type: %s", err) - } - if !cmp.Equal(primaryKey.Type, colType) { - return fmt.Errorf("primary key type not equals") - } - - return nil -}