pact

package module
v0.0.0-...-b92c034 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2021 License: MIT Imports: 14 Imported by: 1

README

go-pact

Module to ease interaction with Pact's development server & ScalableBFT

Install

   go install github.com/jfamousket/go-pact@latest

Functions

Hashing

Create a blake2b hash

import (
    "github.com/jfamousket/go-pact"
)

pact.CreateBlake2Hash(<cmd_string>) string
Pact API functions

This functions are same as described in pact-api-documentation

import (
    "github.com/jfamousket/go-pact"
)

pact.Send(<valid_cmd_object>, <api_host>) pact.SendResponse
pact.Local(<valid_cmd_object>, <api_host>) pact.LocalResponse
pact.Listen(<request_key>, <api_host>) pact.ListenResponse
pact.Poll(<array_of_request_keys>, <api_host>) pact.PollResponse

Usage

See the example directory in this project, for an example TODO app.

TODOS

  • Improve docs

Contributors

Built with ❤ by jfamousket

Documentation

Index

Constants

View Source
const (
	TEST_PACT_URL  = "https://api.testnet.chainweb.com/chainweb/0.0/testnet04/chain/0/pact"
	TEST_URL       = "https://api.testnet.chainweb.com"
	LOCAL_PACT_URL = "http://localhost:9001"
)

Variables

This section is empty.

Functions

func CreateBlake2Hash

func CreateBlake2Hash(data []byte) ([32]byte, string)

func EnforceNoError

func EnforceNoError(err error)

func EnforceType

func EnforceType(value, valueType interface{}, msg string)

func EnforceValid

func EnforceValid(valid bool, err error)

func MakeExpression

func MakeExpression(programName string, args ...interface{}) string

func MarshalBody

func MarshalBody(value interface{}) (b *bytes.Buffer, err error)

func SPV

func SPV(spvCmd SPVCommand, apiHost string) (res interface{}, err error)

Types

type Command

type Command struct {
	Cmd  string `json:"cmd"`
	Hash string `json:"hash"`
	Sigs []Sig  `json:"sigs"`
}

func PrepareContCmd

func PrepareContCmd(cmd PrepareCont) Command

func PrepareExecCommand

func PrepareExecCommand(cmd PrepareExec) Command

PrepareExecCommand creates a command that can be sent to the /exec pact server route

type CommandField

type CommandField struct {
	Nonce     string   `json:"nonce"`
	Meta      *Meta    `json:"meta"`
	Signers   []Signer `json:"signers"`
	Payload   Payload  `json:"payload"`
	NetworkId string   `json:"networkId,omitempty"`
}

type Cont

type Cont struct {
	PactId   string      `json:"pactId"`
	Rollback bool        `json:"rollback"`
	Step     uint64      `json:"step"`
	Data     interface{} `json:"data"`
	Proof    string      `json:"proof"`
}

func (Cont) PayloadType

func (Cont) PayloadType()

type Error

type Error string

func (Error) Error

func (e Error) Error() string

type Exec

type Exec struct {
	Code string       `json:"code"`
	Data *interface{} `json:"data"`
}

func (Exec) PayloadType

func (Exec) PayloadType()

type KeyPair

type KeyPair struct {
	Private ed25519.PrivateKey
	Public  ed25519.PublicKey
}

func GenKeyPair

func GenKeyPair(password string) (keyPair KeyPair, err error)

type ListenResponse

type ListenResponse struct {
	Gas          uint64      `json:"gas"`
	Result       Result      `json:"result"`
	ReqKey       string      `json:"reqKey"`
	Logs         string      `json:"logs"`
	MetaData     interface{} `json:"metaData"`
	Continuation interface{} `json:"continuation"`
	TxId         interface{} `json:"txId"`
}

func Listen

func Listen(requestKey string, apiHost string) (res *ListenResponse, err error)

type LocalResponse

