bluzelle

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

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

Go to latest
Published: Jun 25, 2020 License: MIT Imports: 24 Imported by: 0

README

Getting started

Ensure you have a recent version of Go installed.

Grab the package from github:

go get github.com/bluzelle/blzgo

Use:

package main

import (
  "github.com/bluzelle/blzgo"
  "log"
)

func main() {
  // create client
  options := &bluzelle.Options{
    Mnemonic: "...",
    Endpoint: "http://dev.testnet.public.bluzelle.com:1317",
    UUID: "...",
  }
  client, err := bluzelle.NewClient(options)
  if err != nil {
    log.Fatalf("%s", err)
  }

  key := "foo"
  value := "bar"

  gasInfo := bluzelle.GasInfo{
    MaxFee: 4000001,
  }
  leaseInfo := bluzelle.LeaseInfo{
    Days: 1,
  }

  // create key
  if err := client.Create(key, value, gasInfo, leaseInfo); err != nil {
    log.Fatalf("%s", err)
  } else {
    log.Printf("create key success: true\n")
  }

  // read key
  if v, err := client.Read(key); err != nil {
    log.Fatalf("%s", err)
  } else {
    log.Printf("read key success: %t\n", v == value)
  }

  // update key
  if err := client.Create(key, value, gasInfo, nil); err != nil {
    log.Fatalf("%s", err)
  } else {
    log.Printf("create key success: true\n")
  }

  // delete key
  if err := client.Delete(key, gasInfo); err != nil {
    log.Fatalf("%s", err)
  } else {
    log.Printf("delete key success: true\n")
  }
}

Examples

You can test out the examples/ included by following these steps:

  1. Copy .env.sample to .env and configure if needed.
cp .env.sample .env
  1. Install dependencies:
go get ./...
  1. Run an example as defined in the Makefile, for example, to read the value of an existing key, foo, run:
make read key=foo

This will run the examples/crud/read.go.

Integration Tests

make test

User Acceptance Testing

Please checkout the UAT.md document for more details.

Licence

MIT

Documentation

Index

Constants

View Source
const ADDRESS_PREFIX string = "bluzelle"
View Source
const BLOCK_TIME_IN_SECONDS = 5
View Source
const BROADCAST_MAX_RETRIES = 10
View Source
const BROADCAST_RETRY_INTERVAL = time.Second
View Source
const DEFAULT_CHAIN_ID string = "bluzelle"
View Source
const DEFAULT_ENDPOINT string = "http://localhost:1317"
View Source
const HD_PATH string = "m/44'/118'/0'/0/0"
View Source
const INVALID_LEASE_TIME = "Invalid lease time"
View Source
const KEY_CANNOT_CONTAIN_A_SLASH string = "Key cannot contain a slash"
View Source
const KEY_IS_REQUIRED string = "Key is required"
View Source
const NEW_KEY_IS_REQUIRED string = "New Key is required"
View Source
const TOKEN_NAME = "ubnt"
View Source
const TX_COMMAND = "/txs"
View Source
const VALUE_IS_REQUIRED string = "Value is required"

Variables

This section is empty.

Functions

func LoadEnv

func LoadEnv()

func SetupLogging

func SetupLogging()

func TestAddress

func TestAddress() string

func UrlPathEscape

func UrlPathEscape(s string) string

PathEscape escapes the string so it can be safely placed inside a URL path segment, replacing special characters (including /) with %XX sequences as needed.

Types

type Account

type Account struct {
	AccountNumber int     `json:"account_number"`
	Address       string  `json:"address"`
	Coins         []*Coin `json:"coins"`
	PublicKey     string  `json:"public_key"`
	Sequence      int     `json:"sequence"`
}

type AccountResponse

type AccountResponse struct {
	Result *AccountResponseResult `json:"result"`
}

type AccountResponseResult

type AccountResponseResult struct {
	Value *Account `json:"value"`
}

type Client

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

func NewClient

func NewClient(options *Options) (*Client, error)

func NewTestClient

func NewTestClient() (*Client, error)

func (*Client) APIMutate

