sidecar

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package sidecar provides a client for interacting with the Near Protocol Sidecar service.

The sidecar service is responsible for submitting and retrieving data blobs to and from the Near blockchain. It acts as an intermediary between the application and the Near blockchain, abstracting away the complexities of interacting with the blockchain directly.

Security Considerations: - The sidecar service should be running on a trusted host and port. - The host and port should be configurable and not hardcoded. - The client should verify the identity of the sidecar service using TLS certificates. - The client should validate and sanitize all input parameters to prevent injection attacks. - The client should handle errors gracefully and not leak sensitive information in error messages. - The client should use secure communication channels (e.g., HTTPS) to prevent eavesdropping and tampering. - The client should have proper authentication and authorization mechanisms to prevent unauthorized access.

Usage:

1. Create a new client instance using the `NewClient` function, providing the host and configuration.

client, err := sidecar.NewClient("http://localhost:5888", &sidecar.ConfigureClientRequest{...})
if err != nil {
    // Handle error
}

2. Use the client to interact with the sidecar service.

// Submit a blob
blob := sidecar.Blob{Data: []byte("test_data")}
blobRef, err := client.SubmitBlob(blob)
if err != nil {
    // Handle error
}

// Get a blob
retrievedBlob, err := client.GetBlob(*blobRef)
if err != nil {
    // Handle error
}

3. Close the client when done.

client.Close()

Index

Constants

View Source
const EncodedBlobRefSize = 32

EncodedBlobRefSize is the size of an encoded BlobRef in bytes.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blob

type Blob struct {
	Data []byte `json:"data"`
}

Blob represents a blob of data stored on the Near blockchain.

func (*Blob) MarshalJSON

func (b *Blob) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Blob to JSON format. It encodes the data as a hex string.

func (*Blob) UnmarshalJSON

func (b *Blob) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the Blob from JSON format. It decodes the data from a hex string.

type BlobRef

type BlobRef struct {
	// contains filtered or unexported fields
}

BlobRef represents a reference to a blob on the Near blockchain.

func NewBlobRef

func NewBlobRef(transactionID []byte) (*BlobRef, error)

NewBlobRef creates a new BlobRef from the provided transaction ID. It returns an error if the transaction ID is not exactly 32 bytes.

func (*BlobRef) Deref

func (r *BlobRef) Deref() []byte

Deref returns the transaction ID of the BlobRef.

func (*BlobRef) ID

func (r *BlobRef) ID() string

ID returns the transaction ID of the BlobRef as a hex-encoded string.

func (*BlobRef) MarshalJSON

func (r *BlobRef) MarshalJSON() ([]byte, error)

MarshalJSON marshals the BlobRef to JSON format. It encodes the transaction ID as a hex string.

func (*BlobRef) UnmarshalJSON

func (r *BlobRef) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the BlobRef from JSON format. It decodes the transaction ID from a hex string.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a client for interacting with the Near Protocol Sidecar service.

func NewClient

func NewClient(host string, config *ConfigureClientRequest) (*Client, error)

NewClient creates a new instance of the Near Protocol Sidecar client. It takes the host and configuration as parameters and returns a pointer to the client. If the host is empty, it defaults to "http://localhost:5888". The configuration can be nil, assuming the sidecar is set up outside of this package.

func (*Client) Close

func (c *Client) Close()

Close closes the Near Protocol Sidecar client. It should be called when the client is no longer needed.

func (*Client) ConfigureClient

func (c *Client) ConfigureClient(req *ConfigureClientRequest) error

ConfigureClient configures the Near Protocol Sidecar client with the provided configuration. It sends a PUT request to the "/configure" endpoint with the configuration as JSON payload.

func (*Client) GetBlob

func (c *Client) GetBlob(b BlobRef) (*Blob, error)

GetBlob retrieves a blob from the Near blockchain using the provided BlobRef. It sends a GET request to the "/blob" endpoint with the transaction ID as a query parameter.

func (*Client) Health

func (c *Client) Health() error

Health checks the health of the Near Protocol Sidecar service. It sends a GET request to the "/health" endpoint and expects a successful response.

func (*Client) SubmitBlob

func (c *Client) SubmitBlob(b Blob) (*BlobRef, error)

SubmitBlob submits a blob to the Near blockchain. It sends a POST request to the "/blob" endpoint with the blob data as JSON payload. The response contains the transaction ID of the submitted blob.

type ConfigureClientRequest

type ConfigureClientRequest struct {
	AccountID  string     `json:"account_id"`
	SecretKey  string     `json:"secret_key"`
	ContractID string     `json:"contract_id"`
	Network    Network    `json:"network"`
	Namespace  *Namespace `json:"namespace"`
}

ConfigureClientRequest represents a request to configure the Near Protocol Sidecar client.

type Namespace

type Namespace struct {
	ID      int `json:"id"`
	Version int `json:"version"`
}

Namespace represents a namespace on the Near blockchain.

type Network

type Network string

Network represents a Near network.

const (
	Mainnet  Network = "mainnet"
	Testnet  Network = "testnet"
	Localnet Network = "localnet"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL