gotezos

package module
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2019 License: MIT Imports: 20 Imported by: 4

README

GoDoc

A Tezos Go Library

Go Tezos is a GoLang driven library for your Tezos node.

Installation

Get goTezos

go get github.com/DefinitelyNotAGoat/go-tezos

Quick Start

Go Tezos is split into multiple services underneath to help organize it's functionality and also makes the library easier to maintain.

To understand how Go Tezos works, take a look at the GoTezos Structure:

type GoTezos struct {
	client    *client
	Constants NetworkConstants
	Block     *BlockService
	SnapShot  *SnapShotService
	Cycle     *CycleService
	Account   *AccountService
	Delegate  *DelegateService
	Network   *NetworkService
	Operation *OperationService
	Contract  *ContractService
}

You can see GoTezos is a wrapper for an http client, and services such as block, SnapShot, Cycle, Account, Delegate, Network, Operation, and Contract. Each service has it's own set of functions. You can see examples of using the Block and SnapShot service below.

Getting A Block
package main

import (
	"fmt"
	goTezos "github.com/DefinitelyNotAGoat/go-tezos"
)

func main() {
	gt, err := goTezos.NewGoTezos("http://127.0.0.1:8732")
	if err != nil {
		fmt.Printf("could not connect to network: %v", err)
	}

	block, err := gt.Block.Get(1000)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(block)
}
Getting a Snap Shot For A Cycle
	snapshot, err := gt.SnapShot.Get(50)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(snapshot)
More Documentation

See github pages

Contributers

Note

Because this project is gaining some traction I made the decision to squash all commits into a single commit, so that we can have a clean and well organized commit history going forward. By doing that, the commit history doesn't reflect the contributions of some very helpful people apart of Tezos community and the go-tezos project. Please take a look at the pull request history to see their individual contributions.

Special Thank You

I want to make sure the following people are recognized and give a special thank you to some of the original contributers to go-tezos:

Pull Requests

Go Tezos is a relatively large project and has the potential to be larger, because of that it's important to maintain quality code and PR's. Please review the pull request guide lines here.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Documentation

Index

Constants

View Source
const MUTEZ = 1000000

MUTEZ is a helper for balance devision

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountService

type AccountService struct {
	// contains filtered or unexported fields
}

AccountService is a struct wrapper for account functions

func (*AccountService) CreateWallet

func (s *AccountService) CreateWallet(mnenomic string, password string) (Wallet, error)

CreateWallet returns Wallet with the mnemonic and password provided

func (*AccountService) GetBalance

func (s *AccountService) GetBalance(tezosAddr string) (float64, error)

GetBalance gets the balance of a public key hash at a specific snapshot for a cycle.

func (*AccountService) GetBalanceAtAssociatedSnapshotBlock added in v1.0.9

func (s *AccountService) GetBalanceAtAssociatedSnapshotBlock(tezosAddr string, associatedBlockHash string) (float64, error)

GetBalanceAtAssociatedSnapshotBlock gets the balance of a contract at a associated snapshot block.

func (*AccountService) GetBalanceAtBlock

func (s *AccountService) GetBalanceAtBlock(tezosAddr string, id interface{}) (int, error)

GetBalanceAtBlock get the balance of an address at a specific hash

func (*AccountService) GetBalanceAtSnapshot

func (s *AccountService) GetBalanceAtSnapshot(tezosAddr string, cycle int) (float64, error)

GetBalanceAtSnapshot gets the balance of a public key hash at a specific snapshot for a cycle.

func (*AccountService) ImportEncryptedWallet

func (s *AccountService) ImportEncryptedWallet(pw, encKey string) (Wallet, error)

ImportEncryptedWallet imports an encrypted wallet using password provided by caller. Caller should remove any 'encrypted:' scheme prefix.

func (*AccountService) ImportWallet

func (s *AccountService) ImportWallet(address, public, secret string) (Wallet, error)

ImportWallet returns an imported Wallet

type BakingRights

type BakingRights []struct {
	Level         int       `json:"level"`
	Delegate      string    `json:"delegate"`
	Priority      int       `json:"priority"`
	EstimatedTime time.Time `json:"estimated_time"`
}