type LocalResponse struct {
	Gas          uint64      `json:"gas,omitempty"`
	Result       Result      `json:"result,omitempty"`
	ReqKey       string      `json:"reqKey,omitempty"`
	Logs         string      `json:"logs,omitempty"`
	MetaData     interface{} `json:"metaData,omitempty"`
	Continuation interface{} `json:"continuation,omitempty"`
	TxId         string      `json:"txId,omitempty"`
}

func Local

func Local(localCmd PrepareExec, apiHost string) (res *LocalResponse, err error)

type Meta

type Meta struct {
	ChainId      string  `json:"chainId"`
	Sender       string  `json:"sender"`
	GasLimit     uint64  `json:"gasLimit"`
	GasPrice     float64 `json:"gasPrice"`
	Ttl          float64 `json:"ttl"`
	CreationTime uint64  `json:"creationTime"`
}

func MakeMeta

func MakeMeta(
	sender, chainId string,
	gasPrice float64,
	gasLimit uint64,
	creationTime uint64,
	ttl float64,
) *Meta

type PactEvents

type PactEvents struct {
	Name       string      `json:"name,omitempty"`
	Params     interface{} `json:"params,omitempty"`
	Module     string      `json:"module,omitempty"`
	ModuleHash string      `json:"moduleHash,omitempty"`
}

type Payload

type Payload struct {
	Exec *Exec `json:"exec,omitempty"`
	Cont *Cont `json:"cont,omitempty"`
}

type PayloadType

type PayloadType interface {
	PayloadType()
}

type PollResponse

type PollResponse struct {
	Gas          int64       `json:"gas,omitempty"`
	ReqKey       string      `json:"reqKey,omitempty"`
	TxId         string      `json:"txId,omitempty"`
	Logs         string      `json:"logs,omitempty"`
	MetaData     interface{} `json:"metaData,omitempty"`
	Continuation interface{} `json:"continuation,omitempty"`
	Events       PactEvents  `json:"events,omitempty"`
}

func Poll

func Poll(requestKeys []string, apiHost string) (res *PollResponse, err error)

type PrepareCommand

type PrepareCommand interface {
	// contains filtered or unexported methods
}

type PrepareCont

type PrepareCont struct {
	KeyPairs  []KeyPair
	Nonce     string
	Proof     string
	Rollback  bool
	Step      uint64
	PactId    string
	EnvData   interface{}
	Meta      *Meta
	NetworkId string
}

type PrepareExec

type PrepareExec struct {
	KeyPairs  []KeyPair
	Nonce     string
	EnvData   interface{}
	Meta      *Meta
	NetworkId string
	PactCode  string
}

type Request

type Request struct {
	RequestKeys string `json:"requestKeys,omitempty"`
}

type RequestKeys

type RequestKeys struct {
	RequestKeys []string `json:"requestKeys,omitempty"`
}

type Result

type Result struct {
	Status string      `json:"status,omitempty"`
	Data   interface{} `json:"data,omitempty"`
}

type SPVCommand

type SPVCommand struct {
	RequestKey    string `json:"requestKey"`
	TargetChainId string `json:"targetChainId"`
}

type Scheme

type Scheme string
const (
	ED25519 Scheme = "ED25519"
	ETH     Scheme = "ETH"
)

type SendCommand

type SendCommand struct {
	Cmds []Command `json:"cmds,omitempty"`
}

type SendResponse

type SendResponse struct {
	RequestKeys []string `json:"requestKeys,omitempty"`
}

SendResponse is the response for a /send api call

func Send

func Send(sendCmd []PrepareCommand, apiHost string) (res *SendResponse, err error)

Send sends a Pact command to a running Pact server and retrieves the transaction result

type Sig

type Sig struct {
	Sig string `json:"sig,omitempty"`
}

type Signer

type Signer struct {
	Scheme Scheme `json:"scheme"`
	PubKey string `json:"pubKey"`
	Addr   string `json:"addr"`
	Caps   string `json:"caps"`
}

func MakeSigner

func MakeSigner(keyPair KeyPair) Signer

Jump to

Keyboard shortcuts

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