func (ctx *Client) APIMutate(method string, endpoint string, payload []byte) ([]byte, error)

func (*Client) APIQuery

func (ctx *Client) APIQuery(endpoint string) ([]byte, error)

func (*Client) Account

func (ctx *Client) Account() (*Account, error)

func (*Client) BroadcastTransaction

func (ctx *Client) BroadcastTransaction(txn *TransactionBroadcastPayload, gasInfo *GasInfo) ([]byte, error)

func (*Client) Count

func (ctx *Client) Count() (int, error)

func (*Client) Create

func (ctx *Client) Create(key string, value string, gasInfo *GasInfo, leaseInfo *LeaseInfo) error

func (*Client) Debugf

func (ctx *Client) Debugf(msg string, v ...interface{})

Debugf level formatted messagctx.logger.

func (*Client) Delete

func (ctx *Client) Delete(key string, gasInfo *GasInfo) error

func (*Client) DeleteAll

func (ctx *Client) DeleteAll(gasInfo *GasInfo) error

func (*Client) Errorf

func (ctx *Client) Errorf(msg string, v ...interface{})

Errorf level formatted messagctx.logger.

func (*Client) Fatalf

func (ctx *Client) Fatalf(msg string, v ...interface{})

Fatalf level formatted messagctx.logger.

func (*Client) GetLease

func (ctx *Client) GetLease(key string) (int64, error)

func (*Client) GetNShortestLeases

func (ctx *Client) GetNShortestLeases(n uint64) ([]*GetNShortestLeasesResponseResultKeyLease, error)

func (*Client) Has

func (ctx *Client) Has(key string) (bool, error)

func (*Client) Infof

func (ctx *Client) Infof(msg string, v ...interface{})

Infof level formatted messagctx.logger.

func (*Client) KeyValues

func (ctx *Client) KeyValues() ([]*KeyValue, error)

func (*Client) Keys

func (ctx *Client) Keys() ([]string, error)

func (*Client) MultiUpdate

func (ctx *Client) MultiUpdate(keyValues []*KeyValue, gasInfo *GasInfo) error

func (*Client) ProcessTransaction

func (ctx *Client) ProcessTransaction(txn *Transaction)

func (*Client) ProvenRead

func (ctx *Client) ProvenRead(key string) (string, error)

func (*Client) Read

func (ctx *Client) Read(key string) (string, error)

func (*Client) Rename

func (ctx *Client) Rename(key string, newKey string, gasInfo *GasInfo) error

func (*Client) RenewAllLeases

func (ctx *Client) RenewAllLeases(gasInfo *GasInfo, leaseInfo *LeaseInfo) error

func (*Client) RenewLease

func (ctx *Client) RenewLease(key string, gasInfo *GasInfo, leaseInfo *LeaseInfo) error

func (*Client) RenewLeaseAll

func (ctx *Client) RenewLeaseAll(gasInfo *GasInfo, leaseInfo *LeaseInfo) error

func (*Client) SendTransaction

func (ctx *Client) SendTransaction(txn *Transaction) ([]byte, error)

func (*Client) SignTransaction

func (ctx *Client) SignTransaction(txn *TransactionBroadcastPayload) (string, error)

func (*Client) TxCount

func (ctx *Client) TxCount(gasInfo *GasInfo) (int, error)

func (*Client) TxGetLease

func (ctx *Client) TxGetLease(key string, gasInfo *GasInfo) (int64, error)

func (*Client) TxGetNShortestLeases

func (ctx *Client) TxGetNShortestLeases(n uint64, gasInfo *GasInfo) ([]*GetNShortestLeasesResponseResultKeyLease, error)

func (*Client) TxHas

func (ctx *Client) TxHas(key string, gasInfo *GasInfo) (bool, error)

func (*Client) TxKeyValues

func (ctx *Client) TxKeyValues(gasInfo *GasInfo) ([]*KeyValue, error)

func (*Client) TxKeys

func (ctx *Client) TxKeys(gasInfo *GasInfo) ([]string, error)

func (*Client) TxRead