BakingRights a representation of baking rights on the Tezos network

type Block

type Block struct {
	Protocol   string               `json:"protocol"`
	ChainID    string               `json:"chain_id"`
	Hash       string               `json:"hash"`
	Header     StructHeader         `json:"header"`
	Metadata   StructMetadata       `json:"metadata"`
	Operations [][]StructOperations `json:"operations"`
}

Block is a block returned by the Tezos RPC API.

type BlockService

type BlockService struct {
	// contains filtered or unexported fields
}

BlockService is a struct wrapper for all block functions

func (*BlockService) Get

func (b *BlockService) Get(id interface{}) (Block, error)

Get returns a Block at a specific level or hash

func (*BlockService) GetHead

func (b *BlockService) GetHead() (Block, error)

GetHead returns the head block

func (*BlockService) IDToString added in v1.0.8

func (b *BlockService) IDToString(id interface{}) (string, error)

IDToString returns a queryable block reference for a specific level or hash

type Bootstrap added in v1.0.4

type Bootstrap struct {
	Block     string
	Timestamp time.Time
}

Bootstrap is a structure representing the bootstrapped response

type Connections added in v1.0.4

type Connections []struct {
	Incoming bool   `json:"incoming"`
	PeerID   string `json:"peer_id"`
	IDPoint  struct {
		Addr string `json:"addr"`
		Port int    `json:"port"`
	} `json:"id_point"`
	RemoteSocketPort int `json:"remote_socket_port"`
	Versions         []struct {
		Name  string `json:"name"`
		Major int    `json:"major"`
		Minor int    `json:"minor"`
	} `json:"versions"`
	Private       bool `json:"private"`
	LocalMetadata struct {
		DisableMempool bool `json:"disable_mempool"`
		PrivateNode    bool `json:"private_node"`
	} `json:"local_metadata"`
	RemoteMetadata struct {
		DisableMempool bool `json:"disable_mempool"`
		PrivateNode    bool `json:"private_node"`
	} `json:"remote_metadata"`
}

Connections represents network connections

type ContentsMetadata

type ContentsMetadata struct {
	BalanceUpdates  []StructBalanceUpdates `json:"balance_updates"`
	OperationResult *StructOperationResult `json:"operation_result, omitempty"`
	Slots           []int                  `json:"slots"`
}

ContentsMetadata is the Metadata found in the Contents in a operation of a block returned by the Tezos RPC API.

type ContractService

type ContractService struct {
	// contains filtered or unexported fields
}

ContractService is a struct wrapper for contract functions

func (*ContractService) GetStorage

func (s *ContractService) GetStorage(contract string) ([]byte, error)

GetStorage gets the contract storage for a contract

type Conts

type Conts struct {
	Contents []StructContents `json:"contents"`
	Branch   string           `json:"branch"`
}

Conts is helper structure to build out the contents of a a transfer operation to post to the Tezos RPC

type CycleService

type CycleService struct {
	// contains filtered or unexported fields
}

CycleService is a struct wrapper for cycle functions

func (*CycleService) GetCurrent

func (s *CycleService) GetCurrent() (int, error)

GetCurrent gets the current cycle of the chain

type Delegate

type Delegate struct {
	Balance              string                 `json:"balance"`
	FrozenBalance        string                 `json:"frozen_balance"`
	FrozenBalanceByCycle []frozenBalanceByCycle `json:"frozen_balance_by_cycle"`
	StakingBalance       string                 `json:"staking_balance"`
	DelegateContracts    []string               `json:"delegated_contracts"`
	DelegatedBalance     string                 `json:"delegated_balance"`
	Deactivated          bool                   `json:"deactivated"`
	GracePeriod          int                    `json:"grace_period"`
}

Delegate is representation of a delegate on the Tezos Network

type DelegateReport

type DelegateReport struct {
	DelegatePhk      string
	Cycle            int
	Delegations      []DelegationReport
	CycleRewards     string
	TotalFeeRewards  string
	SelfBakedRewards string
	TotalRewards     string
}

DelegateReport represents a rewards report for a delegate and all their delegations for a cycle

func (*DelegateReport) GetPayments

func (dr *DelegateReport) GetPayments(minimum int) []Payment

