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 ¶
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 ¶
MarshalJSON marshals the Blob to JSON format. It encodes the data as a hex string.
func (*Blob) UnmarshalJSON ¶
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 ¶
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) MarshalJSON ¶
MarshalJSON marshals the BlobRef to JSON format. It encodes the transaction ID as a hex string.
func (*BlobRef) UnmarshalJSON ¶
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 ¶
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.
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.