func (ctx *Client) TxRead(key string, gasInfo *GasInfo) (string, error)

func (*Client) UUID

func (root *Client) UUID(uuid string) *Client

func (*Client) Update

func (ctx *Client) Update(key string, value string, gasInfo *GasInfo, leaseInfo *LeaseInfo) error

func (*Client) ValidateTransaction

func (ctx *Client) ValidateTransaction(txn *Transaction) (*TransactionBroadcastPayload, error)

Get required min gas

func (*Client) Version

func (ctx *Client) Version() (string, error)

func (*Client) Warnf

func (ctx *Client) Warnf(msg string, v ...interface{})

Warnf level formatted messagctx.logger.

type Coin

type Coin struct {
	Denom  string `json:"denom"`
	Amount string `json:"amount"`
}

type CountResponse

type CountResponse struct {
	Result *CountResponseResult `json:"result"`
}

type CountResponseResult

type CountResponseResult struct {
	Count string `json:"count"`
}

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

type GasInfo

type GasInfo struct {
	MaxGas   int `json:"max_gas"`
	MaxFee   int `json:"max_fee"`
	GasPrice int `json:"gas_price"`
}

func TestGasInfo

func TestGasInfo() *GasInfo

type GetLeaseResponse

type GetLeaseResponse struct {
	Result *GetLeaseResponseResult `json:"result"`
}

type GetLeaseResponseResult

type GetLeaseResponseResult struct {
	Lease string `json:"lease"`
}

type GetNShortestLeasesResponse

type GetNShortestLeasesResponse struct {
	Result *GetNShortestLeasesResponseResult `json:"result"`
}

type GetNShortestLeasesResponseResult

type GetNShortestLeasesResponseResult struct {
	KeyLeases []*KeyLease `json:"keyleases"`
}

func (*GetNShortestLeasesResponseResult) GetHumanizedKeyLeases

type GetNShortestLeasesResponseResultKeyLease

type GetNShortestLeasesResponseResultKeyLease struct {
	Key   string `json:"key"`
	Lease int64  `json:"lease"`
}

type HasResponse

type HasResponse struct {
	Result *HasResponseResult `json:"result"`
}

type HasResponseResult

type HasResponseResult struct {
	Has bool `json:"has"`
}

type KeyLease

type KeyLease struct {
	Key   string `json:"key,omitempty"`
	Lease string `json:"lease,omitempty"`
}

type KeyValue

type KeyValue struct {
	Key   string `json:"key,omitempty"`
	Value string `json:"value,omitempty"`
}

type KeyValuesResponse

type KeyValuesResponse struct {
	Result *KeyValuesResponseResult `json:"result"`
}

type KeyValuesResponseResult

type KeyValuesResponseResult struct {
	KeyValues []*KeyValue `json:"keyvalues"`
}

type KeysResponse

type KeysResponse struct {
	Result *KeysResponseResult `json:"result"`
}

type KeysResponseResult

type KeysResponseResult struct {
	Keys []string `json:"keys"`
}

type LeaseInfo

type LeaseInfo struct {
	Days    int64 `json:"days"`
	Hours   int64 `json:"hours"`
	Minutes int64 `json:"minutes"`
	Seconds int64 `json:"seconds"`
}

func (*LeaseInfo) ToBlocks

func (lease *LeaseInfo) ToBlocks() int64

type Options

type Options struct {
	Mnemonic string
	Endpoint string
	UUID     string
	ChainId  string
	Debug    bool
}

type ReadResponse

type ReadResponse struct {
	Result *ReadResponseResult `json:"result"`
}

type ReadResponseResult

type ReadResponseResult struct {
	Value string `json:"value"`
}

type Test

type Test struct {
	Client *Client
	Key1   string
	Key2   string
	Key3   string
	Value1 string
	Value2 string
	Value3 string
}

func (*Test) TestSetUp

func (ctx *Test) TestSetUp() error

func (*Test) TestTearDown

func (ctx *Test) TestTearDown() error

type Transaction