GetPayments will convert a delegate report into payments for batch pay with a minimum requirement in mutez

type DelegateService

type DelegateService struct {
	// contains filtered or unexported fields
}

DelegateService is a struct wrapper for delegate related functions

func (*DelegateService) GetAllDelegates

func (d *DelegateService) GetAllDelegates() ([]string, error)

GetAllDelegates a list of all tz1 addresses at the head block

func (*DelegateService) GetAllDelegatesByHash

func (d *DelegateService) GetAllDelegatesByHash(hash string) ([]string, error)

GetAllDelegatesByHash gets a list of all tz1 addresses at a certain hash

func (*DelegateService) GetBakingRights

func (d *DelegateService) GetBakingRights(cycle int) (BakingRights, error)

GetBakingRights gets the baking rights for a specific cycle

func (*DelegateService) GetBakingRightsForDelegate

func (d *DelegateService) GetBakingRightsForDelegate(cycle int, delegatePhk string, priority int) (BakingRights, error)

GetBakingRightsForDelegate gets the baking rights for a delegate at a specific cycle with a certain priority level

func (*DelegateService) GetDelegate

func (d *DelegateService) GetDelegate(delegatePhk string) (Delegate, error)

GetDelegate retrieves information about a delegate at the head block

func (*DelegateService) GetDelegations

func (d *DelegateService) GetDelegations(delegatePhk string) ([]string, error)

GetDelegations retrieves a list of all currently delegated contracts for a delegate.

func (*DelegateService) GetDelegationsAtCycle

func (d *DelegateService) GetDelegationsAtCycle(delegatePhk string, cycle int) ([]string, error)

GetDelegationsAtCycle retrieves a list of all currently delegated contracts for a delegate at a specific cycle.

func (*DelegateService) GetEndorsingRights

func (d *DelegateService) GetEndorsingRights(cycle int) (EndorsingRights, error)

GetEndorsingRights gets the endorsing rights for a specific cycle

func (*DelegateService) GetEndorsingRightsForDelegate

func (d *DelegateService) GetEndorsingRightsForDelegate(cycle int, delegatePhk string) (EndorsingRights, error)

GetEndorsingRightsForDelegate gets the endorsing rights for a specific cycle

func (*DelegateService) GetReport

func (d *DelegateService) GetReport(delegatePhk string, cycle int, fee float64) (*DelegateReport, error)

GetReport gets the total rewards for a delegate earned and calculates the gross rewards earned by each delegation for a single cycle. Also includes the share of each delegation.

func (*DelegateService) GetRewards

func (d *DelegateService) GetRewards(delegatePhk string, cycle int) (string, error)

GetRewards gets the rewards earned by a delegate for a specific cycle.

func (*DelegateService) GetStakingBalance

func (d *DelegateService) GetStakingBalance(delegateAddr string, cycle int) (float64, error)

GetStakingBalance gets the staking balance for a delegate at a specific snapshot for a cycle.

func (*DelegateService) GetStakingBalanceAtCycle

func (d *DelegateService) GetStakingBalanceAtCycle(delegateAddr string, cycle int) (string, error)

GetStakingBalanceAtCycle gets the staking balance of a delegate at a specific cycle

type DelegationReport added in v1.0.2

type DelegationReport struct {
	DelegationPhk string
	Share         float64
	GrossRewards  string
	Fee           string
	NetRewards    string
}

DelegationReport represents a rewards report for a delegation in DelegateReport

type EndorsingRights

type EndorsingRights []struct {
	Level         int       `json:"level"`
	Delegate      string    `json:"delegate"`
	Slots         []int     `json:"slots"`
	EstimatedTime time.Time `json:"estimated_time"`
}

EndorsingRights is a representation of endorsing rights on the Tezos network

type FrozenBalance

type FrozenBalance struct {
	Deposits string `json:"deposits"`
	Fees     string `json:"fees"`
	Rewards  string `json:"rewards"`
}

FrozenBalance is representation of frozen balance on the Tezos network

type FrozenBalanceRewards

type FrozenBalanceRewards struct {
	Deposits string `json:"deposits"`
	Fees     string `json:"fees"`
	Rewards  string `json:"rewards"`
}

