gokadena

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

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

Go to latest
Published: Dec 14, 2022 License: MIT Imports: 4 Imported by: 0

README

Kadena and Pact SDK

A simple library to interact with Pact API and easy-to-build command structure.

How to install

go get github.com/BoostyLabs/kadena-go

Usage

Note

The library is still in progress and some endpoints that are provided by Pact API have not been implemented yet.

Example how to construct command payload which named as request.
    req := gokadena.Request{
		Payload: gokadena.Payload{
			Exec: gokadena.Exec{
				Data: "some_data",
				Code: "(+a b)",
			},
		},
		NetworkID: "testnet04",
		Meta: gokadena.Meta{
			ChainID:      "testnet04",
			Sender:       "ba54b224d1924dd98403f5c751abdd10de6cd81b0121800bf7bdbdcfaec7388d",
			GasLimit:     1000,
			GasPrice:     gokadena.DefaultGasPrice,
			TTL:          gokadena.DefaultTTL,
			CreationTime: gokadena.CreationTime(),
		},
		Nonce: gokadena.Nonce(),
		Signers: []gokadena.Signer{
			{
				PubKey:  "ba54b224d1924dd98403f5c751abdd10de6cd81b0121800bf7bdbdcfaec7388d",
				Address: "ba54b224d1924dd98403f5c751abdd10de6cd81b0121800bf7bdbdcfaec7388d",
				Schema:  gokadena.SchemaED25519,
				CList: gokadena.CapabilityItem{
					Name: "coin.TRANSFER",
					Args: []interface{}{"bob", "alice", 0.1},
				},
			},
		},
		Type: gokadena.TypeExec,
    }
Example of API client creation and interaction with endpoint supported by Pact
	kadena := client.New(client.Config{
		NodeAddress: "https://api.chainweb.com/chainweb",
		ChainName:   "mainnet01",
		APIVersion:  "0.0",
		ChainID:     2,
	})

	cmdsResult := client.CommandsResultRequest{
		RequestKeys: []string{"vpIr7t79FRROh-uzZ12VLvXgXdNJlhXIlYYOwOLH6qI"},
	}

Tests

You can also interact with this library using tests. Repository has two types of tests:

  • The first type is unit tests, mostly used for CI, to run use the command from the makefile
make tests
  • The second type is integration tests that are used during development and interact with 3rd party services/nodes. To use run this command
make dev_tests

Documentation

Index

Constants

View Source
const (
	// DefaultTTL is default time to live for tx in mempool.
	DefaultTTL int64 = 28000 // 8 hours.

	// DefaultGasPrice is default gas price in Kadena network.
	DefaultGasPrice float64 = 1e-5
)

Variables

This section is empty.

Functions

func CreationTime

func CreationTime() int64

CreationTime is helper that returns creation unix time of tx.

func Nonce

func Nonce() string

Nonce is helper that returns nonce of current tx.

Types

type CapabilityItem

type CapabilityItem struct {
	Name string      `json:"name"`
	Args interface{} `json:"args"`
}

CapabilityItem defines scope what the signing keys are allowed to sign.

type Command

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

Command describes Kadena command to interact with blockchain.

type Exec

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

Exec contains Pact code where defines what to do with tx and which data should be passed into.

type Meta

type Meta struct {
	ChainID      string  `json:"chainId"`
	Sender       string  `json:"sender"`
	GasLimit     int     `json:"gasLimit"`
	GasPrice     float64 `json:"gasPrice"`
	TTL          int64   `json:"ttl"`
	CreationTime int64   `json:"creationTime"`
}

Meta contains public/private metadata for txs.

type Network

type Network string

Network defines list of all possible Kadena networks.

const (
	// NetworkTestnet defines testnet network.
	NetworkTestnet Network = "testnet"
	// NetworkMainnet defines mainnet network.
	NetworkMainnet Network = "mainnet"
)

type Payload

type Payload struct {
	Exec Exec `json:"exec"`
}

Payload is wrapper above exec.

type Request

type Request struct {
	PactCode  string   `json:"pactCode"`
	EnvData   string   `json:"envData"`
	Payload   Payload  `json:"payload"`
	NetworkID string   `json:"networkId"`
	Meta      Meta     `json:"meta"`
	Nonce     string   `json:"nonce"`
	Signers   []Signer `json:"signers"`
	Type      Type     `json:"type"`
}

Request defines command request aka payload.

func (Request) ToCmd

func (request Request) ToCmd() (Command, error)

ToCmd returns cmd hash with decoded to json command payload.

func (Request) ToHash

func (request Request) ToHash() (string, error)

ToHash returns hash of payload. Hash in Kadena could be can be calculated using this algorithm base64(blake2b(command_json)).

func (Request) ToJSON

func (request Request) ToJSON() (string, error)

ToJSON converts request to json.

type Schema

type Schema string

Schema defines approach to sign data.

const (
	// SchemaED25519 defines ED25519 way.
	SchemaED25519 Schema = "ED25519"
	// SchemaETH defines ETH way.
	SchemaETH Schema = "ETH"
)

type Signer

type Signer struct {
	PubKey  string         `json:"pubKey"`
	Address string         `json:"address"`
	Schema  Schema         `json:"schema"`
	CList   CapabilityItem `json:"clist"`
}

Signer is list of signers, corresponding with list of signatures in outer command.

type Type

type Type string

Type defines different types of command execution.

const (
	// TypeExec defines immediate command execution.
	TypeExec Type = "exec"
	// TypeCont defines continuous command execution, used for listener etc.
	TypeCont Type = "cont"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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