type Transaction struct {
	Key       string
	KeyValues []*KeyValue
	Lease     int64
	N         uint64
	NewKey    string
	Value     string

	ApiRequestMethod   string
	ApiRequestEndpoint string
	GasInfo            *GasInfo
	// contains filtered or unexported fields
}

type TransactionBroadcastPayload

type TransactionBroadcastPayload struct {
	Fee        *TransactionFee         `json:"fee"`
	Memo       string                  `json:"memo"`
	Msg        []*TransactionMsg       `json:"msg"`
	Signatures []*TransactionSignature `json:"signatures"`
}

type TransactionBroadcastPayloadSignPayload

type TransactionBroadcastPayloadSignPayload struct {
	AccountNumber string            `json:"account_number"`
	ChainId       string            `json:"chain_id"`
	Fee           *TransactionFee   `json:"fee"`
	Memo          string            `json:"memo"`
	Msgs          []*TransactionMsg `json:"msgs"`
	Sequence      string            `json:"sequence"`
}

type TransactionBroadcastRequest

type TransactionBroadcastRequest struct {
	Transaction *TransactionBroadcastPayload `json:"tx"`
	Mode        string                       `json:"mode"`
}

type TransactionBroadcastResponse

type TransactionBroadcastResponse struct {
	Height    string `json:"height"`
	TxHash    string `json:"txhash"`
	Data      string `json:"data"`
	Codespace string `json:"codespace"`
	Code      int    `json:"code"`
	RawLog    string `json:"raw_log"`
	GasWanted string `json:"gas_wanted"`
}

type TransactionFee

type TransactionFee struct {
	Amount []*TransactionFeeAmount `json:"amount"`
	Gas    string                  `json:"gas"`
}

type TransactionFeeAmount

type TransactionFeeAmount struct {
	Amount string `json:"amount"`
	Denom  string `json:"denom"`
}

type TransactionMsg

type TransactionMsg struct {
	Type  string               `json:"type"`
	Value *TransactionMsgValue `json:"value"`
}

type TransactionMsgValue

type TransactionMsgValue struct {
	Key       string      `json:"Key,omitempty"`
	KeyValues []*KeyValue `json:"KeyValues,omitempty"`
	Lease     string      `json:"Lease,omitempty"`
	N         string      `json:"N,omitempty"`
	NewKey    string      `json:"NewKey,omitempty"`
	Owner     string      `json:"Owner"`
	UUID      string      `json:"UUID"`
	Value     string      `json:"Value,omitempty"`
}

type TransactionSignature

type TransactionSignature struct {
	AccountNumber string                      `json:"account_number"`
	PubKey        *TransactionSignaturePubKey `json:"pub_key"`
	Sequence      string                      `json:"sequence"`
	Signature     string                      `json:"signature"`
}

type TransactionSignaturePubKey

type TransactionSignaturePubKey struct {
	Type  string `json:"type"`
	Value string `json:"value"`
}

type TransactionValidateRequest

type TransactionValidateRequest struct {
	BaseReq   *TransactionValidateRequestBaseReq `json:"BaseReq"`
	Key       string                             `json:"Key,omitempty"`
	KeyValues []*KeyValue                        `json:"KeyValues,omitempty"`
	Lease     string                             `json:"Lease,omitempty"`
	N         string                             `json:"N,omitempty"`
	NewKey    string                             `json:"NewKey,omitempty"`
	Owner     string                             `json:"Owner"`
	UUID      string                             `json:"UUID"`
	Value     string                             `json:"Value,omitempty"`
}

type TransactionValidateRequestBaseReq

type TransactionValidateRequestBaseReq struct {
	From    string `json:"from"`
	ChainId string `json:"chain_id"`
}

type TransactionValidateResponse

type TransactionValidateResponse struct {
	Type  string                       `json:"type"`
	Value *TransactionBroadcastPayload `json:"value"`
}

type VersionResponse

type VersionResponse struct {
	ApplicationVersion *VersionResponseApplicationVersion `json:"application_version"`
}

type VersionResponseApplicationVersion

type VersionResponseApplicationVersion struct {
	Version string `json:"version"`
}

Jump to

Keyboard shortcuts

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