FrozenBalanceRewards is a FrozenBalanceRewards query returned by the Tezos RPC API.

type GoTezos

type GoTezos struct {
	Constants NetworkConstants
	Block     *BlockService
	SnapShot  *SnapShotService
	Cycle     *CycleService
	Account   *AccountService
	Delegate  *DelegateService
	Network   *NetworkService
	Operation *OperationService
	Contract  *ContractService
	Node      *NodeService
	// contains filtered or unexported fields
}

GoTezos is the driver of the library, it inludes the several RPC services like Block, SnapSHot, Cycle, Account, Delegate, Operations, Contract, and Network

func NewGoTezos

func NewGoTezos(URL ...string) (*GoTezos, error)

NewGoTezos is a constructor that returns a GoTezos object

func (*GoTezos) Get

func (gt *GoTezos) Get(path string, params map[string]string) ([]byte, error)

Get takes path endpoint and returns the response of the query

func (*GoTezos) Post

func (gt *GoTezos) Post(path string, args string) ([]byte, error)

Post takes path endpoint and any arguments and returns the response of the POST

func (*GoTezos) SetHTTPClient

func (gt *GoTezos) SetHTTPClient(client *http.Client)

SetHTTPClient allows you to pass your own Go http client, with your own settings

type NetworkConstants

type NetworkConstants struct {
	ProofOfWorkNonceSize         int      `json:"proof_of_work_nonce_size"`
	NonceLength                  int      `json:"nonce_length"`
	MaxRevelationsPerBlock       int      `json:"max_revelations_per_block"`
	MaxOperationDataLength       int      `json:"max_operation_data_length"`
	MaxProposalsPerDelegate      int      `json:"max_proposals_per_delegate"`
	PreservedCycles              int      `json:"preserved_cycles"`
	BlocksPerCycle               int      `json:"blocks_per_cycle"`
	BlocksPerCommitment          int      `json:"blocks_per_commitment"`
	BlocksPerRollSnapshot        int      `json:"blocks_per_roll_snapshot"`
	BlocksPerVotingPeriod        int      `json:"blocks_per_voting_period"`
	TimeBetweenBlocks            []string `json:"time_between_blocks"`
	EndorsersPerBlock            int      `json:"endorsers_per_block"`
	HardGasLimitPerOperation     string   `json:"hard_gas_limit_per_operation"`
	HardGasLimitPerBlock         string   `json:"hard_gas_limit_per_block"`
	ProofOfWorkThreshold         string   `json:"proof_of_work_threshold"`
	TokensPerRoll                string   `json:"tokens_per_roll"`
	MichelsonMaximumTypeSize     int      `json:"michelson_maximum_type_size"`
	SeedNonceRevelationTip       string   `json:"seed_nonce_revelation_tip"`
	OriginationSize              int      `json:"origination_size"`
	BlockSecurityDeposit         string   `json:"block_security_deposit"`
	EndorsementSecurityDeposit   string   `json:"endorsement_security_deposit"`
	BlockReward                  string   `json:"block_reward"`
	EndorsementReward            string   `json:"endorsement_reward"`
	CostPerByte                  string   `json:"cost_per_byte"`
	HardStorageLimitPerOperation string   `json:"hard_storage_limit_per_operation"`
}

NetworkConstants represents the network constants returned by the Tezos network.

type NetworkService

type NetworkService struct {
	// contains filtered or unexported fields
}

NetworkService is wrapper representing network functions

func (*NetworkService) Connections added in v1.0.4

func (n *NetworkService) Connections() (Connections, error)

Connections gets the network connections

func (*NetworkService) GetChainID

func (n *NetworkService) GetChainID() (string, error)

GetChainID gets the id of the chain with the most fitness

func (*NetworkService) GetConstants

func (n *NetworkService) GetConstants() (NetworkConstants, error)

GetConstants gets the network constants for the Tezos network the client is using.

func (*NetworkService) GetVersions

func (n *NetworkService) GetVersions() ([]NetworkVersion, error)

GetVersions gets the network versions of Tezos network the client is using.

type NetworkVersion

type NetworkVersion struct {
	Name    string `json:"name"`
	Major   int    `json:"major"`
	Minor   int    `json:"minor"`
	Network string // Human readable network name
}

