Documentation ¶
Overview ¶
Package api implements the Mappchain API.
Index ¶
- func CadenceArgs(args ...cadence.Value) ([]json.RawMessage, error)
- func JSONMessagesToByteSlices(args []json.RawMessage) [][]byte
- func MustCadenceArgs(args ...cadence.Value) []json.RawMessage
- type ChallengeRequest
- type Client
- func (c *Client) CreateAccount(ctx context.Context, key *SigningKey, req *CreateAccountRequest) (*CreateAccountResponse, error)
- func (c *Client) ExecuteRead(ctx context.Context, req *ExecuteReadRequest) (*ExecuteReadResponse, error)
- func (c *Client) ExecuteWrite(ctx context.Context, req *ExecuteWriteRequest) (*ExecuteWriteResponse, error)
- func (c *Client) GetBlock(ctx context.Context, req *GetBlockRequest) (*GetBlockResponse, error)
- func (c *Client) GetChainInfo(ctx context.Context) (*GetChainInfoResponse, error)
- func (c *Client) GetTransactionResult(ctx context.Context, req *GetTransactionResultRequest) (*GetTransactionResultResponse, error)
- func (c *Client) ListFieldValues(ctx context.Context, req *ListFieldValuesRequest) (*ListFieldValuesResponse, error)
- func (c *Client) QueryEvents(ctx context.Context, req *QueryEventsRequest) (*QueryEventsResponse, error)
- func (c *Client) SetSigner(s *Signer) error
- func (c *Client) UploadFile(ctx context.Context, req *UploadFileRequest) (*UploadFileResponse, error)
- type ClientOption
- type CreateAccountRequest
- type CreateAccountResponse
- type Difficulty
- type ErrorInfo
- type ErrorResponse
- type Event
- type EventOccurence
- type ExecuteReadRequest
- type ExecuteReadResponse
- type ExecuteWriteRequest
- type ExecuteWriteResponse
- type Field
- type Filter
- type GetBlockRequest
- type GetBlockResponse
- type GetChainInfoResponse
- type GetTransactionResultRequest
- type GetTransactionResultResponse
- type KDFParams
- type LatestBlock
- type ListFieldValuesRequest
- type ListFieldValuesResponse
- type PublicKey
- type QueryEventsRequest
- type QueryEventsResponse
- type Seal
- type Signature
- type Signer
- type SigningKey
- type Transaction
- type TransactionResult
- type UploadFileRequest
- type UploadFileResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CadenceArgs ¶
func CadenceArgs(args ...cadence.Value) ([]json.RawMessage, error)
CadenceArgs serializes the given Cadence values.
func JSONMessagesToByteSlices ¶
func JSONMessagesToByteSlices(args []json.RawMessage) [][]byte
JSONMessagesToByteSlices converts a slice of json RawMessage values to a slice of plain byte slices.
func MustCadenceArgs ¶
func MustCadenceArgs(args ...cadence.Value) []json.RawMessage
MustCadenceArgs tries to serialize the given Cadence values and panics with an error if it fails.
Types ¶
type ChallengeRequest ¶
type ChallengeRequest interface { Difficulty(cfg Difficulty) int ToTxn() (*raw.Transaction, error) }
ChallengeRequest defines the interface a client request struct needs to implement if it needs to be accompanied with a challenge and proof.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides a Mappchain API client.
func NewClient ¶
func NewClient(opts ...ClientOption) *Client
NewClient returns a new Mappchain API client.
func (*Client) CreateAccount ¶
func (c *Client) CreateAccount(ctx context.Context, key *SigningKey, req *CreateAccountRequest) (*CreateAccountResponse, error)
CreateAccount sends a request to create a new account.
func (*Client) ExecuteRead ¶
func (c *Client) ExecuteRead(ctx context.Context, req *ExecuteReadRequest) (*ExecuteReadResponse, error)
ExecuteRead sends a request to execute a read transaction.
func (*Client) ExecuteWrite ¶
func (c *Client) ExecuteWrite(ctx context.Context, req *ExecuteWriteRequest) (*ExecuteWriteResponse, error)
ExecuteWrite sends a request to execute a write transaction.
func (*Client) GetBlock ¶
func (c *Client) GetBlock(ctx context.Context, req *GetBlockRequest) (*GetBlockResponse, error)
GetBlock sends a request to get the info for a specific block.
func (*Client) GetChainInfo ¶
func (c *Client) GetChainInfo(ctx context.Context) (*GetChainInfoResponse, error)
GetChainInfo sends a request to get the chain metadata.
func (*Client) GetTransactionResult ¶
func (c *Client) GetTransactionResult(ctx context.Context, req *GetTransactionResultRequest) (*GetTransactionResultResponse, error)
GetTransactionResult sends a request to get the state of a transaction.
func (*Client) ListFieldValues ¶
func (c *Client) ListFieldValues(ctx context.Context, req *ListFieldValuesRequest) (*ListFieldValuesResponse, error)
ListFieldValues sends a request to get all values of a specific event field.
func (*Client) QueryEvents ¶
func (c *Client) QueryEvents(ctx context.Context, req *QueryEventsRequest) (*QueryEventsResponse, error)
QueryEvents sends a request to query blocks for a specific event type.
func (*Client) UploadFile ¶
func (c *Client) UploadFile(ctx context.Context, req *UploadFileRequest) (*UploadFileResponse, error)
UploadFile sends a request to upload a file to the chain.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption values can be used to configure the API client.
func WithDebugLogger ¶
func WithDebugLogger(log func(format string, args ...interface{})) ClientOption
WithDebugLogger configures the API client with a specific debug logger.
func WithEndpoint ¶
func WithEndpoint(v string) ClientOption
WithEndpoint configures the API client with a specific API endpoint.
func WithTimeout ¶
func WithTimeout(d time.Duration) ClientOption
WithTimeout configures the API client with a specific timeout duration.
type CreateAccountRequest ¶
type CreateAccountRequest struct { About string `json:"about"` Challenge string `json:"challenge"` Image string `json:"image"` Name string `json:"name"` Nonce string `json:"nonce"` Proof string `json:"proof"` PublicKey PublicKey `json:"publicKey"` Tags []string `json:"tags"` }
CreateAccountRequest represents the /api/v1/CreateAccount request.
func (*CreateAccountRequest) Difficulty ¶
func (c *CreateAccountRequest) Difficulty(cfg Difficulty) int
func (*CreateAccountRequest) ToTxn ¶
func (c *CreateAccountRequest) ToTxn() (*raw.Transaction, error)
type CreateAccountResponse ¶
type CreateAccountResponse struct {
TransactionHash string `json:"transactionHash"`
}
CreateAccountResponse represents the /api/v1/CreateAccount response.
type Difficulty ¶
type Difficulty struct { CreateAccount float64 `json:"createAccount"` ExecuteWrite float64 `json:"executeWrite"` PerKilobyte float64 `json:"perKilobyte"` UploadFile float64 `json:"uploadFile"` }
Difficulty specifies the difficulty level for different operations.
type ErrorResponse ¶
type ErrorResponse struct {
Error ErrorInfo `json:"error"`
}
ErrorResponse represents a site error response.
type EventOccurence ¶
type EventOccurence struct { BlockHeight uint64 `json:"blockHeight"` Event Event `json:"event"` EventIndex uint32 `json:"eventIndex"` TransactionHash string `json:"transactionHash"` TransactionIndex uint32 `json:"transactionIndex"` }
EventOccurence represents the individual occurence of an event within a transaction.
type ExecuteReadRequest ¶
type ExecuteReadRequest struct { Arguments []json.RawMessage `json:"args"` Height uint64 `json:"height"` Script string `json:"script"` }
ExecuteReadRequest represents the /api/v1/ExecuteRead request.
type ExecuteReadResponse ¶
type ExecuteReadResponse struct {
Result json.RawMessage `json:"result"`
}
ExecuteReadResponse represents the /api/v1/ExecuteRead response.
type ExecuteWriteRequest ¶
type ExecuteWriteRequest struct { Arguments []json.RawMessage `json:"args"` Challenge string `json:"challenge"` Nonce string `json:"nonce"` Proof string `json:"proof"` Script string `json:"script"` Signatures []Signature `json:"signatures"` }
ExecuteWriteRequest represents the /api/v1/ExecuteWrite request.
func (*ExecuteWriteRequest) Difficulty ¶
func (e *ExecuteWriteRequest) Difficulty(cfg Difficulty) int
func (*ExecuteWriteRequest) ToTxn ¶
func (e *ExecuteWriteRequest) ToTxn() (*raw.Transaction, error)
type ExecuteWriteResponse ¶
type ExecuteWriteResponse struct {
TransactionHash string `json:"transactionHash"`
}
ExecuteWriteResponse represents the /api/v1/ExecuteWrite response.
type Field ¶
type Field struct { Name string `json:"name"` Value json.RawMessage `json:"value"` }
Field represents an individual field within an emitted event.
type Filter ¶
type Filter struct { FieldIndex uint8 `json:"fieldIndex"` Operation string `json:"operation"` Value json.RawMessage `json:"value"` }
Filter defines a sub-query on the value of an event field.
type GetBlockRequest ¶
type GetBlockRequest struct {
Height uint64 `json:"height"`
}
GetBlockRequest represents the /api/v1/GetBlock request.
type GetBlockResponse ¶
type GetBlockResponse struct { Executed bool `json:"executed"` Hash string `json:"hash"` Height uint64 `json:"height"` PrevBlockHash string `json:"prevBlockHash"` Timestamp uint64 `json:"timestamp"` Transactions []Transaction `json:"transactions"` }
GetBlockResponse represents the /api/v1/GetBlock response.
type GetChainInfoResponse ¶
type GetChainInfoResponse struct { ChainID uint64 `json:"chainId"` Challenge string `json:"challenge"` ChallengeRotation uint32 `json:"challengeRotation"` Difficulty Difficulty `json:"difficulty"` KDFParams KDFParams `json:"kdfParams"` LatestBlock LatestBlock `json:"latestBlock"` MaxUploadFileSize int64 `json:"maxUploadFileSize"` }
GetChainInfoResponse represents the /api/v1/GetChainInfo response.
func (*GetChainInfoResponse) CheckInterval ¶
func (g *GetChainInfoResponse) CheckInterval() time.Duration
CheckInterval returns the time duration for updating the challenge.
type GetTransactionResultRequest ¶
type GetTransactionResultRequest struct {
TransactionHash string `json:"transactionHash"`
}
GetTransactionResultRequest represents the /api/v1/GetTransactionResult request.
type GetTransactionResultResponse ¶
type GetTransactionResultResponse struct { Executed bool `json:"executed"` Height uint64 `json:"height"` Result *TransactionResult `json:"result"` }
GetTransactionResultResponse represents the /api/v1/GetTransactionResult response.
type KDFParams ¶
type KDFParams struct { Algorithm string `json:"algorithm"` Iterations int `json:"iterations"` KeyLength int `json:"keyLength"` Memory int `json:"memory"` Parallelism int `json:"parallelism"` }
KDFParams defines the configuration for applying the key derivation function.
type LatestBlock ¶
type LatestBlock struct { Executed uint64 `json:"executed"` Hash string `json:"hash"` Height uint64 `json:"height"` }
LatestBlock specifies the state of the latest blocks that have been produced and executed.
type ListFieldValuesRequest ¶
type ListFieldValuesRequest struct { Cursor string `json:"cursor"` EventType string `json:"eventType"` FieldIndex uint8 `json:"fieldIndex"` }
ListFieldValuesRequest represents the /api/v1/ListFieldValues request.
type ListFieldValuesResponse ¶
type ListFieldValuesResponse struct { Cursor string `json:"cursor"` Values []json.RawMessage `json:"values"` }
ListFieldValuesResponse represents the /api/v1/ListFieldValues request.
type PublicKey ¶
type PublicKey struct { HashAlgorithm string `json:"hashAlgorithm"` SigningAlgorithm string `json:"signingAlgorithm"` Value string `json:"value"` Weight uint32 `json:"weight"` }
PublicKey represents a public key for an account.
type QueryEventsRequest ¶
type QueryEventsRequest struct { StartBlock uint64 `json:"startBlock"` EventType string `json:"eventType"` Filters []Filter `json:"filters"` }
QueryEventsRequest represents the /api/v1/QueryEvents request.
type QueryEventsResponse ¶
type QueryEventsResponse struct { EndBlock uint64 `json:"endBlock"` Results []*EventOccurence `json:"results"` }
QueryEventsResponse represents the /api/v1/QueryEvents response.
type Signature ¶
type Signature struct { AccountID string `json:"accountId"` KeyIndex uint32 `json:"keyIndex"` Value string `json:"value"` }
Signature represents the signature for an on-chain transaction.
type Signer ¶
type Signer struct { AccountID string KeyIndex uint32 SigningKey *SigningKey }
Signer represents an on-chain account and its signing key.
type SigningKey ¶
type SigningKey struct {
// contains filtered or unexported fields
}
SigningKey represents a key to use for signing transactions.
func GenerateKey ¶
func GenerateKey() (*SigningKey, error)
GenerateKey creates a fresh key for signing transactions.
func LoadKey ¶
func LoadKey(privkey []byte) (*SigningKey, error)
LoadKey creates a signing key from the raw private key.
func (*SigningKey) PublicKey ¶
func (s *SigningKey) PublicKey() PublicKey
PublicKey returns the default public key specification for the signing key.
func (*SigningKey) RawPrivateKey ¶
func (s *SigningKey) RawPrivateKey() []byte
RawPrivateKey returns the raw bytes of the underlying private key.
type Transaction ¶
type Transaction struct { Arguments []json.RawMessage `json:"args"` Hash string `json:"hash"` Nonce string `json:"nonce"` Script string `json:"script"` Signatures []Signature `json:"signatures"` Type string `json:"type"` }
Transaction represents a transaction that has been processed on-chain.
type TransactionResult ¶
type TransactionResult struct { Error string `json:"error"` Events []*Event `json:"events"` Log []string `json:"log"` Status string `json:"status"` TransactionIndex uint32 `json:"transactionIndex"` }
TransactionResult represents the result of executing a transaction.
type UploadFileRequest ¶
type UploadFileRequest struct { Challenge string `json:"challenge"` File []byte `json:"file"` Nonce string `json:"nonce"` Proof string `json:"proof"` }
UploadFileRequest represents the /api/v1/UploadFile request.
func (*UploadFileRequest) Difficulty ¶
func (u *UploadFileRequest) Difficulty(cfg Difficulty) int
func (*UploadFileRequest) ToTxn ¶
func (u *UploadFileRequest) ToTxn() (*raw.Transaction, error)
type UploadFileResponse ¶
type UploadFileResponse struct {
FileID string `json:"fileId"`
}
UploadFileResponse represents the /api/v1/UploadFile response.
Directories ¶
Path | Synopsis |
---|---|
Package jsoncdc provides support for JSON encoding and decoding of Cadence values.
|
Package jsoncdc provides support for JSON encoding and decoding of Cadence values. |
Package script defines some Cadence scripts for the core Mapp framework.
|
Package script defines some Cadence scripts for the core Mapp framework. |