teztool

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 12 Imported by: 1

README

teztool

An operation injection helper

Example

package example

import (
    "context"
    "fmt"
    "math/big"

    "github.com/ecadlabs/gotez/v2"
    "github.com/ecadlabs/gotez/v2/b58"
    "github.com/ecadlabs/gotez/v2/client"
    "github.com/ecadlabs/gotez/v2/crypt"
    "github.com/ecadlabs/gotez/v2/protocol/core"
    "github.com/ecadlabs/gotez/v2/protocol/latest"
    "github.com/ecadlabs/gotez/v2/teztool"
)

type logger struct{}

func (logger) Printf(format string, a ...any) {
    fmt.Printf(format, a...)
    fmt.Printf("\n")
}

func TransferToWallet(url, chainID, address, privateKey string, amount *big.Int) (core.OperationsGroup, error) {
    chain, err := b58.ParseChainID([]byte(chainID))
    if err != nil {
        return nil, err
    }
    addr, err := b58.ParsePublicKeyHash([]byte(address))
    if err != nil {
        return nil, err
    }
    c := client.Client{
        URL: url,
    }
    pk, err := b58.ParsePrivateKey([]byte(privateKey))
    if err != nil {
        return nil, err
    }
    priv, err := crypt.NewPrivateKey(pk)
    if err != nil {
        return nil, err
    }

    // initialize tezool
    tool := teztool.New(&c, chain)
    tool.DebugLogger = logger{}

    // initialize signer
    signer := teztool.NewLocalSigner(priv)

    // make a transaction
    val, err := gotez.NewBigUint(amount)
    if err != nil {
        // amount is negative
        return nil, err
    }
    tx := latest.Transaction{
        ManagerOperation: latest.ManagerOperation{
            Source: priv.Public().Hash(),
        },
        Amount:      val,
        Destination: core.ImplicitContract{PublicKeyHash: addr},
    }

    return tool.FillSignAndInjectWait(context.Background(), signer, []latest.OperationContents{&tx}, client.MetadataAlways, teztool.FillAll)
}

Documentation

Overview

Package teztool is an operation injection helper

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FillAll

func FillAll(a *fillAttrs)

func FillCounter

func FillCounter(a *fillAttrs)

func FillFee

func FillFee(a *fillAttrs)

func FillGasLimit

func FillGasLimit(a *fillAttrs)

func FillStorageLimit

func FillStorageLimit(a *fillAttrs)

Types

type FillAttr

type FillAttr func(*fillAttrs)

type LocalSigner

type LocalSigner struct {
	crypt.PrivateKey
}

func NewLocalSigner

func NewLocalSigner(priv crypt.PrivateKey) LocalSigner

func (LocalSigner) Sign

func (s LocalSigner) Sign(_ context.Context, message []byte) (signature tz.Signature, err error)

type Signer

type Signer interface {
	Sign(context.Context, []byte) (signature tz.Signature, err error)
}

type Tool

type Tool struct {
	Client      *client.Client
	ChainID     *tz.ChainID
	DebugLogger client.Logger
}

func New

func New(client *client.Client, chain *tz.ChainID) *Tool

func (*Tool) Fill

func (t *Tool) Fill(ctx context.Context, group *latest.UnsignedOperation, attributes ...FillAttr) error

Fill fills requested missed fields like fee, counter, gas_limit, and storage_limit based on protocol constants, source contract state and the result of operation dry run

func (*Tool) FillSignAndInject

func (t *Tool) FillSignAndInject(ctx context.Context, signer Signer, ops []latest.OperationContents, attributes ...FillAttr) (*tz.OperationHash, error)

FillSignAndInject is an all in one function which fills missing fields and injects the operation without waiting

func (*Tool) FillSignAndInjectWait

func (t *Tool) FillSignAndInjectWait(ctx context.Context, signer Signer, ops []latest.OperationContents, meta client.MetadataMode, attributes ...FillAttr) (core.OperationsGroup, error)

FillSignAndInjectWait is an all in one function which fills missing fields, injects the operation and waits for it to appear on chain

func (*Tool) InjectAndWait

InjectAndWait injects the operation and waits for it to appear on chain

Jump to

Keyboard shortcuts

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