NetworkVersion represents the network version returned by the Tezos network.

type NetworkVersions

type NetworkVersions []NetworkVersion

NetworkVersions is an array of NetworkVersion

type NodeService added in v1.0.4

type NodeService struct {
	// contains filtered or unexported fields
}

NodeService is a service for node related functions

func (*NodeService) Bootstrapped added in v1.0.4

func (n *NodeService) Bootstrapped() (Bootstrap, error)

Bootstrapped gets the current node bootstrap

func (*NodeService) CommitHash added in v1.0.4

func (n *NodeService) CommitHash() (string, error)

CommitHash gets the current commit the node is running

type OperationService

type OperationService struct {
	// contains filtered or unexported fields
}

OperationService is a struct wrapper for operation related functions

func (*OperationService) CreateBatchPayment

func (o *OperationService) CreateBatchPayment(payments []Payment, wallet Wallet, paymentFee int, gaslimit int, batchSize int) ([]string, error)

CreateBatchPayment forges batch payments and returns them ready to inject to a Tezos RPC. PaymentFee must be expressed in mutez and the max batch size allowed is 200.

func (*OperationService) GetBlockOperationHashes

func (o *OperationService) GetBlockOperationHashes(id interface{}) ([]string, error)

GetBlockOperationHashes returns list of operations in block at specific level

func (*OperationService) InjectOperation

func (o *OperationService) InjectOperation(op string) ([]byte, error)

InjectOperation injects an signed operation string and returns the response

type Payment

type Payment struct {
	Address string
	Amount  float64
}

Payment is a helper struct for transfers

type SnapShot

type SnapShot struct {
	Cycle           int
	Number          int
	AssociatedHash  string
	AssociatedBlock int
}

SnapShot is a SnapShot on the Tezos Network.

type SnapShotQuery

type SnapShotQuery struct {
	RandomSeed   string `json:"random_seed"`
	RollSnapShot int    `json:"roll_snapshot"`
}

SnapShotQuery is a SnapShot returned by the Tezos RPC API.

type SnapShotService

type SnapShotService struct {
	// contains filtered or unexported fields
}

SnapShotService is a struct wrapper for snap shot functions

func (*SnapShotService) Get

func (s *SnapShotService) Get(cycle int) (SnapShot, error)

Get takes a cycle number and returns a helper structure describing a snap shot on the tezos network.

func (*SnapShotService) GetAll

func (s *SnapShotService) GetAll() ([]SnapShot, error)

GetAll gets a list of all known snapshots to the network

type StructBalanceUpdates

type StructBalanceUpdates struct {
	Kind     string `json:"kind"`
	Contract string `json:"contract,omitempty"`
	Change   string `json:"change"`
	Category string `json:"category,omitempty"`
	Delegate string `json:"delegate,omitempty"`
	Cycle    int    `json:"cycle,omitempty"`
	Level    int    `json:"level,omitempty"`
}

StructBalanceUpdates is the BalanceUpdates found in the Metadata of a block returned by the Tezos RPC API.

type StructContents

type StructContents struct {
	Kind             string            `json:"kind,omitempty"`
	Source           string            `json:"source,omitempty"`
	Fee              string            `json:"fee,omitempty"`
	Counter          string            `json:"counter,omitempty"`
	GasLimit         string            `json:"gas_limit,omitempty"`
	StorageLimit     string            `json:"storage_limit,omitempty"`
	Amount           string            `json:"amount,omitempty"`
	Destination      string            `json:"destination,omitempty"`
	Delegate         string            `json:"delegate,omitempty"`
	Phk              string            `json:"phk,omitempty"`
	Secret           string            `json:"secret,omitempty"`
	Level            int               `json:"level,omitempty"`
	ManagerPublicKey string            `json:"managerPubkey,omitempty"`
	Balance          string            `json:"balance,omitempty"`
	Period           int               `json:"period,omitempty"`
	Proposal         string            `json:"proposal,omitempty"`
	Proposals        []string          `json:"proposals,omitempty"`
	Ballot           string            `json:"ballot,omitempty"`
	Metadata         *ContentsMetadata `json:"metadata,omitempty"`
}

StructContents is the Contents found in a operation of a block returned by the Tezos RPC API.

type StructError added in v1.0.9

type StructError struct {
	Kind string `json:"kind"`
	ID   string `json:"id"`
}

StructError is the Error found in the OperationResult in a metadata of operation of a block returned by the Tezos RPC API.

type StructHeader

type StructHeader struct {
	Level            int       `json:"level"`
	Proto            int       `json:"proto"`
	Predecessor      string    `json:"Predecessor"`
	Timestamp        time.Time `json:"timestamp"`
	ValidationPass   int       `json:"validation_pass"`
	OperationsHash   string    `json:"operations_hash"`
	Fitness          []string  `json:"fitness"`
	Context          string    `json:"context"`
	Priority         int       `json:"priority"`
	ProofOfWorkNonce string    `json:"proof_of_work_nonce"`
	Signature        string    `json:"signature"`
}

StructHeader is a header in a block returned by the Tezos RPC API.

type StructLevel

type StructLevel struct {
	Level                int  `json:"level"`
	LevelPosition        int  `json:"level_position"`
	Cycle                int  `json:"cycle"`
	CyclePosition        int  `json:"cycle_position"`
	VotingPeriod         int  `json:"voting_period"`
	VotingPeriodPosition int  `json:"voting_period_position"`
	ExpectedCommitment   bool `json:"expected_commitment"`
}

StructLevel the Level found in the Metadata of a block returned by the Tezos RPC API.

type StructMaxOperationListLength

type StructMaxOperationListLength struct {
	MaxSize int `json:"max_size"`
	MaxOp   int `json:"max_op,omitempty"`
}

StructMaxOperationListLength is the MaxOperationListLength found in the Metadata of a block returned by the Tezos RPC API.

type StructMetadata

type StructMetadata struct {
	Protocol               string                         `json:"protocol"`
	NextProtocol           string                         `json:"next_protocol"`
	TestChainStatus        StructTestChainStatus          `json:"test_chain_status"`
	MaxOperationsTTL       int                            `json:"max_operations_ttl"`
	MaxOperationDataLength int                            `json:"max_operation_data_length"`
	MaxBlockHeaderLength   int                            `json:"max_block_header_length"`
	MaxOperationListLength []StructMaxOperationListLength `json:"max_operation_list_length"`
	Baker                  string                         `json:"baker"`
	Level                  StructLevel                    `json:"level"`
	VotingPeriodKind       string                         `json:"voting_period_kind"`
	NonceHash              interface{}                    `json:"nonce_hash"`
	ConsumedGas            string                         `json:"consumed_gas"`
	Deactivated            []string                       `json:"deactivated"`
	BalanceUpdates         []StructBalanceUpdates         `json:"balance_updates"`
}

StructMetadata is the Metadata in a block returned by the Tezos RPC API.

type StructOperationResult added in v1.0.9

type StructOperationResult struct {
	Status      string        `json:"status"`
	ConsumedGas string        `json:"consumed_gas, omitempty"`
	Errors      []StructError `json:"errors, omitempty"`
}

StructOperationResult is the OperationResult found in metadata of block returned by the Tezos RPC API.

type StructOperations

type StructOperations struct {
	Protocol  string           `json:"protocol"`
	ChainID   string           `json:"chain_id"`
	Hash      string           `json:"hash"`
	Branch    string           `json:"branch"`
	Contents  []StructContents `json:"contents"`
	Signature string           `json:"signature"`
}

StructOperations is the Operations found in a block returned by the Tezos RPC API.

type StructTestChainStatus

type StructTestChainStatus struct {
	Status string `json:"status"`
}

StructTestChainStatus is the TestChainStatus found in the Metadata of a block returned by the Tezos RPC API.

type Transfer

type Transfer struct {
	Conts
	Protocol  string `json:"protocol"`
	Signature string `json:"signature"`
}

Transfer a complete transfer request

type Wallet

type Wallet struct {
	Address  string
	Mnemonic string
	Seed     []byte
	Kp       keyPair
	Sk       string
	Pk       string
}

Wallet needed for signing operations

Jump to

Keyboard shortcuts

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